linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/23] btrfs device related patch set
@ 2015-08-14 10:32 Anand Jain
  2015-08-14 10:32 ` [PATCH 01/23] Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted Anand Jain
                   ` (23 more replies)
  0 siblings, 24 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

This patch set includes patches which has been sent before
independently, however here they are consolidated on the
current integration 4.3.

Most of them are cleanup and preparatory work for the RFE
which are published before, viz.. addition of sys volume attributes
and introduce a method to offline device.

And except for the patch
 Btrfs: device delete by devid
provides a way to delete device using devid (assume that devid
has failed) thus fixes the issue reported by the user in the
community.

and the patch
 Btrfs: allow -o rw,degraded for single group profile
fixes an important btrfs volume availability issue


Anand Jain (22):
  Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted
  Btrfs: rename btrfs_sysfs_remove_one to btrfs_sysfs_remove_mounted
  Btrfs: rename btrfs_kobj_add_device to btrfs_sysfs_add_device_link
  Btrfs: rename btrfs_kobj_rm_device to btrfs_sysfs_rm_device_link
  Btrfs: rename super_kobj to fsid_kobj
  Btrfs: SB read failure should return EIO for __bread failure
  Btrfs: __btrfs_std_error() logic should be consistent w/out
    CONFIG_PRINTK defined
  Btrfs: device delete by devid
  Btrfs: move check for min number of devices to a function
  Btrfs: rename btrfs_dev_replace_find_srcdev()
  Btrfs: use BTRFS_ERROR_DEV_MISSING_NOT_FOUND when missing device is
    not found
  Btrfs: use btrfs_find_device_by_user_input()
  Btrfs: add btrfs_read_dev_one_super() to read one specific SB
  Btrfs: fix btrfs_scratch_superblock() with fixes from device delete
  Btrfs: use btrfs_scratch_superblock() in btrfs_rm_device()
  Btrfs: device path change must be logged
  Btrfs: kernel operation should come after user input has been verified
  Btrfs: check device_path in btrfs_find_device_by_user_input()
  Btrfs: avoid user cli usage error logging into the sys log
  Btrfs: move device close to btrfs_close_one_device
  Btrfs: fix fs logging for multi device
  Btrfs: allow -o rw,degraded for single group profile

Liu Bo (1):
  Btrfs: move kobj stuff out of dev_replace lock range

 fs/btrfs/ctree.h           |   4 +-
 fs/btrfs/dev-replace.c     |  64 +++------
 fs/btrfs/disk-io.c         |  65 ++++++---
 fs/btrfs/disk-io.h         |   2 +
 fs/btrfs/ioctl.c           |  50 ++++++-
 fs/btrfs/super.c           |  34 ++---
 fs/btrfs/sysfs.c           |  52 +++----
 fs/btrfs/sysfs.h           |   4 +-
 fs/btrfs/volumes.c         | 345 +++++++++++++++++++++------------------------
 fs/btrfs/volumes.h         |  10 +-
 include/uapi/linux/btrfs.h |   8 ++
 11 files changed, 331 insertions(+), 307 deletions(-)

-- 
2.4.1


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 01/23] Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 02/23] Btrfs: rename btrfs_sysfs_remove_one to btrfs_sysfs_remove_mounted Anand Jain
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/ctree.h   | 2 +-
 fs/btrfs/disk-io.c | 2 +-
 fs/btrfs/sysfs.c   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 938efe3..afce306 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -4004,7 +4004,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 /* sysfs.c */
 int btrfs_init_sysfs(void);
 void btrfs_exit_sysfs(void);
-int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info);
+int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
 void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info);
 
 /* xattr.c */
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index cc15514b..376a6ef 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2928,7 +2928,7 @@ retry_root_backup:
 		goto fail_fsdev_sysfs;
 	}
 
-	ret = btrfs_sysfs_add_one(fs_info);
+	ret = btrfs_sysfs_add_mounted(fs_info);
 	if (ret) {
 		pr_err("BTRFS: failed to init sysfs interface: %d\n", ret);
 		goto fail_fsdev_sysfs;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 603b0cc..cabf840 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -736,7 +736,7 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 	return error;
 }
 
-int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
+int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 {
 	int error;
 	struct btrfs_fs_devices *fs_devs = fs_info->fs_devices;
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 02/23] Btrfs: rename btrfs_sysfs_remove_one to btrfs_sysfs_remove_mounted
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
  2015-08-14 10:32 ` [PATCH 01/23] Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 03/23] Btrfs: rename btrfs_kobj_add_device to btrfs_sysfs_add_device_link Anand Jain
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

---
 fs/btrfs/ctree.h   | 2 +-
 fs/btrfs/disk-io.c | 4 ++--
 fs/btrfs/sysfs.c   | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index afce306..4484063 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -4005,7 +4005,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
 int btrfs_init_sysfs(void);
 void btrfs_exit_sysfs(void);
 int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
-void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info);
+void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
 
 /* xattr.c */
 ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 376a6ef..8571025 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3108,7 +3108,7 @@ fail_cleaner:
 	filemap_write_and_wait(fs_info->btree_inode->i_mapping);
 
 fail_sysfs:
-	btrfs_sysfs_remove_one(fs_info);
+	btrfs_sysfs_remove_mounted(fs_info);
 
 fail_fsdev_sysfs:
 	btrfs_sysfs_remove_fsid(fs_info->fs_devices);
@@ -3791,7 +3791,7 @@ void close_ctree(struct btrfs_root *root)
 		       percpu_counter_sum(&fs_info->delalloc_bytes));
 	}
 
-	btrfs_sysfs_remove_one(fs_info);
+	btrfs_sysfs_remove_mounted(fs_info);
 	btrfs_sysfs_remove_fsid(fs_info->fs_devices);
 
 	btrfs_free_fs_roots(fs_info);
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index cabf840..095a302 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -545,7 +545,7 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 	}
 }
 
-void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
+void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
 {
 	btrfs_reset_fs_info_ptr(fs_info);
 
@@ -776,7 +776,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 
 	return 0;
 failure:
-	btrfs_sysfs_remove_one(fs_info);
+	btrfs_sysfs_remove_mounted(fs_info);
 	return error;
 }
 
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 03/23] Btrfs: rename btrfs_kobj_add_device to btrfs_sysfs_add_device_link
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
  2015-08-14 10:32 ` [PATCH 01/23] Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted Anand Jain
  2015-08-14 10:32 ` [PATCH 02/23] Btrfs: rename btrfs_sysfs_remove_one to btrfs_sysfs_remove_mounted Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 04/23] Btrfs: rename btrfs_kobj_rm_device to btrfs_sysfs_rm_device_link Anand Jain
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

---
 fs/btrfs/dev-replace.c | 2 +-
 fs/btrfs/sysfs.c       | 4 ++--
 fs/btrfs/sysfs.h       | 2 +-
 fs/btrfs/volumes.c     | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 564a7de..c1bf0d6 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -376,7 +376,7 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
 	WARN_ON(!tgt_device);
 	dev_replace->tgtdev = tgt_device;
 
-	ret = btrfs_kobj_add_device(tgt_device->fs_devices, tgt_device);
+	ret = btrfs_sysfs_add_device_link(tgt_device->fs_devices, tgt_device);
 	if (ret)
 		btrfs_err(root->fs_info, "kobj add dev failed %d\n", ret);
 
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 095a302..df67f6b 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -683,7 +683,7 @@ int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs)
 	return 0;
 }
 
-int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
+int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
 				struct btrfs_device *one_device)
 {
 	int error = 0;
@@ -744,7 +744,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 
 	btrfs_set_fs_info_ptr(fs_info);
 
-	error = btrfs_kobj_add_device(fs_devs, NULL);
+	error = btrfs_sysfs_add_device_link(fs_devs, NULL);
 	if (error)
 		return error;
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 6392527..6529680 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -82,7 +82,7 @@ char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
 extern const char * const btrfs_feature_set_names[3];
 extern struct kobj_type space_info_ktype;
 extern struct kobj_type btrfs_raid_ktype;
-int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
+int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
 int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
                 struct btrfs_device *one_device);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 7c84a81..18ea1eb 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2309,7 +2309,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 				    tmp + 1);
 
 	/* add sysfs device entry */
-	btrfs_kobj_add_device(root->fs_info->fs_devices, device);
+	btrfs_sysfs_add_device_link(root->fs_info->fs_devices, device);
 
 	/*
 	 * we've got more storage, clear any full flags on the space
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 04/23] Btrfs: rename btrfs_kobj_rm_device to btrfs_sysfs_rm_device_link
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (2 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 03/23] Btrfs: rename btrfs_kobj_add_device to btrfs_sysfs_add_device_link Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 05/23] Btrfs: rename super_kobj to fsid_kobj Anand Jain
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

---
 fs/btrfs/dev-replace.c | 2 +-
 fs/btrfs/sysfs.c       | 6 +++---
 fs/btrfs/sysfs.h       | 2 +-
 fs/btrfs/volumes.c     | 6 +++---
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index c1bf0d6..6eb9324 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -587,7 +587,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 	mutex_unlock(&uuid_mutex);
 
 	/* replace the sysfs entry */
-	btrfs_kobj_rm_device(fs_info->fs_devices, src_device);
+	btrfs_sysfs_rm_device_link(fs_info->fs_devices, src_device);
 	btrfs_rm_dev_replace_free_srcdev(fs_info, src_device);
 
 	/* write back the superblocks */
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index df67f6b..52319d1 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -557,7 +557,7 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->fs_devices->super_kobj, &btrfs_feature_attr_group);
 	sysfs_remove_files(&fs_info->fs_devices->super_kobj, btrfs_attrs);
-	btrfs_kobj_rm_device(fs_info->fs_devices, NULL);
+	btrfs_sysfs_rm_device_link(fs_info->fs_devices, NULL);
 }
 
 const char * const btrfs_feature_set_names[3] = {
@@ -637,7 +637,7 @@ static void init_feature_attrs(void)
 
 /* when one_device is NULL, it removes all device links */
 
-int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
+int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device)
 {
 	struct hd_struct *disk;
@@ -750,7 +750,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 
 	error = sysfs_create_files(super_kobj, btrfs_attrs);
 	if (error) {
-		btrfs_kobj_rm_device(fs_devs, NULL);
+		btrfs_sysfs_rm_device_link(fs_devs, NULL);
 		return error;
 	}
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 6529680..9c09522 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -84,7 +84,7 @@ extern struct kobj_type space_info_ktype;
 extern struct kobj_type btrfs_raid_ktype;
 int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
-int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
+int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
                 struct btrfs_device *one_device);
 int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 				struct kobject *parent);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 18ea1eb..4c7c344 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1801,7 +1801,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 	if (device->bdev) {
 		device->fs_devices->open_devices--;
 		/* remove sysfs entry */
-		btrfs_kobj_rm_device(root->fs_info->fs_devices, device);
+		btrfs_sysfs_rm_device_link(root->fs_info->fs_devices, device);
 	}
 
 	call_rcu(&device->rcu, free_device);
@@ -1971,7 +1971,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 	WARN_ON(!tgtdev);
 	mutex_lock(&fs_info->fs_devices->device_list_mutex);
 
-	btrfs_kobj_rm_device(fs_info->fs_devices, tgtdev);
+	btrfs_sysfs_rm_device_link(fs_info->fs_devices, tgtdev);
 
 	if (tgtdev->bdev) {
 		btrfs_scratch_superblock(tgtdev);
@@ -2388,7 +2388,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 error_trans:
 	btrfs_end_transaction(trans, root);
 	rcu_string_free(device->name);
-	btrfs_kobj_rm_device(root->fs_info->fs_devices, device);
+	btrfs_sysfs_rm_device_link(root->fs_info->fs_devices, device);
 	kfree(device);
 error:
 	blkdev_put(bdev, FMODE_EXCL);
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 05/23] Btrfs: rename super_kobj to fsid_kobj
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (3 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 04/23] Btrfs: rename btrfs_kobj_rm_device to btrfs_sysfs_rm_device_link Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 06/23] Btrfs: SB read failure should return EIO for __bread failure Anand Jain
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c   | 36 ++++++++++++++++++------------------
 fs/btrfs/volumes.c |  2 +-
 fs/btrfs/volumes.h |  2 +-
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 52319d1..e0ac859 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -437,24 +437,24 @@ static const struct attribute *btrfs_attrs[] = {
 	NULL,
 };
 
-static void btrfs_release_super_kobj(struct kobject *kobj)
+static void btrfs_release_fsid_kobj(struct kobject *kobj)
 {
 	struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj);
 
-	memset(&fs_devs->super_kobj, 0, sizeof(struct kobject));
+	memset(&fs_devs->fsid_kobj, 0, sizeof(struct kobject));
 	complete(&fs_devs->kobj_unregister);
 }
 
 static struct kobj_type btrfs_ktype = {
 	.sysfs_ops	= &kobj_sysfs_ops,
-	.release	= btrfs_release_super_kobj,
+	.release	= btrfs_release_fsid_kobj,
 };
 
 static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj)
 {
 	if (kobj->ktype != &btrfs_ktype)
 		return NULL;
-	return container_of(kobj, struct btrfs_fs_devices, super_kobj);
+	return container_of(kobj, struct btrfs_fs_devices, fsid_kobj);
 }
 
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
@@ -502,12 +502,12 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
 			attrs[0] = &fa->kobj_attr.attr;
 			if (add) {
 				int ret;
-				ret = sysfs_merge_group(&fs_info->fs_devices->super_kobj,
+				ret = sysfs_merge_group(&fs_info->fs_devices->fsid_kobj,
 							&agroup);
 				if (ret)
 					return ret;
 			} else
-				sysfs_unmerge_group(&fs_info->fs_devices->super_kobj,
+				sysfs_unmerge_group(&fs_info->fs_devices->fsid_kobj,
 						    &agroup);
 		}
 
@@ -523,9 +523,9 @@ static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 		fs_devs->device_dir_kobj = NULL;
 	}
 
-	if (fs_devs->super_kobj.state_initialized) {
-		kobject_del(&fs_devs->super_kobj);
-		kobject_put(&fs_devs->super_kobj);
+	if (fs_devs->fsid_kobj.state_initialized) {
+		kobject_del(&fs_devs->fsid_kobj);
+		kobject_put(&fs_devs->fsid_kobj);
 		wait_for_completion(&fs_devs->kobj_unregister);
 	}
 }
@@ -555,8 +555,8 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
 		kobject_put(fs_info->space_info_kobj);
 	}
 	addrm_unknown_feature_attrs(fs_info, false);
-	sysfs_remove_group(&fs_info->fs_devices->super_kobj, &btrfs_feature_attr_group);
-	sysfs_remove_files(&fs_info->fs_devices->super_kobj, btrfs_attrs);
+	sysfs_remove_group(&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group);
+	sysfs_remove_files(&fs_info->fs_devices->fsid_kobj, btrfs_attrs);
 	btrfs_sysfs_rm_device_link(fs_info->fs_devices, NULL);
 }
 
@@ -675,7 +675,7 @@ int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs)
 {
 	if (!fs_devs->device_dir_kobj)
 		fs_devs->device_dir_kobj = kobject_create_and_add("devices",
-						&fs_devs->super_kobj);
+						&fs_devs->fsid_kobj);
 
 	if (!fs_devs->device_dir_kobj)
 		return -ENOMEM;
@@ -730,8 +730,8 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 	int error;
 
 	init_completion(&fs_devs->kobj_unregister);
-	fs_devs->super_kobj.kset = btrfs_kset;
-	error = kobject_init_and_add(&fs_devs->super_kobj,
+	fs_devs->fsid_kobj.kset = btrfs_kset;
+	error = kobject_init_and_add(&fs_devs->fsid_kobj,
 				&btrfs_ktype, parent, "%pU", fs_devs->fsid);
 	return error;
 }
@@ -740,7 +740,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 {
 	int error;
 	struct btrfs_fs_devices *fs_devs = fs_info->fs_devices;
-	struct kobject *super_kobj = &fs_devs->super_kobj;
+	struct kobject *fsid_kobj = &fs_devs->fsid_kobj;
 
 	btrfs_set_fs_info_ptr(fs_info);
 
@@ -748,13 +748,13 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 	if (error)
 		return error;
 
-	error = sysfs_create_files(super_kobj, btrfs_attrs);
+	error = sysfs_create_files(fsid_kobj, btrfs_attrs);
 	if (error) {
 		btrfs_sysfs_rm_device_link(fs_devs, NULL);
 		return error;
 	}
 
-	error = sysfs_create_group(super_kobj,
+	error = sysfs_create_group(fsid_kobj,
 				   &btrfs_feature_attr_group);
 	if (error)
 		goto failure;
@@ -764,7 +764,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 		goto failure;
 
 	fs_info->space_info_kobj = kobject_create_and_add("allocation",
-						  super_kobj);
+						  fsid_kobj);
 	if (!fs_info->space_info_kobj) {
 		error = -ENOMEM;
 		goto failure;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 4c7c344..8368393 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2350,7 +2350,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 		 */
 		snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU",
 						root->fs_info->fsid);
-		if (kobject_rename(&root->fs_info->fs_devices->super_kobj,
+		if (kobject_rename(&root->fs_info->fs_devices->fsid_kobj,
 								fsid_buf))
 			pr_warn("BTRFS: sysfs: failed to create fsid for sprout\n");
 	}
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2ca784a..413a70c 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -256,7 +256,7 @@ struct btrfs_fs_devices {
 
 	struct btrfs_fs_info *fs_info;
 	/* sysfs kobjects */
-	struct kobject super_kobj;
+	struct kobject fsid_kobj;
 	struct kobject *device_dir_kobj;
 	struct completion kobj_unregister;
 };
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 06/23] Btrfs: SB read failure should return EIO for __bread failure
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (4 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 05/23] Btrfs: rename super_kobj to fsid_kobj Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 07/23] Btrfs: __btrfs_std_error() logic should be consistent w/out CONFIG_PRINTK defined Anand Jain
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

This will return EIO when __bread() fails to read SB,
instead of EINVAL.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/disk-io.c | 18 +++++++++++++++---
 fs/btrfs/volumes.c |  8 ++++----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8571025..faf5b8d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2648,8 +2648,8 @@ int open_ctree(struct super_block *sb,
 	 * Read super block and check the signature bytes only
 	 */
 	bh = btrfs_read_dev_super(fs_devices->latest_bdev);
-	if (!bh) {
-		err = -EINVAL;
+	if (IS_ERR(bh)) {
+		err = PTR_ERR(bh);
 		goto fail_alloc;
 	}
 
@@ -3191,6 +3191,7 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
 	int i;
 	u64 transid = 0;
 	u64 bytenr;
+	int ret = -EINVAL;
 
 	/* we would like to check all the supers, but that would make
 	 * a btrfs mount succeed after a mkfs from a different FS.
@@ -3204,13 +3205,20 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
 			break;
 		bh = __bread(bdev, bytenr / 4096,
 					BTRFS_SUPER_INFO_SIZE);
-		if (!bh)
+		/*
+		 * If we fail to read from the underlaying drivers, as of now
+		 * the best option we have is to mark it EIO.
+		 */
+		if (!bh) {
+			ret = -EIO;
 			continue;
+		}
 
 		super = (struct btrfs_super_block *)bh->b_data;
 		if (btrfs_super_bytenr(super) != bytenr ||
 		    btrfs_super_magic(super) != BTRFS_MAGIC) {
 			brelse(bh);
+			ret = -EINVAL;
 			continue;
 		}
 
@@ -3222,6 +3230,10 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
 			brelse(bh);
 		}
 	}
+
+	if (!latest)
+		return ERR_PTR(ret);
+
 	return latest;
 }
 
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 8368393..a3fde18 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -211,8 +211,8 @@ btrfs_get_bdev_and_sb(const char *device_path, fmode_t flags, void *holder,
 	}
 	invalidate_bdev(*bdev);
 	*bh = btrfs_read_dev_super(*bdev);
-	if (!*bh) {
-		ret = -EINVAL;
+	if (IS_ERR(*bh)) {
+		ret = PTR_ERR(*bh);
 		blkdev_put(*bdev, flags);
 		goto error;
 	}
@@ -6842,8 +6842,8 @@ int btrfs_scratch_superblock(struct btrfs_device *device)
 	struct btrfs_super_block *disk_super;
 
 	bh = btrfs_read_dev_super(device->bdev);
-	if (!bh)
-		return -EINVAL;
+	if (IS_ERR(bh))
+		return PTR_ERR(bh);
 	disk_super = (struct btrfs_super_block *)bh->b_data;
 
 	memset(&disk_super->magic, 0, sizeof(disk_super->magic));
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 07/23] Btrfs: __btrfs_std_error() logic should be consistent w/out CONFIG_PRINTK defined
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (5 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 06/23] Btrfs: SB read failure should return EIO for __bread failure Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 08/23] Btrfs: device delete by devid Anand Jain
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

error handling logic behaves differently with or without
CONFIG_PRINTK defined, since there are two copies of the same
function which a bit of different logic

One, when CONFIG_PRINTK is defined, code is

__btrfs_std_error(..)
{
::
       save_error_info(fs_info);
       if (sb->s_flags & MS_BORN)
               btrfs_handle_error(fs_info);
}

and two when CONFIG_PRINTK is not defined, the code is

__btrfs_std_error(..)
{
::
       if (sb->s_flags & MS_BORN) {
               save_error_info(fs_info);
               btrfs_handle_error(fs_info);
        }
}

I doubt if this was intentional ? and appear to have caused since
we maintain two copies of the same function and they got diverged
with commits.

Now to decide which logic is correct reviewed changes as below,

 533574c6bc30cf526cc1c41bde050c854a945efb
Commit added two copies of this function

 cf79ffb5b79e8a2b587fbf218809e691bb396c98
Commit made change to only one copy of the function and to the
copy when CONFIG_PRINTK is defined.

To fix this, instead of maintaining two copies of same function
approach, maintain single function, and just put the extra
portion of the code under CONFIG_PRINTK define.

This patch just does that. And keeps code of with CONFIG_PRINTK
defined.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/super.c | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index c389c13..56c0174 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -130,7 +130,6 @@ static void btrfs_handle_error(struct btrfs_fs_info *fs_info)
 	}
 }
 
-#ifdef CONFIG_PRINTK
 /*
  * __btrfs_std_error decodes expected errors from the caller and
  * invokes the approciate error response.
@@ -140,7 +139,9 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
 		       unsigned int line, int errno, const char *fmt, ...)
 {
 	struct super_block *sb = fs_info->sb;
+#ifdef CONFIG_PRINTK
 	const char *errstr;
+#endif
 
 	/*
 	 * Special case: if the error is EROFS, and we're already
@@ -149,6 +150,7 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
 	if (errno == -EROFS && (sb->s_flags & MS_RDONLY))
   		return;
 
+#ifdef CONFIG_PRINTK
 	errstr = btrfs_decode_error(errno);
 	if (fmt) {
 		struct va_format vaf;
@@ -166,6 +168,7 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
 		printk(KERN_CRIT "BTRFS: error (device %s) in %s:%d: errno=%d %s\n",
 			sb->s_id, function, line, errno, errstr);
 	}
+#endif
 
 	/* Don't go through full error handling during mount */
 	save_error_info(fs_info);
@@ -173,6 +176,7 @@ void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
 		btrfs_handle_error(fs_info);
 }
 
+#ifdef CONFIG_PRINTK
 static const char * const logtypes[] = {
 	"emergency",
 	"alert",
@@ -212,27 +216,6 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 
 	va_end(args);
 }
-
-#else
-
-void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
-		       unsigned int line, int errno, const char *fmt, ...)
-{
-	struct super_block *sb = fs_info->sb;
-
-	/*
-	 * Special case: if the error is EROFS, and we're already
-	 * under MS_RDONLY, then it is safe here.
-	 */
-	if (errno == -EROFS && (sb->s_flags & MS_RDONLY))
-		return;
-
-	/* Don't go through full error handling during mount */
-	if (sb->s_flags & MS_BORN) {
-		save_error_info(fs_info);
-		btrfs_handle_error(fs_info);
-	}
-}
 #endif
 
 /*
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 08/23] Btrfs: device delete by devid
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (6 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 07/23] Btrfs: __btrfs_std_error() logic should be consistent w/out CONFIG_PRINTK defined Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-10-06  9:38   ` [PATCH V4 08/23] Btrfs: Introduce " Anand Jain
  2015-08-14 10:32 ` [PATCH 09/23] Btrfs: move check for min number of devices to a function Anand Jain
                   ` (15 subsequent siblings)
  23 siblings, 1 reply; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

This introduces BTRFS_IOC_RM_DEV_V2, which can accept devid as
an argument to delete the device.

Current only choice to is to pass device path for the device delete
cli, but if btrfs is unable to read device SB, then cli fails. And
user won't be able to delete the device.

With this patch now the user can specify devid as the device
to delete.

The patch won't delete the old interface so that kernel will
remain compatible with the older user-interface programs like
btrfs-progs.

Test case/script:
echo "0 $(blockdev --getsz /dev/sdf) linear /dev/sdf 0" | dmsetup create bad_disk
mkfs.btrfs -f -d raid1 -m raid1 /dev/sdd /dev/sde /dev/mapper/bad_disk
mount /dev/sdd /btrfs
dmsetup suspend bad_disk
echo "0 $(blockdev --getsz /dev/sdf) error /dev/sdf 0" | dmsetup load bad_disk
dmsetup resume bad_disk
echo "bad disk failed. now deleting/replacing"
btrfs dev del  3  /btrfs
echo $?
btrfs fi show /btrfs
umount /btrfs
btrfs-show-super /dev/sdd | egrep num_device
dmsetup remove bad_disk
wipefs -a /dev/sdf

v3: commit update, included test case

v2: don't use device->name after free
commit update with the test script which I have been using

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reported-by: Martin <m_btrfs@ml1.co.uk>
---
 fs/btrfs/ioctl.c           | 50 ++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/volumes.c         | 51 ++++++++++++++++++++++++++++++++++++----------
 fs/btrfs/volumes.h         |  2 +-
 include/uapi/linux/btrfs.h |  8 ++++++++
 4 files changed, 98 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0adf542..6c9e58c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2653,6 +2653,52 @@ out:
 	return ret;
 }
 
+static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
+{
+	struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
+	struct btrfs_ioctl_vol_args_v3 *vol_args;
+	int ret;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	ret = mnt_want_write_file(file);
+	if (ret)
+		return ret;
+
+	vol_args = memdup_user(arg, sizeof(*vol_args));
+	if (IS_ERR(vol_args)) {
+		ret = PTR_ERR(vol_args);
+		goto err_drop;
+	}
+
+	vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
+
+	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
+			1)) {
+		ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
+		goto out;
+	}
+
+	mutex_lock(&root->fs_info->volume_mutex);
+	ret = btrfs_rm_device(root, vol_args->name, vol_args->devid);
+	mutex_unlock(&root->fs_info->volume_mutex);
+	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
+
+	if (!ret) {
+		if (vol_args->devid)
+			btrfs_info(root->fs_info, "disk devid %llu deleted",
+								vol_args->devid);
+		else
+			btrfs_info(root->fs_info, "disk deleted - %s", vol_args->name);
+	}
+out:
+	kfree(vol_args);
+err_drop:
+	mnt_drop_write_file(file);
+	return ret;
+}
+
 static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 {
 	struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
@@ -2681,7 +2727,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 	}
 
 	mutex_lock(&root->fs_info->volume_mutex);
-	ret = btrfs_rm_device(root, vol_args->name);
+	ret = btrfs_rm_device(root, vol_args->name, 0);
 	mutex_unlock(&root->fs_info->volume_mutex);
 	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
 
@@ -5419,6 +5465,8 @@ long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_add_dev(root, argp);
 	case BTRFS_IOC_RM_DEV:
 		return btrfs_ioctl_rm_dev(file, argp);
+	case BTRFS_IOC_RM_DEV_V2:
+		return btrfs_ioctl_rm_dev_v2(file, argp);
 	case BTRFS_IOC_FS_INFO:
 		return btrfs_ioctl_fs_info(root, argp);
 	case BTRFS_IOC_DEV_INFO:
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index a3fde18..2f8b974 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1637,21 +1637,21 @@ out:
 	return ret;
 }
 
-int btrfs_rm_device(struct btrfs_root *root, char *device_path)
+int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 {
 	struct btrfs_device *device;
 	struct btrfs_device *next_device;
-	struct block_device *bdev;
+	struct block_device *bdev = NULL;
 	struct buffer_head *bh = NULL;
-	struct btrfs_super_block *disk_super;
+	struct btrfs_super_block *disk_super = NULL;
 	struct btrfs_fs_devices *cur_devices;
 	u64 all_avail;
-	u64 devid;
 	u64 num_devices;
 	u8 *dev_uuid;
 	unsigned seq;
 	int ret = 0;
 	bool clear_super = false;
+	char *dev_name = NULL;
 
 	mutex_lock(&uuid_mutex);
 
@@ -1692,7 +1692,15 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 		goto out;
 	}
 
-	if (strcmp(device_path, "missing") == 0) {
+	if (devid) {
+		device = btrfs_find_device(root->fs_info, devid,
+				NULL, NULL);
+		if (!device) {
+			ret = -ENOENT;
+			goto out;
+		}
+		device_path = rcu_str_deref(device->name);
+	} else if (strcmp(device_path, "missing") == 0) {
 		struct list_head *devices;
 		struct btrfs_device *tmp;
 
@@ -1710,9 +1718,6 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 				break;
 			}
 		}
-		bdev = NULL;
-		bh = NULL;
-		disk_super = NULL;
 		if (!device) {
 			ret = BTRFS_ERROR_DEV_MISSING_NOT_FOUND;
 			goto out;
@@ -1750,6 +1755,11 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 		list_del_init(&device->dev_alloc_list);
 		device->fs_devices->rw_devices--;
 		unlock_chunks(root);
+		dev_name = kstrdup(device->name->str, GFP_NOFS);
+		if (!dev_name) {
+			ret = -ENOMEM;
+			goto error_undo;
+		}
 		clear_super = true;
 	}
 
@@ -1832,10 +1842,26 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 	 * at this point, the device is zero sized.  We want to
 	 * remove it from the devices list and zero out the old super
 	 */
-	if (clear_super && disk_super) {
+	if (clear_super) {
 		u64 bytenr;
 		int i;
 
+		if (!disk_super) {
+			ret = btrfs_get_bdev_and_sb(dev_name,
+					    FMODE_WRITE | FMODE_EXCL,
+					    root->fs_info->bdev_holder, 0,
+					    &bdev, &bh);
+			if (ret) {
+				/*
+				 * It could be a failed device ok for clear_super
+				 * to fail. So return success
+				 */
+				ret = 0;
+				goto done;
+			}
+
+			disk_super = (struct btrfs_super_block *)bh->b_data;
+		}
 		/* make sure this device isn't detected as part of
 		 * the FS anymore
 		 */
@@ -1872,14 +1898,14 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 		}
 	}
 
+done:
 	ret = 0;
-
 	if (bdev) {
 		/* Notify udev that device has changed */
 		btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
 
 		/* Update ctime/mtime for device path for libblkid */
-		update_dev_time(device_path);
+		update_dev_time(dev_name);
 	}
 
 error_brelse:
@@ -1887,6 +1913,9 @@ error_brelse:
 	if (bdev)
 		blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
 out:
+	if (dev_name)
+		kfree(dev_name);
+
 	mutex_unlock(&uuid_mutex);
 	return ret;
 error_undo:
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 413a70c..f4b0ed8 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -432,7 +432,7 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
 struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
 					const u64 *devid,
 					const u8 *uuid);
-int btrfs_rm_device(struct btrfs_root *root, char *device_path);
+int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid);
 void btrfs_cleanup_fs_uuids(void);
 int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
 int btrfs_grow_device(struct btrfs_trans_handle *trans,
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index b6dec05..074affe 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -31,6 +31,12 @@ struct btrfs_ioctl_vol_args {
 	char name[BTRFS_PATH_NAME_MAX + 1];
 };
 
+struct btrfs_ioctl_vol_args_v3 {
+	__s64 fd;
+	char name[BTRFS_PATH_NAME_MAX + 1];
+	__u64 devid;
+};
+
 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
 
 #define BTRFS_SUBVOL_CREATE_ASYNC	(1ULL << 0)
@@ -634,5 +640,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
 				   struct btrfs_ioctl_feature_flags[2])
 #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
 				   struct btrfs_ioctl_feature_flags[3])
+#define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \
+				   struct btrfs_ioctl_vol_args_v3)
 
 #endif /* _UAPI_LINUX_BTRFS_H */
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 09/23] Btrfs: move check for min number of devices to a function
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (7 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 08/23] Btrfs: device delete by devid Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 10/23] Btrfs: rename btrfs_dev_replace_find_srcdev() Anand Jain
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

btrfs_rm_device() has a section of the code to check for min number
of the devices required by various group profile. This patch move
that part of the code in the function __check_raid_min_devices()

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 78 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 43 insertions(+), 35 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 2f8b974..1573997 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1637,61 +1637,69 @@ out:
 	return ret;
 }
 
-int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
+static int __check_raid_min_devices(struct btrfs_fs_info *fs_info)
 {
-	struct btrfs_device *device;
-	struct btrfs_device *next_device;
-	struct block_device *bdev = NULL;
-	struct buffer_head *bh = NULL;
-	struct btrfs_super_block *disk_super = NULL;
-	struct btrfs_fs_devices *cur_devices;
 	u64 all_avail;
 	u64 num_devices;
-	u8 *dev_uuid;
 	unsigned seq;
-	int ret = 0;
-	bool clear_super = false;
-	char *dev_name = NULL;
-
-	mutex_lock(&uuid_mutex);
 
-	do {
-		seq = read_seqbegin(&root->fs_info->profiles_lock);
-
-		all_avail = root->fs_info->avail_data_alloc_bits |
-			    root->fs_info->avail_system_alloc_bits |
-			    root->fs_info->avail_metadata_alloc_bits;
-	} while (read_seqretry(&root->fs_info->profiles_lock, seq));
-
-	num_devices = root->fs_info->fs_devices->num_devices;
-	btrfs_dev_replace_lock(&root->fs_info->dev_replace);
-	if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) {
+	num_devices = fs_info->fs_devices->num_devices;
+	btrfs_dev_replace_lock(&fs_info->dev_replace);
+	if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) {
 		WARN_ON(num_devices < 1);
 		num_devices--;
 	}
-	btrfs_dev_replace_unlock(&root->fs_info->dev_replace);
+	btrfs_dev_replace_unlock(&fs_info->dev_replace);
+
+	do {
+		seq = read_seqbegin(&fs_info->profiles_lock);
+
+		all_avail = fs_info->avail_data_alloc_bits |
+			    fs_info->avail_system_alloc_bits |
+			    fs_info->avail_metadata_alloc_bits;
+	} while (read_seqretry(&fs_info->profiles_lock, seq));
 
 	if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) {
-		ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
-		goto out;
+		return BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
 	}
 
 	if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices <= 2) {
-		ret = BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET;
-		goto out;
+		return BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET;
 	}
 
 	if ((all_avail & BTRFS_BLOCK_GROUP_RAID5) &&
-	    root->fs_info->fs_devices->rw_devices <= 2) {
-		ret = BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET;
-		goto out;
+	    fs_info->fs_devices->rw_devices <= 2) {
+		return BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET;
 	}
+
 	if ((all_avail & BTRFS_BLOCK_GROUP_RAID6) &&
-	    root->fs_info->fs_devices->rw_devices <= 3) {
-		ret = BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET;
-		goto out;
+	    fs_info->fs_devices->rw_devices <= 3) {
+		return BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET;
 	}
 
+	return 0;
+}
+
+int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
+{
+	struct btrfs_device *device;
+	struct btrfs_device *next_device;
+	struct block_device *bdev = NULL;
+	struct buffer_head *bh = NULL;
+	struct btrfs_super_block *disk_super = NULL;
+	struct btrfs_fs_devices *cur_devices;
+	u64 num_devices;
+	u8 *dev_uuid;
+	int ret = 0;
+	bool clear_super = false;
+	char *dev_name = NULL;
+
+	mutex_lock(&uuid_mutex);
+
+	ret = __check_raid_min_devices(root->fs_info);
+	if (ret)
+		goto out;
+
 	if (devid) {
 		device = btrfs_find_device(root->fs_info, devid,
 				NULL, NULL);
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 10/23] Btrfs: rename btrfs_dev_replace_find_srcdev()
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (8 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 09/23] Btrfs: move check for min number of devices to a function Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 11/23] Btrfs: use BTRFS_ERROR_DEV_MISSING_NOT_FOUND when missing device is not found Anand Jain
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

The patch renames btrfs_dev_replace_find_srcdev() to
btrfs_find_device_by_user_input() so that it can be used
by btrfs_rm_device() as well in the next patches.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/dev-replace.c | 24 +-----------------------
 fs/btrfs/volumes.c     | 19 +++++++++++++++++++
 fs/btrfs/volumes.h     |  3 +++
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 6eb9324..673a2c3 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -44,9 +44,6 @@ static void btrfs_dev_replace_update_device_in_mapping_tree(
 						struct btrfs_fs_info *fs_info,
 						struct btrfs_device *srcdev,
 						struct btrfs_device *tgtdev);
-static int btrfs_dev_replace_find_srcdev(struct btrfs_root *root, u64 srcdevid,
-					 char *srcdev_name,
-					 struct btrfs_device **device);
 static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info);
 static int btrfs_dev_replace_kthread(void *data);
 static int btrfs_dev_replace_continue_on_mount(struct btrfs_fs_info *fs_info);
@@ -343,7 +340,7 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
 
 	/* the disk copy procedure reuses the scrub code */
 	mutex_lock(&fs_info->volume_mutex);
-	ret = btrfs_dev_replace_find_srcdev(root, args->start.srcdevid,
+	ret = btrfs_find_device_by_user_input(root, args->start.srcdevid,
 					    args->start.srcdev_name,
 					    &src_device);
 	if (ret) {
@@ -626,25 +623,6 @@ static void btrfs_dev_replace_update_device_in_mapping_tree(
 	write_unlock(&em_tree->lock);
 }
 
-static int btrfs_dev_replace_find_srcdev(struct btrfs_root *root, u64 srcdevid,
-					 char *srcdev_name,
-					 struct btrfs_device **device)
-{
-	int ret;
-
-	if (srcdevid) {
-		ret = 0;
-		*device = btrfs_find_device(root->fs_info, srcdevid, NULL,
-					    NULL);
-		if (!*device)
-			ret = -ENOENT;
-	} else {
-		ret = btrfs_find_device_missing_or_by_path(root, srcdev_name,
-							   device);
-	}
-	return ret;
-}
-
 void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info,
 			      struct btrfs_ioctl_dev_replace_args *args)
 {
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1573997..101a473 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2089,6 +2089,25 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
 	}
 }
 
+int btrfs_find_device_by_user_input(struct btrfs_root *root, u64 srcdevid,
+					 char *srcdev_name,
+					 struct btrfs_device **device)
+{
+	int ret;
+
+	if (srcdevid) {
+		ret = 0;
+		*device = btrfs_find_device(root->fs_info, srcdevid, NULL,
+					    NULL);
+		if (!*device)
+			ret = -ENOENT;
+	} else {
+		ret = btrfs_find_device_missing_or_by_path(root, srcdev_name,
+							   device);
+	}
+	return ret;
+}
+
 /*
  * does all the dirty work required for changing file system's UUID.
  */
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index f4b0ed8..a093b36 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -429,6 +429,9 @@ void btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices, int step);
 int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
 					 char *device_path,
 					 struct btrfs_device **device);
+int btrfs_find_device_by_user_input(struct btrfs_root *root, u64 srcdevid,
+					 char *srcdev_name,
+					 struct btrfs_device **device);
 struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
 					const u64 *devid,
 					const u8 *uuid);
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 11/23] Btrfs: use BTRFS_ERROR_DEV_MISSING_NOT_FOUND when missing device is not found
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (9 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 10/23] Btrfs: rename btrfs_dev_replace_find_srcdev() Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 12/23] Btrfs: use btrfs_find_device_by_user_input() Anand Jain
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

use btrfs specific error code BTRFS_ERROR_DEV_MISSING_NOT_FOUND instead of -ENOENT.
Next this removes the logging when user specifies "missing" and we don't find
it in the kernel device list. logging are for system events not for user input errors.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 101a473..f1b36b9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2078,10 +2078,8 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_root *root,
 			}
 		}
 
-		if (!*device) {
-			btrfs_err(root->fs_info, "no missing device found");
-			return -ENOENT;
-		}
+		if (!*device)
+			return BTRFS_ERROR_DEV_MISSING_NOT_FOUND;
 
 		return 0;
 	} else {
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 12/23] Btrfs: use btrfs_find_device_by_user_input()
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (10 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 11/23] Btrfs: use BTRFS_ERROR_DEV_MISSING_NOT_FOUND when missing device is not found Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 13/23] Btrfs: add btrfs_read_dev_one_super() to read one specific SB Anand Jain
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

btrfs_rm_device() has a section of the code which can be replaced
btrfs_find_device_by_user_input()

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 84 ++++++++++++------------------------------------------
 1 file changed, 19 insertions(+), 65 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index f1b36b9..1d35332 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1689,7 +1689,6 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 	struct btrfs_super_block *disk_super = NULL;
 	struct btrfs_fs_devices *cur_devices;
 	u64 num_devices;
-	u8 *dev_uuid;
 	int ret = 0;
 	bool clear_super = false;
 	char *dev_name = NULL;
@@ -1700,62 +1699,19 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 	if (ret)
 		goto out;
 
-	if (devid) {
-		device = btrfs_find_device(root->fs_info, devid,
-				NULL, NULL);
-		if (!device) {
-			ret = -ENOENT;
-			goto out;
-		}
-		device_path = rcu_str_deref(device->name);
-	} else if (strcmp(device_path, "missing") == 0) {
-		struct list_head *devices;
-		struct btrfs_device *tmp;
-
-		device = NULL;
-		devices = &root->fs_info->fs_devices->devices;
-		/*
-		 * It is safe to read the devices since the volume_mutex
-		 * is held.
-		 */
-		list_for_each_entry(tmp, devices, dev_list) {
-			if (tmp->in_fs_metadata &&
-			    !tmp->is_tgtdev_for_dev_replace &&
-			    !tmp->bdev) {
-				device = tmp;
-				break;
-			}
-		}
-		if (!device) {
-			ret = BTRFS_ERROR_DEV_MISSING_NOT_FOUND;
-			goto out;
-		}
-	} else {
-		ret = btrfs_get_bdev_and_sb(device_path,
-					    FMODE_WRITE | FMODE_EXCL,
-					    root->fs_info->bdev_holder, 0,
-					    &bdev, &bh);
-		if (ret)
-			goto out;
-		disk_super = (struct btrfs_super_block *)bh->b_data;
-		devid = btrfs_stack_device_id(&disk_super->dev_item);
-		dev_uuid = disk_super->dev_item.uuid;
-		device = btrfs_find_device(root->fs_info, devid, dev_uuid,
-					   disk_super->fsid);
-		if (!device) {
-			ret = -ENOENT;
-			goto error_brelse;
-		}
-	}
+	ret = btrfs_find_device_by_user_input(root, devid, device_path,
+				&device);
+	if (ret)
+		goto out;
 
 	if (device->is_tgtdev_for_dev_replace) {
 		ret = BTRFS_ERROR_DEV_TGT_REPLACE;
-		goto error_brelse;
+		goto out;
 	}
 
 	if (device->writeable && root->fs_info->fs_devices->rw_devices == 1) {
 		ret = BTRFS_ERROR_DEV_ONLY_WRITABLE;
-		goto error_brelse;
+		goto out;
 	}
 
 	if (device->writeable) {
@@ -1865,7 +1821,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 				 * to fail. So return success
 				 */
 				ret = 0;
-				goto done;
+				goto out;
 			}
 
 			disk_super = (struct btrfs_super_block *)bh->b_data;
@@ -1876,6 +1832,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 		memset(&disk_super->magic, 0, sizeof(disk_super->magic));
 		set_buffer_dirty(bh);
 		sync_dirty_buffer(bh);
+		brelse(bh);
 
 		/* clear the mirror copies of super block on the disk
 		 * being removed, 0th copy is been taken care above and
@@ -1887,7 +1844,6 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 					i_size_read(bdev->bd_inode))
 				break;
 
-			brelse(bh);
 			bh = __bread(bdev, bytenr / 4096,
 					BTRFS_SUPER_INFO_SIZE);
 			if (!bh)
@@ -1897,35 +1853,33 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 
 			if (btrfs_super_bytenr(disk_super) != bytenr ||
 				btrfs_super_magic(disk_super) != BTRFS_MAGIC) {
+				brelse(bh);
 				continue;
 			}
 			memset(&disk_super->magic, 0,
 						sizeof(disk_super->magic));
 			set_buffer_dirty(bh);
 			sync_dirty_buffer(bh);
+			brelse(bh);
 		}
-	}
 
-done:
-	ret = 0;
-	if (bdev) {
-		/* Notify udev that device has changed */
-		btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
+		if (bdev) {
+			/* Notify udev that device has changed */
+			btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
 
-		/* Update ctime/mtime for device path for libblkid */
-		update_dev_time(dev_name);
+			/* Update ctime/mtime for device path for libblkid */
+			update_dev_time(dev_name);
+			blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
+		}
 	}
 
-error_brelse:
-	brelse(bh);
-	if (bdev)
-		blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
 out:
 	if (dev_name)
 		kfree(dev_name);
 
 	mutex_unlock(&uuid_mutex);
 	return ret;
+
 error_undo:
 	if (device->writeable) {
 		lock_chunks(root);
@@ -1934,7 +1888,7 @@ error_undo:
 		device->fs_devices->rw_devices++;
 		unlock_chunks(root);
 	}
-	goto error_brelse;
+	goto out;
 }
 
 void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_fs_info *fs_info,
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 13/23] Btrfs: add btrfs_read_dev_one_super() to read one specific SB
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (11 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 12/23] Btrfs: use btrfs_find_device_by_user_input() Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:32 ` [PATCH 14/23] Btrfs: fix btrfs_scratch_superblock() with fixes from device delete Anand Jain
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

This uses a chunk of code from btrfs_read_dev_super() and creates
a function called btrfs_read_dev_one_super() so that next patch
can use it for scratch superblock.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/disk-io.c | 54 ++++++++++++++++++++++++++++++++++--------------------
 fs/btrfs/disk-io.h |  2 ++
 2 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index faf5b8d..2f2379d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3183,6 +3183,37 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
 	put_bh(bh);
 }
 
+int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
+			struct buffer_head **bh)
+{
+	struct buffer_head *bufhead;
+	struct btrfs_super_block *super;
+	u64 bytenr;
+
+	bytenr = btrfs_sb_offset(copy_num);
+	if (bytenr + BTRFS_SUPER_INFO_SIZE >= i_size_read(bdev->bd_inode))
+		return -EINVAL;
+
+	bufhead = __bread(bdev, bytenr / 4096, BTRFS_SUPER_INFO_SIZE);
+	/*
+	 * If we fail to read from the underlaying drivers, as of now
+	 * the best option we have is to mark it EIO.
+	 */
+	if (!bufhead)
+		return -EIO;
+
+	super = (struct btrfs_super_block *)bufhead->b_data;
+	if (btrfs_super_bytenr(super) != bytenr ||
+		    btrfs_super_magic(super) != BTRFS_MAGIC) {
+		brelse(bufhead);
+		return -EINVAL;
+	}
+
+	*bh = bufhead;
+	return 0;
+}
+
+
 struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
 {
 	struct buffer_head *bh;
@@ -3190,7 +3221,6 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
 	struct btrfs_super_block *super;
 	int i;
 	u64 transid = 0;
-	u64 bytenr;
 	int ret = -EINVAL;
 
 	/* we would like to check all the supers, but that would make
@@ -3199,28 +3229,12 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
 	 * later supers, using BTRFS_SUPER_MIRROR_MAX instead
 	 */
 	for (i = 0; i < 1; i++) {
-		bytenr = btrfs_sb_offset(i);
-		if (bytenr + BTRFS_SUPER_INFO_SIZE >=
-					i_size_read(bdev->bd_inode))
-			break;
-		bh = __bread(bdev, bytenr / 4096,
-					BTRFS_SUPER_INFO_SIZE);
-		/*
-		 * If we fail to read from the underlaying drivers, as of now
-		 * the best option we have is to mark it EIO.
-		 */
-		if (!bh) {
-			ret = -EIO;
+
+		ret = btrfs_read_dev_one_super(bdev, i, &bh);
+		if (ret)
 			continue;
-		}
 
 		super = (struct btrfs_super_block *)bh->b_data;
-		if (btrfs_super_bytenr(super) != bytenr ||
-		    btrfs_super_magic(super) != BTRFS_MAGIC) {
-			brelse(bh);
-			ret = -EINVAL;
-			continue;
-		}
 
 		if (!latest || btrfs_super_generation(super) > transid) {
 			brelse(latest);
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index d4cbfee..8dc9ff1 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -60,6 +60,8 @@ void close_ctree(struct btrfs_root *root);
 int write_ctree_super(struct btrfs_trans_handle *trans,
 		      struct btrfs_root *root, int max_mirrors);
 struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
+int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
+			struct buffer_head **bh);
 int btrfs_commit_super(struct btrfs_root *root);
 struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
 					    u64 bytenr);
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 14/23] Btrfs: fix btrfs_scratch_superblock() with fixes from device delete
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (12 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 13/23] Btrfs: add btrfs_read_dev_one_super() to read one specific SB Anand Jain
@ 2015-08-14 10:32 ` Anand Jain
  2015-08-14 10:33 ` [PATCH 15/23] Btrfs: use btrfs_scratch_superblock() in btrfs_rm_device() Anand Jain
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

This patch updates the btrfs_scratch_superblock(), (which is used
by the replace device thread), with those fixes from the
scratch superblock code section of btrfs_rm_device(). The fixes are:
  Scratch all copies of superblock
  Notify kobject that superblock has been changed
  Update time on the device

so that btrfs_rm_device() can use the function btrfs_scratch_superblock()
instead of its own scratch code. And further replace deivce code which
similarly releases device back to the system, will have the fixes from
the btrfs device delete.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 40 ++++++++++++++++++++++++++++------------
 fs/btrfs/volumes.h |  2 +-
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1d35332..b2a19ea 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1915,7 +1915,8 @@ void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_fs_info *fs_info,
 	if (srcdev->writeable) {
 		fs_devices->rw_devices--;
 		/* zero out the old super if it is writable */
-		btrfs_scratch_superblock(srcdev);
+		btrfs_scratch_superblock(srcdev->bdev,
+					rcu_str_deref(srcdev->name));
 	}
 
 	if (srcdev->bdev)
@@ -1965,7 +1966,8 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 	btrfs_sysfs_rm_device_link(fs_info->fs_devices, tgtdev);
 
 	if (tgtdev->bdev) {
-		btrfs_scratch_superblock(tgtdev);
+		btrfs_scratch_superblock(tgtdev->bdev,
+					rcu_str_deref(tgtdev->name));
 		fs_info->fs_devices->open_devices--;
 	}
 	fs_info->fs_devices->num_devices--;
@@ -6844,22 +6846,36 @@ int btrfs_get_dev_stats(struct btrfs_root *root,
 	return 0;
 }
 
-int btrfs_scratch_superblock(struct btrfs_device *device)
+void btrfs_scratch_superblock(struct block_device *bdev, char *device_path)
 {
 	struct buffer_head *bh;
 	struct btrfs_super_block *disk_super;
+	int copy_num;
 
-	bh = btrfs_read_dev_super(device->bdev);
-	if (IS_ERR(bh))
-		return PTR_ERR(bh);
-	disk_super = (struct btrfs_super_block *)bh->b_data;
+	if (!bdev)
+		return;
 
-	memset(&disk_super->magic, 0, sizeof(disk_super->magic));
-	set_buffer_dirty(bh);
-	sync_dirty_buffer(bh);
-	brelse(bh);
+	for (copy_num = 0; copy_num < BTRFS_SUPER_MIRROR_MAX;
+		copy_num++) {
 
-	return 0;
+		if (btrfs_read_dev_one_super(bdev, copy_num, &bh))
+			continue;
+
+		disk_super = (struct btrfs_super_block *)bh->b_data;
+
+		memset(&disk_super->magic, 0, sizeof(disk_super->magic));
+		set_buffer_dirty(bh);
+		sync_dirty_buffer(bh);
+		brelse(bh);
+	}
+
+	/* Notify udev that device has changed */
+	btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
+
+	/* Update ctime/mtime for device path for libblkid */
+	update_dev_time(device_path);
+
+	return;
 }
 
 /*
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index a093b36..32a66c7 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -477,7 +477,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 				      struct btrfs_device *tgtdev);
 void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
 					      struct btrfs_device *tgtdev);
-int btrfs_scratch_superblock(struct btrfs_device *device);
+void btrfs_scratch_superblock(struct block_device *bdev, char *device_path);
 int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree,
 			   u64 logical, u64 len, int mirror_num);
 unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 15/23] Btrfs: use btrfs_scratch_superblock() in btrfs_rm_device()
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (13 preceding siblings ...)
  2015-08-14 10:32 ` [PATCH 14/23] Btrfs: fix btrfs_scratch_superblock() with fixes from device delete Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-08-14 10:33 ` [PATCH 16/23] Btrfs: device path change must be logged Anand Jain
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

With the previous patches now the btrfs_scratch_superblock()
is ready to be used in btrfs_rm_device() so use it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 69 ++++--------------------------------------------------
 1 file changed, 5 insertions(+), 64 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b2a19ea..ebf37a9 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1684,9 +1684,6 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 {
 	struct btrfs_device *device;
 	struct btrfs_device *next_device;
-	struct block_device *bdev = NULL;
-	struct buffer_head *bh = NULL;
-	struct btrfs_super_block *disk_super = NULL;
 	struct btrfs_fs_devices *cur_devices;
 	u64 num_devices;
 	int ret = 0;
@@ -1807,68 +1804,12 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 	 * remove it from the devices list and zero out the old super
 	 */
 	if (clear_super) {
-		u64 bytenr;
-		int i;
-
-		if (!disk_super) {
-			ret = btrfs_get_bdev_and_sb(dev_name,
-					    FMODE_WRITE | FMODE_EXCL,
-					    root->fs_info->bdev_holder, 0,
-					    &bdev, &bh);
-			if (ret) {
-				/*
-				 * It could be a failed device ok for clear_super
-				 * to fail. So return success
-				 */
-				ret = 0;
-				goto out;
-			}
-
-			disk_super = (struct btrfs_super_block *)bh->b_data;
-		}
-		/* make sure this device isn't detected as part of
-		 * the FS anymore
-		 */
-		memset(&disk_super->magic, 0, sizeof(disk_super->magic));
-		set_buffer_dirty(bh);
-		sync_dirty_buffer(bh);
-		brelse(bh);
-
-		/* clear the mirror copies of super block on the disk
-		 * being removed, 0th copy is been taken care above and
-		 * the below would take of the rest
-		 */
-		for (i = 1; i < BTRFS_SUPER_MIRROR_MAX; i++) {
-			bytenr = btrfs_sb_offset(i);
-			if (bytenr + BTRFS_SUPER_INFO_SIZE >=
-					i_size_read(bdev->bd_inode))
-				break;
-
-			bh = __bread(bdev, bytenr / 4096,
-					BTRFS_SUPER_INFO_SIZE);
-			if (!bh)
-				continue;
-
-			disk_super = (struct btrfs_super_block *)bh->b_data;
-
-			if (btrfs_super_bytenr(disk_super) != bytenr ||
-				btrfs_super_magic(disk_super) != BTRFS_MAGIC) {
-				brelse(bh);
-				continue;
-			}
-			memset(&disk_super->magic, 0,
-						sizeof(disk_super->magic));
-			set_buffer_dirty(bh);
-			sync_dirty_buffer(bh);
-			brelse(bh);
-		}
-
-		if (bdev) {
-			/* Notify udev that device has changed */
-			btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
+		struct block_device *bdev;
 
-			/* Update ctime/mtime for device path for libblkid */
-			update_dev_time(dev_name);
+		bdev = blkdev_get_by_path(dev_name, FMODE_READ | FMODE_EXCL,
+						root->fs_info->bdev_holder);
+		if (!IS_ERR(bdev)) {
+			btrfs_scratch_superblock(bdev, dev_name);
 			blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
 		}
 	}
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 16/23] Btrfs: device path change must be logged
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (14 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 15/23] Btrfs: use btrfs_scratch_superblock() in btrfs_rm_device() Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-10-01 13:40   ` David Sterba
  2015-08-14 10:33 ` [PATCH 17/23] Btrfs: kernel operation should come after user input has been verified Anand Jain
                   ` (7 subsequent siblings)
  23 siblings, 1 reply; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

>From the issue diagnosable point of view, log if the device path is
changed.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ebf37a9..dcb10fa 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -595,6 +595,10 @@ static noinline int device_list_add(const char *path,
 			return -EEXIST;
 		}
 
+		printk_in_rcu(KERN_INFO \
+			"BTRFS: device fsid %pU devid %llu old path %s new path %s\n",
+			disk_super->fsid, devid, rcu_str_deref(device->name), path);
+
 		name = rcu_string_strdup(path, GFP_NOFS);
 		if (!name)
 			return -ENOMEM;
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 17/23] Btrfs: kernel operation should come after user input has been verified
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (15 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 16/23] Btrfs: device path change must be logged Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-08-14 10:33 ` [PATCH 18/23] Btrfs: check device_path in btrfs_find_device_by_user_input() Anand Jain
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

By general rule of thumb there shouldn't be any way that user land
could trigger a kernel operation just by sending wrong arguments.

Here do commit cleanups after user input has been verified.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/dev-replace.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 673a2c3..937e53b 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -325,19 +325,6 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
 	    args->start.tgtdev_name[0] == '\0')
 		return -EINVAL;
 
-	/*
-	 * Here we commit the transaction to make sure commit_total_bytes
-	 * of all the devices are updated.
-	 */
-	trans = btrfs_attach_transaction(root);
-	if (!IS_ERR(trans)) {
-		ret = btrfs_commit_transaction(trans, root);
-		if (ret)
-			return ret;
-	} else if (PTR_ERR(trans) != -ENOENT) {
-		return PTR_ERR(trans);
-	}
-
 	/* the disk copy procedure reuses the scrub code */
 	mutex_lock(&fs_info->volume_mutex);
 	ret = btrfs_find_device_by_user_input(root, args->start.srcdevid,
@@ -354,6 +341,19 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
 	if (ret)
 		return ret;
 
+	/*
+	 * Here we commit the transaction to make sure commit_total_bytes
+	 * of all the devices are updated.
+	 */
+	trans = btrfs_attach_transaction(root);
+	if (!IS_ERR(trans)) {
+		ret = btrfs_commit_transaction(trans, root);
+		if (ret)
+			return ret;
+	} else if (PTR_ERR(trans) != -ENOENT) {
+		return PTR_ERR(trans);
+	}
+
 	btrfs_dev_replace_lock(dev_replace);
 	switch (dev_replace->replace_state) {
 	case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 18/23] Btrfs: check device_path in btrfs_find_device_by_user_input()
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (16 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 17/23] Btrfs: kernel operation should come after user input has been verified Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-08-14 10:33 ` [PATCH 19/23] Btrfs: avoid user cli usage error logging into the sys log Anand Jain
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

so btrfs_dev_replace_start() can be sleak and btrfs_rm_device() will
also need it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/dev-replace.c | 4 ----
 fs/btrfs/volumes.c     | 3 +++
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 937e53b..0df3d9b 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -321,10 +321,6 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
 		return -EINVAL;
 	}
 
-	if ((args->start.srcdevid == 0 && args->start.srcdev_name[0] == '\0') ||
-	    args->start.tgtdev_name[0] == '\0')
-		return -EINVAL;
-
 	/* the disk copy procedure reuses the scrub code */
 	mutex_lock(&fs_info->volume_mutex);
 	ret = btrfs_find_device_by_user_input(root, args->start.srcdevid,
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index dcb10fa..5803c45 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2001,6 +2001,9 @@ int btrfs_find_device_by_user_input(struct btrfs_root *root, u64 srcdevid,
 		if (!*device)
 			ret = -ENOENT;
 	} else {
+		if (!srcdev_name || !srcdev_name[0])
+			return -EINVAL;
+
 		ret = btrfs_find_device_missing_or_by_path(root, srcdev_name,
 							   device);
 	}
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 19/23] Btrfs: avoid user cli usage error logging into the sys log
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (17 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 18/23] Btrfs: check device_path in btrfs_find_device_by_user_input() Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-08-14 10:33 ` [PATCH 20/23] Btrfs: move device close to btrfs_close_one_device Anand Jain
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 5803c45..f3ca87d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -198,7 +198,6 @@ btrfs_get_bdev_and_sb(const char *device_path, fmode_t flags, void *holder,
 
 	if (IS_ERR(*bdev)) {
 		ret = PTR_ERR(*bdev);
-		printk(KERN_INFO "BTRFS: open %s failed\n", device_path);
 		goto error;
 	}
 
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 20/23] Btrfs: move device close to btrfs_close_one_device
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (18 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 19/23] Btrfs: avoid user cli usage error logging into the sys log Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-08-14 10:33 ` [PATCH 21/23] Btrfs: fix fs logging for multi device Anand Jain
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

this will help to add the proposed device offline RFE
---
 fs/btrfs/volumes.c | 66 +++++++++++++++++++++++++++++-------------------------
 fs/btrfs/volumes.h |  1 +
 2 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index f3ca87d..00ca858 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -768,36 +768,7 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
 
 	mutex_lock(&fs_devices->device_list_mutex);
 	list_for_each_entry_safe(device, tmp, &fs_devices->devices, dev_list) {
-		struct btrfs_device *new_device;
-		struct rcu_string *name;
-
-		if (device->bdev)
-			fs_devices->open_devices--;
-
-		if (device->writeable &&
-		    device->devid != BTRFS_DEV_REPLACE_DEVID) {
-			list_del_init(&device->dev_alloc_list);
-			fs_devices->rw_devices--;
-		}
-
-		if (device->missing)
-			fs_devices->missing_devices--;
-
-		new_device = btrfs_alloc_device(NULL, &device->devid,
-						device->uuid);
-		BUG_ON(IS_ERR(new_device)); /* -ENOMEM */
-
-		/* Safe because we are under uuid_mutex */
-		if (device->name) {
-			name = rcu_string_strdup(device->name->str, GFP_NOFS);
-			BUG_ON(!name); /* -ENOMEM */
-			rcu_assign_pointer(new_device->name, name);
-		}
-
-		list_replace_rcu(&device->dev_list, &new_device->dev_list);
-		new_device->fs_devices = device->fs_devices;
-
-		call_rcu(&device->rcu, free_device);
+		btrfs_close_one_device(device);
 	}
 	mutex_unlock(&fs_devices->device_list_mutex);
 
@@ -6890,3 +6861,38 @@ void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info)
 		fs_devices = fs_devices->seed;
 	}
 }
+
+void btrfs_close_one_device(struct btrfs_device *device)
+{
+	struct btrfs_fs_devices *fs_devices = device->fs_devices;
+	struct btrfs_device *new_device;
+	struct rcu_string *name;
+
+	if (device->bdev)
+		fs_devices->open_devices--;
+
+	if (device->writeable &&
+	    device->devid != BTRFS_DEV_REPLACE_DEVID) {
+		list_del_init(&device->dev_alloc_list);
+		fs_devices->rw_devices--;
+	}
+
+	if (device->missing)
+		fs_devices->missing_devices--;
+
+	new_device = btrfs_alloc_device(NULL, &device->devid,
+					device->uuid);
+	BUG_ON(IS_ERR(new_device)); /* -ENOMEM */
+
+	/* Safe because we are under uuid_mutex */
+	if (device->name) {
+		name = rcu_string_strdup(device->name->str, GFP_NOFS);
+		BUG_ON(!name); /* -ENOMEM */
+		rcu_assign_pointer(new_device->name, name);
+	}
+
+	list_replace_rcu(&device->dev_list, &new_device->dev_list);
+	new_device->fs_devices = device->fs_devices;
+
+	call_rcu(&device->rcu, free_device);
+}
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 32a66c7..5f4911a 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -550,5 +550,6 @@ static inline void unlock_chunks(struct btrfs_root *root)
 struct list_head *btrfs_get_fs_uuids(void);
 void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info);
 void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info);
+void btrfs_close_one_device(struct btrfs_device *device);
 
 #endif
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 21/23] Btrfs: fix fs logging for multi device
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (19 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 20/23] Btrfs: move device close to btrfs_close_one_device Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-10-01 13:45   ` David Sterba
  2015-08-14 10:33 ` [PATCH 22/23] Btrfs: move kobj stuff out of dev_replace lock range Anand Jain
                   ` (2 subsequent siblings)
  23 siblings, 1 reply; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

In case of multi device btrfs fs, using one of device for
the logging purpose it quite confusing, instead use the
fsid. FSID is bit long, but the device path can be long
as well in some cases.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 56c0174..a8a0109 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -190,12 +190,12 @@ static const char * const logtypes[] = {
 
 void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 {
-	struct super_block *sb = fs_info->sb;
 	char lvl[4];
 	struct va_format vaf;
 	va_list args;
 	const char *type = logtypes[4];
 	int kern_level;
+	struct btrfs_fs_devices *fs_devs = fs_info->fs_devices;
 
 	va_start(args, fmt);
 
@@ -212,7 +212,7 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 	vaf.fmt = fmt;
 	vaf.va = &args;
 
-	printk("%sBTRFS %s (device %s): %pV\n", lvl, type, sb->s_id, &vaf);
+	printk("%sBTRFS: %pU %s: %pV\n", lvl, fs_devs->fsid, type, &vaf);
 
 	va_end(args);
 }
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 22/23] Btrfs: move kobj stuff out of dev_replace lock range
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (20 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 21/23] Btrfs: fix fs logging for multi device Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-08-14 10:33 ` [PATCH 23/23] Btrfs: allow -o rw,degraded for single group profile Anand Jain
  2015-09-29 14:34 ` [PATCH 00/23] btrfs device related patch set David Sterba
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Liu Bo <bo.li.liu@oracle.com>

To avoid deadlock described in commit 084b6e7c7607 ("btrfs: Fix a lockdep warning when running xfstest."),
we should move kobj stuff out of dev_replace lock range.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/dev-replace.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 0df3d9b..c326d51 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -369,10 +369,6 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
 	WARN_ON(!tgt_device);
 	dev_replace->tgtdev = tgt_device;
 
-	ret = btrfs_sysfs_add_device_link(tgt_device->fs_devices, tgt_device);
-	if (ret)
-		btrfs_err(root->fs_info, "kobj add dev failed %d\n", ret);
-
 	printk_in_rcu(KERN_INFO
 		      "BTRFS: dev_replace from %s (devid %llu) to %s started\n",
 		      src_device->missing ? "<missing disk>" :
@@ -395,6 +391,10 @@ int btrfs_dev_replace_start(struct btrfs_root *root,
 	args->result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
 	btrfs_dev_replace_unlock(dev_replace);
 
+	ret = btrfs_sysfs_add_device_link(tgt_device->fs_devices, tgt_device);
+	if (ret)
+		btrfs_err(root->fs_info, "kobj add dev failed %d\n", ret);
+
 	btrfs_wait_ordered_roots(root->fs_info, -1);
 
 	/* force writing the updated state information to disk */
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [PATCH 23/23] Btrfs: allow -o rw,degraded for single group profile
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (21 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 22/23] Btrfs: move kobj stuff out of dev_replace lock range Anand Jain
@ 2015-08-14 10:33 ` Anand Jain
  2015-09-29 14:34 ` [PATCH 00/23] btrfs device related patch set David Sterba
  23 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-08-14 10:33 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

As of now only the exception to allow mount when number of missing
device is more than group profile tolerance count is
 RDONLY
this patch adds another lateral exception
 DEGRADED

This will enable user to recover from the following and
similar volume unavailability issue

raid1 volume:
 mkfs.btrfs -draid1 -mraid1 /dev/sdc /dev/sdd

unscan the device scan:
 modprobe -r btrfs && modprobe btrfs <= dev scanned is cleared

since kernel does not know about /dev/sdd use degraded
option to mount:
 mount -o degraded /dev/sdc /btrfs   <= sdd is not used
 umount /btrfs

problem: following umount the mount fails even with degraded option:
 mount -o degraded /dev/sdc /btrfs   <== fails.

because: unmount triggered commit used single profile which needs
all the disks

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/disk-io.c | 3 ++-
 fs/btrfs/super.c   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 2f2379d..3377f1a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2949,7 +2949,8 @@ retry_root_backup:
 		btrfs_calc_num_tolerated_disk_barrier_failures(fs_info);
 	if (fs_info->fs_devices->missing_devices >
 	     fs_info->num_tolerated_disk_barrier_failures &&
-	    !(sb->s_flags & MS_RDONLY)) {
+	    !(sb->s_flags & MS_RDONLY ||
+		btrfs_test_opt(fs_info->dev_root, DEGRADED))) {
 		pr_warn("BTRFS: missing devices(%llu) exceeds the limit(%d), writeable mount is not allowed\n",
 			fs_info->fs_devices->missing_devices,
 			fs_info->num_tolerated_disk_barrier_failures);
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index a8a0109..315035a2 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1666,7 +1666,8 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
 
 		if (fs_info->fs_devices->missing_devices >
 		     fs_info->num_tolerated_disk_barrier_failures &&
-		    !(*flags & MS_RDONLY)) {
+		    !(*flags & MS_RDONLY ||
+			btrfs_test_opt(root, DEGRADED))) {
 			btrfs_warn(fs_info,
 				"too many missing devices, writeable remount is not allowed");
 			ret = -EACCES;
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/23] btrfs device related patch set
  2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
                   ` (22 preceding siblings ...)
  2015-08-14 10:33 ` [PATCH 23/23] Btrfs: allow -o rw,degraded for single group profile Anand Jain
@ 2015-09-29 14:34 ` David Sterba
  2015-09-29 22:10   ` Anand Jain
  23 siblings, 1 reply; 37+ messages in thread
From: David Sterba @ 2015-09-29 14:34 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm, dsterba

On Fri, Aug 14, 2015 at 06:32:45PM +0800, Anand Jain wrote:
> Anand Jain (22):
>   Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted
>   Btrfs: rename btrfs_sysfs_remove_one to btrfs_sysfs_remove_mounted
>   Btrfs: rename btrfs_kobj_add_device to btrfs_sysfs_add_device_link
>   Btrfs: rename btrfs_kobj_rm_device to btrfs_sysfs_rm_device_link
>   Btrfs: rename super_kobj to fsid_kobj
>   Btrfs: SB read failure should return EIO for __bread failure
>   Btrfs: __btrfs_std_error() logic should be consistent w/out
>     CONFIG_PRINTK defined

FYI, I'm picking the above for 4.4 as they're quite straightforward, the
other patches touch interfaces and I have some comments.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/23] btrfs device related patch set
  2015-09-29 14:34 ` [PATCH 00/23] btrfs device related patch set David Sterba
@ 2015-09-29 22:10   ` Anand Jain
  2015-09-30 15:05     ` David Sterba
  0 siblings, 1 reply; 37+ messages in thread
From: Anand Jain @ 2015-09-29 22:10 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm



On 09/29/2015 10:34 PM, David Sterba wrote:
> On Fri, Aug 14, 2015 at 06:32:45PM +0800, Anand Jain wrote:
>> Anand Jain (22):
>>    Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted
>>    Btrfs: rename btrfs_sysfs_remove_one to btrfs_sysfs_remove_mounted
>>    Btrfs: rename btrfs_kobj_add_device to btrfs_sysfs_add_device_link
>>    Btrfs: rename btrfs_kobj_rm_device to btrfs_sysfs_rm_device_link
>>    Btrfs: rename super_kobj to fsid_kobj
>>    Btrfs: SB read failure should return EIO for __bread failure
>>    Btrfs: __btrfs_std_error() logic should be consistent w/out
>>      CONFIG_PRINTK defined
>
> FYI, I'm picking the above for 4.4 as they're quite straightforward,
 > the other patches touch interfaces and I have some comments.

Thanks David.
Except for
   [PATCH 08/23] Btrfs: device delete by devid
   [PATCH 23/23] Btrfs: allow -o rw,degraded for single group profile

rest are straightforward as well. If there is any comment will take it.
In fact 08/23 and 23/23 are stable at me end. however for 23/23 I am 
testing Qu approach to count missing per Chunk. So far I couldn't break 
both 23/23 or the Qu approach the patch below..
   [PATCH 0/5] Btrfs: Per-chunk degradable check

Thanks, Anand


> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/23] btrfs device related patch set
  2015-09-29 22:10   ` Anand Jain
@ 2015-09-30 15:05     ` David Sterba
  2015-10-01 14:42       ` David Sterba
  0 siblings, 1 reply; 37+ messages in thread
From: David Sterba @ 2015-09-30 15:05 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm

On Wed, Sep 30, 2015 at 06:10:53AM +0800, Anand Jain wrote:
> 
> 
> On 09/29/2015 10:34 PM, David Sterba wrote:
> > On Fri, Aug 14, 2015 at 06:32:45PM +0800, Anand Jain wrote:
> >> Anand Jain (22):
> >>    Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted
> >>    Btrfs: rename btrfs_sysfs_remove_one to btrfs_sysfs_remove_mounted
> >>    Btrfs: rename btrfs_kobj_add_device to btrfs_sysfs_add_device_link
> >>    Btrfs: rename btrfs_kobj_rm_device to btrfs_sysfs_rm_device_link
> >>    Btrfs: rename super_kobj to fsid_kobj
> >>    Btrfs: SB read failure should return EIO for __bread failure
> >>    Btrfs: __btrfs_std_error() logic should be consistent w/out
> >>      CONFIG_PRINTK defined
> >
> > FYI, I'm picking the above for 4.4 as they're quite straightforward,
>  > the other patches touch interfaces and I have some comments.
> 
> Thanks David.
> Except for
>    [PATCH 08/23] Btrfs: device delete by devid
>    [PATCH 23/23] Btrfs: allow -o rw,degraded for single group profile

In case the two patches are independent on the rest of series, it would
be better to put them towards the end of the series. I was going down
the list and stpeed at 08/23 because it introduced something nontrivial
and then I can't be sure that skipping the single patch would not break
the whole series.

> rest are straightforward as well. If there is any comment will take it.

I'll have another look and will let you know.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 16/23] Btrfs: device path change must be logged
  2015-08-14 10:33 ` [PATCH 16/23] Btrfs: device path change must be logged Anand Jain
@ 2015-10-01 13:40   ` David Sterba
  2015-10-01 13:47     ` Anand Jain
  0 siblings, 1 reply; 37+ messages in thread
From: David Sterba @ 2015-10-01 13:40 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm, dsterba

On Fri, Aug 14, 2015 at 06:33:01PM +0800, Anand Jain wrote:
> >From the issue diagnosable point of view, log if the device path is
> changed.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/volumes.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index ebf37a9..dcb10fa 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -595,6 +595,10 @@ static noinline int device_list_add(const char *path,

>  			return -EEXIST;
>  		}
>  
> +		printk_in_rcu(KERN_INFO \
> +			"BTRFS: device fsid %pU devid %llu old path %s new path %s\n",
> +			disk_super->fsid, devid, rcu_str_deref(device->name), path);

I don't think that the message should be put into device_list_add. Its
only callsite in btrfs_scan_one_device prints some device info messages
so it would be better to extend and use the return value if possible.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 21/23] Btrfs: fix fs logging for multi device
  2015-08-14 10:33 ` [PATCH 21/23] Btrfs: fix fs logging for multi device Anand Jain
@ 2015-10-01 13:45   ` David Sterba
  2015-10-01 13:48     ` Anand Jain
  0 siblings, 1 reply; 37+ messages in thread
From: David Sterba @ 2015-10-01 13:45 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm, dsterba

On Fri, Aug 14, 2015 at 06:33:06PM +0800, Anand Jain wrote:
> In case of multi device btrfs fs, using one of device for
> the logging purpose it quite confusing, instead use the
> fsid. FSID is bit long, but the device path can be long
> as well in some cases.

The fsid in the log would be good but yeah it's quite long. Though the
device paths could be long as well, they are not in most cases. The uuid
length is 36 bytes, a device mapper path starts at 12 (prefix) plus the
volume name.

Please send this patch separately with a RFC tag so we can hopeully have
a discussion among more people.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 16/23] Btrfs: device path change must be logged
  2015-10-01 13:40   ` David Sterba
@ 2015-10-01 13:47     ` Anand Jain
  2015-10-05  8:50       ` Anand Jain
  0 siblings, 1 reply; 37+ messages in thread
From: Anand Jain @ 2015-10-01 13:47 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm



On 10/01/2015 09:40 PM, David Sterba wrote:
> On Fri, Aug 14, 2015 at 06:33:01PM +0800, Anand Jain wrote:
>> >From the issue diagnosable point of view, log if the device path is
>> changed.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   fs/btrfs/volumes.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index ebf37a9..dcb10fa 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -595,6 +595,10 @@ static noinline int device_list_add(const char *path,
>
>>   			return -EEXIST;
>>   		}
>>
>> +		printk_in_rcu(KERN_INFO \
>> +			"BTRFS: device fsid %pU devid %llu old path %s new path %s\n",
>> +			disk_super->fsid, devid, rcu_str_deref(device->name), path);
>
> I don't think that the message should be put into device_list_add. Its
> only callsite in btrfs_scan_one_device prints some device info messages
> so it would be better to extend and use the return value if possible.


  Right. will fix it.

Thanks, Anand


> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 21/23] Btrfs: fix fs logging for multi device
  2015-10-01 13:45   ` David Sterba
@ 2015-10-01 13:48     ` Anand Jain
  0 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-10-01 13:48 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm



On 10/01/2015 09:45 PM, David Sterba wrote:
> On Fri, Aug 14, 2015 at 06:33:06PM +0800, Anand Jain wrote:
>> In case of multi device btrfs fs, using one of device for
>> the logging purpose it quite confusing, instead use the
>> fsid. FSID is bit long, but the device path can be long
>> as well in some cases.
>
> The fsid in the log would be good but yeah it's quite long. Though the
> device paths could be long as well, they are not in most cases. The uuid
> length is 36 bytes, a device mapper path starts at 12 (prefix) plus the
> volume name.
>
> Please send this patch separately with a RFC tag so we can hopeully have
> a discussion among more people.

  got it. will do.

Thanks, Anand

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/23] btrfs device related patch set
  2015-09-30 15:05     ` David Sterba
@ 2015-10-01 14:42       ` David Sterba
  2015-10-01 15:00         ` Anand Jain
  0 siblings, 1 reply; 37+ messages in thread
From: David Sterba @ 2015-10-01 14:42 UTC (permalink / raw)
  To: dsterba, Anand Jain, linux-btrfs, clm

On Wed, Sep 30, 2015 at 05:05:16PM +0200, David Sterba wrote:
> >    [PATCH 08/23] Btrfs: device delete by devid
> >    [PATCH 23/23] Btrfs: allow -o rw,degraded for single group profile
> 
> In case the two patches are independent on the rest of series, it would
> be better to put them towards the end of the series. I was going down
> the list and stpeed at 08/23 because it introduced something nontrivial
> and then I can't be sure that skipping the single patch would not break
> the whole series.
> 
> > rest are straightforward as well. If there is any comment will take it.
> 
> I'll have another look and will let you know.

There are several patches that I'll add to the branch, some other have
minor issues and the rest seem to depend on the skipped patches. ATM I
can't say what exacly will end up in the branch but you can watch it in
my gits, anand/sysfs-updates-v4.3-rc3. The series is mixing various
patch types and I don't se a better approach.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/23] btrfs device related patch set
  2015-10-01 14:42       ` David Sterba
@ 2015-10-01 15:00         ` Anand Jain
  2015-10-01 16:17           ` David Sterba
  0 siblings, 1 reply; 37+ messages in thread
From: Anand Jain @ 2015-10-01 15:00 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm



On 10/01/2015 10:42 PM, David Sterba wrote:
> On Wed, Sep 30, 2015 at 05:05:16PM +0200, David Sterba wrote:
>>>     [PATCH 08/23] Btrfs: device delete by devid
>>>     [PATCH 23/23] Btrfs: allow -o rw,degraded for single group profile
>>
>> In case the two patches are independent on the rest of series, it would
>> be better to put them towards the end of the series. I was going down
>> the list and stpeed at 08/23 because it introduced something nontrivial
>> and then I can't be sure that skipping the single patch would not break
>> the whole series.
>>
>>> rest are straightforward as well. If there is any comment will take it.
>>
>> I'll have another look and will let you know.
>
> There are several patches that I'll add to the branch, some other have
> minor issues and the rest seem to depend on the skipped patches. ATM I
> can't say what exacly will end up in the branch but you can watch it in
> my gits, anand/sysfs-updates-v4.3-rc3. The series is mixing various
> patch types and I don't se a better approach.

  Its been challenging to realign the patch sequence at my end as well, 
I am trying. I think it will take a bit longer than expected.

Thanks, Anand

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/23] btrfs device related patch set
  2015-10-01 15:00         ` Anand Jain
@ 2015-10-01 16:17           ` David Sterba
  2015-10-02  8:07             ` Anand Jain
  0 siblings, 1 reply; 37+ messages in thread
From: David Sterba @ 2015-10-01 16:17 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, linux-btrfs, clm

On Thu, Oct 01, 2015 at 11:00:39PM +0800, Anand Jain wrote:
>   Its been challenging to realign the patch sequence at my end as well, 
> I am trying. I think it will take a bit longer than expected.

I'd suggest to send several small patchsets instead of one of such size.
A big patchset makes sense if all the patches are logically related so
there's not a limit on the number.

I've picked patches 11, 13, 14, 17, 19, 20 and 22, and made some minor
changes. I'll do some testing here before I ask Chris to pull the
updated branch.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/23] btrfs device related patch set
  2015-10-01 16:17           ` David Sterba
@ 2015-10-02  8:07             ` Anand Jain
  0 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-10-02  8:07 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm



On 10/02/2015 12:17 AM, David Sterba wrote:
> On Thu, Oct 01, 2015 at 11:00:39PM +0800, Anand Jain wrote:
>>    Its been challenging to realign the patch sequence at my end as well,
>> I am trying. I think it will take a bit longer than expected.
>
> I'd suggest to send several small patchsets instead of one of such size.
> A big patchset makes sense if all the patches are logically related so
> there's not a limit on the number.
>
> I've picked patches 11, 13, 14, 17, 19, 20 and 22, and made some minor
> changes. I'll do some testing here before I ask Chris to pull the
> updated branch.

David,

  I believe you are applying (11, 13, 14, 17, 19, 20 and 22) on top
  of anand/sysfs-updates-v4.3-rc3. ? which the branch already contains
  8 patches from this set.

  I am rebase-ing rest of the patches on top of these. With RFC
  patches moving to the last in this patching sequence.

Thanks, Anand

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 16/23] Btrfs: device path change must be logged
  2015-10-01 13:47     ` Anand Jain
@ 2015-10-05  8:50       ` Anand Jain
  0 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-10-05  8:50 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm


Hi David,

  Kindly note. This is accepted and sent out as part of the patch
  which are dependinding together.

Thanks, Anand

On 10/01/2015 09:47 PM, Anand Jain wrote:
>
>
> On 10/01/2015 09:40 PM, David Sterba wrote:
>> On Fri, Aug 14, 2015 at 06:33:01PM +0800, Anand Jain wrote:
>>> >From the issue diagnosable point of view, log if the device path is
>>> changed.
>>>
>>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>>> ---
>>>   fs/btrfs/volumes.c | 4 ++++
>>>   1 file changed, 4 insertions(+)
>>>
>>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>>> index ebf37a9..dcb10fa 100644
>>> --- a/fs/btrfs/volumes.c
>>> +++ b/fs/btrfs/volumes.c
>>> @@ -595,6 +595,10 @@ static noinline int device_list_add(const char
>>> *path,
>>
>>>               return -EEXIST;
>>>           }
>>>
>>> +        printk_in_rcu(KERN_INFO \
>>> +            "BTRFS: device fsid %pU devid %llu old path %s new path
>>> %s\n",
>>> +            disk_super->fsid, devid, rcu_str_deref(device->name),
>>> path);
>>
>> I don't think that the message should be put into device_list_add. Its
>> only callsite in btrfs_scan_one_device prints some device info messages
>> so it would be better to extend and use the return value if possible.
>
>
>   Right. will fix it.
>
> Thanks, Anand
>
>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH V4 08/23] Btrfs: Introduce device delete by devid
  2015-08-14 10:32 ` [PATCH 08/23] Btrfs: device delete by devid Anand Jain
@ 2015-10-06  9:38   ` Anand Jain
  0 siblings, 0 replies; 37+ messages in thread
From: Anand Jain @ 2015-10-06  9:38 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

This introduces new ioctl BTRFS_IOC_RM_DEV_V2, which uses
enhanced struct btrfs_ioctl_vol_args_v2 to carry devid as
an user argument.

The patch won't delete the old ioctl interface and remains
backward compatible with user land progs.

Test case/script:
echo "0 $(blockdev --getsz /dev/sdf) linear /dev/sdf 0" | dmsetup create bad_disk
mkfs.btrfs -f -d raid1 -m raid1 /dev/sdd /dev/sde /dev/mapper/bad_disk
mount /dev/sdd /btrfs
dmsetup suspend bad_disk
echo "0 $(blockdev --getsz /dev/sdf) error /dev/sdf 0" | dmsetup load bad_disk
dmsetup resume bad_disk
echo "bad disk failed. now deleting/replacing"
btrfs dev del  3  /btrfs
echo $?
btrfs fi show /btrfs
umount /btrfs
btrfs-show-super /dev/sdd | egrep num_device
dmsetup remove bad_disk
wipefs -a /dev/sdf

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reported-by: Martin <m_btrfs@ml1.co.uk>
---
v4: enahnced btrfs_ioctl_vol_args_v2 to accept devid instead of
    creating a new structure. Thanks to David.
    commit update and title changed from..
    Btrfs: device delete by devid

v3: commit update, included test case

v2: don't use device->name after free

 fs/btrfs/ioctl.c           | 58 +++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/volumes.c         |  4 ++--
 fs/btrfs/volumes.h         |  2 +-
 include/uapi/linux/btrfs.h | 14 ++++++++++-
 4 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index f43a104..f3aa37c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2653,6 +2653,60 @@ out:
 	return ret;
 }
 
+static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
+{
+	struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
+	struct btrfs_ioctl_vol_args_v2 *vol_args;
+	int ret;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	ret = mnt_want_write_file(file);
+	if (ret)
+		return ret;
+
+	vol_args = memdup_user(arg, sizeof(*vol_args));
+	if (IS_ERR(vol_args)) {
+		ret = PTR_ERR(vol_args);
+		goto err_drop;
+	}
+
+	/* Check for compatibility reject unknown flags */
+	if (vol_args->flags & ~BTRFS_VOL_ARG_V2_FLAGS)
+		return -ENOTTY;
+
+	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
+			1)) {
+		ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
+		goto out;
+	}
+
+	mutex_lock(&root->fs_info->volume_mutex);
+	if (vol_args->flags & BTRFS_DEVICE_BY_ID) {
+		ret = btrfs_rm_device(root, NULL, vol_args->devid);
+	} else {
+		vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
+		ret = btrfs_rm_device(root, vol_args->name, 0);
+	}
+
+	mutex_unlock(&root->fs_info->volume_mutex);
+	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
+
+	if (!ret) {
+		if (vol_args->flags & BTRFS_DEVICE_BY_ID)
+			btrfs_info(root->fs_info, "disk devid %llu deleted",
+								vol_args->devid);
+		else
+			btrfs_info(root->fs_info, "disk deleted - %s", vol_args->name);
+	}
+out:
+	kfree(vol_args);
+err_drop:
+	mnt_drop_write_file(file);
+	return ret;
+}
+
 static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 {
 	struct btrfs_root *root = BTRFS_I(file_inode(file))->root;
@@ -2681,7 +2735,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 	}
 
 	mutex_lock(&root->fs_info->volume_mutex);
-	ret = btrfs_rm_device(root, vol_args->name);
+	ret = btrfs_rm_device(root, vol_args->name, 0);
 	mutex_unlock(&root->fs_info->volume_mutex);
 	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
 
@@ -5424,6 +5478,8 @@ long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_add_dev(root, argp);
 	case BTRFS_IOC_RM_DEV:
 		return btrfs_ioctl_rm_dev(file, argp);
+	case BTRFS_IOC_RM_DEV_V2:
+		return btrfs_ioctl_rm_dev_v2(file, argp);
 	case BTRFS_IOC_FS_INFO:
 		return btrfs_ioctl_fs_info(root, argp);
 	case BTRFS_IOC_DEV_INFO:
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 65c6f89..91758d0 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1667,7 +1667,7 @@ static int __check_raid_min_devices(struct btrfs_fs_info *fs_info)
 	return 0;
 }
 
-int btrfs_rm_device(struct btrfs_root *root, char *device_path)
+int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
 {
 	struct btrfs_device *device;
 	struct btrfs_device *next_device;
@@ -1683,7 +1683,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 	if (ret)
 		goto out;
 
-	ret = btrfs_find_device_by_user_input(root, 0, device_path,
+	ret = btrfs_find_device_by_user_input(root, devid, device_path,
 				&device);
 	if (ret)
 		goto out;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 15ee0dd..4150d9d 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -436,7 +436,7 @@ int btrfs_find_device_by_user_input(struct btrfs_root *root, u64 srcdevid,
 struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
 					const u64 *devid,
 					const u8 *uuid);
-int btrfs_rm_device(struct btrfs_root *root, char *device_path);
+int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid);
 void btrfs_cleanup_fs_uuids(void);
 int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len);
 int btrfs_grow_device(struct btrfs_trans_handle *trans,
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index b6dec05..ff40c48 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -36,6 +36,13 @@ struct btrfs_ioctl_vol_args {
 #define BTRFS_SUBVOL_CREATE_ASYNC	(1ULL << 0)
 #define BTRFS_SUBVOL_RDONLY		(1ULL << 1)
 #define BTRFS_SUBVOL_QGROUP_INHERIT	(1ULL << 2)
+#define BTRFS_DEVICE_BY_ID		(1ULL << 3)
+#define BTRFS_VOL_ARG_V2_FLAGS				\
+			(BTRFS_SUBVOL_CREATE_ASYNC |	\
+			BTRFS_SUBVOL_RDONLY |		\
+			BTRFS_SUBVOL_QGROUP_INHERIT |	\
+			BTRFS_DEVICE_BY_ID)
+
 #define BTRFS_FSID_SIZE 16
 #define BTRFS_UUID_SIZE 16
 #define BTRFS_UUID_UNPARSED_SIZE	37
@@ -76,7 +83,10 @@ struct btrfs_ioctl_vol_args_v2 {
 		};
 		__u64 unused[4];
 	};
-	char name[BTRFS_SUBVOL_NAME_MAX + 1];
+	union {
+		char name[BTRFS_SUBVOL_NAME_MAX + 1];
+		u64 devid;
+	};
 };
 
 /*
@@ -634,5 +644,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
 				   struct btrfs_ioctl_feature_flags[2])
 #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
 				   struct btrfs_ioctl_feature_flags[3])
+#define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \
+				   struct btrfs_ioctl_vol_args_v2)
 
 #endif /* _UAPI_LINUX_BTRFS_H */
-- 
2.4.1


^ permalink raw reply related	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2015-10-06  9:39 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-14 10:32 [PATCH 00/23] btrfs device related patch set Anand Jain
2015-08-14 10:32 ` [PATCH 01/23] Btrfs: rename btrfs_sysfs_add_one to btrfs_sysfs_add_mounted Anand Jain
2015-08-14 10:32 ` [PATCH 02/23] Btrfs: rename btrfs_sysfs_remove_one to btrfs_sysfs_remove_mounted Anand Jain
2015-08-14 10:32 ` [PATCH 03/23] Btrfs: rename btrfs_kobj_add_device to btrfs_sysfs_add_device_link Anand Jain
2015-08-14 10:32 ` [PATCH 04/23] Btrfs: rename btrfs_kobj_rm_device to btrfs_sysfs_rm_device_link Anand Jain
2015-08-14 10:32 ` [PATCH 05/23] Btrfs: rename super_kobj to fsid_kobj Anand Jain
2015-08-14 10:32 ` [PATCH 06/23] Btrfs: SB read failure should return EIO for __bread failure Anand Jain
2015-08-14 10:32 ` [PATCH 07/23] Btrfs: __btrfs_std_error() logic should be consistent w/out CONFIG_PRINTK defined Anand Jain
2015-08-14 10:32 ` [PATCH 08/23] Btrfs: device delete by devid Anand Jain
2015-10-06  9:38   ` [PATCH V4 08/23] Btrfs: Introduce " Anand Jain
2015-08-14 10:32 ` [PATCH 09/23] Btrfs: move check for min number of devices to a function Anand Jain
2015-08-14 10:32 ` [PATCH 10/23] Btrfs: rename btrfs_dev_replace_find_srcdev() Anand Jain
2015-08-14 10:32 ` [PATCH 11/23] Btrfs: use BTRFS_ERROR_DEV_MISSING_NOT_FOUND when missing device is not found Anand Jain
2015-08-14 10:32 ` [PATCH 12/23] Btrfs: use btrfs_find_device_by_user_input() Anand Jain
2015-08-14 10:32 ` [PATCH 13/23] Btrfs: add btrfs_read_dev_one_super() to read one specific SB Anand Jain
2015-08-14 10:32 ` [PATCH 14/23] Btrfs: fix btrfs_scratch_superblock() with fixes from device delete Anand Jain
2015-08-14 10:33 ` [PATCH 15/23] Btrfs: use btrfs_scratch_superblock() in btrfs_rm_device() Anand Jain
2015-08-14 10:33 ` [PATCH 16/23] Btrfs: device path change must be logged Anand Jain
2015-10-01 13:40   ` David Sterba
2015-10-01 13:47     ` Anand Jain
2015-10-05  8:50       ` Anand Jain
2015-08-14 10:33 ` [PATCH 17/23] Btrfs: kernel operation should come after user input has been verified Anand Jain
2015-08-14 10:33 ` [PATCH 18/23] Btrfs: check device_path in btrfs_find_device_by_user_input() Anand Jain
2015-08-14 10:33 ` [PATCH 19/23] Btrfs: avoid user cli usage error logging into the sys log Anand Jain
2015-08-14 10:33 ` [PATCH 20/23] Btrfs: move device close to btrfs_close_one_device Anand Jain
2015-08-14 10:33 ` [PATCH 21/23] Btrfs: fix fs logging for multi device Anand Jain
2015-10-01 13:45   ` David Sterba
2015-10-01 13:48     ` Anand Jain
2015-08-14 10:33 ` [PATCH 22/23] Btrfs: move kobj stuff out of dev_replace lock range Anand Jain
2015-08-14 10:33 ` [PATCH 23/23] Btrfs: allow -o rw,degraded for single group profile Anand Jain
2015-09-29 14:34 ` [PATCH 00/23] btrfs device related patch set David Sterba
2015-09-29 22:10   ` Anand Jain
2015-09-30 15:05     ` David Sterba
2015-10-01 14:42       ` David Sterba
2015-10-01 15:00         ` Anand Jain
2015-10-01 16:17           ` David Sterba
2015-10-02  8:07             ` Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).