xref: /linux/drivers/md/md-bitmap.h (revision 6d8854216ebb60959ddb6f4ea4123bd449ba6cf6)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * bitmap.h: Copyright (C) Peter T. Breuer (ptb@ot.uc3m.es) 2003
4  *
5  * additions: Copyright (C) 2003-2004, Paul Clements, SteelEye Technology, Inc.
6  */
7 #ifndef BITMAP_H
8 #define BITMAP_H 1
9 
10 #define BITMAP_MAGIC 0x6d746962
11 
12 /* use these for bitmap->flags and bitmap->sb->state bit-fields */
13 enum bitmap_state {
14 	BITMAP_STALE	   = 1,  /* the bitmap file is out of date or had -EIO */
15 	BITMAP_WRITE_ERROR = 2, /* A write error has occurred */
16 	BITMAP_HOSTENDIAN  =15,
17 };
18 
19 /* the superblock at the front of the bitmap file -- little endian */
20 typedef struct bitmap_super_s {
21 	__le32 magic;        /*  0  BITMAP_MAGIC */
22 	__le32 version;      /*  4  the bitmap major for now, could change... */
23 	__u8  uuid[16];      /*  8  128 bit uuid - must match md device uuid */
24 	__le64 events;       /* 24  event counter for the bitmap (1)*/
25 	__le64 events_cleared;/*32  event counter when last bit cleared (2) */
26 	__le64 sync_size;    /* 40  the size of the md device's sync range(3) */
27 	__le32 state;        /* 48  bitmap state information */
28 	__le32 chunksize;    /* 52  the bitmap chunk size in bytes */
29 	__le32 daemon_sleep; /* 56  seconds between disk flushes */
30 	__le32 write_behind; /* 60  number of outstanding write-behind writes */
31 	__le32 sectors_reserved; /* 64 number of 512-byte sectors that are
32 				  * reserved for the bitmap. */
33 	__le32 nodes;        /* 68 the maximum number of nodes in cluster. */
34 	__u8 cluster_name[64]; /* 72 cluster name to which this md belongs */
35 	__u8  pad[256 - 136]; /* set to zero */
36 } bitmap_super_t;
37 
38 /* notes:
39  * (1) This event counter is updated before the eventcounter in the md superblock
40  *    When a bitmap is loaded, it is only accepted if this event counter is equal
41  *    to, or one greater than, the event counter in the superblock.
42  * (2) This event counter is updated when the other one is *if*and*only*if* the
43  *    array is not degraded.  As bits are not cleared when the array is degraded,
44  *    this represents the last time that any bits were cleared.
45  *    If a device is being added that has an event count with this value or
46  *    higher, it is accepted as conforming to the bitmap.
47  * (3)This is the number of sectors represented by the bitmap, and is the range that
48  *    resync happens across.  For raid1 and raid5/6 it is the size of individual
49  *    devices.  For raid10 it is the size of the array.
50  */
51 
52 struct md_bitmap_stats {
53 	u64		events_cleared;
54 	int		behind_writes;
55 	bool		behind_wait;
56 
57 	unsigned long	missing_pages;
58 	unsigned long	file_pages;
59 	unsigned long	sync_size;
60 	unsigned long	pages;
61 	struct file	*file;
62 };
63 
64 struct bitmap_operations {
65 	bool (*enabled)(struct mddev *mddev);
66 	int (*create)(struct mddev *mddev);
67 	int (*resize)(struct mddev *mddev, sector_t blocks, int chunksize,
68 		      bool init);
69 
70 	int (*load)(struct mddev *mddev);
71 	void (*destroy)(struct mddev *mddev);
72 	void (*flush)(struct mddev *mddev);
73 	void (*write_all)(struct mddev *mddev);
74 	void (*dirty_bits)(struct mddev *mddev, unsigned long s,
75 			   unsigned long e);
76 	void (*unplug)(struct mddev *mddev, bool sync);
77 	void (*daemon_work)(struct mddev *mddev);
78 
79 	void (*start_behind_write)(struct mddev *mddev);
80 	void (*end_behind_write)(struct mddev *mddev);
81 	void (*wait_behind_writes)(struct mddev *mddev);
82 
83 	void (*start_write)(struct mddev *mddev, sector_t offset,
84 			    unsigned long sectors);
85 	void (*end_write)(struct mddev *mddev, sector_t offset,
86 			  unsigned long sectors);
87 	bool (*start_sync)(struct mddev *mddev, sector_t offset,
88 			   sector_t *blocks, bool degraded);
89 	void (*end_sync)(struct mddev *mddev, sector_t offset, sector_t *blocks);
90 	void (*cond_end_sync)(struct mddev *mddev, sector_t sector, bool force);
91 	void (*close_sync)(struct mddev *mddev);
92 
93 	void (*update_sb)(void *data);
94 	int (*get_stats)(void *data, struct md_bitmap_stats *stats);
95 
96 	void (*sync_with_cluster)(struct mddev *mddev,
97 				  sector_t old_lo, sector_t old_hi,
98 				  sector_t new_lo, sector_t new_hi);
99 	void *(*get_from_slot)(struct mddev *mddev, int slot);
100 	int (*copy_from_slot)(struct mddev *mddev, int slot, sector_t *lo,
101 			      sector_t *hi, bool clear_bits);
102 	void (*set_pages)(void *data, unsigned long pages);
103 	void (*free)(void *data);
104 };
105 
106 /* the bitmap API */
107 void mddev_set_bitmap_ops(struct mddev *mddev);
108 
109 #endif
110