btrfs: sysfs: export currently running exclusive operation
authorGoldwyn Rodrigues <rgoldwyn@suse.com>
Tue, 25 Aug 2020 15:02:33 +0000 (10:02 -0500)
committerDavid Sterba <dsterba@suse.com>
Wed, 7 Oct 2020 10:12:20 +0000 (12:12 +0200)
/sys/fs/<fsid>/exclusive_operation contains the currently executing
exclusive operation. Add a sysfs_notify() when operation end, so
userspace can be notified of exclusive operation is finished.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c
fs/btrfs/sysfs.c

index f30231596fe0c118bec6f9752db6fb8dbd6ddc01..8091324341a536856c699c01b5558dee544f6f4e 100644 (file)
@@ -387,6 +387,7 @@ bool btrfs_exclop_start(struct btrfs_fs_info *fs_info,
 void btrfs_exclop_finish(struct btrfs_fs_info *fs_info)
 {
        WRITE_ONCE(fs_info->exclusive_operation, BTRFS_EXCLOP_NONE);
+       sysfs_notify(&fs_info->fs_devices->fsid_kobj, NULL, "exclusive_operation");
 }
 
 /*
index 438a367371c4360b21ad1b64d9dba1905cfa39c9..eb8f23578c16fc85e78b5763730de124b6e30968 100644 (file)
@@ -809,6 +809,42 @@ static ssize_t btrfs_checksum_show(struct kobject *kobj,
 
 BTRFS_ATTR(, checksum, btrfs_checksum_show);
 
+static ssize_t btrfs_exclusive_operation_show(struct kobject *kobj,
+               struct kobj_attribute *a, char *buf)
+{
+       struct btrfs_fs_info *fs_info = to_fs_info(kobj);
+       const char *str;
+
+       switch (READ_ONCE(fs_info->exclusive_operation)) {
+               case  BTRFS_EXCLOP_NONE:
+                       str = "none\n";
+                       break;
+               case BTRFS_EXCLOP_BALANCE:
+                       str = "balance\n";
+                       break;
+               case BTRFS_EXCLOP_DEV_ADD:
+                       str = "device add\n";
+                       break;
+               case BTRFS_EXCLOP_DEV_REMOVE:
+                       str = "device remove\n";
+                       break;
+               case BTRFS_EXCLOP_DEV_REPLACE:
+                       str = "device replace\n";
+                       break;
+               case BTRFS_EXCLOP_RESIZE:
+                       str = "resize\n";
+                       break;
+               case BTRFS_EXCLOP_SWAP_ACTIVATE:
+                       str = "swap activate\n";
+                       break;
+               default:
+                       str = "UNKNOWN\n";
+                       break;
+       }
+       return scnprintf(buf, PAGE_SIZE, "%s", str);
+}
+BTRFS_ATTR(, exclusive_operation, btrfs_exclusive_operation_show);
+
 static const struct attribute *btrfs_attrs[] = {
        BTRFS_ATTR_PTR(, label),
        BTRFS_ATTR_PTR(, nodesize),
@@ -817,6 +853,7 @@ static const struct attribute *btrfs_attrs[] = {
        BTRFS_ATTR_PTR(, quota_override),
        BTRFS_ATTR_PTR(, metadata_uuid),
        BTRFS_ATTR_PTR(, checksum),
+       BTRFS_ATTR_PTR(, exclusive_operation),
        NULL,
 };