* [PATCH v2 1/5] btrfs: add command to zero out superblock
@ 2012-05-01 12:40 Hubert Kario
2012-05-01 12:40 ` [PATCH v2 2/5] handle null pointers in btrfs_prepare_device Hubert Kario
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Hubert Kario @ 2012-05-01 12:40 UTC (permalink / raw)
To: linux-btrfs
Signed-off-by: Hubert Kario <kario@wit.edu.pl>
diff --git a/cmds-device.c b/cmds-device.c
index db625a6..05a549c 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -246,11 +246,58 @@ static int cmd_scan_dev(int argc, char **argv)
return 0;
}
+static const char * const cmd_zero_dev_usage[] = {
+ "btrfs device zero-superblock <device> [<device> ...]",
+ "Remove btrfs filesystem superblock from devices.",
+ "WARNING! This command will make filesystem residing on the devices",
+ "completely unmountable!",
+ NULL
+};
+
+static int cmd_zero_dev(int argc, char **argv)
+{
+ int fd;
+ char *file;
+ int arg_processed;
+ int ret = 0;
+ int n;
+ u64 device_len;
+ int mixed_mode_needed = 1; /* keep btrfs_prepare_device() quiet */
+ const int ZERO_END = 1;
+
+ if( argc < 2 ) {
+ usage(cmd_zero_dev_usage);
+ }
+
+ for(arg_processed = 1; arg_processed < argc; arg_processed++) {
+ file = argv[arg_processed];
+
+ fd = open(file, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "Unable to open %s\n", file);
+ ret |= 1;
+ continue;
+ }
+
+ n = btrfs_prepare_device(fd, file, ZERO_END, &device_len,
+ &mixed_mode_needed);
+ if (n) {
+ fprintf(stderr, "Error when zeroing out %s\n", file);
+ ret |= n;
+ }
+
+ close(fd);
+ }
+
+ return ret;
+}
+
const struct cmd_group device_cmd_group = {
device_cmd_group_usage, NULL, {
{ "add", cmd_add_dev, cmd_add_dev_usage, NULL, 0 },
{ "delete", cmd_rm_dev, cmd_rm_dev_usage, NULL, 0 },
{ "scan", cmd_scan_dev, cmd_scan_dev_usage, NULL, 0 },
+ { "zero-superblock", cmd_zero_dev, cmd_zero_dev_usage, NULL, 0 },
{ 0, 0, 0, 0, 0 }
}
};
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index be478e0..a840f7e 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -39,6 +39,8 @@ btrfs \- control a btrfs filesystem
.PP
\fBbtrfs\fP \fBdevice delete\fP\fI <device> [<device>...] <path> \fP
.PP
+\fBbtrfs\fP \fBdevice zero-superblock\fP\fI <device> [<device>...] \fP
+.PP
\fBbtrfs\fP \fBscrub start\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP}
.PP
\fBbtrfs\fP \fBscrub cancel\fP {\fI<path>\fP|\fI<device>\fP}
@@ -230,6 +232,11 @@ Finally, if \fB--all-devices\fP is passed, all the devices under /dev are
scanned.
.TP
+\fBdevice zero-superblock\fR\fI <dev> [<dev>..]\fR
+The space on the disk where btrfs metadata can reside is overwritten with
+zeros.
+.TP
+
\fBscrub start\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP}
Start a scrub on all devices of the filesystem identified by \fI<path>\fR or on
a single \fI<device>\fR. Without options, scrub is started as a background
--
1.7.10
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/5] handle null pointers in btrfs_prepare_device
2012-05-01 12:40 [PATCH v2 1/5] btrfs: add command to zero out superblock Hubert Kario
@ 2012-05-01 12:40 ` Hubert Kario
2012-05-01 12:40 ` [PATCH v2 3/5] Remove unused option " Hubert Kario
2012-05-02 14:28 ` [PATCH v2 1/5] btrfs: add command to zero out superblock David Sterba
2 siblings, 0 replies; 10+ messages in thread
From: Hubert Kario @ 2012-05-01 12:40 UTC (permalink / raw)
To: linux-btrfs
When calling the function from `btrfs device zero-super` we don't need
the additional information returned and don't want the "SMALL VOLUME"
warning printed.
Signed-off-by: Hubert Kario <kario@wit.edu.pl>
diff --git a/utils.c b/utils.c
index ee7fa1b..6773be0 100644
--- a/utils.c
+++ b/utils.c
@@ -557,7 +557,7 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
}
zero_end = 1;
- if (block_count < 1024 * 1024 * 1024 && !(*mixed)) {
+ if (mixed && block_count < 1024 * 1024 * 1024 && !(*mixed)) {
printf("SMALL VOLUME: forcing mixed metadata/data groups\n");
*mixed = 1;
}
@@ -588,7 +588,9 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
exit(1);
}
}
- *block_count_ret = block_count;
+
+ if (block_count_ret)
+ *block_count_ret = block_count;
return 0;
}
--
1.7.10
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/5] Remove unused option in btrfs_prepare_device
2012-05-01 12:40 [PATCH v2 1/5] btrfs: add command to zero out superblock Hubert Kario
2012-05-01 12:40 ` [PATCH v2 2/5] handle null pointers in btrfs_prepare_device Hubert Kario
@ 2012-05-01 12:40 ` Hubert Kario
2012-05-02 14:28 ` [PATCH v2 1/5] btrfs: add command to zero out superblock David Sterba
2 siblings, 0 replies; 10+ messages in thread
From: Hubert Kario @ 2012-05-01 12:40 UTC (permalink / raw)
To: linux-btrfs
zero_end is set explicitly to 1 inside the fuction so the device end
always will be zeroed out
Signed-off-by: Hubert Kario <kario@wit.edu.pl>
diff --git a/btrfs-vol.c b/btrfs-vol.c
index 0efdbc1..c7b9f80 100644
--- a/btrfs-vol.c
+++ b/btrfs-vol.c
@@ -150,7 +150,7 @@ int main(int ac, char **av)
if (cmd == BTRFS_IOC_ADD_DEV) {
int mixed = 0;
- ret = btrfs_prepare_device(devfd, device, 1, &dev_block_count, &mixed);
+ ret = btrfs_prepare_device(devfd, device, &dev_block_count, &mixed);
if (ret) {
fprintf(stderr, "Unable to init %s\n", device);
exit(1);
diff --git a/cmds-device.c b/cmds-device.c
index 05a549c..a28752f 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -107,7 +107,7 @@ static int cmd_add_dev(int argc, char **argv)
continue;
}
- res = btrfs_prepare_device(devfd, argv[i], 1, &dev_block_count, &mixed);
+ res = btrfs_prepare_device(devfd, argv[i], &dev_block_count, &mixed);
if (res) {
fprintf(stderr, "ERROR: Unable to init '%s'\n", argv[i]);
close(devfd);
@@ -263,7 +263,6 @@ static int cmd_zero_dev(int argc, char **argv)
int n;
u64 device_len;
int mixed_mode_needed = 1; /* keep btrfs_prepare_device() quiet */
- const int ZERO_END = 1;
if( argc < 2 ) {
usage(cmd_zero_dev_usage);
@@ -279,8 +278,8 @@ static int cmd_zero_dev(int argc, char **argv)
continue;
}
- n = btrfs_prepare_device(fd, file, ZERO_END, &device_len,
- &mixed_mode_needed);
+ n = btrfs_prepare_device(fd, file, &device_len,
+ &mixed_mode_needed);
if (n) {
fprintf(stderr, "Error when zeroing out %s\n", file);
ret |= n;
diff --git a/mkfs.c b/mkfs.c
index c531ef2..7d1165f 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1209,7 +1209,6 @@ int main(int ac, char **av)
u32 sectorsize = 4096;
u32 nodesize = leafsize;
u32 stripesize = 4096;
- int zero_end = 1;
int option_index = 0;
int fd;
int ret;
@@ -1264,7 +1263,6 @@ int main(int ac, char **av)
"metadata/data groups\n");
mixed = 1;
}
- zero_end = 0;
break;
case 'V':
print_version();
@@ -1311,7 +1309,7 @@ int main(int ac, char **av)
exit(1);
}
first_file = file;
- ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count, &mixed);
+ ret = btrfs_prepare_device(fd, file, &dev_block_count, &mixed);
if (block_count == 0)
block_count = dev_block_count;
} else {
@@ -1376,7 +1374,6 @@ int main(int ac, char **av)
btrfs_register_one_device(file);
- zero_end = 1;
while(ac-- > 0) {
int old_mixed = mixed;
@@ -1404,8 +1401,7 @@ int main(int ac, char **av)
close(fd);
continue;
}
- ret = btrfs_prepare_device(fd, file, zero_end,
- &dev_block_count, &mixed);
+ ret = btrfs_prepare_device(fd, file, &dev_block_count, &mixed);
mixed = old_mixed;
BUG_ON(ret);
diff --git a/utils.c b/utils.c
index 6773be0..e2c72ad 100644
--- a/utils.c
+++ b/utils.c
@@ -536,8 +536,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
return 0;
}
-int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
- int *mixed)
+int btrfs_prepare_device(int fd, char *file, u64 *block_count_ret, int *mixed)
{
u64 block_count;
u64 bytenr;
@@ -555,7 +554,6 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
fprintf(stderr, "unable to find %s size\n", file);
exit(1);
}
- zero_end = 1;
if (mixed && block_count < 1024 * 1024 * 1024 && !(*mixed)) {
printf("SMALL VOLUME: forcing mixed metadata/data groups\n");
@@ -581,12 +579,10 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
zero_blocks(fd, bytenr, BTRFS_SUPER_INFO_SIZE);
}
- if (zero_end) {
- ret = zero_dev_end(fd, block_count);
- if (ret) {
- fprintf(stderr, "failed to zero device end %d\n", ret);
- exit(1);
- }
+ ret = zero_dev_end(fd, block_count);
+ if (ret) {
+ fprintf(stderr, "failed to zero device end %d\n", ret);
+ exit(1);
}
if (block_count_ret)
diff --git a/utils.h b/utils.h
index c5f55e1..b7ba663 100644
--- a/utils.h
+++ b/utils.h
@@ -26,8 +26,8 @@ int make_btrfs(int fd, const char *device, const char *label,
u32 leafsize, u32 sectorsize, u32 stripesize);
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid);
-int btrfs_prepare_device(int fd, char *file, int zero_end,
- u64 *block_count_ret, int *mixed);
+int btrfs_prepare_device(int fd, char *file, u64 *block_count_ret,
+ int *mixed);
int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
struct btrfs_root *root, int fd, char *path,
u64 block_count, u32 io_width, u32 io_align,
--
1.7.10
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/5] btrfs: add command to zero out superblock
2012-05-01 12:40 [PATCH v2 1/5] btrfs: add command to zero out superblock Hubert Kario
2012-05-01 12:40 ` [PATCH v2 2/5] handle null pointers in btrfs_prepare_device Hubert Kario
2012-05-01 12:40 ` [PATCH v2 3/5] Remove unused option " Hubert Kario
@ 2012-05-02 14:28 ` David Sterba
2012-05-02 14:48 ` David Sterba
2012-05-02 16:42 ` Hubert Kario
2 siblings, 2 replies; 10+ messages in thread
From: David Sterba @ 2012-05-02 14:28 UTC (permalink / raw)
To: Hubert Kario; +Cc: linux-btrfs
On Tue, May 01, 2012 at 02:40:29PM +0200, Hubert Kario wrote:
> +static const char * const cmd_zero_dev_usage[] = {
> + "btrfs device zero-superblock <device> [<device> ...]",
FYI, this step is named 'clear superblock' in kernel code as done after the
device is removed, and I suggest to consider to name the command like
'clear-superblock' or 'clear-sb'.
Also, kernel clears only the "superblock magic" string, ie. the
"_BHRfS_M" bytes. This leaves the rest of the superblock intact, for
possible recovery when it's cleared accidentally.
I had prototyped a similar utility (in perl, so nothing for progs
inclusion for now) and rewrote the magic string with _BHRf$_M ie. the
S -> $ for visual similarity with the action performed. This allows to
detect cleared superblocks and activate them back eventually.
I'm not sure if this is useful and sensible usecase, clearing superblock
is a one-time action anyway, so it's more for the sake of tool
flexibility.
To your implementation: I think adding a function doing the superblock
reset would be enough here. Something like this (in pseudocode):
for (i = 0 ; i < BTRFS_SUPER_MIRROR_MAX; i++) {
bytenr = btrfs_sb_offset(i);
"break if bytenr > device size"
memset(superblock buffer, CLEARPATTERN, sizeof(...))
}
write_all_supers(root);
david
> + "Remove btrfs filesystem superblock from devices.",
> + "WARNING! This command will make filesystem residing on the devices",
> + "completely unmountable!",
> + NULL
> +};
> +
> +static int cmd_zero_dev(int argc, char **argv)
> +{
> + int fd;
> + char *file;
> + int arg_processed;
> + int ret = 0;
> + int n;
> + u64 device_len;
> + int mixed_mode_needed = 1; /* keep btrfs_prepare_device() quiet */
> + const int ZERO_END = 1;
> +
> + if( argc < 2 ) {
> + usage(cmd_zero_dev_usage);
> + }
> +
> + for(arg_processed = 1; arg_processed < argc; arg_processed++) {
> + file = argv[arg_processed];
> +
> + fd = open(file, O_RDWR);
> + if (fd < 0) {
> + fprintf(stderr, "Unable to open %s\n", file);
> + ret |= 1;
> + continue;
> + }
> +
> + n = btrfs_prepare_device(fd, file, ZERO_END, &device_len,
> + &mixed_mode_needed);
> + if (n) {
> + fprintf(stderr, "Error when zeroing out %s\n", file);
> + ret |= n;
> + }
> +
> + close(fd);
> + }
> +
> + return ret;
> +}
> +
> const struct cmd_group device_cmd_group = {
> device_cmd_group_usage, NULL, {
> { "add", cmd_add_dev, cmd_add_dev_usage, NULL, 0 },
> { "delete", cmd_rm_dev, cmd_rm_dev_usage, NULL, 0 },
> { "scan", cmd_scan_dev, cmd_scan_dev_usage, NULL, 0 },
> + { "zero-superblock", cmd_zero_dev, cmd_zero_dev_usage, NULL, 0 },
> { 0, 0, 0, 0, 0 }
> }
> };
> diff --git a/man/btrfs.8.in b/man/btrfs.8.in
> index be478e0..a840f7e 100644
> --- a/man/btrfs.8.in
> +++ b/man/btrfs.8.in
> @@ -39,6 +39,8 @@ btrfs \- control a btrfs filesystem
> .PP
> \fBbtrfs\fP \fBdevice delete\fP\fI <device> [<device>...] <path> \fP
> .PP
> +\fBbtrfs\fP \fBdevice zero-superblock\fP\fI <device> [<device>...] \fP
> +.PP
> \fBbtrfs\fP \fBscrub start\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP}
> .PP
> \fBbtrfs\fP \fBscrub cancel\fP {\fI<path>\fP|\fI<device>\fP}
> @@ -230,6 +232,11 @@ Finally, if \fB--all-devices\fP is passed, all the devices under /dev are
> scanned.
> .TP
>
> +\fBdevice zero-superblock\fR\fI <dev> [<dev>..]\fR
> +The space on the disk where btrfs metadata can reside is overwritten with
> +zeros.
> +.TP
> +
> \fBscrub start\fP [-Bdqru] {\fI<path>\fP|\fI<device>\fP}
> Start a scrub on all devices of the filesystem identified by \fI<path>\fR or on
> a single \fI<device>\fR. Without options, scrub is started as a background
> --
> 1.7.10
>
> --
> 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] 10+ messages in thread
* Re: [PATCH v2 1/5] btrfs: add command to zero out superblock
2012-05-02 14:28 ` [PATCH v2 1/5] btrfs: add command to zero out superblock David Sterba
@ 2012-05-02 14:48 ` David Sterba
2012-05-02 16:42 ` Hubert Kario
1 sibling, 0 replies; 10+ messages in thread
From: David Sterba @ 2012-05-02 14:48 UTC (permalink / raw)
To: Hubert Kario, linux-btrfs
[-- Attachment #1: Type: text/plain, Size: 169 bytes --]
On Wed, May 02, 2012 at 04:28:43PM +0200, David Sterba wrote:
> I had prototyped a similar utility (in perl, so nothing for progs
> inclusion for now)
attached.
david
[-- Attachment #2: btrfs-dev-clear-sb --]
[-- Type: text/plain, Size: 1708 bytes --]
#!/usr/bin/perl
# clear btrfs signature from a device
use Fcntl;
use constant BTRFS_SUPER_INFO_OFFSET => 64 * 1024;
use constant BTRFS_SUPER_INFO_SIZE => 4096;
use constant BTRFS_SUPER_MIRROR_MAX => 3;
use constant BTRFS_SUPER_MIRROR_SHIFT => 12;
use constant BTRFS_MAGIC => "_BHRfS_M";
use constant BTRFS_DEAD => '_BHRf$_M';
sub btrfs_sb_offset($) {
my $mirror =$_[0];
my $start = 16 * 1024;
if ($mirror>0) {
return $start << (BTRFS_SUPER_MIRROR_SHIFT * $mirror);
}
return BTRFS_SUPER_INFO_OFFSET;
}
my $dbg=1;
my $savesb=0;
# main
my $dev=$ARGV[0];
my $size;
if(!-b $dev) {
print("Not a block device: $dev\n");
$size=(stat($dev))[7];
} else {
$size=`blockdev --getsize64 "$dev"`;
}
sysopen(F, $dev, O_EXCL | O_RDWR) or die("Cannot open $dev exclusively: $!");
print("Device size: $size\n") if($dbg);
for(my $i=0;$i<6;$i++) {
my $off=btrfs_sb_offset($i);
if($off > $size) {
print("Offset for SB $i beyond EOF\n") if($dbg);
last;
}
print("Offset $i is $off\n") if($dbg);
sysseek(F, $off, 0);
sysread(F, $buf, BTRFS_SUPER_INFO_SIZE);
if($savesb) {
open(Q,">SB$i");
print Q ($buf);
close(Q);
}
my $sbmagic=substr($buf, 0x40, length(BTRFS_MAGIC));
print("SB magic: $sbmagic\n") if($dbg);
if(BTRFS_MAGIC eq $sbmagic) {
print("Found a valid signature of superblock $i\n");
sysseek(F, $off + 0x40, 0);
print("Clearing...\n");
syswrite(F, BTRFS_DEAD, length(BTRFS_DEAD));
} elsif(BTRFS_DEAD eq $sbmagic) {
print("Found a signature of a dead superblock $i\n");
} else {
print("Superblock $i does not look like a btrfs one\n");
}
}
close(F);
print("Syncing dev\n");
if (!-b $dev) {
system("fsync \'$dev\'");
} else {
system("blockdev --flushbufs \'$dev\'");
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/5] btrfs: add command to zero out superblock
2012-05-02 14:28 ` [PATCH v2 1/5] btrfs: add command to zero out superblock David Sterba
2012-05-02 14:48 ` David Sterba
@ 2012-05-02 16:42 ` Hubert Kario
2012-05-02 17:36 ` David Sterba
1 sibling, 1 reply; 10+ messages in thread
From: Hubert Kario @ 2012-05-02 16:42 UTC (permalink / raw)
To: dave, linux-btrfs
On Wednesday 02 of May 2012 16:28:43 David Sterba wrote:
> On Tue, May 01, 2012 at 02:40:29PM +0200, Hubert Kario wrote:
> > +static const char * const cmd_zero_dev_usage[] =3D {
> > + "btrfs device zero-superblock <device> [<device> ...]",
>=20
> FYI, this step is named 'clear superblock' in kernel code as done aft=
er the
> device is removed, and I suggest to consider to name the command like
> 'clear-superblock' or 'clear-sb'.
A similar function in mdadm is called zero superblock so I just re used=
the=20
name (according to the principle of least surprise). Users, even admins=
,=20
generally don't read kernel code...
=20
> Also, kernel clears only the "superblock magic" string, ie. the
> "_BHRfS_M" bytes. This leaves the rest of the superblock intact, for
> possible recovery when it's cleared accidentally.
That's when a device is removed from the filesystem, not when a filesys=
tem is=20
just not used any more and you want to re-purpose the devices.
> I had prototyped a similar utility (in perl, so nothing for progs
> inclusion for now) and rewrote the magic string with _BHRf$_M ie. the
> S -> $ for visual similarity with the action performed. This allows t=
o
> detect cleared superblocks and activate them back eventually.
>=20
> I'm not sure if this is useful and sensible usecase, clearing superbl=
ock
> is a one-time action anyway, so it's more for the sake of tool
> flexibility.
Clearing superblock is not a light decision and should generally be per=
formed=20
just before formatting the partition with some other fs or physical vol=
ume for=20
LVM. IMHO recoverability of "cleared" superblock is a function hardly a=
nyone=20
would use.
=20
> To your implementation: I think adding a function doing the superbloc=
k
> reset would be enough here. Something like this (in pseudocode):
>=20
> for (i =3D 0 ; i < BTRFS_SUPER_MIRROR_MAX; i++) {
> bytenr =3D btrfs_sb_offset(i);
> "break if bytenr > device size"
> memset(superblock buffer, CLEARPATTERN, sizeof(...))
> }
> write_all_supers(root);
That's exactly what btrfs_prepare_device does. And it's a function run =
by btfs=20
just before btrfs dev add and by mkfs. Duplicating its code would be a =
bad=20
idea.
Regards,
--=20
Hubert Kario
QBS - Quality Business Software
02-656 Warszawa, ul. Ksawer=F3w 30/85
tel. +48 (22) 646-61-51, 646-74-24
www.qbs.com.pl
--
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] 10+ messages in thread
* Re: [PATCH v2 1/5] btrfs: add command to zero out superblock
2012-05-02 16:42 ` Hubert Kario
@ 2012-05-02 17:36 ` David Sterba
2012-05-03 13:11 ` Hubert Kario
0 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2012-05-02 17:36 UTC (permalink / raw)
To: Hubert Kario; +Cc: dave, linux-btrfs
On Wed, May 02, 2012 at 06:42:16PM +0200, Hubert Kario wrote:
> A similar function in mdadm is called zero superblock so I just re used the
> name (according to the principle of least surprise). Users, even admins,
> generally don't read kernel code...
I intended to point out that the functionality is there under different
name, but the 'least surprise' and tool compatibility plays for
'zero-superblock' naming.
> > I'm not sure if this is useful and sensible usecase, clearing superblock
> > is a one-time action anyway, so it's more for the sake of tool
> > flexibility.
>
> Clearing superblock is not a light decision and should generally be performed
> just before formatting the partition with some other fs or physical volume for
> LVM. IMHO recoverability of "cleared" superblock is a function hardly anyone
> would use.
googled, a few users asking about recovering from md zero-superblock, and
the solution was to recreate the array, md is said to be smart and
recognize traces of previous array and will not destroy it if the
parameters are same. Point for md, btrfs does not do this.
> > To your implementation: I think adding a function doing the superblock
> > reset would be enough here. Something like this (in pseudocode):
> >
> > for (i = 0 ; i < BTRFS_SUPER_MIRROR_MAX; i++) {
> > bytenr = btrfs_sb_offset(i);
> > "break if bytenr > device size"
> > memset(superblock buffer, CLEARPATTERN, sizeof(...))
> > }
> > write_all_supers(root);
>
> That's exactly what btrfs_prepare_device does. And it's a function run by btfs
> just before btrfs dev add and by mkfs. Duplicating its code would be a bad
> idea.
Not 'exactly' IMO:
* calls TRIM/discard on the device
* zeroes first 2 megabytes
* zeroes all reachable superblocks
* zeroes last 2 megabytes
Too many undocumented and unobvious side-efects.
Code duplication can be avoided by factoring the 'zero superblock' into
a function and calling it from btrfs_prepare_device() .
david
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/5] btrfs: add command to zero out superblock
2012-05-02 17:36 ` David Sterba
@ 2012-05-03 13:11 ` Hubert Kario
2012-05-09 17:18 ` David Sterba
0 siblings, 1 reply; 10+ messages in thread
From: Hubert Kario @ 2012-05-03 13:11 UTC (permalink / raw)
To: dave; +Cc: linux-btrfs
On Wednesday 02 of May 2012 19:36:29 David Sterba wrote:
> On Wed, May 02, 2012 at 06:42:16PM +0200, Hubert Kario wrote:
> > > I'm not sure if this is useful and sensible usecase, clearing sup=
erblock
> > > is a one-time action anyway, so it's more for the sake of tool
> > > flexibility.
> >=20
> > Clearing superblock is not a light decision and should generally be
> > performed just before formatting the partition with some other fs o=
r
> > physical volume for LVM. IMHO recoverability of "cleared" superbloc=
k is a
> > function hardly anyone would use.
>=20
> googled, a few users asking about recovering from md zero-superblock,=
and
> the solution was to recreate the array, md is said to be smart and
> recognize traces of previous array and will not destroy it if the
> parameters are same. Point for md, btrfs does not do this.
nice, didn't know about this. Such functionality would be nice to have.
But then I don't think that a "recreate the array if the parameters are=
the=20
same" is actually a good idea, lots of space for error. A pair of funct=
ions:
btrfs dev zero-superblock
btrfs dev restore-superblock
would be a better solution IMO
=20
> > > To your implementation: I think adding a function doing the super=
block
> > > reset would be enough here. Something like this (in pseudocode):
> > >=20
> > > for (i =3D 0 ; i < BTRFS_SUPER_MIRROR_MAX; i++) {
> > >=20
> > > bytenr =3D btrfs_sb_offset(i);
> > > "break if bytenr > device size"
> > > memset(superblock buffer, CLEARPATTERN, sizeof(...))
> > >=20
> > > }
> > > write_all_supers(root);
> >=20
> > That's exactly what btrfs_prepare_device does. And it's a function =
run by
> > btfs just before btrfs dev add and by mkfs. Duplicating its code wo=
uld be
> > a bad idea.
>=20
> Not 'exactly' IMO:
>=20
> * calls TRIM/discard on the device
> * zeroes first 2 megabytes
> * zeroes all reachable superblocks
> * zeroes last 2 megabytes
>=20
> Too many undocumented and unobvious side-efects.
True. But close enough ;)
> Code duplication can be avoided by factoring the 'zero superblock' in=
to
> a function and calling it from btrfs_prepare_device().
Then there's also the "actually zero" vs "reversibly destroy" differenc=
e but=20
it's trivial to fix using a single option.
Regards
--=20
Hubert Kario
QBS - Quality Business Software
02-656 Warszawa, ul. Ksawer=F3w 30/85
tel. +48 (22) 646-61-51, 646-74-24
www.qbs.com.pl
--
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] 10+ messages in thread
* Re: [PATCH v2 1/5] btrfs: add command to zero out superblock
2012-05-03 13:11 ` Hubert Kario
@ 2012-05-09 17:18 ` David Sterba
2012-05-09 17:23 ` Hubert Kario
0 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2012-05-09 17:18 UTC (permalink / raw)
To: Hubert Kario; +Cc: dave, linux-btrfs
On Thu, May 03, 2012 at 03:11:45PM +0200, Hubert Kario wrote:
> nice, didn't know about this. Such functionality would be nice to have.
> But then I don't think that a "recreate the array if the parameters are the
> same" is actually a good idea, lots of space for error. A pair of functions:
>
> btrfs dev zero-superblock
> btrfs dev restore-superblock
As a user, I'm not sure what can I expect from the restore command. From
where does it restore? Eg. a file?
As a tester I have use for a temporary clearing of a superblock on a
device, then mount it with -o degraded, work work, and then undo
clearing. So, my idea is like
btrfs device zero-superblock --undo
with the obvious sanity checks. A regular user would never need to call
this.
david
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/5] btrfs: add command to zero out superblock
2012-05-09 17:18 ` David Sterba
@ 2012-05-09 17:23 ` Hubert Kario
0 siblings, 0 replies; 10+ messages in thread
From: Hubert Kario @ 2012-05-09 17:23 UTC (permalink / raw)
To: dave; +Cc: linux-btrfs
On Wednesday 09 of May 2012 19:18:07 David Sterba wrote:
> On Thu, May 03, 2012 at 03:11:45PM +0200, Hubert Kario wrote:
> > nice, didn't know about this. Such functionality would be nice to h=
ave.
> > But then I don't think that a "recreate the array if the parameters=
are
> > the
> > same" is actually a good idea, lots of space for error. A pair of
> > functions:
> >=20
> > btrfs dev zero-superblock
> > btrfs dev restore-superblock
>=20
> As a user, I'm not sure what can I expect from the restore command. F=
rom
> where does it restore? Eg. a file?
>=20
> As a tester I have use for a temporary clearing of a superblock on a
> device, then mount it with -o degraded, work work, and then undo
> clearing. So, my idea is like
>=20
> btrfs device zero-superblock --undo
>=20
> with the obvious sanity checks. A regular user would never need to ca=
ll
> this.
Yes, that's a better idea.
--=20
Hubert Kario
QBS - Quality Business Software
02-656 Warszawa, ul. Ksawer=F3w 30/85
tel. +48 (22) 646-61-51, 646-74-24
www.qbs.com.pl
--
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] 10+ messages in thread
end of thread, other threads:[~2012-05-09 17:23 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-01 12:40 [PATCH v2 1/5] btrfs: add command to zero out superblock Hubert Kario
2012-05-01 12:40 ` [PATCH v2 2/5] handle null pointers in btrfs_prepare_device Hubert Kario
2012-05-01 12:40 ` [PATCH v2 3/5] Remove unused option " Hubert Kario
2012-05-02 14:28 ` [PATCH v2 1/5] btrfs: add command to zero out superblock David Sterba
2012-05-02 14:48 ` David Sterba
2012-05-02 16:42 ` Hubert Kario
2012-05-02 17:36 ` David Sterba
2012-05-03 13:11 ` Hubert Kario
2012-05-09 17:18 ` David Sterba
2012-05-09 17:23 ` Hubert Kario
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).