2001-10-16 02:04:27 +04:00
/*
2008-01-30 17:00:02 +03:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2009-05-13 17:02:52 +04:00
* Copyright ( C ) 2004 - 2009 Red Hat , Inc . All rights reserved .
2001-10-16 02:04:27 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2001-10-16 02:04:27 +04:00
*
2004-03-30 23:35:44 +04:00
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2001-10-16 02:04:27 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2001-10-16 02:04:27 +04:00
*/
# include "tools.h"
2010-10-13 14:34:31 +04:00
static int _restore_pv ( struct volume_group * vg , char * pv_name )
{
struct pv_list * pvl = NULL ;
pvl = find_pv_in_vg ( vg , pv_name ) ;
if ( ! pvl ) {
log_warn ( " WARNING: PV %s not found in VG %s " , pv_name , vg - > name ) ;
return 0 ;
}
if ( ! ( pvl - > pv - > status & MISSING_PV ) ) {
log_warn ( " WARNING: PV %s was not missing in VG %s " , pv_name , vg - > name ) ;
return 0 ;
}
if ( ! pvl - > pv - > dev ) {
log_warn ( " WARNING: The PV %s is still missing. " , pv_name ) ;
return 0 ;
}
pvl - > pv - > status & = ~ MISSING_PV ;
return 1 ;
}
2002-02-11 23:50:53 +03:00
int vgextend ( struct cmd_context * cmd , int argc , char * * argv )
2001-10-16 02:04:27 +04:00
{
2011-02-18 17:47:28 +03:00
const char * vg_name ;
2001-10-16 02:04:27 +04:00
struct volume_group * vg = NULL ;
2009-04-10 14:01:38 +04:00
int r = ECMD_FAILED ;
2009-10-06 00:04:08 +04:00
struct pvcreate_params pp ;
2010-10-13 14:34:31 +04:00
int fixed = 0 , i = 0 ;
2001-10-16 02:04:27 +04:00
if ( ! argc ) {
log_error ( " Please enter volume group name and "
2002-02-12 00:00:35 +03:00
" physical volume(s) " ) ;
2001-10-16 02:04:27 +04:00
return EINVALID_CMD_LINE ;
}
2007-03-09 23:47:41 +03:00
vg_name = skip_dev_dir ( cmd , argv [ 0 ] , NULL ) ;
2001-10-16 02:04:27 +04:00
argc - - ;
argv + + ;
2009-10-06 00:55:56 +04:00
if ( arg_count ( cmd , metadatacopies_ARG ) ) {
log_error ( " Invalid option --metadatacopies, "
" use --pvmetadatacopies instead. " ) ;
return EINVALID_CMD_LINE ;
}
2009-11-01 22:51:54 +03:00
pvcreate_params_set_defaults ( & pp ) ;
if ( ! pvcreate_params_validate ( cmd , argc , argv , & pp ) ) {
2009-10-06 00:03:37 +04:00
return EINVALID_CMD_LINE ;
}
2012-07-27 02:06:06 +04:00
/*
* It is always ok to add new PVs to a VG - even if there are
* missing PVs . No LVs are affected by this operation , but
* repair processes - particularly for RAID segtypes - can
* be facilitated .
*/
cmd - > handles_missing_pvs = 1 ;
2010-10-13 14:34:31 +04:00
2002-01-30 18:04:48 +03:00
log_verbose ( " Checking for volume group \" %s \" " , vg_name ) ;
2009-07-14 06:14:04 +04:00
vg = vg_read_for_update ( cmd , vg_name , NULL , 0 ) ;
2009-07-01 20:59:37 +04:00
if ( vg_read_error ( vg ) ) {
2011-08-11 00:25:29 +04:00
release_vg ( vg ) ;
2009-09-15 02:47:49 +04:00
stack ;
2007-07-23 21:27:55 +04:00
return ECMD_FAILED ;
2009-07-01 20:59:37 +04:00
}
2009-07-24 19:01:43 +04:00
2009-08-13 16:03:46 +04:00
if ( ! archive ( vg ) )
2009-09-15 02:47:49 +04:00
goto_bad ;
2009-08-13 16:03:46 +04:00
2010-10-13 14:34:31 +04:00
if ( arg_count ( cmd , restoremissing_ARG ) ) {
for ( i = 0 ; i < argc ; + + i ) {
if ( _restore_pv ( vg , argv [ i ] ) )
+ + fixed ;
}
if ( ! fixed ) {
log_error ( " No PV has been restored. " ) ;
2013-05-23 18:17:08 +04:00
goto bad ;
2010-10-13 14:34:31 +04:00
}
} else { /* no --restore, normal vgextend */
2013-03-18 00:29:58 +04:00
if ( ! lock_vol ( cmd , VG_ORPHANS , LCK_VG_WRITE , NULL ) ) {
2010-10-13 14:34:31 +04:00
log_error ( " Can't get lock for orphan PVs " ) ;
2011-08-11 00:25:29 +04:00
unlock_and_release_vg ( cmd , vg , vg_name ) ;
2010-10-13 14:34:31 +04:00
return ECMD_FAILED ;
}
if ( arg_count ( cmd , metadataignore_ARG ) & &
( vg_mda_copies ( vg ) ! = VGMETADATACOPIES_UNMANAGED ) & &
( pp . force = = PROMPT ) & &
yes_no_prompt ( " Override preferred number of copies "
2010-07-08 01:30:07 +04:00
" of VG %s metadata? [y/n]: " ,
2010-10-13 14:34:31 +04:00
vg_name ) = = ' n ' ) {
log_error ( " Volume group %s not changed " , vg_name ) ;
2013-05-23 18:17:08 +04:00
goto bad ;
2010-10-13 14:34:31 +04:00
}
2010-07-07 23:02:50 +04:00
2010-10-13 14:34:31 +04:00
/* extend vg */
2011-02-18 17:47:28 +03:00
if ( ! vg_extend ( vg , argc , ( const char * const * ) argv , & pp ) )
2010-10-13 14:34:31 +04:00
goto_bad ;
2001-10-16 02:04:27 +04:00
2010-10-13 14:34:31 +04:00
if ( arg_count ( cmd , metadataignore_ARG ) & &
( vg_mda_copies ( vg ) ! = VGMETADATACOPIES_UNMANAGED ) & &
( vg_mda_copies ( vg ) ! = vg_mda_used_count ( vg ) ) ) {
log_warn ( " WARNING: Changing preferred number of copies of VG %s "
2010-07-07 22:59:45 +04:00
" metadata from % " PRIu32 " to % " PRIu32 , vg_name ,
2010-10-13 14:34:31 +04:00
vg_mda_copies ( vg ) , vg_mda_used_count ( vg ) ) ;
vg_set_mda_copies ( vg , vg_mda_used_count ( vg ) ) ;
}
2010-07-07 22:59:45 +04:00
2010-10-13 14:34:31 +04:00
/* ret > 0 */
log_verbose ( " Volume group \" %s \" will be extended by %d new "
" physical volumes " , vg_name , argc ) ;
}
2001-10-16 02:04:27 +04:00
2002-02-12 00:00:35 +03:00
/* store vg on disk(s) */
2003-07-05 02:34:56 +04:00
if ( ! vg_write ( vg ) | | ! vg_commit ( vg ) )
2009-09-15 02:47:49 +04:00
goto_bad ;
2001-10-16 02:04:27 +04:00
2002-01-07 14:12:11 +03:00
backup ( vg ) ;
config: add silent mode
Accept -q as the short form of --quiet.
Suppress non-essential standard output if -q is given twice.
Treat log/silent in lvm.conf as equivalent to -qq.
Review all log_print messages and change some to
log_print_unless_silent.
When silent, the following commands still produce output:
dumpconfig, lvdisplay, lvmdiskscan, lvs, pvck, pvdisplay,
pvs, version, vgcfgrestore -l, vgdisplay, vgs.
[Needs checking.]
Non-essential messages are shifted from log level 4 to log level 5
for syslog and lvm2_log_fn purposes.
2012-08-25 23:35:48 +04:00
log_print_unless_silent ( " Volume group \" %s \" successfully extended " , vg_name ) ;
2009-04-10 14:01:38 +04:00
r = ECMD_PROCESSED ;
2001-10-16 02:04:27 +04:00
2009-09-15 02:47:49 +04:00
bad :
2010-10-18 21:27:10 +04:00
if ( ! arg_count ( cmd , restoremissing_ARG ) )
unlock_vg ( cmd , VG_ORPHANS ) ;
2011-08-11 00:25:29 +04:00
unlock_and_release_vg ( cmd , vg , vg_name ) ;
2009-04-10 14:01:38 +04:00
return r ;
2001-10-16 02:04:27 +04:00
}