History

Btrfs: add ioctl to wait for qgroup rescan completion

btrfs_qgroup_wait_for_completion waits until the currently running qgroup operation completes. It returns immediately when no rescan process is in progress. This is useful to automate things around the rescan process (e.g. testing).

Jan Schmidt committed 13 years ago

Commit 57254b61 parent 1e8f9154 files · +36 −0Browse files

Unified · Split

4 files
  1. fs/btrfs/ctree.h +2 −0
  2. fs/btrfs/ioctl.c +12 −0
  3. fs/btrfs/qgroup.c +21 −0
  4. include/uapi/linux/btrfs.h +1 −0
fs/btrfs/ctree.h+2−0
@@ -1613,6 +1613,7 @@ struct btrfs_fs_info { · 1612 unmodified lines
16131613 struct mutex qgroup_rescan_lock; /* protects the progress item */
16141614 struct btrfs_key qgroup_rescan_progress;
16151615 struct btrfs_workers qgroup_rescan_workers;
1616+ struct completion qgroup_rescan_completion;
16161617
16171618 /* filesystem state */
16181619 unsigned long fs_state;
@@ -3820,6 +3821,7 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans, · 2201 unmodified lines
38203821 int btrfs_quota_disable(struct btrfs_trans_handle *trans,
38213822 struct btrfs_fs_info *fs_info);
38223823 int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info);
3824+int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info);
38233825 int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
38243826 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
38253827 int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
fs/btrfs/ioctl.c+12−0
@@ -3937,6 +3937,16 @@ static long btrfs_ioctl_quota_rescan_status(struct file *file, void __user *arg) · 3936 unmodified lines
39373937 return ret;
39383938 }
39393939
3940+static long btrfs_ioctl_quota_rescan_wait(struct file *file, void __user *arg)
3941+{
3942+ struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
3943+
3944+ if (!capable(CAP_SYS_ADMIN))
3945+ return -EPERM;
3946+
3947+ return btrfs_qgroup_wait_for_completion(root->fs_info);
3948+}
3949+
39403950 static long btrfs_ioctl_set_received_subvol(struct file *file,
39413951 void __user *arg)
39423952 {
@@ -4179,6 +4189,8 @@ long btrfs_ioctl(struct file *file, unsigned int · 236 unmodified lines
41794189 return btrfs_ioctl_quota_rescan(file, argp);
41804190 case BTRFS_IOC_QUOTA_RESCAN_STATUS:
41814191 return btrfs_ioctl_quota_rescan_status(file, argp);
4192+ case BTRFS_IOC_QUOTA_RESCAN_WAIT:
4193+ return btrfs_ioctl_quota_rescan_wait(file, argp);
41824194 case BTRFS_IOC_DEV_REPLACE:
41834195 return btrfs_ioctl_dev_replace(root, argp);
41844196 case BTRFS_IOC_GET_FSLABEL:
fs/btrfs/qgroup.c+21−0
@@ -2070,6 +2070,8 @@ out: · 2069 unmodified lines
20702070 } else {
20712071 pr_err("btrfs: qgroup scan failed with %d\n", err);
20722072 }
2073+
2074+ complete_all(&fs_info->qgroup_rescan_completion);
20732075 }
20742076
20752077 static void
@@ -2110,6 +2112,7 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info) · 34 unmodified lines
21102112 fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_RESCAN;
21112113 memset(&fs_info->qgroup_rescan_progress, 0,
21122114 sizeof(fs_info->qgroup_rescan_progress));
2115+ init_completion(&fs_info->qgroup_rescan_completion);
21132116
21142117 /* clear all current qgroup tracking information */
21152118 for (n = rb_first(&fs_info->qgroup_tree); n; n = rb_next(n)) {
@@ -2126,3 +2129,21 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info) · 10 unmodified lines
21262129
21272130 return 0;
21282131 }
2132+
2133+int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info)
2134+{
2135+ int running;
2136+ int ret = 0;
2137+
2138+ mutex_lock(&fs_info->qgroup_rescan_lock);
2139+ spin_lock(&fs_info->qgroup_lock);
2140+ running = fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN;
2141+ spin_unlock(&fs_info->qgroup_lock);
2142+ mutex_unlock(&fs_info->qgroup_rescan_lock);
2143+
2144+ if (running)
2145+ ret = wait_for_completion_interruptible(
2146+ &fs_info->qgroup_rescan_completion);
2147+
2148+ return ret;
2149+}
include/uapi/linux/btrfs.h+1−0
@@ -530,6 +530,7 @@ struct btrfs_ioctl_send_args { · 529 unmodified lines
530530 struct btrfs_ioctl_quota_rescan_args)
531531 #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
532532 struct btrfs_ioctl_quota_rescan_args)
533+#define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
533534 #define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
534535 char[BTRFS_LABEL_SIZE])
535536 #define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t