1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_IOCTL_H
3 #define _BCACHEFS_IOCTL_H
5 #include <linux/uuid.h>
7 #include "bcachefs_format.h"
10 * Flags common to multiple ioctls:
12 #define BCH_FORCE_IF_DATA_LOST (1 << 0)
13 #define BCH_FORCE_IF_METADATA_LOST (1 << 1)
14 #define BCH_FORCE_IF_DATA_DEGRADED (1 << 2)
15 #define BCH_FORCE_IF_METADATA_DEGRADED (1 << 3)
17 #define BCH_FORCE_IF_DEGRADED \
18 (BCH_FORCE_IF_DATA_DEGRADED| \
19 BCH_FORCE_IF_METADATA_DEGRADED)
22 * If cleared, ioctl that refer to a device pass it as a pointer to a pathname
23 * (e.g. /dev/sda1); if set, the dev field is the device's index within the
26 #define BCH_BY_INDEX (1 << 4)
29 * For BCH_IOCTL_READ_SUPER: get superblock of a specific device, not filesystem
32 #define BCH_READ_DEV (1 << 5)
34 /* global control dev: */
36 /* These are currently broken, and probably unnecessary: */
38 #define BCH_IOCTL_ASSEMBLE _IOW(0xbc, 1, struct bch_ioctl_assemble)
39 #define BCH_IOCTL_INCREMENTAL _IOW(0xbc, 2, struct bch_ioctl_incremental)
41 struct bch_ioctl_assemble {
48 struct bch_ioctl_incremental {
55 /* filesystem ioctls: */
57 #define BCH_IOCTL_QUERY_UUID _IOR(0xbc, 1, struct bch_ioctl_query_uuid)
59 /* These only make sense when we also have incremental assembly */
61 #define BCH_IOCTL_START _IOW(0xbc, 2, struct bch_ioctl_start)
62 #define BCH_IOCTL_STOP _IO(0xbc, 3)
65 #define BCH_IOCTL_DISK_ADD _IOW(0xbc, 4, struct bch_ioctl_disk)
66 #define BCH_IOCTL_DISK_REMOVE _IOW(0xbc, 5, struct bch_ioctl_disk)
67 #define BCH_IOCTL_DISK_ONLINE _IOW(0xbc, 6, struct bch_ioctl_disk)
68 #define BCH_IOCTL_DISK_OFFLINE _IOW(0xbc, 7, struct bch_ioctl_disk)
69 #define BCH_IOCTL_DISK_SET_STATE _IOW(0xbc, 8, struct bch_ioctl_disk_set_state)
70 #define BCH_IOCTL_DATA _IOW(0xbc, 10, struct bch_ioctl_data)
71 #define BCH_IOCTL_FS_USAGE _IOWR(0xbc, 11, struct bch_ioctl_fs_usage)
72 #define BCH_IOCTL_DEV_USAGE _IOWR(0xbc, 11, struct bch_ioctl_dev_usage)
73 #define BCH_IOCTL_READ_SUPER _IOW(0xbc, 12, struct bch_ioctl_read_super)
74 #define BCH_IOCTL_DISK_GET_IDX _IOW(0xbc, 13, struct bch_ioctl_disk_get_idx)
75 #define BCH_IOCTL_DISK_RESIZE _IOW(0xbc, 14, struct bch_ioctl_disk_resize)
76 #define BCH_IOCTL_DISK_RESIZE_JOURNAL _IOW(0xbc,15, struct bch_ioctl_disk_resize_journal)
78 /* ioctl below act on a particular file, not the filesystem as a whole: */
80 #define BCHFS_IOC_REINHERIT_ATTRS _IOR(0xbc, 64, const char __user *)
83 * BCH_IOCTL_QUERY_UUID: get filesystem UUID
85 * Returns user visible UUID, not internal UUID (which may not ever be changed);
86 * the filesystem's sysfs directory may be found under /sys/fs/bcachefs with
89 struct bch_ioctl_query_uuid {
94 struct bch_ioctl_start {
101 * BCH_IOCTL_DISK_ADD: add a new device to an existing filesystem
103 * The specified device must not be open or in use. On success, the new device
104 * will be an online member of the filesystem just like any other member.
106 * The device must first be prepared by userspace by formatting with a bcachefs
107 * superblock, which is only used for passing in superblock options/parameters
108 * for that device (in struct bch_member). The new device's superblock should
109 * not claim to be a member of any existing filesystem - UUIDs on it will be
114 * BCH_IOCTL_DISK_REMOVE: permanently remove a member device from a filesystem
116 * Any data present on @dev will be permanently deleted, and @dev will be
117 * removed from its slot in the filesystem's list of member devices. The device
118 * may be either offline or offline.
120 * Will fail removing @dev would leave us with insufficient read write devices
121 * or degraded/unavailable data, unless the approprate BCH_FORCE_IF_* flags are
126 * BCH_IOCTL_DISK_ONLINE: given a disk that is already a member of a filesystem
127 * but is not open (e.g. because we started in degraded mode), bring it online
129 * all existing data on @dev will be available once the device is online,
130 * exactly as if @dev was present when the filesystem was first mounted
134 * BCH_IOCTL_DISK_OFFLINE: offline a disk, causing the kernel to close that
135 * block device, without removing it from the filesystem (so it can be brought
138 * Data present on @dev will be unavailable while @dev is offline (unless
139 * replicated), but will still be intact and untouched if @dev is brought back
142 * Will fail (similarly to BCH_IOCTL_DISK_SET_STATE) if offlining @dev would
143 * leave us with insufficient read write devices or degraded/unavailable data,
144 * unless the approprate BCH_FORCE_IF_* flags are set.
147 struct bch_ioctl_disk {
154 * BCH_IOCTL_DISK_SET_STATE: modify state of a member device of a filesystem
156 * @new_state - one of the bch_member_state states (rw, ro, failed,
159 * Will refuse to change member state if we would then have insufficient devices
160 * to write to, or if it would result in degraded data (when @new_state is
161 * failed or spare) unless the appropriate BCH_FORCE_IF_* flags are set.
163 struct bch_ioctl_disk_set_state {
171 BCH_DATA_OP_SCRUB = 0,
172 BCH_DATA_OP_REREPLICATE = 1,
173 BCH_DATA_OP_MIGRATE = 2,
178 * BCH_IOCTL_DATA: operations that walk and manipulate filesystem data (e.g.
179 * scrub, rereplicate, migrate).
181 * This ioctl kicks off a job in the background, and returns a file descriptor.
182 * Reading from the file descriptor returns a struct bch_ioctl_data_event,
183 * indicating current progress, and closing the file descriptor will stop the
184 * job. The file descriptor is O_CLOEXEC.
186 struct bch_ioctl_data {
202 } __attribute__((packed, aligned(8)));
204 enum bch_data_event {
205 BCH_DATA_EVENT_PROGRESS = 0,
206 /* XXX: add an event for reporting errors */
207 BCH_DATA_EVENT_NR = 1,
210 struct bch_ioctl_data_progress {
218 } __attribute__((packed, aligned(8)));
220 struct bch_ioctl_data_event {
224 struct bch_ioctl_data_progress p;
227 } __attribute__((packed, aligned(8)));
229 struct bch_replicas_usage {
231 struct bch_replicas_entry r;
232 } __attribute__((packed));
234 static inline struct bch_replicas_usage *
235 replicas_usage_next(struct bch_replicas_usage *u)
237 return (void *) u + replicas_entry_bytes(&u->r) + 8;
241 * BCH_IOCTL_FS_USAGE: query filesystem disk space usage
243 * Returns disk space usage broken out by data type, number of replicas, and
244 * by component device
246 * @replica_entries_bytes - size, in bytes, allocated for replica usage entries
248 * On success, @replica_entries_bytes will be changed to indicate the number of
249 * bytes actually used.
251 * Returns -ERANGE if @replica_entries_bytes was too small
253 struct bch_ioctl_fs_usage {
256 __u64 online_reserved;
257 __u64 persistent_reserved[BCH_REPLICAS_MAX];
259 __u32 replica_entries_bytes;
262 struct bch_replicas_usage replicas[0];
266 * BCH_IOCTL_DEV_USAGE: query device disk space usage
268 * Returns disk space usage broken out by data type - both by buckets and
271 struct bch_ioctl_dev_usage {
279 __u64 available_buckets;
281 __u64 buckets[BCH_DATA_NR];
282 __u64 sectors[BCH_DATA_NR];
289 * BCH_IOCTL_READ_SUPER: read filesystem superblock
291 * Equivalent to reading the superblock directly from the block device, except
292 * avoids racing with the kernel writing the superblock or having to figure out
293 * which block device to read
295 * @sb - buffer to read into
296 * @size - size of userspace allocated buffer
297 * @dev - device to read superblock for, if BCH_READ_DEV flag is
300 * Returns -ERANGE if buffer provided is too small
302 struct bch_ioctl_read_super {
311 * BCH_IOCTL_DISK_GET_IDX: give a path to a block device, query filesystem to
312 * determine if disk is a (online) member - if so, returns device's index
314 * Returns -ENOENT if not found
316 struct bch_ioctl_disk_get_idx {
321 * BCH_IOCTL_DISK_RESIZE: resize filesystem on a device
323 * @dev - member to resize
324 * @nbuckets - new number of buckets
326 struct bch_ioctl_disk_resize {
334 * BCH_IOCTL_DISK_RESIZE_JOURNAL: resize journal on a device
336 * @dev - member to resize
337 * @nbuckets - new number of buckets
339 struct bch_ioctl_disk_resize_journal {
346 #endif /* _BCACHEFS_IOCTL_H */