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[] = { > > + "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'.
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... > 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 filesystem is 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 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. 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. > 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. Regards, -- Hubert Kario QBS - Quality Business Software 02-656 Warszawa, ul. Ksawerów 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 majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html