mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-24 06:04:19 +03:00
o Removed the -z (suspend) option from the tools
o New function: int lv_setup_cow_store(struct logical_volume *lv) This zeroes the start of the cow device. o Made lvcreate call above fn.
This commit is contained in:
parent
ff941ffc16
commit
426dc7836c
@ -15,6 +15,7 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <linux/kdev_t.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define _skip(fmt, args...) log_very_verbose("Skipping: " fmt , ## args)
|
||||
|
||||
@ -105,30 +106,20 @@ static inline int _read_only_lv(struct logical_volume *lv)
|
||||
return (lv->status & LVM_WRITE) && (lv->vg->status & LVM_WRITE);
|
||||
}
|
||||
|
||||
int lv_activate(struct logical_volume *lv)
|
||||
int _lv_activate_named(struct logical_volume *lv, const char *name)
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
char buffer[128];
|
||||
|
||||
if (test_mode()) {
|
||||
_skip("Activation of '%s'.", lv->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decide what we're going to call this device.
|
||||
*/
|
||||
if (!build_dm_name(buffer, sizeof(buffer), "",
|
||||
lv->vg->name, lv->name)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a task.
|
||||
*/
|
||||
if (!(dmt = setup_dm_task(buffer, DM_DEVICE_CREATE))) {
|
||||
if (!(dmt = setup_dm_task(name, DM_DEVICE_CREATE))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
@ -174,12 +165,6 @@ int lv_activate(struct logical_volume *lv)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create device nodes and symbolic links.
|
||||
*/
|
||||
if (!fs_add_lv(lv, lv->minor))
|
||||
stack;
|
||||
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
log_verbose("Logical volume %s%s activated", lv->name,
|
||||
@ -187,6 +172,28 @@ int lv_activate(struct logical_volume *lv)
|
||||
return r;
|
||||
}
|
||||
|
||||
int lv_activate(struct logical_volume *lv)
|
||||
{
|
||||
char buffer[128];
|
||||
|
||||
/*
|
||||
* Decide what we're going to call this device.
|
||||
*/
|
||||
if (!build_dm_name(buffer, sizeof(buffer), "",
|
||||
lv->vg->name, lv->name)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_lv_activate_named(lv, buffer) ||
|
||||
!fs_add_lv(lv, lv->minor)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _reload(const char *name, struct logical_volume *lv)
|
||||
{
|
||||
int r = 0;
|
||||
@ -359,6 +366,52 @@ int lv_rename(const char *old_name, struct logical_volume *lv)
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
char buffer[128];
|
||||
char path[PATH_MAX];
|
||||
struct device *dev;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
int activate_lvs_in_vg(struct volume_group *vg)
|
||||
{
|
||||
|
@ -34,6 +34,11 @@ int lv_deactivate(struct logical_volume *lv);
|
||||
int lv_suspend(struct logical_volume *lv);
|
||||
int lv_rename(const char *old_name, struct logical_volume *lv);
|
||||
|
||||
/*
|
||||
* Snapshot volume need kernel specific initialisation.
|
||||
*/
|
||||
int lv_setup_cow_store(struct logical_volume *lv);
|
||||
|
||||
/*
|
||||
* Return number of LVs in the VG that are active.
|
||||
*/
|
||||
|
@ -206,8 +206,7 @@ static int _read_params(struct lvcreate_params *lp, struct cmd_context *cmd,
|
||||
/*
|
||||
* Should we zero the lv.
|
||||
*/
|
||||
lp->zero = strcmp(arg_str_value(cmd, zero_ARG, "y"), "n") ||
|
||||
arg_count(cmd, snapshot_ARG);
|
||||
lp->zero = strcmp(arg_str_value(cmd, zero_ARG, "y"), "n");
|
||||
|
||||
/*
|
||||
* Contiguous ?
|
||||
@ -376,16 +375,15 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp,
|
||||
return 0;
|
||||
|
||||
backup(vg);
|
||||
|
||||
log_print("Logical volume \"%s\" created", lv->name);
|
||||
|
||||
if (!lv_activate(lv))
|
||||
return 0;
|
||||
|
||||
*plv = lv;
|
||||
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;
|
||||
@ -445,14 +443,24 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!lp.zero) {
|
||||
log_print("WARNING: \"%s\" not zeroed", lv->name);
|
||||
|
||||
} else if (!_zero(cmd, lv)) {
|
||||
if (!lp.snapshot && !lv_setup_cow_store(lv)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!lv_activate(lv))
|
||||
goto out;
|
||||
|
||||
if (!lp.snapshot) {
|
||||
if (!lp.zero)
|
||||
log_print("WARNING: \"%s\" not zeroed", lv->name);
|
||||
|
||||
else if (!_zero(cmd, lv)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: as a sanity check we could try reading the
|
||||
* last block of the device ?
|
||||
|
@ -342,7 +342,7 @@ char yes_no_prompt(const char *prompt, ...)
|
||||
static void register_commands()
|
||||
{
|
||||
#define xx(a, b, c...) register_command(# a, a, b, ## c, \
|
||||
debug_ARG, help_ARG, suspend_ARG, \
|
||||
debug_ARG, help_ARG, \
|
||||
version_ARG, verbose_ARG, \
|
||||
quiet_ARG, -1);
|
||||
#include "commands.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user