1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

o Break creating a snapshot down into:

i)   create cow
   ii)  activate cow
   iii) zero cow
   iv)  deactivate
   v)   add snapshot info
   vi)  reactivate
This commit is contained in:
Joe Thornber 2002-03-04 13:46:37 +00:00
parent 623df7a068
commit 9db196e6c5
3 changed files with 70 additions and 105 deletions

View File

@ -238,56 +238,33 @@ int lv_rename(const char *old_name, struct logical_volume *lv)
#endif
}
/*
* Zero the start of a cow store so the driver spots that it is a
* new store.
*/
int lv_setup_cow_store(struct logical_volume *lv)
int activate_lvs_in_vg(struct volume_group *vg)
{
#if 0
char buffer[128];
char path[PATH_MAX];
struct device *dev;
struct list *lvh;
struct logical_volume *lv;
int count = 0;
/*
* Decide what we're going to call this device.
*/
if (!build_dm_name(buffer, sizeof(buffer), "cow_init",
lv->vg->name, lv->name)) {
stack;
return 0;
list_iterate(lvh, &vg->lvs) {
lv = list_item(lvh, struct lv_list)->lv;
count += (!lv_active(lv) && lv_activate(lv));
}
if (!_lv_activate_named(lv, buffer)) {
log_err("Unable to activate cow store logical volume.");
return 0;
}
/* FIXME: hard coded dir */
if (lvm_snprintf(path, sizeof(path), "/dev/device-mapper/%s",
buffer) < 0) {
log_error("Name too long - device not zeroed (%s)",
lv->name);
return 0;
}
if (!(dev = dev_cache_get(path, NULL))) {
log_error("\"%s\" not found: device not zeroed", path);
return 0;
}
if (!(dev_open(dev, O_WRONLY)))
return 0;
dev_zero(dev, 0, 4096);
dev_close(dev);
return 1;
#else
return 0;
#endif
return count;
}
int deactivate_lvs_in_vg(struct volume_group *vg)
{
struct list *lvh;
struct logical_volume *lv;
int count = 0;
list_iterate(lvh, &vg->lvs) {
lv = list_item(lvh, struct lv_list)->lv;
count += ((lv_active(lv) == 1) && lv_deactivate(lv));
}
return count;
}
/*
* These two functions return the number of LVs in the state,

View File

@ -182,7 +182,6 @@ static int lvchange_availability(struct cmd_context *cmd,
struct logical_volume *lv)
{
int activate = 0;
int active;
char lvidbuf[128];
if (strcmp(arg_str_value(cmd, available_ARG, "n"), "n"))

View File

@ -252,6 +252,49 @@ 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(dev, O_WRONLY)))
return 0;
dev_zero(dev, 0, 4096);
dev_close(dev);
return 1;
}
static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp,
struct logical_volume **plv)
{
@ -356,6 +399,11 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp,
vg, pvh)))
return 0;
if (lp->zero)
_zero_lv(cmd, lv);
else
log_print("WARNING: \"%s\" not zeroed", lv->name);
if (lp->snapshot && !vg_add_snapshot(org, lv, 1, lp->chunk_size)) {
log_err("Couldn't create snapshot.");
return 0;
@ -383,49 +431,6 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp,
return 1;
}
/*
* Non-snapshot volumes may be zeroed to remove old filesystems.
*/
static int _zero(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(dev, O_WRONLY)))
return 0;
dev_zero(dev, 0, 4096);
dev_close(dev);
return 1;
}
int lvcreate(struct cmd_context *cmd, int argc, char **argv)
{
int r = ECMD_FAILED;
@ -448,26 +453,12 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
goto out;
}
if (lp.snapshot && !lv_setup_cow_store(lv)) {
stack;
goto out;
}
if (!lvid(lv, lvidbuf, sizeof(lvidbuf)))
return 0;
if (!lock_vol(cmd, lvidbuf, LCK_LV_ACTIVATE))
goto out;
if (!lp.snapshot) {
if (!lp.zero)
log_print("WARNING: \"%s\" not zeroed", lv->name);
else if (!_zero(cmd, lv)) {
stack;
goto out_lv;
}
}
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
/*
* FIXME: as a sanity check we could try reading the
@ -476,8 +467,6 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
r = 0;
out_lv:
lock_vol(cmd, lvidbuf, LCK_LV_UNLOCK);
out:
lock_vol(cmd, lp.vg_name, LCK_VG_UNLOCK);
return r;