All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/3] btrfs: undo writable when sprouting fails
@ 2017-09-28  6:51 Anand Jain
  2017-09-28  6:51 ` [PATCH v4 2/3] btrfs: fix BUG_ON in btrfs_init_new_device() Anand Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Anand Jain @ 2017-09-28  6:51 UTC (permalink / raw)
  To: linux-btrfs

When new device is being added to seed FS, seed FS is marked writable,
but when we fail to bring in the new device, we missed to undo the
writable part. This patch fixes it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
---
v4: none
v3: none
v2: add commit log
v1: moving sb->s_flags |= MS_RDONLY; to further below to error:
    is not a good idea because, goto error; comes from a place
    where sb->s_flags &= ~MS_RDONLY; has not yet been called.

 fs/btrfs/volumes.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 0e8f16c305df..9d64700cc9b6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2501,6 +2501,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	return ret;
 
 error_trans:
+	if (seeding_dev)
+		sb->s_flags |= MS_RDONLY;
 	btrfs_end_transaction(trans);
 	rcu_string_free(device->name);
 	btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
-- 
2.13.1


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

* [PATCH v4 2/3] btrfs: fix BUG_ON in btrfs_init_new_device()
  2017-09-28  6:51 [PATCH v4 1/3] btrfs: undo writable when sprouting fails Anand Jain
@ 2017-09-28  6:51 ` Anand Jain
  2017-09-28  6:51 ` [PATCH v4 3/3] btrfs: error out if btrfs_attach_transaction() fails Anand Jain
  2017-09-29 17:39 ` [PATCH v4 1/3] btrfs: undo writable when sprouting fails David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Anand Jain @ 2017-09-28  6:51 UTC (permalink / raw)
  To: linux-btrfs

Instead of BUG_ON return error to the caller. And handle the fail
condition by calling the abort transaction and going through the
error path.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
---
v4: none;
v3: meld this with
     btrfs: cleanup btrfs_init_new_device()
v2: do not consolidate btrfs_abort_transaction()

 fs/btrfs/volumes.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 9d64700cc9b6..4cb575fbf643 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2399,7 +2399,10 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	if (seeding_dev) {
 		sb->s_flags &= ~MS_RDONLY;
 		ret = btrfs_prepare_sprout(fs_info);
-		BUG_ON(ret); /* -ENOMEM */
+		if (ret) {
+			btrfs_abort_transaction(trans, ret);
+			goto error_trans;
+		}
 	}
 
 	device->fs_devices = fs_info->fs_devices;
@@ -2445,14 +2448,14 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 		mutex_unlock(&fs_info->chunk_mutex);
 		if (ret) {
 			btrfs_abort_transaction(trans, ret);
-			goto error_trans;
+			goto error_sysfs;
 		}
 	}
 
 	ret = btrfs_add_device(trans, fs_info, device);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
-		goto error_trans;
+		goto error_sysfs;
 	}
 
 	if (seeding_dev) {
@@ -2461,7 +2464,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 		ret = btrfs_finish_sprout(trans, fs_info);
 		if (ret) {
 			btrfs_abort_transaction(trans, ret);
-			goto error_trans;
+			goto error_sysfs;
 		}
 
 		/* Sprouting would change fsid of the mounted root,
@@ -2500,12 +2503,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	update_dev_time(device_path);
 	return ret;
 
+error_sysfs:
+	btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
 error_trans:
 	if (seeding_dev)
 		sb->s_flags |= MS_RDONLY;
 	btrfs_end_transaction(trans);
 	rcu_string_free(device->name);
-	btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
 	kfree(device);
 error:
 	blkdev_put(bdev, FMODE_EXCL);
-- 
2.13.1


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

* [PATCH v4 3/3] btrfs: error out if btrfs_attach_transaction() fails
  2017-09-28  6:51 [PATCH v4 1/3] btrfs: undo writable when sprouting fails Anand Jain
  2017-09-28  6:51 ` [PATCH v4 2/3] btrfs: fix BUG_ON in btrfs_init_new_device() Anand Jain
@ 2017-09-28  6:51 ` Anand Jain
  2017-09-29 17:39 ` [PATCH v4 1/3] btrfs: undo writable when sprouting fails David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Anand Jain @ 2017-09-28  6:51 UTC (permalink / raw)
  To: linux-btrfs

btrfs_init_new_device() calls btrfs_attach_transaction() to
commit sys chunks, and it should error out if it fails.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
---
v4: make this patch as part of this set.
    avoid double mutext unlock.
v3: not part of this set
v2: patch did not exist
v1: patch did not exist
 fs/btrfs/volumes.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 4cb575fbf643..bdb8f04663a4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2323,6 +2323,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	u64 tmp;
 	int seeding_dev = 0;
 	int ret = 0;
+	bool unlocked = false;
 
 	if (sb_rdonly(sb) && !fs_info->fs_devices->seeding)
 		return -EROFS;
@@ -2482,6 +2483,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	if (seeding_dev) {
 		mutex_unlock(&uuid_mutex);
 		up_write(&sb->s_umount);
+		unlocked = true;
 
 		if (ret) /* transaction commit */
 			return ret;
@@ -2494,7 +2496,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 		if (IS_ERR(trans)) {
 			if (PTR_ERR(trans) == -ENOENT)
 				return 0;
-			return PTR_ERR(trans);
+			ret = PTR_ERR(trans);
+			goto error_sysfs;
 		}
 		ret = btrfs_commit_transaction(trans);
 	}
@@ -2513,7 +2516,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	kfree(device);
 error:
 	blkdev_put(bdev, FMODE_EXCL);
-	if (seeding_dev) {
+	if (seeding_dev && !unlocked) {
 		mutex_unlock(&uuid_mutex);
 		up_write(&sb->s_umount);
 	}
-- 
2.13.1


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

* Re: [PATCH v4 1/3] btrfs: undo writable when sprouting fails
  2017-09-28  6:51 [PATCH v4 1/3] btrfs: undo writable when sprouting fails Anand Jain
  2017-09-28  6:51 ` [PATCH v4 2/3] btrfs: fix BUG_ON in btrfs_init_new_device() Anand Jain
  2017-09-28  6:51 ` [PATCH v4 3/3] btrfs: error out if btrfs_attach_transaction() fails Anand Jain
@ 2017-09-29 17:39 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2017-09-29 17:39 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Thu, Sep 28, 2017 at 02:51:09PM +0800, Anand Jain wrote:
> When new device is being added to seed FS, seed FS is marked writable,
> but when we fail to bring in the new device, we missed to undo the
> writable part. This patch fixes it.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> Reviewed-by: Nikolay Borisov <nborisov@suse.com>

Thanks, 1-3 added to the queue.

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

end of thread, other threads:[~2017-09-29 17:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-28  6:51 [PATCH v4 1/3] btrfs: undo writable when sprouting fails Anand Jain
2017-09-28  6:51 ` [PATCH v4 2/3] btrfs: fix BUG_ON in btrfs_init_new_device() Anand Jain
2017-09-28  6:51 ` [PATCH v4 3/3] btrfs: error out if btrfs_attach_transaction() fails Anand Jain
2017-09-29 17:39 ` [PATCH v4 1/3] btrfs: undo writable when sprouting fails David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.