mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o lvcreate no longer needs the explicit -n flag
o disabled zeroing of lv until bug's worked out
This commit is contained in:
parent
bb2250f097
commit
e55ae5d32e
@ -174,6 +174,29 @@ static int _allocate(struct volume_group *vg, struct logical_volume *lv,
|
||||
return r;
|
||||
}
|
||||
|
||||
static char *_make_up_lv_name(struct volume_group *vg,
|
||||
char *buffer, size_t len)
|
||||
{
|
||||
struct list *lvh;
|
||||
struct logical_volume *lv;
|
||||
int high = 1, i;
|
||||
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
lv = &(list_item(lvh, struct lv_list)->lv);
|
||||
|
||||
if (sscanf(lv->name, "lvol%d", &i) != 1)
|
||||
continue;
|
||||
|
||||
if (i > high)
|
||||
high = i + 1;
|
||||
}
|
||||
|
||||
if (snprintf(buffer, len, "lvol%d", high) < 0)
|
||||
return NULL;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
struct logical_volume *lv_create(const char *name,
|
||||
uint32_t status,
|
||||
uint32_t stripes,
|
||||
@ -185,17 +208,18 @@ struct logical_volume *lv_create(const char *name,
|
||||
struct cmd_context *cmd = vg->cmd;
|
||||
struct lv_list *ll = NULL;
|
||||
struct logical_volume *lv;
|
||||
char dname[32];
|
||||
int i;
|
||||
|
||||
if (!extents) {
|
||||
log_error("Unable to create logical volume %s with no extents",
|
||||
name);
|
||||
log_err("Unable to create logical volume %s with no extents",
|
||||
name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vg->free_count < extents) {
|
||||
log_error("Insufficient free extents (%u) in volume group %s: "
|
||||
"%u required", vg->free_count, vg->name, extents);
|
||||
log_err("Insufficient free extents (%u) in volume group %s: "
|
||||
"%u required", vg->free_count, vg->name, extents);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -205,6 +229,14 @@ struct logical_volume *lv_create(const char *name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!name &&
|
||||
!(name = _make_up_lv_name(vg, dname, sizeof(dname)))) {
|
||||
log_err("Unable to think of a name for logical volume.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
log_verbose("Creating logical volume %s", name);
|
||||
|
||||
if (!(ll = pool_zalloc(cmd->mem, sizeof(*ll)))) {
|
||||
stack;
|
||||
return NULL;
|
||||
|
@ -81,21 +81,16 @@ int lvcreate(int argc, char **argv)
|
||||
|
||||
if (arg_count(name_ARG))
|
||||
lv_name = arg_value(name_ARG);
|
||||
else {
|
||||
log_error("LVM2 currently requires you to give a name "
|
||||
"using -n");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
/* If VG not on command line, try -n arg and then environment */
|
||||
if (!argc) {
|
||||
if (!(vg_name = extract_vgname(fid, lv_name))) {
|
||||
if (!lv_name || !(vg_name = extract_vgname(fid, lv_name))) {
|
||||
log_error("Please provide a volume group name");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
} else {
|
||||
/* Ensure lv_name doesn't contain a different VG! */
|
||||
if (strchr(lv_name, '/')) {
|
||||
if (lv_name && strchr(lv_name, '/')) {
|
||||
if (!(vg_name = extract_vgname(fid, lv_name)))
|
||||
return EINVALID_CMD_LINE;
|
||||
if (strcmp(vg_name, argv[0])) {
|
||||
@ -109,7 +104,7 @@ int lvcreate(int argc, char **argv)
|
||||
argc--;
|
||||
}
|
||||
|
||||
if ((st = strrchr(lv_name, '/')))
|
||||
if (lv_name && (st = strrchr(lv_name, '/')))
|
||||
lv_name = st + 1;
|
||||
|
||||
/* does VG exist? */
|
||||
@ -126,8 +121,8 @@ int lvcreate(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (lv_name && (lvh = find_lv_in_vg(vg, lv_name))) {
|
||||
log_error("Logical volume %s already exists in volume group %s",
|
||||
lv_name, vg_name);
|
||||
log_error("Logical volume %s already exists in "
|
||||
"volume group %s", lv_name, vg_name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
@ -225,8 +220,6 @@ int lvcreate(int argc, char **argv)
|
||||
}
|
||||
*************/
|
||||
|
||||
log_verbose("Creating logical volume %s", lv_name);
|
||||
|
||||
if (!(lv = lv_create(lv_name, status, stripes, stripesize,
|
||||
extents, vg, pvh)))
|
||||
return ECMD_FAILED;
|
||||
@ -243,30 +236,31 @@ int lvcreate(int argc, char **argv)
|
||||
if (!lv_activate(lv))
|
||||
return ECMD_FAILED;
|
||||
|
||||
if (zero) {
|
||||
if (0) {
|
||||
struct device *dev;
|
||||
/* FIXME 2 blocks */
|
||||
char buf[4096];
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
log_verbose("Zeroing start of logical volume %s", lv_name);
|
||||
log_verbose("Zeroing start of logical volume %s", lv->name);
|
||||
|
||||
/* FIXME get dev = dev_cache_get(lv_name, fid->cmd->filter); */
|
||||
/* FIXME Add fsync! */
|
||||
if (!(dev_write(dev, 0, sizeof(buf), &buf) == sizeof(buf))) {
|
||||
log_error("Initialisation of %s failed", dev_name(dev));
|
||||
log_error("Initialisation of %s failed",
|
||||
dev_name(dev));
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
} else
|
||||
log_print("WARNING: %s not zeroed", lv_name);
|
||||
log_print("WARNING: %s not zeroed", lv->name);
|
||||
|
||||
/******** FIXME backup
|
||||
if ((ret = do_autobackup(vg_name, vg)))
|
||||
return ret;
|
||||
***********/
|
||||
|
||||
log_print("Logical volume %s created", lv_name);
|
||||
log_print("Logical volume %s created", lv->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ int process_each_vg(int argc, char **argv,
|
||||
int (*process_single) (const char *vg_name));
|
||||
|
||||
int process_each_pv(int argc, char **argv, struct volume_group *vg,
|
||||
int (*process_single) (struct volume_group * vg,
|
||||
struct physical_volume * pv));
|
||||
int (*process_single) (struct volume_group *vg,
|
||||
struct physical_volume *pv));
|
||||
|
||||
int is_valid_chars(char *n);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user