mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-23 21:35:29 +03:00
vgmerge first cut
This commit is contained in:
parent
b31dc66628
commit
d3bb140f89
@ -42,6 +42,7 @@ SOURCES=\
|
||||
vgcreate.c \
|
||||
vgdisplay.c \
|
||||
vgextend.c \
|
||||
vgmerge.c \
|
||||
vgreduce.c \
|
||||
vgremove.c \
|
||||
vgrename.c \
|
||||
|
@ -76,12 +76,12 @@ int lvresize(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (arg_count(stripes_ARG)) {
|
||||
log_print("Stripes not yet implemented in LVM2. Ignoring.");
|
||||
stripes = arg_int_value(stripes_ARG, 1);
|
||||
}
|
||||
|
||||
if (arg_count(stripesize_ARG))
|
||||
stripesize = 2 * arg_int_value(stripesize_ARG, 0);
|
||||
log_print("Stripes not yet implemented in LVM2. Ignoring.");
|
||||
stripes = arg_int_value(stripes_ARG, 1);
|
||||
}
|
||||
|
||||
if (arg_count(stripesize_ARG))
|
||||
stripesize = 2 * arg_int_value(stripesize_ARG, 0);
|
||||
|
||||
if (!argc) {
|
||||
log_error("Please provide the logical volume name");
|
||||
@ -183,10 +183,9 @@ int lvresize(int argc, char **argv)
|
||||
uint32_t sz = lv->segments[seg]->stripesize;
|
||||
uint32_t str = lv->segments[seg]->stripes;
|
||||
|
||||
if ((seg_stripesize && seg_stripesize != sz
|
||||
if ((seg_stripesize && seg_stripesize != sz
|
||||
&& !stripesize) ||
|
||||
(seg_stripes && seg_stripes != str
|
||||
&& !stripes)) {
|
||||
(seg_stripes && seg_stripes != str && !stripes)) {
|
||||
log_error("Please specify number of "
|
||||
"stripes (-i) and stripesize (-I)");
|
||||
return EINVALID_CMD_LINE;
|
||||
@ -213,8 +212,8 @@ int lvresize(int argc, char **argv)
|
||||
log_error("Ignoring stripes and stripesize arguments "
|
||||
"when reducing");
|
||||
for (seg = 0; seg < lv->segment_count; seg++) {
|
||||
uint32_t seg_extents = lv->segments[seg]->pe_count *
|
||||
vg->extent_size;
|
||||
uint32_t seg_extents = lv->segments[seg]->pe_count *
|
||||
vg->extent_size;
|
||||
|
||||
seg_stripesize = lv->segments[seg]->stripesize;
|
||||
seg_stripes = lv->segments[seg]->stripes;
|
||||
@ -230,12 +229,12 @@ int lvresize(int argc, char **argv)
|
||||
stripes = seg_stripes;
|
||||
}
|
||||
|
||||
if ((size_rest = seg_size % (stripes * vg->extent_size))) {
|
||||
log_print("Rounding size (%d extents) down to stripe boundary "
|
||||
"size of last segment (%d extents)", extents,
|
||||
extents - size_rest );
|
||||
extents = extents - size_rest;
|
||||
}
|
||||
if ((size_rest = seg_size % (stripes * vg->extent_size))) {
|
||||
log_print("Rounding size (%d extents) down to stripe boundary "
|
||||
"size of last segment (%d extents)", extents,
|
||||
extents - size_rest);
|
||||
extents = extents - size_rest;
|
||||
}
|
||||
|
||||
if (extents == lv->le_count) {
|
||||
log_error("New size (%d extents) matches existing size "
|
||||
@ -326,8 +325,7 @@ int lvresize(int argc, char **argv)
|
||||
log_print("Extending logical volume %s to %s", lv_name, dummy);
|
||||
dbg_free(dummy);
|
||||
|
||||
lv_extend(lv, stripes, stripesize, extents - lv->le_count,
|
||||
pvh);
|
||||
lv_extend(lv, stripes, stripesize, extents - lv->le_count, pvh);
|
||||
}
|
||||
|
||||
/********* FIXME Suspend lv ***********/
|
||||
|
@ -27,7 +27,6 @@ int vgcfgbackup(int argc, char **argv) {return 1;}
|
||||
int vgcfgrestore(int argc, char **argv) {return 1;}
|
||||
int vgexport(int argc, char **argv) {return 1;}
|
||||
int vgimport(int argc, char **argv) {return 1;}
|
||||
int vgmerge(int argc, char **argv) {return 1;}
|
||||
int vgmknodes(int argc, char **argv) {return 1;}
|
||||
int vgsplit(int argc, char **argv) {return 1;}
|
||||
|
||||
|
144
tools/vgmerge.c
Normal file
144
tools/vgmerge.c
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tools.h"
|
||||
|
||||
int vgmerge_single(const char *vg_name_to, const char *vg_name_from);
|
||||
|
||||
int vgmerge(int argc, char **argv)
|
||||
{
|
||||
char *vg_name_to;
|
||||
int opt = 0;
|
||||
int ret = 0, ret_max = 0;
|
||||
|
||||
if (argc < 2) {
|
||||
log_error("Please enter 2 or more volume groups to merge");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
vg_name_to = argv[0];
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
for (; opt < argc; opt++) {
|
||||
ret = vgmerge_single(vg_name_to, argv[opt]);
|
||||
if (ret > ret_max)
|
||||
ret_max = ret;
|
||||
}
|
||||
|
||||
return ret_max;
|
||||
}
|
||||
|
||||
int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
|
||||
{
|
||||
struct volume_group *vg_to, *vg_from;
|
||||
struct list *lvh1, *lvh2;
|
||||
|
||||
if (!strcmp(vg_name_to, vg_name_from)) {
|
||||
log_error("Duplicate volume group name %s", vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
log_verbose("Checking for volume group %s", vg_name_to);
|
||||
if (!(vg_to = fid->ops->vg_read(fid, vg_name_to))) {
|
||||
log_error("Volume group %s doesn't exist", vg_name_to);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
log_verbose("Checking for volume group %s", vg_name_from);
|
||||
if (!(vg_from = fid->ops->vg_read(fid, vg_name_from))) {
|
||||
log_error("Volume group %s doesn't exist", vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
/* FIXME status - confirm no active LVs? */
|
||||
if (vg_from->status & ACTIVE) {
|
||||
log_error("Volume group %s must be inactive", vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
/* Check compatibility */
|
||||
if (vg_to->extent_size != vg_from->extent_size) {
|
||||
log_error("Extent sizes differ: %d (%s) and %d (%s)",
|
||||
vg_to->extent_size, vg_to->name,
|
||||
vg_from->extent_size, vg_from->name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (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);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (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);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
/* Check no conflicts with LV names */
|
||||
list_iterate(lvh1, &vg_to->lvs) {
|
||||
list_iterate(lvh2, &vg_from->lvs) {
|
||||
char *name1 = list_item(lvh1, struct lv_list)->lv.name;
|
||||
char *name2 = list_item(lvh2, struct lv_list)->lv.name;
|
||||
if (!strcmp(name1, name2)) {
|
||||
log_error("Duplicate logical volume name %s "
|
||||
"in %s and %s", name1, vg_to->name,
|
||||
vg_from->name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME List arg: vg_show_with_pv_and_lv(vg_to); */
|
||||
|
||||
/* FIXME Test arg (into all tools) */
|
||||
|
||||
/* Merge volume groups */
|
||||
while (!list_empty(&vg_from->pvs)) {
|
||||
list_del(&vg_from->pvs);
|
||||
list_add(&vg_to->pvs, &vg_from->pvs);
|
||||
}
|
||||
vg_to->pv_count += vg_from->pv_count;
|
||||
|
||||
while (!list_empty(&vg_from->lvs)) {
|
||||
list_del(&vg_from->lvs);
|
||||
list_add(&vg_to->lvs, &vg_from->lvs);
|
||||
}
|
||||
vg_to->lv_count += vg_from->lv_count;
|
||||
|
||||
vg_to->extent_count += vg_from->extent_count;
|
||||
vg_to->free_count += vg_from->free_count;
|
||||
|
||||
/* store it on disks */
|
||||
log_verbose("Writing out updated volume group");
|
||||
if (!(fid->ops->vg_write(fid, vg_to))) {
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
/* FIXME Remove /dev/vgfrom */
|
||||
|
||||
log_print("Volume group %s successfully merged into %s",
|
||||
vg_from->name, vg_to->name);
|
||||
return 0;
|
||||
}
|
@ -33,7 +33,7 @@ int vgrename(int argc, char **argv)
|
||||
struct list *pvh;
|
||||
|
||||
if (argc != 2) {
|
||||
log_error("old and new volume group names need specifying");
|
||||
log_error("Old and new volume group names need specifying");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user