1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Move zero_lv to toollib.

This commit is contained in:
Alasdair Kergon 2005-08-04 01:14:36 +00:00
parent d07af06363
commit a9b5af1d62
4 changed files with 49 additions and 45 deletions

View File

@ -1,6 +1,7 @@
Version 2.01.14 -
================================
Fix pool format handler to work with pv segment code
Move zero_lv to toollib.
Fix pool format handler to work with pv segment code.
Version 2.01.13 - 13th July 2005
================================

View File

@ -414,48 +414,6 @@ static int _read_params(struct lvcreate_params *lp, struct cmd_context *cmd,
return 1;
}
/*
* Volumes may be zeroed to remove old application data.
*/
static int _zero_lv(struct cmd_context *cmd, struct logical_volume *lv)
{
struct device *dev;
char *name;
/*
* FIXME:
* <clausen> also, more than 4k
* <clausen> say, reiserfs puts it's superblock 32k in, IIRC
* <ejt_> k, I'll drop a fixme to that effect
* (I know the device is at least 4k, but not 32k)
*/
if (!(name = pool_alloc(cmd->mem, PATH_MAX))) {
log_error("Name allocation failed - device not zeroed");
return 0;
}
if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
lv->vg->name, lv->name) < 0) {
log_error("Name too long - device not zeroed (%s)", lv->name);
return 0;
}
log_verbose("Zeroing start of logical volume \"%s\"", lv->name);
if (!(dev = dev_cache_get(name, NULL))) {
log_error("%s: not found: device not zeroed", name);
return 0;
}
if (!dev_open_quiet(dev))
return 0;
dev_zero(dev, UINT64_C(0), (size_t) 4096);
dev_close_immediate(dev);
return 1;
}
static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
{
uint32_t size_rest, region_max;
@ -685,7 +643,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
goto error;
}
if (activation() && !_zero_lv(cmd, log_lv)) {
if (activation() && !zero_lv(cmd, log_lv)) {
log_error("Aborting. Failed to wipe mirror log. "
"Remove new LV and retry.");
goto error;
@ -778,7 +736,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
}
if ((lp->zero || lp->snapshot) && activation()) {
if (!_zero_lv(cmd, lv) && lp->snapshot) {
if (!zero_lv(cmd, lv) && lp->snapshot) {
/* FIXME Remove the failed lv we just added */
log_error("Aborting. Failed to wipe snapshot "
"exception store. Remove new LV and retry.");

View File

@ -1057,3 +1057,46 @@ int validate_vg_name(struct cmd_context *cmd, const char *vg_name)
return 1;
}
/*
* Volumes may be zeroed to remove old application data.
*/
int zero_lv(struct cmd_context *cmd, struct logical_volume *lv)
{
struct device *dev;
char *name;
/*
* FIXME:
* <clausen> also, more than 4k
* <clausen> say, reiserfs puts it's superblock 32k in, IIRC
* <ejt_> k, I'll drop a fixme to that effect
* (I know the device is at least 4k, but not 32k)
*/
if (!(name = pool_alloc(cmd->mem, PATH_MAX))) {
log_error("Name allocation failed - device not zeroed");
return 0;
}
if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
lv->vg->name, lv->name) < 0) {
log_error("Name too long - device not zeroed (%s)", lv->name);
return 0;
}
log_verbose("Zeroing start of logical volume \"%s\"", lv->name);
if (!(dev = dev_cache_get(name, NULL))) {
log_error("%s: not found: device not zeroed", name);
return 0;
}
if (!dev_open_quiet(dev))
return 0;
dev_zero(dev, UINT64_C(0), (size_t) 4096);
dev_close_immediate(dev);
return 1;
}

View File

@ -94,4 +94,6 @@ int apply_lvname_restrictions(const char *name);
int validate_vg_name(struct cmd_context *cmd, const char *vg_name);
int zero_lv(struct cmd_context *cmd, struct logical_volume *lv);
#endif