History

btrfs: add new ioctl to wait for cleaned subvolumes

Add a new unprivileged ioctl that will let the command 'btrfs subvolume sync' work without the (privileged) SEARCH_TREE ioctl. There are several modes of operation, where the most common ones are to wait on a specific subvolume or all currently queued for cleaning. This is utilized e.g. in backup applications that delete subvolumes and wait until they're cleaned to check for remaining space. The other modes are for flexibility, e.g. for monitoring or checkpoints in the queue of deleted subvolumes, again without the need to use SEARCH_TREE. Notes: - waiting is interruptible, the timeout is set to 1 second and is not configurable - repeated calls to the ioctl see a different state, so this is inherently racy when using e.g. the count or peek next/last Use cases: - a subvolume A was deleted, wait for cleaning (WAIT_FOR_ONE) - a bunch of subvolumes were deleted, wait for all (WAIT_FOR_QUEUED or PEEK_LAST + WAIT_FOR_ONE) - count how many are queued (not blocking), for monitoring purposes - report progress (PEEK_NEXT), may miss some if cleaning is quick - own waiting in user space (PEEK_LAST until it's 0)

David Sterba committed 2 years ago

Commit 6c83d151 parent 5599f392 files · +153 −0Browse files

Showing the changes to include/uapi (1 of 2 files). Show all

Unified · Split

include/uapi/linux/btrfs.h+25−0
@@ -1049,6 +1049,29 @@ struct btrfs_ioctl_encoded_io_args { · 1048 unmodified lines
10491049 #define BTRFS_ENCODED_IO_ENCRYPTION_NONE 0
10501050 #define BTRFS_ENCODED_IO_ENCRYPTION_TYPES 1
10511051
1052+/*
1053+ * Wait for subvolume cleaning process. This queries the kernel queue and it
1054+ * can change between the calls.
1055+ *
1056+ * - FOR_ONE - specify the subvolid
1057+ * - FOR_QUEUED - wait for all currently queued
1058+ * - COUNT - count number of queued
1059+ * - PEEK_FIRST - read which is the first in the queue (to be cleaned or being
1060+ * cleaned already), or 0 if the queue is empty
1061+ * - PEEK_LAST - read the last subvolid in the queue, or 0 if the queue is empty
1062+ */
1063+struct btrfs_ioctl_subvol_wait {
1064+ __u64 subvolid;
1065+ __u32 mode;
1066+ __u32 count;
1067+};
1068+
1069+#define BTRFS_SUBVOL_SYNC_WAIT_FOR_ONE (0)
1070+#define BTRFS_SUBVOL_SYNC_WAIT_FOR_QUEUED (1)
1071+#define BTRFS_SUBVOL_SYNC_COUNT (2)
1072+#define BTRFS_SUBVOL_SYNC_PEEK_FIRST (3)
1073+#define BTRFS_SUBVOL_SYNC_PEEK_LAST (4)
1074+
10521075 /* Error codes as returned by the kernel */
10531076 enum btrfs_err_code {
10541077 BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
@@ -1181,6 +1204,8 @@ enum btrfs_err_code { · 126 unmodified lines
11811204 struct btrfs_ioctl_encoded_io_args)
11821205 #define BTRFS_IOC_ENCODED_WRITE _IOW(BTRFS_IOCTL_MAGIC, 64, \
11831206 struct btrfs_ioctl_encoded_io_args)
1207+#define BTRFS_IOC_SUBVOL_SYNC_WAIT _IOW(BTRFS_IOCTL_MAGIC, 65, \
1208+ struct btrfs_ioctl_subvol_wait)
11841209
11851210 #ifdef __cplusplus
11861211 }