All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF
@ 2015-10-18  5:44 Liu Bo
  2015-10-18 11:41 ` Qu Wenruo
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Bo @ 2015-10-18  5:44 UTC (permalink / raw)
  To: linux-btrfs

Btrfs has changed to delete subvolume/snapshot asynchronously, which means that
after umount itself, if we've already deleted 'ext2_saved', rollback can still
be completed.

So this adds a check for ROOT_BACKREF before checking ROOT_ITEM since
ROOT_BACKREF is immediately not in the btree after ioctl(BTRFS_IOC_SNAP_DESTROY)
returns.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 btrfs-convert.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/btrfs-convert.c b/btrfs-convert.c
index 802930c..f8a6c16 100644
--- a/btrfs-convert.c
+++ b/btrfs-convert.c
@@ -2591,6 +2591,22 @@ static int do_rollback(const char *devname)
 	btrfs_init_path(&path);
 
 	key.objectid = CONV_IMAGE_SUBVOL_OBJECTID;
+	key.type = BTRFS_ROOT_BACKREF_KEY;
+	key.offset = BTRFS_FS_TREE_OBJECTID;
+	ret = btrfs_search_slot(NULL, root->fs_info->tree_root, &key, &path, 0,
+				0);
+	btrfs_release_path(&path);
+	if (ret > 0) {
+		fprintf(stderr, "unable to open subvol %llu\n",
+			(unsigned long long)key.objectid);
+		goto fail;
+	} else if (ret < 0) {
+		fprintf(stderr, "unable to open subvol %llu ret %d\n",
+			(unsigned long long)key.objectid, ret);
+		goto fail;
+	}
+
+	key.objectid = CONV_IMAGE_SUBVOL_OBJECTID;
 	key.type = BTRFS_ROOT_ITEM_KEY;
 	key.offset = (u64)-1;
 	image_root = btrfs_read_fs_root(root->fs_info, &key);
-- 
1.8.2.1


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

* Re: [PATCH] Btrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF
  2015-10-18  5:44 [PATCH] Btrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF Liu Bo
@ 2015-10-18 11:41 ` Qu Wenruo
  2015-10-22 17:08   ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2015-10-18 11:41 UTC (permalink / raw)
  To: Liu Bo, linux-btrfs



在 2015年10月18日 13:44, Liu Bo 写道:
> Btrfs has changed to delete subvolume/snapshot asynchronously, which means that
> after umount itself, if we've already deleted 'ext2_saved', rollback can still
> be completed.
>
> So this adds a check for ROOT_BACKREF before checking ROOT_ITEM since
> ROOT_BACKREF is immediately not in the btree after ioctl(BTRFS_IOC_SNAP_DESTROY)
> returns.
>
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Looks good to me.

Although the error message for ret > 0 case can be improved a little, like:
"unable to find convert image subvolume, maybe it's already deleted?\n".


BTW, would you please submit a test case for fstests? It won't be a hard 
one though.

Thanks,
Qu

> ---
>   btrfs-convert.c | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
>
> diff --git a/btrfs-convert.c b/btrfs-convert.c
> index 802930c..f8a6c16 100644
> --- a/btrfs-convert.c
> +++ b/btrfs-convert.c
> @@ -2591,6 +2591,22 @@ static int do_rollback(const char *devname)
>   	btrfs_init_path(&path);
>
>   	key.objectid = CONV_IMAGE_SUBVOL_OBJECTID;
> +	key.type = BTRFS_ROOT_BACKREF_KEY;
> +	key.offset = BTRFS_FS_TREE_OBJECTID;
> +	ret = btrfs_search_slot(NULL, root->fs_info->tree_root, &key, &path, 0,
> +				0);
> +	btrfs_release_path(&path);
> +	if (ret > 0) {
> +		fprintf(stderr, "unable to open subvol %llu\n",
> +			(unsigned long long)key.objectid);
> +		goto fail;
> +	} else if (ret < 0) {
> +		fprintf(stderr, "unable to open subvol %llu ret %d\n",
> +			(unsigned long long)key.objectid, ret);
> +		goto fail;
> +	}
> +
> +	key.objectid = CONV_IMAGE_SUBVOL_OBJECTID;
>   	key.type = BTRFS_ROOT_ITEM_KEY;
>   	key.offset = (u64)-1;
>   	image_root = btrfs_read_fs_root(root->fs_info, &key);
>

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

* Re: [PATCH] Btrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF
  2015-10-18 11:41 ` Qu Wenruo
@ 2015-10-22 17:08   ` David Sterba
  0 siblings, 0 replies; 3+ messages in thread
From: David Sterba @ 2015-10-22 17:08 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: Liu Bo, linux-btrfs

On Sun, Oct 18, 2015 at 07:41:27PM +0800, Qu Wenruo wrote:
> 在 2015年10月18日 13:44, Liu Bo 写道:
> > Btrfs has changed to delete subvolume/snapshot asynchronously, which means that
> > after umount itself, if we've already deleted 'ext2_saved', rollback can still
> > be completed.
> >
> > So this adds a check for ROOT_BACKREF before checking ROOT_ITEM since
> > ROOT_BACKREF is immediately not in the btree after ioctl(BTRFS_IOC_SNAP_DESTROY)
> > returns.
> >
> > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> 
> Looks good to me.
> 
> Although the error message for ret > 0 case can be improved a little, like:
> "unable to find convert image subvolume, maybe it's already deleted?\n".

I've adjusted the error messages.

> BTW, would you please submit a test case for fstests? It won't be a hard 
> one though.

Test added.

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

end of thread, other threads:[~2015-10-22 17:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-18  5:44 [PATCH] Btrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF Liu Bo
2015-10-18 11:41 ` Qu Wenruo
2015-10-22 17:08   ` 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.