From 12bb377f9b326f7fe0fa7daf251e20158c04a2c7 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 6 Nov 2003 20:33:34 +0000 Subject: [PATCH] Default to unlimited number of LVs/PVs in lvm2 format. --- lib/format1/format1.c | 4 +-- lib/metadata/lv_manip.c | 2 +- lib/metadata/metadata.c | 2 +- tools/vgchange.c | 11 ++++++- tools/vgcreate.c | 69 +++++++++++++++++++++++------------------ tools/vgmerge.c | 6 ++-- 6 files changed, 56 insertions(+), 38 deletions(-) diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 254b787df..bd618a73e 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -422,10 +422,10 @@ static int _pv_write(const struct format_type *fmt, struct physical_volume *pv, static int _vg_setup(struct format_instance *fid, struct volume_group *vg) { /* just check max_pv and max_lv */ - if (vg->max_lv >= MAX_LV) + if (!vg->max_lv || vg->max_lv >= MAX_LV) vg->max_lv = MAX_LV - 1; - if (vg->max_pv >= MAX_PV) + if (!vg->max_pv || vg->max_pv >= MAX_PV) vg->max_pv = MAX_PV - 1; if (vg->extent_size > MAX_PE_SIZE || vg->extent_size < MIN_PE_SIZE) { diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 1ea2a83cb..e72abae12 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -478,7 +478,7 @@ struct logical_volume *lv_create_empty(struct format_instance *fi, struct logical_volume *lv; char dname[32]; - if (vg->max_lv == vg->lv_count) { + if (vg->max_lv && (vg->max_lv == vg->lv_count)) { log_error("Maximum number of logical volumes (%u) reached " "in volume group %s", vg->max_lv, vg->name); return NULL; diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 50f7be411..bf92ec139 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -83,7 +83,7 @@ static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg, return 0; } - if (vg->pv_count == vg->max_pv) { + if (vg->pv_count && (vg->pv_count == vg->max_pv)) { log_error("No space for '%s' - volume group '%s' " "holds max %d physical volume(s).", pv_name, vg->name, vg->max_pv); diff --git a/tools/vgchange.c b/tools/vgchange.c index 2f0640ab7..412dbf3bd 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -132,7 +132,16 @@ static int _vgchange_logicalvolume(struct cmd_context *cmd, return ECMD_FAILED; } - if (max_lv < vg->lv_count) { + if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) { + if (!max_lv) + max_lv = 255; + else if (max_lv > 255) { + log_error("MaxLogicalVolume limit is 255"); + return ECMD_FAILED; + } + } + + if (max_lv && max_lv < vg->lv_count) { log_error("MaxLogicalVolume is less than the current number " "%d of logical volume(s) for \"%s\"", vg->lv_count, vg->name); diff --git a/tools/vgcreate.c b/tools/vgcreate.c index bba795fc5..0530b1e37 100644 --- a/tools/vgcreate.c +++ b/tools/vgcreate.c @@ -20,10 +20,6 @@ #include "tools.h" -/* FIXME From config file? */ -#define DEFAULT_PV 256 -#define DEFAULT_LV 256 - #define DEFAULT_EXTENT 4096 /* In KB */ int vgcreate(struct cmd_context *cmd, int argc, char **argv) @@ -46,36 +42,47 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv) } vg_name = argv[0]; - max_lv = arg_uint_value(cmd, maxlogicalvolumes_ARG, DEFAULT_LV); - max_pv = arg_uint_value(cmd, maxphysicalvolumes_ARG, DEFAULT_PV); + max_lv = arg_uint_value(cmd, maxlogicalvolumes_ARG, 0); + max_pv = arg_uint_value(cmd, maxphysicalvolumes_ARG, 0); - if (arg_sign_value(cmd, physicalextentsize_ARG, 0) == SIGN_MINUS) { - log_error("Physical extent size may not be negative"); - return EINVALID_CMD_LINE; - } - - /* Units of 512-byte sectors */ - extent_size = - arg_uint_value(cmd, physicalextentsize_ARG, DEFAULT_EXTENT) * 2; - - if (max_lv < 1) { - log_error("maxlogicalvolumes too low"); - return EINVALID_CMD_LINE; - } - - if (max_pv < 1) { - log_error("maxphysicalvolumes too low"); - return EINVALID_CMD_LINE; - } + if (!(cmd->fmt->features & FMT_UNLIMITED_VOLS)) { + if (!max_lv) + max_lv = 255; + if (!max_pv) + max_pv = 255; + if (max_lv > 255 || max_pv > 255) { + log_error("Number of volumes may not exceed 255"); + return EINVALID_CMD_LINE; + } + } + + if (arg_sign_value(cmd, physicalextentsize_ARG, 0) == SIGN_MINUS) { + log_error("Physical extent size may not be negative"); + return EINVALID_CMD_LINE; + } + + if (arg_sign_value(cmd, maxlogicalvolumes_ARG, 0) == SIGN_MINUS) { + log_error("Max Logical Volumes may not be negative"); + return EINVALID_CMD_LINE; + } + + if (arg_sign_value(cmd, maxphysicalvolumes_ARG, 0) == SIGN_MINUS) { + log_error("Max Physical Volumes may not be negative"); + return EINVALID_CMD_LINE; + } + + /* Units of 512-byte sectors */ + extent_size = + arg_uint_value(cmd, physicalextentsize_ARG, DEFAULT_EXTENT) * 2; if (!extent_size) { log_error("Physical extent size may not be zero"); return EINVALID_CMD_LINE; } - /* Strip dev_dir if present */ - if (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir))) - vg_name += strlen(cmd->dev_dir); + /* Strip dev_dir if present */ + if (!strncmp(vg_name, cmd->dev_dir, strlen(cmd->dev_dir))) + vg_name += strlen(cmd->dev_dir); snprintf(vg_path, PATH_MAX, "%s%s", cmd->dev_dir, vg_name); if (path_exists(vg_path)) { @@ -94,12 +101,12 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv) return ECMD_FAILED; if (max_lv != vg->max_lv) - log_error("Warning: Setting maxlogicalvolumes to %d", - vg->max_lv); + log_error("Warning: Setting maxlogicalvolumes to %d " + "(0 means unlimited)", vg->max_lv); if (max_pv != vg->max_pv) - log_error("Warning: Setting maxphysicalvolumes to %d", - vg->max_pv); + log_error("Warning: Setting maxphysicalvolumes to %d " + "(0 means unlimited)", vg->max_pv); if (!lock_vol(cmd, "", LCK_VG_WRITE)) { log_error("Can't get lock for orphan PVs"); diff --git a/tools/vgmerge.c b/tools/vgmerge.c index 6efe163e9..dc85fb922 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -94,14 +94,16 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, goto error; } - if (vg_to->max_pv < vg_to->pv_count + vg_from->pv_count) { + if (vg_to->max_pv && + (vg_to->max_pv < vg_to->pv_count + vg_from->pv_count)) { log_error("Maximum number of physical volumes (%d) exceeded " " for \"%s\" and \"%s\"", vg_to->max_pv, vg_to->name, vg_from->name); goto error; } - if (vg_to->max_lv < vg_to->lv_count + vg_from->lv_count) { + if (vg_to->max_lv && + (vg_to->max_lv < vg_to->lv_count + vg_from->lv_count)) { log_error("Maximum number of logical volumes (%d) exceeded " " for \"%s\" and \"%s\"", vg_to->max_lv, vg_to->name, vg_from->name);