@@ -197,9 +197,10 @@ static int cmd_rm_dev(int argc, char **argv)
}
static const char * const cmd_scan_dev_usage[] = {
- "btrfs device scan [(-d|--all-devices)|<device> [<device>...]]",
+ "btrfs device scan [-s][(-d|--all-devices)|<device> [<device>...]]",
"Scan devices for a btrfs filesystem",
" -d|--all-devices (deprecated)",
+ " -s don't skip lvm snapshot\n",
NULL
};
@@ -209,6 +210,7 @@ static int cmd_scan_dev(int argc, char **argv)
int devstart = 1;
int all = 0;
int ret = 0;
+ int skip_snapshot = btrfs_scan_get_skip_lvm_snapshot();
optind = 1;
while (1) {
@@ -217,7 +219,7 @@ static int cmd_scan_dev(int argc, char **argv)
{ "all-devices", no_argument, NULL, 'd'},
{ 0, 0, 0, 0 },
};
- int c = getopt_long(argc, argv, "d", long_options,
+ int c = getopt_long(argc, argv, "sd", long_options,
&long_index);
if (c < 0)
break;
@@ -225,6 +227,10 @@ static int cmd_scan_dev(int argc, char **argv)
case 'd':
all = 1;
break;
+ case 's':
+ skip_snapshot = 0;
+ devstart++;
+ break;
default:
usage(cmd_scan_dev_usage);
}
@@ -233,7 +239,7 @@ static int cmd_scan_dev(int argc, char **argv)
if (all && check_argc_max(argc, 2))
usage(cmd_scan_dev_usage);
- if (all || argc == 1) {
+ if (all || argc == devstart) {
printf("Scanning for Btrfs filesystems\n");
ret = btrfs_scan_lblkid();
if (ret)
@@ -261,6 +267,11 @@ static int cmd_scan_dev(int argc, char **argv)
ret = 1;
goto out;
}
+ if (skip_snapshot && is_low_priority_device(path)) {
+ fprintf(stderr, "WARNING: skip device '%s' because it is a snapshot\n",
+ argv[i]);
+ continue;
+ }
printf("Scanning for Btrfs filesystems in '%s'\n", path);
if (btrfs_register_one_device(path) != 0) {
ret = 1;
LVM snapshots create a problem to the btrfs devices management. BTRFS assumes that each device has an unique 'device UUID'. A LVM snapshot breaks this assumption. With this patch, 'btrfs device scan' skips LVM snapshot. If you need to consider a LVM snapshot you have to pass the '-s' switch ot set the environment variable BTRFS_SKIP_LVM_SNAPSHOT to "no". Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it> --- cmds-device.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)