From 2245e1c41f8e9d14b0c5acf22d1232dee83cd954 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 5 Jan 2005 17:25:25 +0000 Subject: [PATCH] pvcreate wipes first 4 sectors unless given --zero n. --- WHATS_NEW | 3 +-- man/pvcreate.8 | 8 ++++++++ tools/commands.h | 3 ++- tools/pvcreate.c | 26 +++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 1f2c54bf6..144e39060 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,12 +1,11 @@ Version 2.00.33 - ==================================== - + pvcreate wipes first 4 sectors unless given --zero n. gulm clvmd now uses new ccsd key names. gulm clvmd now doesn't ignore the first node in cluster.conf Improve clvmd failure message if it's already running. Allow user to kill clvmd during initialisation. - Version 2.00.32 - 22nd December 2004 ==================================== Drop static/dl restriction for now. diff --git a/man/pvcreate.8 b/man/pvcreate.8 index 5bec86fd8..5171f0684 100644 --- a/man/pvcreate.8 +++ b/man/pvcreate.8 @@ -16,6 +16,7 @@ pvcreate \- initialize a disk or partition for use by LVM .RB [ \-\-restorefile file ] .RB [ \-\-setphysicalvolumesize size ] .RB [ \-\-version ] +.RB [ \-Z | \-\-zero y/n ] .IR PhysicalVolume " [" PhysicalVolume ...] .SH DESCRIPTION .B pvcreate @@ -59,6 +60,13 @@ onto a replacement device - see \fBvgcfgrestore\fP(8). .TP .BR \-y ", " \-\-yes Answer yes to all questions. +.TP +.BR \-Z ", " \-\-zero " y/n" +Whether or not the first 4 sectors (2048 bytes) of the device should be +wiped. +If this option is not given, the +default is to wipe these sectors unless either or both of the --restorefile +or --uuid options were specified. .SH NEW METADATA OPTIONS LVM2 introduces a new format for storing metadata on disk. This new format is more efficient and resilient than the format the diff --git a/tools/commands.h b/tools/commands.h index 438eda8d6..cd06e5625 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -367,12 +367,13 @@ xx(pvcreate, "\t[-u|--uuid uuid] " "\n" "\t[-v|--verbose] " "\n" "\t[-y|--yes]" "\n" + "\t[-Z|--zero {y|n}]\n" "\t[--version] " "\n" "\tPhysicalVolume [PhysicalVolume...]\n", force_ARG, test_ARG, labelsector_ARG, metadatatype_ARG, metadatacopies_ARG, metadatasize_ARG, physicalvolumesize_ARG, restorefile_ARG, uuidstr_ARG, - yes_ARG) + yes_ARG, zero_ARG) xx(pvdata, "Display the on-disk metadata for physical volume(s)", diff --git a/tools/pvcreate.c b/tools/pvcreate.c index f1c1b837f..fd3a8a39a 100644 --- a/tools/pvcreate.c +++ b/tools/pvcreate.c @@ -15,6 +15,10 @@ #include "tools.h" +struct pvcreate_params { + int zero; +}; + const char _really_init[] = "Really INITIALIZE physical volume \"%s\" of volume group \"%s\" [y/n]? "; @@ -107,6 +111,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name) static int pvcreate_single(struct cmd_context *cmd, const char *pv_name, void *handle) { + struct pvcreate_params *pp = (struct pvcreate_params *) handle; struct physical_volume *pv, *existing_pv; struct id id, *idp = NULL; const char *uuid = NULL; @@ -207,6 +212,17 @@ static int pvcreate_single(struct cmd_context *cmd, const char *pv_name, goto error; } + if (pp->zero) { + log_verbose("Zeroing start of device %s", pv_name); + if (!dev_open_quiet(dev)) { + log_error("%s not opened: device not zeroed", pv_name); + goto error; + } + + dev_zero(dev, UINT64_C(0), (size_t) 2048); + dev_close(dev); + } + log_very_verbose("Writing physical volume data to disk \"%s\"", pv_name); if (!(pv_write(cmd, pv, &mdas, arg_int64_value(cmd, labelsector_ARG, @@ -229,6 +245,7 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv) { int i, r; int ret = ECMD_PROCESSED; + struct pvcreate_params pp; if (!argc) { log_error("Please enter a physical volume path"); @@ -269,8 +286,15 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } + if (arg_count(cmd, zero_ARG)) + pp.zero = strcmp(arg_str_value(cmd, zero_ARG, "y"), "n"); + else if (arg_count(cmd, restorefile_ARG) || arg_count(cmd, uuidstr_ARG)) + pp.zero = 0; + else + pp.zero = 1; + for (i = 0; i < argc; i++) { - r = pvcreate_single(cmd, argv[i], NULL); + r = pvcreate_single(cmd, argv[i], &pp); if (r > ret) ret = r; }