brintos

brintos / linux-shallow public Read only

0
0
Text · 11.5 KiB · 3c23bdf Raw
447 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2#ifndef _BCACHEFS_IOCTL_H3#define _BCACHEFS_IOCTL_H4 5#include <linux/uuid.h>6#include <asm/ioctl.h>7#include "bcachefs_format.h"8#include "bkey_types.h"9 10/*11 * Flags common to multiple ioctls:12 */13#define BCH_FORCE_IF_DATA_LOST		(1 << 0)14#define BCH_FORCE_IF_METADATA_LOST	(1 << 1)15#define BCH_FORCE_IF_DATA_DEGRADED	(1 << 2)16#define BCH_FORCE_IF_METADATA_DEGRADED	(1 << 3)17 18#define BCH_FORCE_IF_LOST			\19	(BCH_FORCE_IF_DATA_LOST|		\20	 BCH_FORCE_IF_METADATA_LOST)21#define BCH_FORCE_IF_DEGRADED			\22	(BCH_FORCE_IF_DATA_DEGRADED|		\23	 BCH_FORCE_IF_METADATA_DEGRADED)24 25/*26 * If cleared, ioctl that refer to a device pass it as a pointer to a pathname27 * (e.g. /dev/sda1); if set, the dev field is the device's index within the28 * filesystem:29 */30#define BCH_BY_INDEX			(1 << 4)31 32/*33 * For BCH_IOCTL_READ_SUPER: get superblock of a specific device, not filesystem34 * wide superblock:35 */36#define BCH_READ_DEV			(1 << 5)37 38/* global control dev: */39 40/* These are currently broken, and probably unnecessary: */41#if 042#define BCH_IOCTL_ASSEMBLE	_IOW(0xbc, 1, struct bch_ioctl_assemble)43#define BCH_IOCTL_INCREMENTAL	_IOW(0xbc, 2, struct bch_ioctl_incremental)44 45struct bch_ioctl_assemble {46	__u32			flags;47	__u32			nr_devs;48	__u64			pad;49	__u64			devs[];50};51 52struct bch_ioctl_incremental {53	__u32			flags;54	__u64			pad;55	__u64			dev;56};57#endif58 59/* filesystem ioctls: */60 61#define BCH_IOCTL_QUERY_UUID	_IOR(0xbc,	1,  struct bch_ioctl_query_uuid)62 63/* These only make sense when we also have incremental assembly */64#if 065#define BCH_IOCTL_START		_IOW(0xbc,	2,  struct bch_ioctl_start)66#define BCH_IOCTL_STOP		_IO(0xbc,	3)67#endif68 69#define BCH_IOCTL_DISK_ADD	_IOW(0xbc,	4,  struct bch_ioctl_disk)70#define BCH_IOCTL_DISK_REMOVE	_IOW(0xbc,	5,  struct bch_ioctl_disk)71#define BCH_IOCTL_DISK_ONLINE	_IOW(0xbc,	6,  struct bch_ioctl_disk)72#define BCH_IOCTL_DISK_OFFLINE	_IOW(0xbc,	7,  struct bch_ioctl_disk)73#define BCH_IOCTL_DISK_SET_STATE _IOW(0xbc,	8,  struct bch_ioctl_disk_set_state)74#define BCH_IOCTL_DATA		_IOW(0xbc,	10, struct bch_ioctl_data)75#define BCH_IOCTL_FS_USAGE	_IOWR(0xbc,	11, struct bch_ioctl_fs_usage)76#define BCH_IOCTL_DEV_USAGE	_IOWR(0xbc,	11, struct bch_ioctl_dev_usage)77#define BCH_IOCTL_READ_SUPER	_IOW(0xbc,	12, struct bch_ioctl_read_super)78#define BCH_IOCTL_DISK_GET_IDX	_IOW(0xbc,	13,  struct bch_ioctl_disk_get_idx)79#define BCH_IOCTL_DISK_RESIZE	_IOW(0xbc,	14,  struct bch_ioctl_disk_resize)80#define BCH_IOCTL_DISK_RESIZE_JOURNAL _IOW(0xbc,15,  struct bch_ioctl_disk_resize_journal)81 82#define BCH_IOCTL_SUBVOLUME_CREATE _IOW(0xbc,	16,  struct bch_ioctl_subvolume)83#define BCH_IOCTL_SUBVOLUME_DESTROY _IOW(0xbc,	17,  struct bch_ioctl_subvolume)84 85#define BCH_IOCTL_DEV_USAGE_V2	_IOWR(0xbc,	18, struct bch_ioctl_dev_usage_v2)86 87#define BCH_IOCTL_FSCK_OFFLINE	_IOW(0xbc,	19,  struct bch_ioctl_fsck_offline)88#define BCH_IOCTL_FSCK_ONLINE	_IOW(0xbc,	20,  struct bch_ioctl_fsck_online)89#define BCH_IOCTL_QUERY_ACCOUNTING _IOW(0xbc,	21,  struct bch_ioctl_query_accounting)90 91/* ioctl below act on a particular file, not the filesystem as a whole: */92 93#define BCHFS_IOC_REINHERIT_ATTRS	_IOR(0xbc, 64, const char __user *)94 95/*96 * BCH_IOCTL_QUERY_UUID: get filesystem UUID97 *98 * Returns user visible UUID, not internal UUID (which may not ever be changed);99 * the filesystem's sysfs directory may be found under /sys/fs/bcachefs with100 * this UUID.101 */102struct bch_ioctl_query_uuid {103	__uuid_t		uuid;104};105 106#if 0107struct bch_ioctl_start {108	__u32			flags;109	__u32			pad;110};111#endif112 113/*114 * BCH_IOCTL_DISK_ADD: add a new device to an existing filesystem115 *116 * The specified device must not be open or in use. On success, the new device117 * will be an online member of the filesystem just like any other member.118 *119 * The device must first be prepared by userspace by formatting with a bcachefs120 * superblock, which is only used for passing in superblock options/parameters121 * for that device (in struct bch_member). The new device's superblock should122 * not claim to be a member of any existing filesystem - UUIDs on it will be123 * ignored.124 */125 126/*127 * BCH_IOCTL_DISK_REMOVE: permanently remove a member device from a filesystem128 *129 * Any data present on @dev will be permanently deleted, and @dev will be130 * removed from its slot in the filesystem's list of member devices. The device131 * may be either offline or offline.132 *133 * Will fail removing @dev would leave us with insufficient read write devices134 * or degraded/unavailable data, unless the approprate BCH_FORCE_IF_* flags are135 * set.136 */137 138/*139 * BCH_IOCTL_DISK_ONLINE: given a disk that is already a member of a filesystem140 * but is not open (e.g. because we started in degraded mode), bring it online141 *142 * all existing data on @dev will be available once the device is online,143 * exactly as if @dev was present when the filesystem was first mounted144 */145 146/*147 * BCH_IOCTL_DISK_OFFLINE: offline a disk, causing the kernel to close that148 * block device, without removing it from the filesystem (so it can be brought149 * back online later)150 *151 * Data present on @dev will be unavailable while @dev is offline (unless152 * replicated), but will still be intact and untouched if @dev is brought back153 * online154 *155 * Will fail (similarly to BCH_IOCTL_DISK_SET_STATE) if offlining @dev would156 * leave us with insufficient read write devices or degraded/unavailable data,157 * unless the approprate BCH_FORCE_IF_* flags are set.158 */159 160struct bch_ioctl_disk {161	__u32			flags;162	__u32			pad;163	__u64			dev;164};165 166/*167 * BCH_IOCTL_DISK_SET_STATE: modify state of a member device of a filesystem168 *169 * @new_state		- one of the bch_member_state states (rw, ro, failed,170 *			  spare)171 *172 * Will refuse to change member state if we would then have insufficient devices173 * to write to, or if it would result in degraded data (when @new_state is174 * failed or spare) unless the appropriate BCH_FORCE_IF_* flags are set.175 */176struct bch_ioctl_disk_set_state {177	__u32			flags;178	__u8			new_state;179	__u8			pad[3];180	__u64			dev;181};182 183#define BCH_DATA_OPS()			\184	x(scrub,		0)	\185	x(rereplicate,		1)	\186	x(migrate,		2)	\187	x(rewrite_old_nodes,	3)	\188	x(drop_extra_replicas,	4)189 190enum bch_data_ops {191#define x(t, n) BCH_DATA_OP_##t = n,192	BCH_DATA_OPS()193#undef x194	BCH_DATA_OP_NR195};196 197/*198 * BCH_IOCTL_DATA: operations that walk and manipulate filesystem data (e.g.199 * scrub, rereplicate, migrate).200 *201 * This ioctl kicks off a job in the background, and returns a file descriptor.202 * Reading from the file descriptor returns a struct bch_ioctl_data_event,203 * indicating current progress, and closing the file descriptor will stop the204 * job. The file descriptor is O_CLOEXEC.205 */206struct bch_ioctl_data {207	__u16			op;208	__u8			start_btree;209	__u8			end_btree;210	__u32			flags;211 212	struct bpos		start_pos;213	struct bpos		end_pos;214 215	union {216	struct {217		__u32		dev;218		__u32		pad;219	}			migrate;220	struct {221		__u64		pad[8];222	};223	};224} __packed __aligned(8);225 226enum bch_data_event {227	BCH_DATA_EVENT_PROGRESS	= 0,228	/* XXX: add an event for reporting errors */229	BCH_DATA_EVENT_NR	= 1,230};231 232struct bch_ioctl_data_progress {233	__u8			data_type;234	__u8			btree_id;235	__u8			pad[2];236	struct bpos		pos;237 238	__u64			sectors_done;239	__u64			sectors_total;240} __packed __aligned(8);241 242struct bch_ioctl_data_event {243	__u8			type;244	__u8			pad[7];245	union {246	struct bch_ioctl_data_progress p;247	__u64			pad2[15];248	};249} __packed __aligned(8);250 251struct bch_replicas_usage {252	__u64			sectors;253	struct bch_replicas_entry_v1 r;254} __packed;255 256static inline unsigned replicas_usage_bytes(struct bch_replicas_usage *u)257{258	return offsetof(struct bch_replicas_usage, r) + replicas_entry_bytes(&u->r);259}260 261static inline struct bch_replicas_usage *262replicas_usage_next(struct bch_replicas_usage *u)263{264	return (void *) u + replicas_usage_bytes(u);265}266 267/* Obsolete */268/*269 * BCH_IOCTL_FS_USAGE: query filesystem disk space usage270 *271 * Returns disk space usage broken out by data type, number of replicas, and272 * by component device273 *274 * @replica_entries_bytes - size, in bytes, allocated for replica usage entries275 *276 * On success, @replica_entries_bytes will be changed to indicate the number of277 * bytes actually used.278 *279 * Returns -ERANGE if @replica_entries_bytes was too small280 */281struct bch_ioctl_fs_usage {282	__u64			capacity;283	__u64			used;284	__u64			online_reserved;285	__u64			persistent_reserved[BCH_REPLICAS_MAX];286 287	__u32			replica_entries_bytes;288	__u32			pad;289 290	struct bch_replicas_usage replicas[];291};292 293/* Obsolete */294/*295 * BCH_IOCTL_DEV_USAGE: query device disk space usage296 *297 * Returns disk space usage broken out by data type - both by buckets and298 * sectors.299 */300struct bch_ioctl_dev_usage {301	__u64			dev;302	__u32			flags;303	__u8			state;304	__u8			pad[7];305 306	__u32			bucket_size;307	__u64			nr_buckets;308 309	__u64			buckets_ec;310 311	struct bch_ioctl_dev_usage_type {312		__u64		buckets;313		__u64		sectors;314		__u64		fragmented;315	}			d[10];316};317 318/* Obsolete */319struct bch_ioctl_dev_usage_v2 {320	__u64			dev;321	__u32			flags;322	__u8			state;323	__u8			nr_data_types;324	__u8			pad[6];325 326	__u32			bucket_size;327	__u64			nr_buckets;328 329	struct bch_ioctl_dev_usage_type d[];330};331 332/*333 * BCH_IOCTL_READ_SUPER: read filesystem superblock334 *335 * Equivalent to reading the superblock directly from the block device, except336 * avoids racing with the kernel writing the superblock or having to figure out337 * which block device to read338 *339 * @sb		- buffer to read into340 * @size	- size of userspace allocated buffer341 * @dev		- device to read superblock for, if BCH_READ_DEV flag is342 *		  specified343 *344 * Returns -ERANGE if buffer provided is too small345 */346struct bch_ioctl_read_super {347	__u32			flags;348	__u32			pad;349	__u64			dev;350	__u64			size;351	__u64			sb;352};353 354/*355 * BCH_IOCTL_DISK_GET_IDX: give a path to a block device, query filesystem to356 * determine if disk is a (online) member - if so, returns device's index357 *358 * Returns -ENOENT if not found359 */360struct bch_ioctl_disk_get_idx {361	__u64			dev;362};363 364/*365 * BCH_IOCTL_DISK_RESIZE: resize filesystem on a device366 *367 * @dev		- member to resize368 * @nbuckets	- new number of buckets369 */370struct bch_ioctl_disk_resize {371	__u32			flags;372	__u32			pad;373	__u64			dev;374	__u64			nbuckets;375};376 377/*378 * BCH_IOCTL_DISK_RESIZE_JOURNAL: resize journal on a device379 *380 * @dev		- member to resize381 * @nbuckets	- new number of buckets382 */383struct bch_ioctl_disk_resize_journal {384	__u32			flags;385	__u32			pad;386	__u64			dev;387	__u64			nbuckets;388};389 390struct bch_ioctl_subvolume {391	__u32			flags;392	__u32			dirfd;393	__u16			mode;394	__u16			pad[3];395	__u64			dst_ptr;396	__u64			src_ptr;397};398 399#define BCH_SUBVOL_SNAPSHOT_CREATE	(1U << 0)400#define BCH_SUBVOL_SNAPSHOT_RO		(1U << 1)401 402/*403 * BCH_IOCTL_FSCK_OFFLINE: run fsck from the 'bcachefs fsck' userspace command,404 * but with the kernel's implementation of fsck:405 */406struct bch_ioctl_fsck_offline {407	__u64			flags;408	__u64			opts;		/* string */409	__u64			nr_devs;410	__u64			devs[] __counted_by(nr_devs);411};412 413/*414 * BCH_IOCTL_FSCK_ONLINE: run fsck from the 'bcachefs fsck' userspace command,415 * but with the kernel's implementation of fsck:416 */417struct bch_ioctl_fsck_online {418	__u64			flags;419	__u64			opts;		/* string */420};421 422/*423 * BCH_IOCTL_QUERY_ACCOUNTING: query filesystem disk accounting424 *425 * Returns disk space usage broken out by data type, number of replicas, and426 * by component device427 *428 * @replica_entries_bytes - size, in bytes, allocated for replica usage entries429 *430 * On success, @replica_entries_bytes will be changed to indicate the number of431 * bytes actually used.432 *433 * Returns -ERANGE if @replica_entries_bytes was too small434 */435struct bch_ioctl_query_accounting {436	__u64			capacity;437	__u64			used;438	__u64			online_reserved;439 440	__u32			accounting_u64s; /* input parameter */441	__u32			accounting_types_mask; /* input parameter */442 443	struct bkey_i_accounting accounting[];444};445 446#endif /* _BCACHEFS_IOCTL_H */447