All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v5 3/3] btrfs: add feature to deregister all unmounted devices
Date: Thu,  7 Dec 2017 22:36:23 +0800	[thread overview]
Message-ID: <20171207143623.26710-4-anand.jain@oracle.com> (raw)
In-Reply-To: <20171207143623.26710-1-anand.jain@oracle.com>

This adds a feature to remove all registered/scanned devices,
which are not mounted or it got staled by some means.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Suggested-by: David Sterba <dsterba@suse.cz>
---
v2-4: Does not exist.

 fs/btrfs/super.c           |  7 ++++++-
 fs/btrfs/volumes.c         | 23 +++++++++++++++++++++++
 fs/btrfs/volumes.h         |  1 +
 include/uapi/linux/btrfs.h |  6 +++++-
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index ea6fe4742834..409804843b74 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -2213,7 +2213,12 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
 					    &btrfs_fs_type, &fs_devices);
 		break;
 	case BTRFS_IOC_PURGE_DEV:
-		ret = btrfs_purge_one_device(vol->name, FMODE_READ,
+		if (vol->ioctl_flag & ~BTRFS_IOCTL_PURGE_ALL_DEVS)
+			return -EOPNOTSUPP;
+		if (vol->ioctl_flag & BTRFS_IOCTL_PURGE_ALL_DEVS)
+			ret = btrfs_purge_devices();
+		else
+			ret = btrfs_purge_one_device(vol->name, FMODE_READ,
 					    &btrfs_fs_type, &fs_devices);
 		break;
 	case BTRFS_IOC_DEVICES_READY:
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 5adab70c7658..9fa2539a8493 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1336,6 +1336,29 @@ int btrfs_purge_one_device(const char *path, fmode_t flags, void *holder,
 	return ret;
 }
 
+int btrfs_purge_devices(void)
+{
+	struct btrfs_fs_devices *fs_devices, *tmp;
+
+	mutex_lock(&uuid_mutex);
+	list_for_each_entry_safe(fs_devices, tmp, &fs_uuids, list) {
+		/*
+		 * For now ignore stale device within a mounted FS.
+		 */
+		if (fs_devices->opened)
+			continue;
+
+		pr_info("BTRFS: %pU num_devices %llu deregistered",
+			fs_devices->fsid, fs_devices->num_devices);
+		btrfs_sysfs_remove_fsid(fs_devices);
+		list_del(&fs_devices->list);
+		free_fs_devices(fs_devices);
+	}
+	mutex_unlock(&uuid_mutex);
+
+	return 0;
+}
+
 /*
  * Look for a btrfs signature on a device. This may be called out of the mount path
  * and we are not allowed to call set_blocksize during the scan. The superblock
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 8389d2815750..dec27ee4f67d 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -424,6 +424,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
 			  struct btrfs_fs_devices **fs_devices_ret);
 int btrfs_purge_one_device(const char *path, fmode_t flags, void *holder,
 			  struct btrfs_fs_devices **fs_devices_ret);
+int btrfs_purge_devices(void);
 int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
 void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step);
 void btrfs_assign_next_active_device(struct btrfs_fs_info *fs_info,
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index de0f1144d945..eaf6ef04b300 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -28,8 +28,12 @@
 
 /* this should be 4k */
 #define BTRFS_PATH_NAME_MAX 4087
+#define BTRFS_IOCTL_PURGE_ALL_DEVS	(1ULL << 0)
 struct btrfs_ioctl_vol_args {
-	__s64 fd;
+	union {
+		__s64 fd;
+		__u64 ioctl_flag;
+	};
 	char name[BTRFS_PATH_NAME_MAX + 1];
 };
 
-- 
2.7.0


  parent reply	other threads:[~2017-12-07 14:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-07 14:36 [PATCH v5 0/3] Add cli and ioctl to deregister devices Anand Jain
2017-12-07 14:36 ` [PATCH v5 1/3] btrfs: add function to device list delete Anand Jain
2017-12-07 14:36 ` [PATCH v5 2/3] btrfs: introduce feature to deregister a btrfs device Anand Jain
2017-12-07 14:36 ` Anand Jain [this message]
2017-12-07 14:52 ` [PATCH v5 0/3] Add cli and ioctl to deregister devices Austin S. Hemmelgarn
2017-12-08  0:51   ` Anand Jain
2017-12-08  2:17     ` Duncan
2017-12-08 13:09       ` Austin S. Hemmelgarn
2017-12-12  7:37         ` Anand Jain
2017-12-07 14:52 ` [PATCH v5 1/2] btrfs-progs: add cli to deregister a device Anand Jain
2017-12-07 14:52   ` [PATCH v5 2/2] btrfs-progs: add feature to deregister all devices Anand Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171207143623.26710-4-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.