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