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_LOST \
18 (BCH_FORCE_IF_DATA_LOST| \
19 BCH_FORCE_IF_METADATA_LOST)
20 #define BCH_FORCE_IF_DEGRADED \
21 (BCH_FORCE_IF_DATA_DEGRADED| \
22 BCH_FORCE_IF_METADATA_DEGRADED)
25 * If cleared, ioctl that refer to a device pass it as a pointer to a pathname
26 * (e.g. /dev/sda1); if set, the dev field is the device's index within the
29 #define BCH_BY_INDEX (1 << 4)
32 * For BCH_IOCTL_READ_SUPER: get superblock of a specific device, not filesystem
35 #define BCH_READ_DEV (1 << 5)
37 /* global control dev: */
39 /* These are currently broken, and probably unnecessary: */
41 #define BCH_IOCTL_ASSEMBLE _IOW(0xbc, 1, struct bch_ioctl_assemble)
42 #define BCH_IOCTL_INCREMENTAL _IOW(0xbc, 2, struct bch_ioctl_incremental)
44 struct bch_ioctl_assemble {
51 struct bch_ioctl_incremental {
58 /* filesystem ioctls: */
60 #define BCH_IOCTL_QUERY_UUID _IOR(0xbc, 1, struct bch_ioctl_query_uuid)
62 /* These only make sense when we also have incremental assembly */
64 #define BCH_IOCTL_START _IOW(0xbc, 2, struct bch_ioctl_start)
65 #define BCH_IOCTL_STOP _IO(0xbc, 3)
68 #define BCH_IOCTL_DISK_ADD _IOW(0xbc, 4, struct bch_ioctl_disk)
69 #define BCH_IOCTL_DISK_REMOVE _IOW(0xbc, 5, struct bch_ioctl_disk)
70 #define BCH_IOCTL_DISK_ONLINE _IOW(0xbc, 6, struct bch_ioctl_disk)
71 #define BCH_IOCTL_DISK_OFFLINE _IOW(0xbc, 7, struct bch_ioctl_disk)
72 #define BCH_IOCTL_DISK_SET_STATE _IOW(0xbc, 8, struct bch_ioctl_disk_set_state)
73 #define BCH_IOCTL_DATA _IOW(0xbc, 10, struct bch_ioctl_data)
74 #define BCH_IOCTL_FS_USAGE _IOWR(0xbc, 11, struct bch_ioctl_fs_usage)
75 #define BCH_IOCTL_DEV_USAGE _IOWR(0xbc, 11, struct bch_ioctl_dev_usage)
76 #define BCH_IOCTL_READ_SUPER _IOW(0xbc, 12, struct bch_ioctl_read_super)
77 #define BCH_IOCTL_DISK_GET_IDX _IOW(0xbc, 13, struct bch_ioctl_disk_get_idx)
78 #define BCH_IOCTL_DISK_RESIZE _IOW(0xbc, 14, struct bch_ioctl_disk_resize)
79 #define BCH_IOCTL_DISK_RESIZE_JOURNAL _IOW(0xbc,15, struct bch_ioctl_disk_resize_journal)
81 #define BCH_IOCTL_SUBVOLUME_CREATE _IOW(0xbc, 16, struct bch_ioctl_subvolume)
82 #define BCH_IOCTL_SUBVOLUME_DESTROY _IOW(0xbc, 17, struct bch_ioctl_subvolume)
84 /* ioctl below act on a particular file, not the filesystem as a whole: */
86 #define BCHFS_IOC_REINHERIT_ATTRS _IOR(0xbc, 64, const char __user *)
89 * BCH_IOCTL_QUERY_UUID: get filesystem UUID
91 * Returns user visible UUID, not internal UUID (which may not ever be changed);
92 * the filesystem's sysfs directory may be found under /sys/fs/bcachefs with
95 struct bch_ioctl_query_uuid {
100 struct bch_ioctl_start {
107 * BCH_IOCTL_DISK_ADD: add a new device to an existing filesystem
109 * The specified device must not be open or in use. On success, the new device
110 * will be an online member of the filesystem just like any other member.
112 * The device must first be prepared by userspace by formatting with a bcachefs
113 * superblock, which is only used for passing in superblock options/parameters
114 * for that device (in struct bch_member). The new device's superblock should
115 * not claim to be a member of any existing filesystem - UUIDs on it will be
120 * BCH_IOCTL_DISK_REMOVE: permanently remove a member device from a filesystem
122 * Any data present on @dev will be permanently deleted, and @dev will be
123 * removed from its slot in the filesystem's list of member devices. The device
124 * may be either offline or offline.
126 * Will fail removing @dev would leave us with insufficient read write devices
127 * or degraded/unavailable data, unless the approprate BCH_FORCE_IF_* flags are
132 * BCH_IOCTL_DISK_ONLINE: given a disk that is already a member of a filesystem
133 * but is not open (e.g. because we started in degraded mode), bring it online
135 * all existing data on @dev will be available once the device is online,
136 * exactly as if @dev was present when the filesystem was first mounted
140 * BCH_IOCTL_DISK_OFFLINE: offline a disk, causing the kernel to close that
141 * block device, without removing it from the filesystem (so it can be brought
144 * Data present on @dev will be unavailable while @dev is offline (unless
145 * replicated), but will still be intact and untouched if @dev is brought back
148 * Will fail (similarly to BCH_IOCTL_DISK_SET_STATE) if offlining @dev would
149 * leave us with insufficient read write devices or degraded/unavailable data,
150 * unless the approprate BCH_FORCE_IF_* flags are set.
153 struct bch_ioctl_disk {
160 * BCH_IOCTL_DISK_SET_STATE: modify state of a member device of a filesystem
162 * @new_state - one of the bch_member_state states (rw, ro, failed,
165 * Will refuse to change member state if we would then have insufficient devices
166 * to write to, or if it would result in degraded data (when @new_state is
167 * failed or spare) unless the appropriate BCH_FORCE_IF_* flags are set.
169 struct bch_ioctl_disk_set_state {
176 #define BCH_DATA_OPS() \
180 x(rewrite_old_nodes, 3) \
181 x(drop_extra_replicas, 4)
184 #define x(t, n) BCH_DATA_OP_##t = n,
191 * BCH_IOCTL_DATA: operations that walk and manipulate filesystem data (e.g.
192 * scrub, rereplicate, migrate).
194 * This ioctl kicks off a job in the background, and returns a file descriptor.
195 * Reading from the file descriptor returns a struct bch_ioctl_data_event,
196 * indicating current progress, and closing the file descriptor will stop the
197 * job. The file descriptor is O_CLOEXEC.
199 struct bch_ioctl_data {
205 struct bpos start_pos;
217 } __packed __aligned(8);
219 enum bch_data_event {
220 BCH_DATA_EVENT_PROGRESS = 0,
221 /* XXX: add an event for reporting errors */
222 BCH_DATA_EVENT_NR = 1,
225 struct bch_ioctl_data_progress {
233 } __packed __aligned(8);
235 struct bch_ioctl_data_event {
239 struct bch_ioctl_data_progress p;
242 } __packed __aligned(8);
244 struct bch_replicas_usage {
246 struct bch_replicas_entry_v1 r;
249 static inline struct bch_replicas_usage *
250 replicas_usage_next(struct bch_replicas_usage *u)
252 return (void *) u + replicas_entry_bytes(&u->r) + 8;
256 * BCH_IOCTL_FS_USAGE: query filesystem disk space usage
258 * Returns disk space usage broken out by data type, number of replicas, and
259 * by component device
261 * @replica_entries_bytes - size, in bytes, allocated for replica usage entries
263 * On success, @replica_entries_bytes will be changed to indicate the number of
264 * bytes actually used.
266 * Returns -ERANGE if @replica_entries_bytes was too small
268 struct bch_ioctl_fs_usage {
271 __u64 online_reserved;
272 __u64 persistent_reserved[BCH_REPLICAS_MAX];
274 __u32 replica_entries_bytes;
277 struct bch_replicas_usage replicas[0];
281 * BCH_IOCTL_DEV_USAGE: query device disk space usage
283 * Returns disk space usage broken out by data type - both by buckets and
286 struct bch_ioctl_dev_usage {
297 struct bch_ioctl_dev_usage_type {
305 * BCH_IOCTL_READ_SUPER: read filesystem superblock
307 * Equivalent to reading the superblock directly from the block device, except
308 * avoids racing with the kernel writing the superblock or having to figure out
309 * which block device to read
311 * @sb - buffer to read into
312 * @size - size of userspace allocated buffer
313 * @dev - device to read superblock for, if BCH_READ_DEV flag is
316 * Returns -ERANGE if buffer provided is too small
318 struct bch_ioctl_read_super {
327 * BCH_IOCTL_DISK_GET_IDX: give a path to a block device, query filesystem to
328 * determine if disk is a (online) member - if so, returns device's index
330 * Returns -ENOENT if not found
332 struct bch_ioctl_disk_get_idx {
337 * BCH_IOCTL_DISK_RESIZE: resize filesystem on a device
339 * @dev - member to resize
340 * @nbuckets - new number of buckets
342 struct bch_ioctl_disk_resize {
350 * BCH_IOCTL_DISK_RESIZE_JOURNAL: resize journal on a device
352 * @dev - member to resize
353 * @nbuckets - new number of buckets
355 struct bch_ioctl_disk_resize_journal {
362 struct bch_ioctl_subvolume {
371 #define BCH_SUBVOL_SNAPSHOT_CREATE (1U << 0)
372 #define BCH_SUBVOL_SNAPSHOT_RO (1U << 1)
374 #endif /* _BCACHEFS_IOCTL_H */