1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-31 21:18:26 +03:00

pv: _pvcreate_write: do label removal and zeroing only if creating a new PV

This commit is contained in:
Peter Rajnoha 2015-03-12 15:18:52 +01:00
parent 73f1d444c8
commit b6e3080fff

View File

@ -1637,32 +1637,33 @@ void pvcreate_params_set_defaults(struct pvcreate_params *pp)
static int _pvcreate_write(struct cmd_context *cmd, struct pv_to_write *pvw) static int _pvcreate_write(struct cmd_context *cmd, struct pv_to_write *pvw)
{ {
int zero = pvw->pp ? pvw->pp->zero : 1;
struct physical_volume *pv = pvw->pv; struct physical_volume *pv = pvw->pv;
struct device *dev = pv->dev; struct device *dev = pv->dev;
const char *pv_name = dev_name(dev); const char *pv_name = dev_name(dev);
/* Wipe existing label first */ if (pvw->new_pv) {
if (!label_remove(pv_dev(pv))) { /* Wipe existing label first */
log_error("Failed to wipe existing label on %s", pv_name); if (!label_remove(pv_dev(pv))) {
return 0; log_error("Failed to wipe existing label on %s", pv_name);
}
if (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);
return 0; return 0;
} }
if (!dev_set(dev, UINT64_C(0), (size_t) 2048, 0)) { if (pvw->pp->zero) {
log_error("%s not wiped: aborting", pv_name); log_verbose("Zeroing start of device %s", pv_name);
if (!dev_open_quiet(dev)) {
log_error("%s not opened: device not zeroed", pv_name);
return 0;
}
if (!dev_set(dev, UINT64_C(0), (size_t) 2048, 0)) {
log_error("%s not wiped: aborting", pv_name);
if (!dev_close(dev))
stack;
return 0;
}
if (!dev_close(dev)) if (!dev_close(dev))
stack; stack;
return 0;
} }
if (!dev_close(dev))
stack;
} }
log_verbose("Writing physical volume data to disk \"%s\"", log_verbose("Writing physical volume data to disk \"%s\"",