All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Lu Fengqi <lufq.fnst@cn.fujitsu.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 08/10] btrfs-progs: undelete-subvol: add undelete-subvol subcommand
Date: Wed, 18 Apr 2018 13:32:29 +0800	[thread overview]
Message-ID: <13f077b1-7128-cf95-5972-383030aa1114@gmx.com> (raw)
In-Reply-To: <20180327070658.13064-9-lufq.fnst@cn.fujitsu.com>


[-- Attachment #1.1: Type: text/plain, Size: 3388 bytes --]



On 2018年03月27日 15:06, Lu Fengqi wrote:
> Add the undelete-subvol subcommand for btrfs rescue. This subcommand is
> used to recover deleted subvolume left intact on the device.
> 
> Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
> ---
> v2: add -s option to specify subvol_id.
> 
>  cmds-rescue.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 70 insertions(+)
> 
> diff --git a/cmds-rescue.c b/cmds-rescue.c
> index c40088ad374e..c5132126e922 100644
> --- a/cmds-rescue.c
> +++ b/cmds-rescue.c
> @@ -25,6 +25,7 @@
>  #include "disk-io.h"
>  #include "commands.h"
>  #include "utils.h"
> +#include "undelete-subvol.h"
>  #include "help.h"
>  
>  static const char * const rescue_cmd_group_usage[] = {
> @@ -248,6 +249,73 @@ out:
>  	return !!ret;
>  }
>  
> +static const char * const cmd_rescue_undelete_subvol_usage[] = {
> +	"btrfs rescue undelete-subvol [-s <subvolid>] <device>",
> +	"Undelete deleted subvolume",
> +	"All deleted subvolume that still left intact on the device will be",
> +	"recovered. If -s <subvolid> option is given, then just recover the",
> +	"subvolume which specified by <subvolid>.",
> +	"",
> +	"-s <subvolid>	specify the subvolume which will be recovered.",
> +	NULL
> +};
> +
> +static int cmd_rescue_undelete_subvol(int argc, char **argv)
> +{
> +	struct btrfs_fs_info *fs_info;
> +	char *devname;
> +	u64 subvol_id = 0;
> +	int ret;
> +
> +	while (1) {
> +		int c = getopt(argc, argv, "s:");
> +
> +		if (c < 0)
> +			break;
> +		switch (c) {
> +		case 's':
> +			subvol_id = arg_strtou64(optarg);
> +			if (!is_fstree(subvol_id)) {
> +				error("%llu is not a valid subvolume id",
> +						subvol_id);
> +				ret = -EINVAL;
> +				goto out;
> +			}
> +			break;
> +		default:
> +			usage(cmd_rescue_undelete_subvol_usage);
> +		}
> +	}
> +
> +	if (check_argc_exact(argc - optind, 1))
> +		usage(cmd_rescue_undelete_subvol_usage);
> +
> +	devname = argv[optind];
> +	ret = check_mounted(devname);
> +	if (ret < 0) {
> +		error("could not check mount status: %s", strerror(-ret));
> +		goto out;
> +	} else if (ret) {
> +		error("%s is currently mounted", devname);
> +		ret = -EBUSY;
> +		goto out;
> +	}
> +
> +	fs_info = open_ctree_fs_info(devname, 0, 0, 0, OPEN_CTREE_WRITES |
> +				     OPEN_CTREE_PARTIAL);

I'm not sure if using OPEN_CTREE_PARTIAL here is a good idea.

As the undelete-subvol looks like a tool to revert stupid user mistake,
and we expect a healthy fs to be provided.
And for corrupted fs, we may make the case worse.

Thanks,
Qu

> +	if (!fs_info) {
> +		error("could not open btrfs");
> +		ret = -EIO;
> +		goto out;
> +	}
> +
> +	ret = btrfs_undelete_intact_subvols(fs_info->tree_root, subvol_id);
> +
> +	close_ctree(fs_info->tree_root);
> +out:
> +	return ret;
> +}
> +
>  static const char rescue_cmd_group_info[] =
>  "toolbox for specific rescue operations";
>  
> @@ -260,6 +328,8 @@ const struct cmd_group rescue_cmd_group = {
>  		{ "zero-log", cmd_rescue_zero_log, cmd_rescue_zero_log_usage, NULL, 0},
>  		{ "fix-device-size", cmd_rescue_fix_device_size,
>  			cmd_rescue_fix_device_size_usage, NULL, 0},
> +		{ "undelete-subvol", cmd_rescue_undelete_subvol,
> +			cmd_rescue_undelete_subvol_usage, NULL, 0},
>  		NULL_CMD_STRUCT
>  	}
>  };
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2018-04-18  5:32 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-27  7:06 [PATCH v2 00/10] undelete subvolume offline version Lu Fengqi
2018-03-27  7:06 ` [PATCH v2 01/10] btrfs-progs: copy btrfs_del_orphan_item from kernel Lu Fengqi
2018-03-27  7:06 ` [PATCH v2 02/10] btrfs-progs: extract btrfs_link_subvol from btrfs_mksubvol Lu Fengqi
2018-04-18  5:02   ` Qu Wenruo
2018-05-07  2:00     ` Lu Fengqi
2018-03-27  7:06 ` [PATCH v2 03/10] btrfs-progs: use btrfs_find_free_dir_index to find free inode index Lu Fengqi
2018-04-18  5:04   ` Qu Wenruo
2018-03-27  7:06 ` [PATCH v2 04/10] btrfs-progs: undelete-subvol: introduce is_subvol_intact Lu Fengqi
2018-04-18  5:12   ` Qu Wenruo
2018-05-07  2:03     ` Lu Fengqi
2018-05-07  2:20       ` Qu Wenruo
2018-05-07 11:40         ` David Sterba
2018-05-07 12:16           ` Qu Wenruo
2018-03-27  7:06 ` [PATCH v2 05/10] btrfs-progs: undelete-subvol: introduce recover_dead_root Lu Fengqi
2018-04-18  5:16   ` Qu Wenruo
2018-05-07  2:04     ` Lu Fengqi
2018-03-27  7:06 ` [PATCH v2 06/10] btrfs-progs: undelete-subvol: introduce link_subvol_to_lostfound Lu Fengqi
2018-04-18  5:21   ` Qu Wenruo
2018-05-07  2:06     ` Lu Fengqi
2018-03-27  7:06 ` [PATCH v2 07/10] btrfs-progs: undelete-subvol: introduce btrfs_undelete_intact_subvols Lu Fengqi
2018-04-18  5:28   ` Qu Wenruo
2018-05-07  2:12     ` Lu Fengqi
2018-03-27  7:06 ` [PATCH v2 08/10] btrfs-progs: undelete-subvol: add undelete-subvol subcommand Lu Fengqi
2018-04-18  5:32   ` Qu Wenruo [this message]
2018-05-07  2:16     ` Lu Fengqi
2018-03-27  7:06 ` [PATCH v2 09/10] btrfs-progs: tests: add testcase for undelete-subvol Lu Fengqi
2018-04-18  5:42   ` Qu Wenruo
2018-05-07  2:28     ` Lu Fengqi
2018-03-27  7:06 ` [PATCH v2 10/10] btrfs-progs: undelete-subvol: update completion and documentation Lu Fengqi
2018-04-18  3:04 ` [PATCH v2 00/10] undelete subvolume offline version Lu Fengqi

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=13f077b1-7128-cf95-5972-383030aa1114@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=lufq.fnst@cn.fujitsu.com \
    /path/to/YOUR_REPLY

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

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