[PATCH v3 0/2] Add a new api wipefs
Hi Rich: This is a alternative patch, if you like the api name called wipefs ;-P Thanks -Wanlong Gao Wanlong Gao (2): NEW API: add a new api wipefs virt-format: erase the filesystem signatures before erase partitions TODO | 2 -- daemon/zero.c | 17 +++++++++++++++++ format/format.c | 19 ++++--------------- generator/generator_actions.ml | 14 ++++++++++++++ src/MAX_PROC_NR | 2 +- 5 files changed, 36 insertions(+), 18 deletions(-) -- 1.7.9
Add the new api wipefs to erase the filesystem signatures on a device but now erase any data. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- TODO | 2 -- daemon/zero.c | 17 +++++++++++++++++ generator/generator_actions.ml | 14 ++++++++++++++ src/MAX_PROC_NR | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 3adb740..b9a4ee9 100644 --- a/TODO +++ b/TODO @@ -318,8 +318,6 @@ Display the structure of an image file as a PS. Greater use of blkid / libblkid ------------------------------- -guestfs_zero should use wipefs. See wipefs(8). - There are various useful functions in libblkid for listing partitions, devices etc which we are essentially duplicating in the daemon. It would make more sense to just use libblkid for this. diff --git a/daemon/zero.c b/daemon/zero.c index 398f844..22a65c4 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -73,6 +73,23 @@ do_zero (const char *device) } int +do_wipefs (const char *device) +{ + int r; + char *err = NULL; + + const char *wipefs[] = {"wipefs", "-a", device, NULL}; + r = commandv (NULL, &err, wipefs); + if (r == -1) { + reply_with_error ("%s", err); + free (err); + return -1; + } + free (err); + return 0; +} + +int do_zero_device (const char *device) { int64_t ssize = do_blockdev_getsize64 (device); diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 3a7be79..b0d0629 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -6651,6 +6651,20 @@ This option may not be specified at the same time as the C<correct> option. =back"); + ("wipefs", (RErr, [Device "device"], []), 305, [Progress], + [InitBasicFSonLVM, Always, TestRun ( + [["wipefs"; "/dev/VG/LV"]])], + "wipe a filesystem signature from a device", + "\ +This command can erase filesystem or raid signatures (magic strings) from +the specified C<device> to make the filesystem invisible for libblkid. +This does not erase the filesystem itself nor any other data from the C<device>. +Compare with C<guestfs_zero> which just zeroes the first few blocks of a +device, contained the partitions on the device, but this C<guestfs_wipefs> +can't erase the partitions of a device. + +=back"); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 873b744..67d04b9 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -304 +305 -- 1.7.9
On Wed, Feb 08, 2012 at 01:32:47PM +0800, Wanlong Gao wrote:
Add the new api wipefs to erase the filesystem signatures on a device but now erase any data.
Having had a bit of time to think about this, I think this comment is right:
-guestfs_zero should use wipefs. See wipefs(8).
wipefs is generally better (than "zero") in that it knows about what's on the disk (via blkid) and only overwrites the minimum necessary to remove partition tables, RAID signatures etc. This is good. What's bad is that: (1) It probably doesn't work for formats that blkid doesn't understand. (2) It doesn't preserve sparseness, although arguably that doesn't matter because it's only overwriting stuff that should be non-zero already. Cf: libblkid/src/probe.c:blkid_do_wipe daemon/zero.c:do_zero On balance, I think that changing guestfs_zero to use wipefs is a better way to approach this, but I'm open to opinions on this ... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
On 02/09/2012 10:12 PM, Richard W.M. Jones wrote:
On Wed, Feb 08, 2012 at 01:32:47PM +0800, Wanlong Gao wrote:
Add the new api wipefs to erase the filesystem signatures on a device but now erase any data.
Having had a bit of time to think about this, I think this comment is right:
-guestfs_zero should use wipefs. See wipefs(8).
wipefs is generally better (than "zero") in that it knows about what's on the disk (via blkid) and only overwrites the minimum necessary to remove partition tables, RAID signatures etc. This is good.
What's bad is that: (1) It probably doesn't work for formats that blkid doesn't understand. (2) It doesn't preserve sparseness, although arguably that doesn't matter because it's only overwriting stuff that should be non-zero already.
Cf: libblkid/src/probe.c:blkid_do_wipe daemon/zero.c:do_zero
On balance, I think that changing guestfs_zero to use wipefs is a better way to approach this, but I'm open to opinions on this ...
Yeah, I also considered about this, since wipefs can't erase the partition table, but guestfs_zero does, so, I'm afraid that if I use wipefs(8) to change the internal of guestfs_zero, the function also changed. Then, I also considered about just using libblkid's api to implement this api, guestfs_wipefs or guestfs_zero, but I looked into util-linux and found that the blkid_do_wipe() was introduced recently, not for long, and it may not be in RHEL5, so, I just used the wipefs(8) to do this thing. Here, if you like to change guestfs_zero's internal to use wipefs, I'd like to do it, too. ;-P Thanks -Wanlong Gao
Rich.
On Thu, Feb 09, 2012 at 11:34:43PM +0800, Wanlong Gao wrote:
On 02/09/2012 10:12 PM, Richard W.M. Jones wrote:
On Wed, Feb 08, 2012 at 01:32:47PM +0800, Wanlong Gao wrote:
Add the new api wipefs to erase the filesystem signatures on a device but now erase any data.
Having had a bit of time to think about this, I think this comment is right:
-guestfs_zero should use wipefs. See wipefs(8).
wipefs is generally better (than "zero") in that it knows about what's on the disk (via blkid) and only overwrites the minimum necessary to remove partition tables, RAID signatures etc. This is good.
What's bad is that: (1) It probably doesn't work for formats that blkid doesn't understand. (2) It doesn't preserve sparseness, although arguably that doesn't matter because it's only overwriting stuff that should be non-zero already.
Cf: libblkid/src/probe.c:blkid_do_wipe daemon/zero.c:do_zero
On balance, I think that changing guestfs_zero to use wipefs is a better way to approach this, but I'm open to opinions on this ...
Yeah, I also considered about this, since wipefs can't erase the partition table, but guestfs_zero does, so, I'm afraid that if I use wipefs(8) to change the internal of guestfs_zero, the function also changed.
Right, I see. It sounds like a new wipefs API is the way to go in that case. However, it needs to be in an optional group. Just add [Optional "wipefs"] to the flags field in generator/generator_actions.ml, and add a function called optgroup_wipefs_available(), and everything else should be generated automatically. See existing optgroup_*_available functions for examples. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
On Wed, Feb 08, 2012 at 01:32:47PM +0800, Wanlong Gao wrote:
+ ("wipefs", (RErr, [Device "device"], []), 305, [Progress],
BTW, I think the 'Progress' flag is wrong here, since this function doesn't generate progress messages. It's not even long-running. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
erase the filesystem signatures on each device, then erase the partitions, avoid to list all the partitions here. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- format/format.c | 19 ++++--------------- 1 files changed, 4 insertions(+), 15 deletions(-) diff --git a/format/format.c b/format/format.c index b3a47cd..6799fd4 100644 --- a/format/format.c +++ b/format/format.c @@ -323,22 +323,11 @@ do_format (void) /* Erase the disks. */ if (!wipe) { - char **parts; - - /* No wipe, but get rid of LVM metadata by erasing each partition. */ - parts = guestfs_list_partitions (g); - if (parts == NULL) - exit (EXIT_FAILURE); - - for (i = 0; parts[i] != NULL; ++i) { - if (guestfs_zero (g, parts[i]) == -1) - exit (EXIT_FAILURE); - free (parts[i]); - } - free (parts); - - /* Then erase the partition table on each device. */ for (i = 0; devices[i] != NULL; ++i) { + /* erase the filesystem signatures on each device */ + if (guestfs_wipefs (g, devices[i]) == -1) + exit (EXIT_FAILURE); + /* Then erase the partition table on each device. */ if (guestfs_zero (g, devices[i]) == -1) exit (EXIT_FAILURE); } -- 1.7.9
participants (3)
-
Richard W.M. Jones -
Wanlong Gao -
Wanlong Gao