mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +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;
|
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,
|
struct logical_volume *lv_create(const char *name,
|
||||||
uint32_t status,
|
uint32_t status,
|
||||||
uint32_t stripes,
|
uint32_t stripes,
|
||||||
@ -185,16 +208,17 @@ struct logical_volume *lv_create(const char *name,
|
|||||||
struct cmd_context *cmd = vg->cmd;
|
struct cmd_context *cmd = vg->cmd;
|
||||||
struct lv_list *ll = NULL;
|
struct lv_list *ll = NULL;
|
||||||
struct logical_volume *lv;
|
struct logical_volume *lv;
|
||||||
|
char dname[32];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!extents) {
|
if (!extents) {
|
||||||
log_error("Unable to create logical volume %s with no extents",
|
log_err("Unable to create logical volume %s with no extents",
|
||||||
name);
|
name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vg->free_count < extents) {
|
if (vg->free_count < extents) {
|
||||||
log_error("Insufficient free extents (%u) in volume group %s: "
|
log_err("Insufficient free extents (%u) in volume group %s: "
|
||||||
"%u required", vg->free_count, vg->name, extents);
|
"%u required", vg->free_count, vg->name, extents);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -205,6 +229,14 @@ struct logical_volume *lv_create(const char *name,
|
|||||||
return NULL;
|
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)))) {
|
if (!(ll = pool_zalloc(cmd->mem, sizeof(*ll)))) {
|
||||||
stack;
|
stack;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -81,21 +81,16 @@ int lvcreate(int argc, char **argv)
|
|||||||
|
|
||||||
if (arg_count(name_ARG))
|
if (arg_count(name_ARG))
|
||||||
lv_name = arg_value(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 VG not on command line, try -n arg and then environment */
|
||||||
if (!argc) {
|
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");
|
log_error("Please provide a volume group name");
|
||||||
return EINVALID_CMD_LINE;
|
return EINVALID_CMD_LINE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Ensure lv_name doesn't contain a different VG! */
|
/* 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)))
|
if (!(vg_name = extract_vgname(fid, lv_name)))
|
||||||
return EINVALID_CMD_LINE;
|
return EINVALID_CMD_LINE;
|
||||||
if (strcmp(vg_name, argv[0])) {
|
if (strcmp(vg_name, argv[0])) {
|
||||||
@ -109,7 +104,7 @@ int lvcreate(int argc, char **argv)
|
|||||||
argc--;
|
argc--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((st = strrchr(lv_name, '/')))
|
if (lv_name && (st = strrchr(lv_name, '/')))
|
||||||
lv_name = st + 1;
|
lv_name = st + 1;
|
||||||
|
|
||||||
/* does VG exist? */
|
/* does VG exist? */
|
||||||
@ -126,8 +121,8 @@ int lvcreate(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lv_name && (lvh = find_lv_in_vg(vg, lv_name))) {
|
if (lv_name && (lvh = find_lv_in_vg(vg, lv_name))) {
|
||||||
log_error("Logical volume %s already exists in volume group %s",
|
log_error("Logical volume %s already exists in "
|
||||||
lv_name, vg_name);
|
"volume group %s", lv_name, vg_name);
|
||||||
return ECMD_FAILED;
|
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,
|
if (!(lv = lv_create(lv_name, status, stripes, stripesize,
|
||||||
extents, vg, pvh)))
|
extents, vg, pvh)))
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
@ -243,30 +236,31 @@ int lvcreate(int argc, char **argv)
|
|||||||
if (!lv_activate(lv))
|
if (!lv_activate(lv))
|
||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
|
|
||||||
if (zero) {
|
if (0) {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
/* FIXME 2 blocks */
|
/* FIXME 2 blocks */
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
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 get dev = dev_cache_get(lv_name, fid->cmd->filter); */
|
||||||
/* FIXME Add fsync! */
|
/* FIXME Add fsync! */
|
||||||
if (!(dev_write(dev, 0, sizeof(buf), &buf) == sizeof(buf))) {
|
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;
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
log_print("WARNING: %s not zeroed", lv_name);
|
log_print("WARNING: %s not zeroed", lv->name);
|
||||||
|
|
||||||
/******** FIXME backup
|
/******** FIXME backup
|
||||||
if ((ret = do_autobackup(vg_name, vg)))
|
if ((ret = do_autobackup(vg_name, vg)))
|
||||||
return ret;
|
return ret;
|
||||||
***********/
|
***********/
|
||||||
|
|
||||||
log_print("Logical volume %s created", lv_name);
|
log_print("Logical volume %s created", lv->name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ int process_each_vg(int argc, char **argv,
|
|||||||
int (*process_single) (const char *vg_name));
|
int (*process_single) (const char *vg_name));
|
||||||
|
|
||||||
int process_each_pv(int argc, char **argv, struct volume_group *vg,
|
int process_each_pv(int argc, char **argv, struct volume_group *vg,
|
||||||
int (*process_single) (struct volume_group * vg,
|
int (*process_single) (struct volume_group *vg,
|
||||||
struct physical_volume * pv));
|
struct physical_volume *pv));
|
||||||
|
|
||||||
int is_valid_chars(char *n);
|
int is_valid_chars(char *n);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user