]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/bcachefs_ioctl.h
check if fs is mounted before running fsck
[bcachefs-tools-debian] / libbcachefs / bcachefs_ioctl.h
1 #ifndef _BCACHEFS_IOCTL_H
2 #define _BCACHEFS_IOCTL_H
3
4 #include <linux/uuid.h>
5 #include <asm/ioctl.h>
6 #include "bcachefs_format.h"
7
8 /*
9  * Flags common to multiple ioctls:
10  */
11 #define BCH_FORCE_IF_DATA_LOST          (1 << 0)
12 #define BCH_FORCE_IF_METADATA_LOST      (1 << 1)
13 #define BCH_FORCE_IF_DATA_DEGRADED      (1 << 2)
14 #define BCH_FORCE_IF_METADATA_DEGRADED  (1 << 3)
15
16 #define BCH_FORCE_IF_DEGRADED                   \
17         (BCH_FORCE_IF_DATA_DEGRADED|            \
18          BCH_FORCE_IF_METADATA_DEGRADED)
19
20 /*
21  * If cleared, ioctl that refer to a device pass it as a pointer to a pathname
22  * (e.g. /dev/sda1); if set, the dev field is the device's index within the
23  * filesystem:
24  */
25 #define BCH_BY_INDEX                    (1 << 4)
26
27 /*
28  * For BCH_IOCTL_READ_SUPER: get superblock of a specific device, not filesystem
29  * wide superblock:
30  */
31 #define BCH_READ_DEV                    (1 << 5)
32
33 /* global control dev: */
34
35 /* These are currently broken, and probably unnecessary: */
36 #if 0
37 #define BCH_IOCTL_ASSEMBLE      _IOW(0xbc, 1, struct bch_ioctl_assemble)
38 #define BCH_IOCTL_INCREMENTAL   _IOW(0xbc, 2, struct bch_ioctl_incremental)
39
40 struct bch_ioctl_assemble {
41         __u32                   flags;
42         __u32                   nr_devs;
43         __u64                   pad;
44         __u64                   devs[];
45 };
46
47 struct bch_ioctl_incremental {
48         __u32                   flags;
49         __u64                   pad;
50         __u64                   dev;
51 };
52 #endif
53
54 /* filesystem ioctls: */
55
56 #define BCH_IOCTL_QUERY_UUID    _IOR(0xbc,      1,  struct bch_ioctl_query_uuid)
57
58 /* These only make sense when we also have incremental assembly */
59 #if 0
60 #define BCH_IOCTL_START         _IOW(0xbc,      2,  struct bch_ioctl_start)
61 #define BCH_IOCTL_STOP          _IO(0xbc,       3)
62 #endif
63
64 #define BCH_IOCTL_DISK_ADD      _IOW(0xbc,      4,  struct bch_ioctl_disk)
65 #define BCH_IOCTL_DISK_REMOVE   _IOW(0xbc,      5,  struct bch_ioctl_disk)
66 #define BCH_IOCTL_DISK_ONLINE   _IOW(0xbc,      6,  struct bch_ioctl_disk)
67 #define BCH_IOCTL_DISK_OFFLINE  _IOW(0xbc,      7,  struct bch_ioctl_disk)
68 #define BCH_IOCTL_DISK_SET_STATE _IOW(0xbc,     8,  struct bch_ioctl_disk_set_state)
69 #define BCH_IOCTL_DATA          _IOW(0xbc,      10, struct bch_ioctl_data)
70 #define BCH_IOCTL_USAGE         _IOWR(0xbc,     11, struct bch_ioctl_usage)
71 #define BCH_IOCTL_READ_SUPER    _IOW(0xbc,      12, struct bch_ioctl_read_super)
72 #define BCH_IOCTL_DISK_GET_IDX  _IOW(0xbc,      13,  struct bch_ioctl_disk_get_idx)
73 #define BCH_IOCTL_DISK_RESIZE   _IOW(0xbc,      14,  struct bch_ioctl_disk_resize)
74
75 /* ioctl below act on a particular file, not the filesystem as a whole: */
76
77 #define BCHFS_IOC_REINHERIT_ATTRS       _IOR(0xbc, 64, const char __user *)
78
79 /*
80  * BCH_IOCTL_QUERY_UUID: get filesystem UUID
81  *
82  * Returns user visible UUID, not internal UUID (which may not ever be changed);
83  * the filesystem's sysfs directory may be found under /sys/fs/bcachefs with
84  * this UUID.
85  */
86 struct bch_ioctl_query_uuid {
87         uuid_le                 uuid;
88 };
89
90 #if 0
91 struct bch_ioctl_start {
92         __u32                   flags;
93         __u32                   pad;
94 };
95 #endif
96
97 /*
98  * BCH_IOCTL_DISK_ADD: add a new device to an existing filesystem
99  *
100  * The specified device must not be open or in use. On success, the new device
101  * will be an online member of the filesystem just like any other member.
102  *
103  * The device must first be prepared by userspace by formatting with a bcachefs
104  * superblock, which is only used for passing in superblock options/parameters
105  * for that device (in struct bch_member). The new device's superblock should
106  * not claim to be a member of any existing filesystem - UUIDs on it will be
107  * ignored.
108  */
109
110 /*
111  * BCH_IOCTL_DISK_REMOVE: permanently remove a member device from a filesystem
112  *
113  * Any data present on @dev will be permanently deleted, and @dev will be
114  * removed from its slot in the filesystem's list of member devices. The device
115  * may be either offline or offline.
116  *
117  * Will fail removing @dev would leave us with insufficient read write devices
118  * or degraded/unavailable data, unless the approprate BCH_FORCE_IF_* flags are
119  * set.
120  */
121
122 /*
123  * BCH_IOCTL_DISK_ONLINE: given a disk that is already a member of a filesystem
124  * but is not open (e.g. because we started in degraded mode), bring it online
125  *
126  * all existing data on @dev will be available once the device is online,
127  * exactly as if @dev was present when the filesystem was first mounted
128  */
129
130 /*
131  * BCH_IOCTL_DISK_OFFLINE: offline a disk, causing the kernel to close that
132  * block device, without removing it from the filesystem (so it can be brought
133  * back online later)
134  *
135  * Data present on @dev will be unavailable while @dev is offline (unless
136  * replicated), but will still be intact and untouched if @dev is brought back
137  * online
138  *
139  * Will fail (similarly to BCH_IOCTL_DISK_SET_STATE) if offlining @dev would
140  * leave us with insufficient read write devices or degraded/unavailable data,
141  * unless the approprate BCH_FORCE_IF_* flags are set.
142  */
143
144 struct bch_ioctl_disk {
145         __u32                   flags;
146         __u32                   pad;
147         __u64                   dev;
148 };
149
150 /*
151  * BCH_IOCTL_DISK_SET_STATE: modify state of a member device of a filesystem
152  *
153  * @new_state           - one of the bch_member_state states (rw, ro, failed,
154  *                        spare)
155  *
156  * Will refuse to change member state if we would then have insufficient devices
157  * to write to, or if it would result in degraded data (when @new_state is
158  * failed or spare) unless the appropriate BCH_FORCE_IF_* flags are set.
159  */
160 struct bch_ioctl_disk_set_state {
161         __u32                   flags;
162         __u8                    new_state;
163         __u8                    pad[3];
164         __u64                   dev;
165 };
166
167 enum bch_data_ops {
168         BCH_DATA_OP_SCRUB       = 0,
169         BCH_DATA_OP_REREPLICATE = 1,
170         BCH_DATA_OP_MIGRATE     = 2,
171         BCH_DATA_OP_NR          = 3,
172 };
173
174 /*
175  * BCH_IOCTL_DATA: operations that walk and manipulate filesystem data (e.g.
176  * scrub, rereplicate, migrate).
177  *
178  * This ioctl kicks off a job in the background, and returns a file descriptor.
179  * Reading from the file descriptor returns a struct bch_ioctl_data_event,
180  * indicating current progress, and closing the file descriptor will stop the
181  * job. The file descriptor is O_CLOEXEC.
182  */
183 struct bch_ioctl_data {
184         __u32                   op;
185         __u32                   flags;
186
187         struct bpos             start;
188         struct bpos             end;
189
190         union {
191         struct {
192                 __u32           dev;
193                 __u32           pad;
194         }                       migrate;
195         struct {
196                 __u64           pad[8];
197         };
198         };
199 } __attribute__((packed, aligned(8)));
200
201 enum bch_data_event {
202         BCH_DATA_EVENT_PROGRESS = 0,
203         /* XXX: add an event for reporting errors */
204         BCH_DATA_EVENT_NR       = 1,
205 };
206
207 struct bch_ioctl_data_progress {
208         __u8                    data_type;
209         __u8                    btree_id;
210         __u8                    pad[2];
211         struct bpos             pos;
212
213         __u64                   sectors_done;
214         __u64                   sectors_total;
215 } __attribute__((packed, aligned(8)));
216
217 struct bch_ioctl_data_event {
218         __u8                    type;
219         __u8                    pad[7];
220         union {
221         struct bch_ioctl_data_progress p;
222         __u64                   pad2[15];
223         };
224 } __attribute__((packed, aligned(8)));
225
226 struct bch_ioctl_dev_usage {
227         __u8                    state;
228         __u8                    alive;
229         __u8                    pad[6];
230         __u32                   dev;
231
232         __u32                   bucket_size;
233         __u64                   nr_buckets;
234
235         __u64                   buckets[BCH_DATA_NR];
236         __u64                   sectors[BCH_DATA_NR];
237 };
238
239 struct bch_ioctl_fs_usage {
240         __u64                   capacity;
241         __u64                   used;
242         __u64                   online_reserved;
243         __u64                   persistent_reserved[BCH_REPLICAS_MAX];
244         __u64                   sectors[BCH_DATA_NR][BCH_REPLICAS_MAX];
245 };
246
247 /*
248  * BCH_IOCTL_USAGE: query filesystem disk space usage
249  *
250  * Returns disk space usage broken out by data type, number of replicas, and
251  * by component device
252  *
253  * @nr_devices  - number of devices userspace allocated space for in @devs
254  *
255  * On success, @fs and @devs will be filled out appropriately and devs[i].alive
256  * will indicate if a device was present in that slot
257  *
258  * Returns -ERANGE if @nr_devices was too small
259  */
260 struct bch_ioctl_usage {
261         __u16                   nr_devices;
262         __u16                   pad[3];
263
264         struct bch_ioctl_fs_usage fs;
265         struct bch_ioctl_dev_usage devs[0];
266 };
267
268 /*
269  * BCH_IOCTL_READ_SUPER: read filesystem superblock
270  *
271  * Equivalent to reading the superblock directly from the block device, except
272  * avoids racing with the kernel writing the superblock or having to figure out
273  * which block device to read
274  *
275  * @sb          - buffer to read into
276  * @size        - size of userspace allocated buffer
277  * @dev         - device to read superblock for, if BCH_READ_DEV flag is
278  *                specified
279  *
280  * Returns -ERANGE if buffer provided is too small
281  */
282 struct bch_ioctl_read_super {
283         __u32                   flags;
284         __u32                   pad;
285         __u64                   dev;
286         __u64                   size;
287         __u64                   sb;
288 };
289
290 /*
291  * BCH_IOCTL_DISK_GET_IDX: give a path to a block device, query filesystem to
292  * determine if disk is a (online) member - if so, returns device's index
293  *
294  * Returns -ENOENT if not found
295  */
296 struct bch_ioctl_disk_get_idx {
297         __u64                   dev;
298 };
299
300 /*
301  * BCH_IOCTL_DISK_RESIZE: resize filesystem on a device
302  *
303  * @dev         - member to resize
304  * @nbuckets    - new number of buckets
305  */
306 struct bch_ioctl_disk_resize {
307         __u32                   flags;
308         __u32                   pad;
309         __u64                   dev;
310         __u64                   nbuckets;
311 };
312
313 #endif /* _BCACHEFS_IOCTL_H */