1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

o vgcreate

This commit is contained in:
Joe Thornber 2001-10-12 14:25:53 +00:00
parent 9711fef759
commit 8a482590fa
5 changed files with 158 additions and 236 deletions

View File

@ -326,21 +326,6 @@ static struct list_head *_get_vgs(struct io_space *is)
static int _pv_setup(struct io_space *is, struct physical_volume *pv, static int _pv_setup(struct io_space *is, struct physical_volume *pv,
struct volume_group *vg) struct volume_group *vg)
{ {
if (!(pv->vg_name = pool_strdup(is->mem, vg->name))) {
stack;
return 0;
}
pv->exported = NULL;
pv->status = ACTIVE;
if (!dev_get_size(pv->dev, &pv->size)) {
stack;
return 0;
}
pv->pe_size = vg->extent_size;
/* /*
* This works out pe_start and pe_count. * This works out pe_start and pe_count.
*/ */
@ -349,8 +334,6 @@ static int _pv_setup(struct io_space *is, struct physical_volume *pv,
return 0; return 0;
} }
pv->pe_allocated = 0;
return 1; return 1;
} }
@ -400,6 +383,17 @@ static int _pv_write(struct io_space *is, struct physical_volume *pv)
return 0; return 0;
} }
int _vg_setup(struct io_space *is, struct volume_group *vg)
{
/* just check max_pv and max_lv */
if (vg->max_lv > MAX_LV)
vg->max_lv = MAX_LV;
if (vg->max_pv > MAX_PV)
vg->max_pv = MAX_PV;
return 1;
}
void _destroy(struct io_space *ios) void _destroy(struct io_space *ios)
{ {

View File

@ -12,6 +12,121 @@
#include <string.h> #include <string.h>
int _add_pv_to_vg(struct io_space *ios, struct volume_group *vg,
const char *name)
{
struct pv_list *pvl = pool_alloc(ios->mem, sizeof(*pvl));
struct physical_volume *pv = &pvl->pv;
if (!pv) {
stack;
return 0;
}
memset(pv, 0, sizeof(*pv));
pv->dev = dev_cache_get(name, ios->filter);
if (!(pv->vg_name = pool_strdup(ios->mem, vg->name))) {
stack;
return 0;
}
pv->exported = NULL;
pv->status = ACTIVE;
if (!dev_get_size(pv->dev, &pv->size)) {
stack;
return 0;
}
pv->pe_size = vg->extent_size;
/*
* The next two fields should be corrected
* by ios->pv_setup.
*/
pv->pe_start = 0;
pv->pe_count = pv->size / pv->pe_size;
pv->pe_allocated = 0;
if (!ios->pv_setup(ios, pv, vg)) {
log_err("Format specific setup of physical volume '%s' "
"failed.", name);
return 0;
}
list_add(&pvl->list, &vg->pvs);
vg->pv_count++;
return 1;
}
struct volume_group *vg_create(struct io_space *ios, const char *name,
uint64_t extent_size, int max_pv, int max_lv,
int pv_count, char **pv_names)
{
int i;
struct volume_group *vg;
if (!(vg = pool_alloc(ios->mem, sizeof(*vg)))) {
stack;
return NULL;
}
/* is this vg name already in use ? */
if (ios->vg_read(ios, name)) {
log_err("A volume group called '%s' already exists.", name);
goto bad;
}
if (!id_create(&vg->id)) {
log_err("Couldn't create uuid for volume group '%s'.", name);
goto bad;
}
if (!(vg->name = pool_strdup(ios->mem, name))) {
stack;
goto bad;
}
vg->status = (ACTIVE | EXTENDABLE_VG | LVM_READ | LVM_WRITE);
vg->extent_size = extent_size;
vg->extent_count = 0;
vg->free_count = 0;
vg->max_lv = max_lv;
vg->max_pv = max_pv;
vg->pv_count = 0;
INIT_LIST_HEAD(&vg->pvs);
vg->lv_count = 0;
INIT_LIST_HEAD(&vg->lvs);
if (!ios->vg_setup(ios, vg)) {
log_err("Format specific setup of volume group '%s' failed.",
name);
goto bad;
}
/* attach the pv's */
for (i = 0; i < pv_count; i++)
if (!_add_pv_to_vg(ios, vg, pv_names[i])) {
log_err("Unable to add physical volume '%s' to "
"volume group '%s'.", pv_names[i], name);
goto bad;
}
return vg;
bad:
pool_free(ios->mem, vg);
return NULL;
}
struct physical_volume *pv_create(struct io_space *ios, const char *name) struct physical_volume *pv_create(struct io_space *ios, const char *name)
{ {
struct physical_volume *pv = pool_alloc(ios->mem, sizeof(*pv)); struct physical_volume *pv = pool_alloc(ios->mem, sizeof(*pv));

View File

@ -136,9 +136,9 @@ struct io_space {
const char *pv_name); const char *pv_name);
/* /*
* Fill out a pv ready for importing into * Tweak an already filled out a pv ready
* a vg. *Be careful*, this allocates * for importing into a vg. eg. pe_count
* vg_name from is->mem. * is format specific.
*/ */
int (*pv_setup)(struct io_space *is, struct physical_volume *pv, int (*pv_setup)(struct io_space *is, struct physical_volume *pv,
struct volume_group *vg); struct volume_group *vg);
@ -150,6 +150,12 @@ struct io_space {
*/ */
int (*pv_write)(struct io_space *is, struct physical_volume *pv); int (*pv_write)(struct io_space *is, struct physical_volume *pv);
/*
* Tweak an already filled out vg. eg,
* max_pv is format specific.
*/
int (*vg_setup)(struct io_space *is, struct volume_group *vg);
/* /*
* If vg_name doesn't contain any slash, * If vg_name doesn't contain any slash,
* this function adds prefix. * this function adds prefix.
@ -193,6 +199,9 @@ struct io_space {
/* /*
* Utility functions * Utility functions
*/ */
struct volume_group *vg_create(struct io_space *ios, const char *name,
uint64_t extent_size, int max_pv, int max_lv,
int pv_count, char **pv_names);
struct physical_volume *pv_create(struct io_space *ios, const char *name); struct physical_volume *pv_create(struct io_space *ios, const char *name);

View File

@ -503,6 +503,11 @@ static int run_command(int argc, char **argv)
ret = com->fn(argc, argv); ret = com->fn(argc, argv);
/*
* free off any memory the command used.
*/
pool_empty(ios->mem);
if (ret == EINVALID_CMD_LINE && !_interactive) if (ret == EINVALID_CMD_LINE && !_interactive)
usage(com->name); usage(com->name);

View File

@ -1,75 +1,19 @@
/* /*
* Copyright (C) 2001 Sistina Software * Copyright (C) 2001 Sistina Software (UK) Limited.
*
* LVM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* LVM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LVM; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* *
* This file is released under the GPL.
*/ */
#include "tools.h" #include "tools.h"
/* FIXME Temporarily to get at MAX_PV etc. Move these tests elsewhere */ #define DEFAULT_PV 128
/* FIXME Also PE_SIZE stuff */ #define DEFAULT_LV 128
#include "../lib/format1/disk-rep.h" #define DEFAULT_EXTENT 8192
int vgcreate(int argc, char **argv) int vgcreate(int argc, char **argv)
{ {
int opt; int max_lv, max_pv, extent_size;
int max_lv = MAX_LV - 1;
int max_pv = MAX_PV - 1;
int min_pv_index = 0;
ulong max_pv_size = 0;
ulong min_pv_size = -1;
/* long pe_size = LVM_DEFAULT_PE_SIZE; */
char *dummy;
char *vg_name;
struct volume_group *vg; struct volume_group *vg;
struct physical_volume *pv;
struct list_head *pvh;
struct pv_list *pvl;
char *pv_name = NULL;
if (arg_count(maxlogicalvolumes_ARG))
max_lv = arg_int_value(maxlogicalvolumes_ARG, 0);
if (arg_count(maxphysicalvolumes_ARG))
max_pv = arg_int_value(maxphysicalvolumes_ARG, 0);
if (arg_count(physicalextentsize_ARG)) {
/* FIXME - Move?
pe_size = arg_int_value(physicalextentsize_ARG, 0);
pe_size = ((unsigned long long) pe_size * 1024) / SECTOR_SIZE;
if (vg_check_pe_size(pe_size) < 0) {
log_error("Invalid physical extent size %s",
display_size(sectors_to_k(pe_size),
SIZE_SHORT));
log_error("Must be power of 2 and between %s and %s",
display_size(sectors_to_k(LVM_MIN_PE_SIZE),
SIZE_SHORT),
display_size(sectors_to_k(LVM_MAX_PE_SIZE),
SIZE_SHORT));
return EINVALID_CMD_LINE;
}
*/
}
if (!argc) { if (!argc) {
log_error("Please provide volume group name and " log_error("Please provide volume group name and "
@ -82,166 +26,21 @@ int vgcreate(int argc, char **argv)
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
vg_name = argv[0]; max_lv = arg_int_value(maxlogicalvolumes_ARG, DEFAULT_LV);
argv++; max_pv = arg_int_value(maxphysicalvolumes_ARG, DEFAULT_PV);
argc--; extent_size = arg_int_value(physicalextentsize_ARG, DEFAULT_EXTENT);
if ((vg = ios->vg_read(ios, vg_name))) { /* create the new vg */
log_error("Volume group already exists: please use a " if (!vg_create(ios, argv[0], extent_size, max_pv, max_lv,
"different name"); argc - 1, argv + 1))
return ECMD_FAILED; return ECMD_FAILED;
}
/***** FIXME: Can we be free of this restriction?
log_verbose("Counting all existing volume groups");
if (vg_count >= MAX_VG) {
log_error("Maximum volume group count of %d reached", MAX_VG);
return ECMD_FAILED;
}
*****/
if (!(vg = vg_create())) {
return ECMD_FAILED;
}
/* check, if PVs are all defined and new */
log_verbose("Ensuring all physical volumes specified are new");
for (; opt < argc; opt++) {
pv_name = argv[opt];
if (!(pv = ios->pv_read(ios, pv_name))) {
log_error("Physical volume %s not found", pv_name);
return ECMD_FAILED;
}
/* FIXME Must PV be ACTIVE & ALLOCATABLE? */
log_verbose("Checking physical volume %s", pv_name);
log_verbose("Getting size of physical volume %s", pv_name);
log_verbose("Physical volume %s is %s 512-byte sectors",
pv_name, pv->size);
log_verbose("Checking physical volume %s is new", pv_name);
if (*pv->vg_name) {
log_error("%s already belongs to volume group %s",
pv_name, pv->vg_name);
}
log_verbose("Checking for identical physical volumes "
"on command line");
if ((pvh = find_pv_in_vg(vg, pv_name))) {
log_error("Physical volume %s listed multiple times",
pv_name);
return ECMD_FAILED;
}
if (max_pv_size < pv->size)
max_pv_size = pv->size;
if (min_pv_size > pv->size) {
min_pv_size = pv->size;
min_pv_index = opt;
}
if (!(pvl = dbg_malloc(sizeof(struct pv_list)))) {
log_error("pv_list allocation failed");
return ECMD_FAILED;
}
pvl->pv = *pv;
list_add(&pvl->list, &vg->pvs);
vg->pv_count++;
}
log_verbose("%d physical volume(s) will be inserted into "
"volume group %s", vg->pv_count, vg->name);
log_verbose("Maximum of %d physical volumes", max_pv);
if (max_pv < 0 || max_pv <= vg->pv_count || max_pv > MAX_PV) {
log_error("Invalid maximum physical volumes -p %d", max_pv);
return EINVALID_CMD_LINE;
}
vg->max_pv = max_pv;
log_verbose("Maximum of %d logical volumes", max_lv);
if (max_lv < 0 || max_lv > MAX_LV) {
log_error("Invalid maximum logical volumes -l %d", max_lv);
return EINVALID_CMD_LINE;
}
vg->max_lv = max_lv;
/******** FIXME: Enforce these checks internally within vg_write?
size = (LVM_PV_DISK_SIZE + LVM_VG_DISK_SIZE + max_pv * NAME_LEN + max_lv * sizeof(lv_t));
if (size / SECTOR_SIZE > min_pv_size / 5) {
log_error("More than 20%% [%d KB] of physical volume %s with %u KB would be used", size,
pvp[min_pv_index]->pv_name, pvp[min_pv_index]->pv_size / 2);
return LVM_E_PV_TOO_SMALL;
}
************/
/************ FIXME More work required here
************ Check extent sizes compatible and set up pe's?
if (
(ret =
vg_setup_for_create(vg_name, &vg, pvp, pe_size, max_pv,
max_lv)) < 0) {
if (ret == -LVM_EVG_SETUP_FOR_CREATE_PV_SIZE_MIN) {
log_error
("%d physical volume%s too small for physical extent size of %s",
count_sav, count_sav > 1 ? "s" : "", vg_name);
log_error
("Minimum physical volume at this physical extent size is %s",
(dummy =
display_size(sectors_to_k(vg.pe_size) *
LVM_PE_SIZE_PV_SIZE_REL,
SIZE_SHORT)));
dbg_free(dummy);
} else if (ret == -LVM_EVG_SETUP_FOR_CREATE_PV_SIZE_MAX) {
log_error
("%d physical volume%s too large for physical extent size of %s",
count_sav, count_sav > 1 ? "s" : "", vg_name);
log_error
("Maximum physical volume at this physical extent size is %s",
(dummy =
display_size(sectors_to_k(vg.pe_size) *
LVM_PE_T_MAX, SHORT)));
dbg_free(dummy);
}
return ECMD_FAILED;
}
************/
if (arg_count(physicalextentsize_ARG) == 0) {
log_print("Using default physical extent size %s",
(dummy = display_size(pe_size / 2, SIZE_SHORT)));
dbg_free(dummy);
}
log_print("Maximum logical volume size is %s",
(dummy = display_size(LVM_LV_SIZE_MAX(&vg) / 2, SIZE_LONG)));
dbg_free(dummy);
vg_remove_dir_and_group_and_nodes(vg_name);
vg->status |= ACTIVE;
/* store vg on disk(s) */ /* store vg on disk(s) */
if (ios->vg_write(ios, vg)) { if (ios->vg_write(ios, vg))
return ECMD_FAILED; return ECMD_FAILED;
}
/******* FIXME /dev/vg???
log_verbose("Creating volume group directory %s%s", prefix, vg_name);
if (vg_create_dir_and_group(&vg)) {
return ECMD_FAILED;
}
*********/
/* FIXME Activate it */
/******* FIXME backups
if ((ret = do_autobackup(vg_name, &vg)))
return ret;
******/
log_print("Volume group %s successfully created and activated", log_print("Volume group %s successfully created and activated",
vg_name); argv[0]);
return 0; return 0;
} }