[PATCH 1/3] NEW API: add a new api zero_fs
Add the new api zero_fs to erase the filesystem signatures on a device but now erase any data. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/zero.c | 17 +++++++++++++++++ generator/generator_actions.ml | 14 ++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 32 insertions(+), 1 deletions(-) diff --git a/daemon/zero.c b/daemon/zero.c index 398f844..348869f 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -73,6 +73,23 @@ do_zero (const char *device) } int +do_zero_fs (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..d27ef43 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"); + ("zero_fs", (RErr, [Device "device"], []), 305, [Progress], + [InitBasicFSonLVM, Always, TestRun ( + [["zero_fs"; "/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_zero_fs> +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
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..3adb639 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_zero_fs (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
fix coding style to be consistent with others. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/md.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/daemon/md.c b/daemon/md.c index 41e2c75..5432213 100644 --- a/daemon/md.c +++ b/daemon/md.c @@ -244,7 +244,7 @@ do_md_detail(const char *md) char **ret = NULL; int size = 0, alloc = 0; - const char *mdadm[] = { "mdadm", "-D", "--export", md, NULL }; + const char *mdadm[] = {"mdadm", "-D", "--export", md, NULL }; r = commandv (&out, &err, mdadm); if (r == -1) { reply_with_error ("%s", err); @@ -315,16 +315,16 @@ error: } int -do_md_stop(const char *md) +do_md_stop (const char *md) { int r; char *err = NULL; - const char *mdadm[] = { "mdadm", "--stop", md, NULL}; - r = commandv(NULL, &err, mdadm); + const char *mdadm[] = {"mdadm", "--stop", md, NULL}; + r = commandv (NULL, &err, mdadm); if (r == -1) { - reply_with_error("%s", err); - free(err); + reply_with_error ("%s", err); + free (err); return -1; } free (err); -- 1.7.9
On Mon, Feb 06, 2012 at 04:17:07PM +0800, Wanlong Gao wrote:
fix coding style to be consistent with others.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/md.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/daemon/md.c b/daemon/md.c index 41e2c75..5432213 100644 --- a/daemon/md.c +++ b/daemon/md.c @@ -244,7 +244,7 @@ do_md_detail(const char *md) char **ret = NULL; int size = 0, alloc = 0;
- const char *mdadm[] = { "mdadm", "-D", "--export", md, NULL }; + const char *mdadm[] = {"mdadm", "-D", "--export", md, NULL };
I think we should either have both spaces or neither space :-)
r = commandv (&out, &err, mdadm); if (r == -1) { reply_with_error ("%s", err); @@ -315,16 +315,16 @@ error: }
int -do_md_stop(const char *md) +do_md_stop (const char *md) { int r; char *err = NULL;
- const char *mdadm[] = { "mdadm", "--stop", md, NULL}; - r = commandv(NULL, &err, mdadm); + const char *mdadm[] = {"mdadm", "--stop", md, NULL}; + r = commandv (NULL, &err, mdadm); if (r == -1) { - reply_with_error("%s", err); - free(err); + reply_with_error ("%s", err); + free (err); return -1; } free (err); -- 1.7.9
Yes, in general these sorts of cleanups are good. 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 Mon, Feb 06, 2012 at 04:17:05PM +0800, Wanlong Gao wrote:
Add the new api zero_fs to erase the filesystem signatures on a device but now erase any data.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/zero.c | 17 +++++++++++++++++ generator/generator_actions.ml | 14 ++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/daemon/zero.c b/daemon/zero.c index 398f844..348869f 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -73,6 +73,23 @@ do_zero (const char *device) }
int +do_zero_fs (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..d27ef43 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");
+ ("zero_fs", (RErr, [Device "device"], []), 305, [Progress], + [InitBasicFSonLVM, Always, TestRun ( + [["zero_fs"; "/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_zero_fs> +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
Ah, wipefs, I think this is a good idea, and it's been on the TODO list for a long time. What do people think about calling the API 'wipefs' instead of 'zero-fs'? Can you update the patch to remove the reference to wipefs in the TODO file? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Add the new api zero_fs 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..348869f 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -73,6 +73,23 @@ do_zero (const char *device) } int +do_zero_fs (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..d27ef43 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"); + ("zero_fs", (RErr, [Device "device"], []), 305, [Progress], + [InitBasicFSonLVM, Always, TestRun ( + [["zero_fs"; "/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_zero_fs> +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 02/06/2012 04:26 PM, Richard W.M. Jones wrote:
On Mon, Feb 06, 2012 at 04:17:05PM +0800, Wanlong Gao wrote:
Add the new api zero_fs to erase the filesystem signatures on a device but now erase any data.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/zero.c | 17 +++++++++++++++++ generator/generator_actions.ml | 14 ++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/daemon/zero.c b/daemon/zero.c index 398f844..348869f 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -73,6 +73,23 @@ do_zero (const char *device) }
int +do_zero_fs (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..d27ef43 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");
+ ("zero_fs", (RErr, [Device "device"], []), 305, [Progress], + [InitBasicFSonLVM, Always, TestRun ( + [["zero_fs"; "/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_zero_fs> +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
Ah, wipefs, I think this is a good idea, and it's been on the TODO list for a long time.
What do people think about calling the API 'wipefs' instead of 'zero-fs'?
I've no idea with this, calling 'wipefs' is good, but 'zero-fs' can be consistent with the "guestfs_zero*" api. So, up to you.
Can you update the patch to remove the reference to wipefs in the TODO file?
sure, done in v2. Thanks -Wanlong Gao
Rich.
participants (2)
-
Richard W.M. Jones -
Wanlong Gao