2001-10-03 20:38:07 +00:00
/*
2004-03-30 19:35:44 +00:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2009-05-13 13:02:52 +00:00
* Copyright ( C ) 2004 - 2009 Red Hat , Inc . All rights reserved .
2001-11-07 08:50:07 +00:00
*
2004-03-30 19:35:44 +00:00
* This file is part of LVM2 .
2001-11-07 08:50:07 +00:00
*
2004-03-30 19:35:44 +00: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-20 20:55:30 +00:00
* of the GNU Lesser General Public License v .2 .1 .
2001-11-07 08:50:07 +00:00
*
2007-08-20 20:55:30 +00:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 19:35:44 +00: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-03 20:38:07 +00:00
*/
# include "tools.h"
2002-02-11 20:50:53 +00:00
int vgcreate ( struct cmd_context * cmd , int argc , char * * argv )
2001-10-03 20:38:07 +00:00
{
2008-01-15 22:56:30 +00:00
struct vgcreate_params vp_new ;
struct vgcreate_params vp_def ;
2001-10-03 20:38:07 +00:00
struct volume_group * vg ;
2004-03-08 17:19:15 +00:00
const char * tag ;
2008-04-08 14:22:13 +00:00
const char * clustered_message = " " ;
2009-10-05 20:03:37 +00:00
char * vg_name ;
2009-10-05 20:04:08 +00:00
struct pvcreate_params pp ;
2010-11-11 17:29:05 +00:00
struct arg_value_group_list * current_group ;
2001-10-03 20:38:07 +00:00
2001-10-12 12:21:43 +00:00
if ( ! argc ) {
log_error ( " Please provide volume group name and "
" physical volumes " ) ;
2001-10-04 22:53:37 +00:00
return EINVALID_CMD_LINE ;
2001-10-03 20:38:07 +00:00
}
2009-10-05 20:03:37 +00:00
vg_name = argv [ 0 ] ;
argc - - ;
argv + + ;
2009-11-01 19:51:54 +00:00
pvcreate_params_set_defaults ( & pp ) ;
if ( ! pvcreate_params_validate ( cmd , argc , argv , & pp ) ) {
2001-10-04 22:53:37 +00:00
return EINVALID_CMD_LINE ;
2001-10-03 20:38:07 +00:00
}
2009-11-01 20:02:32 +00:00
vgcreate_params_set_defaults ( & vp_def , NULL ) ;
2009-11-01 20:03:24 +00:00
vp_def . vg_name = vg_name ;
2012-10-16 10:07:27 +02:00
if ( ! vgcreate_params_set_from_args ( cmd , & vp_new , & vp_def ) )
2004-03-26 15:46:37 +00:00
return EINVALID_CMD_LINE ;
2012-10-16 10:07:27 +02:00
if ( ! vgcreate_params_validate ( cmd , & vp_new ) )
2008-01-11 07:02:35 +00:00
return EINVALID_CMD_LINE ;
2001-10-15 18:39:40 +00:00
2012-02-23 13:11:07 +00:00
lvmcache_seed_infos_from_lvmetad ( cmd ) ;
2001-11-21 19:32:35 +00:00
/* Create the new VG */
Change vg_create() to take only minimal parameters and obtain a lock.
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name);
This is the first step towards the API called to create a VG.
Call vg_lock_newname() inside this function. Use _vg_make_handle()
where possible.
Now we have 2 ways to construct a volume group:
1) vg_read: Used when constructing an existing VG from disks
2) vg_create: Used when constructing a new VG
Both of these interfaces obtain a lock, and return a vg_t *.
The usage of _vg_make_handle() inside vg_create() doesn't fit
perfectly but it's ok for now. Needs some cleanup though and I've
noted "FIXME" in the code.
Add the new vg_create() plus vg 'set' functions for non-default
VG parameters in the following tools:
- vgcreate: Fairly straightforward refactoring. We just moved
vg_lock_newname inside vg_create so we check the return via
vg_read_error.
- vgsplit: The refactoring here is a bit more tricky. Originally
we called vg_lock_newname and depending on the error code, we either
read the existing vg or created the new one. Now vg_create()
calls vg_lock_newname, so we first try to create the VG. If this
fails with FAILED_EXIST, we can then do the vg_read. If the
create succeeds, we check the input parameters and set any new
values on the VG.
TODO in future patches:
1. The VG_ORPHAN lock needs some thought. We may want to treat
this as any other VG, and require the application to obtain a handle
and pass it to other API calls (for example, vg_extend). Or,
we may find that hiding the VG_ORPHAN lock inside other APIs is
the way to go. I thought of placing the VG_ORPHAN lock inside
vg_create() and tying it to the vg handle, but was not certain
this was the right approach.
2. Cleanup error paths. Integrate vg_read_error() with vg_create and
vg_read* error codes and/or the new error APIs.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:09:33 +00:00
vg = vg_create ( cmd , vp_new . vg_name ) ;
2009-12-03 19:20:48 +00:00
if ( vg_read_error ( vg ) ) {
if ( vg_read_error ( vg ) = = FAILED_EXIST )
log_error ( " A volume group called %s already exists. " , vp_new . vg_name ) ;
else
log_error ( " Can't get lock for %s. " , vp_new . vg_name ) ;
2011-08-10 20:25:29 +00:00
release_vg ( vg ) ;
2009-12-28 18:34:45 +00:00
return ECMD_FAILED ;
2009-12-03 19:20:48 +00:00
}
Change vg_create() to take only minimal parameters and obtain a lock.
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name);
This is the first step towards the API called to create a VG.
Call vg_lock_newname() inside this function. Use _vg_make_handle()
where possible.
Now we have 2 ways to construct a volume group:
1) vg_read: Used when constructing an existing VG from disks
2) vg_create: Used when constructing a new VG
Both of these interfaces obtain a lock, and return a vg_t *.
The usage of _vg_make_handle() inside vg_create() doesn't fit
perfectly but it's ok for now. Needs some cleanup though and I've
noted "FIXME" in the code.
Add the new vg_create() plus vg 'set' functions for non-default
VG parameters in the following tools:
- vgcreate: Fairly straightforward refactoring. We just moved
vg_lock_newname inside vg_create so we check the return via
vg_read_error.
- vgsplit: The refactoring here is a bit more tricky. Originally
we called vg_lock_newname and depending on the error code, we either
read the existing vg or created the new one. Now vg_create()
calls vg_lock_newname, so we first try to create the VG. If this
fails with FAILED_EXIST, we can then do the vg_read. If the
create succeeds, we check the input parameters and set any new
values on the VG.
TODO in future patches:
1. The VG_ORPHAN lock needs some thought. We may want to treat
this as any other VG, and require the application to obtain a handle
and pass it to other API calls (for example, vg_extend). Or,
we may find that hiding the VG_ORPHAN lock inside other APIs is
the way to go. I thought of placing the VG_ORPHAN lock inside
vg_create() and tying it to the vg handle, but was not certain
this was the right approach.
2. Cleanup error paths. Integrate vg_read_error() with vg_create and
vg_read* error codes and/or the new error APIs.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:09:33 +00:00
2013-06-25 12:32:09 +02:00
if ( vg - > fid - > fmt - > features & FMT_CONFIG_PROFILE )
vg - > profile = vg - > cmd - > profile_params - > global_profile ;
Change vg_create() to take only minimal parameters and obtain a lock.
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name);
This is the first step towards the API called to create a VG.
Call vg_lock_newname() inside this function. Use _vg_make_handle()
where possible.
Now we have 2 ways to construct a volume group:
1) vg_read: Used when constructing an existing VG from disks
2) vg_create: Used when constructing a new VG
Both of these interfaces obtain a lock, and return a vg_t *.
The usage of _vg_make_handle() inside vg_create() doesn't fit
perfectly but it's ok for now. Needs some cleanup though and I've
noted "FIXME" in the code.
Add the new vg_create() plus vg 'set' functions for non-default
VG parameters in the following tools:
- vgcreate: Fairly straightforward refactoring. We just moved
vg_lock_newname inside vg_create so we check the return via
vg_read_error.
- vgsplit: The refactoring here is a bit more tricky. Originally
we called vg_lock_newname and depending on the error code, we either
read the existing vg or created the new one. Now vg_create()
calls vg_lock_newname, so we first try to create the VG. If this
fails with FAILED_EXIST, we can then do the vg_read. If the
create succeeds, we check the input parameters and set any new
values on the VG.
TODO in future patches:
1. The VG_ORPHAN lock needs some thought. We may want to treat
this as any other VG, and require the application to obtain a handle
and pass it to other API calls (for example, vg_extend). Or,
we may find that hiding the VG_ORPHAN lock inside other APIs is
the way to go. I thought of placing the VG_ORPHAN lock inside
vg_create() and tying it to the vg handle, but was not certain
this was the right approach.
2. Cleanup error paths. Integrate vg_read_error() with vg_create and
vg_read* error codes and/or the new error APIs.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:09:33 +00:00
if ( ! vg_set_extent_size ( vg , vp_new . extent_size ) | |
! vg_set_max_lv ( vg , vp_new . max_lv ) | |
! vg_set_max_pv ( vg , vp_new . max_pv ) | |
2009-10-31 17:39:22 +00:00
! vg_set_alloc_policy ( vg , vp_new . alloc ) | |
2010-06-28 20:38:23 +00:00
! vg_set_clustered ( vg , vp_new . clustered ) | |
2010-06-30 20:03:52 +00:00
! vg_set_mda_copies ( vg , vp_new . vgmetadatacopies ) )
2009-12-28 18:34:45 +00:00
goto bad_orphan ;
Change vg_create() to take only minimal parameters and obtain a lock.
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name);
This is the first step towards the API called to create a VG.
Call vg_lock_newname() inside this function. Use _vg_make_handle()
where possible.
Now we have 2 ways to construct a volume group:
1) vg_read: Used when constructing an existing VG from disks
2) vg_create: Used when constructing a new VG
Both of these interfaces obtain a lock, and return a vg_t *.
The usage of _vg_make_handle() inside vg_create() doesn't fit
perfectly but it's ok for now. Needs some cleanup though and I've
noted "FIXME" in the code.
Add the new vg_create() plus vg 'set' functions for non-default
VG parameters in the following tools:
- vgcreate: Fairly straightforward refactoring. We just moved
vg_lock_newname inside vg_create so we check the return via
vg_read_error.
- vgsplit: The refactoring here is a bit more tricky. Originally
we called vg_lock_newname and depending on the error code, we either
read the existing vg or created the new one. Now vg_create()
calls vg_lock_newname, so we first try to create the VG. If this
fails with FAILED_EXIST, we can then do the vg_read. If the
create succeeds, we check the input parameters and set any new
values on the VG.
TODO in future patches:
1. The VG_ORPHAN lock needs some thought. We may want to treat
this as any other VG, and require the application to obtain a handle
and pass it to other API calls (for example, vg_extend). Or,
we may find that hiding the VG_ORPHAN lock inside other APIs is
the way to go. I thought of placing the VG_ORPHAN lock inside
vg_create() and tying it to the vg handle, but was not certain
this was the right approach.
2. Cleanup error paths. Integrate vg_read_error() with vg_create and
vg_read* error codes and/or the new error APIs.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:09:33 +00:00
2013-03-17 21:29:58 +01:00
if ( ! lock_vol ( cmd , VG_ORPHANS , LCK_VG_WRITE , NULL ) ) {
2009-07-24 15:01:43 +00:00
log_error ( " Can't get lock for orphan PVs " ) ;
goto bad_orphan ;
}
Change vg_create() to take only minimal parameters and obtain a lock.
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name);
This is the first step towards the API called to create a VG.
Call vg_lock_newname() inside this function. Use _vg_make_handle()
where possible.
Now we have 2 ways to construct a volume group:
1) vg_read: Used when constructing an existing VG from disks
2) vg_create: Used when constructing a new VG
Both of these interfaces obtain a lock, and return a vg_t *.
The usage of _vg_make_handle() inside vg_create() doesn't fit
perfectly but it's ok for now. Needs some cleanup though and I've
noted "FIXME" in the code.
Add the new vg_create() plus vg 'set' functions for non-default
VG parameters in the following tools:
- vgcreate: Fairly straightforward refactoring. We just moved
vg_lock_newname inside vg_create so we check the return via
vg_read_error.
- vgsplit: The refactoring here is a bit more tricky. Originally
we called vg_lock_newname and depending on the error code, we either
read the existing vg or created the new one. Now vg_create()
calls vg_lock_newname, so we first try to create the VG. If this
fails with FAILED_EXIST, we can then do the vg_read. If the
create succeeds, we check the input parameters and set any new
values on the VG.
TODO in future patches:
1. The VG_ORPHAN lock needs some thought. We may want to treat
this as any other VG, and require the application to obtain a handle
and pass it to other API calls (for example, vg_extend). Or,
we may find that hiding the VG_ORPHAN lock inside other APIs is
the way to go. I thought of placing the VG_ORPHAN lock inside
vg_create() and tying it to the vg handle, but was not certain
this was the right approach.
2. Cleanup error paths. Integrate vg_read_error() with vg_create and
vg_read* error codes and/or the new error APIs.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:09:33 +00:00
/* attach the pv's */
2011-02-18 14:47:28 +00:00
if ( ! vg_extend ( vg , argc , ( const char * const * ) argv , & pp ) )
Change vg_create() to take only minimal parameters and obtain a lock.
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name);
This is the first step towards the API called to create a VG.
Call vg_lock_newname() inside this function. Use _vg_make_handle()
where possible.
Now we have 2 ways to construct a volume group:
1) vg_read: Used when constructing an existing VG from disks
2) vg_create: Used when constructing a new VG
Both of these interfaces obtain a lock, and return a vg_t *.
The usage of _vg_make_handle() inside vg_create() doesn't fit
perfectly but it's ok for now. Needs some cleanup though and I've
noted "FIXME" in the code.
Add the new vg_create() plus vg 'set' functions for non-default
VG parameters in the following tools:
- vgcreate: Fairly straightforward refactoring. We just moved
vg_lock_newname inside vg_create so we check the return via
vg_read_error.
- vgsplit: The refactoring here is a bit more tricky. Originally
we called vg_lock_newname and depending on the error code, we either
read the existing vg or created the new one. Now vg_create()
calls vg_lock_newname, so we first try to create the VG. If this
fails with FAILED_EXIST, we can then do the vg_read. If the
create succeeds, we check the input parameters and set any new
values on the VG.
TODO in future patches:
1. The VG_ORPHAN lock needs some thought. We may want to treat
this as any other VG, and require the application to obtain a handle
and pass it to other API calls (for example, vg_extend). Or,
we may find that hiding the VG_ORPHAN lock inside other APIs is
the way to go. I thought of placing the VG_ORPHAN lock inside
vg_create() and tying it to the vg handle, but was not certain
this was the right approach.
2. Cleanup error paths. Integrate vg_read_error() with vg_create and
vg_read* error codes and/or the new error APIs.
Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
2009-07-09 10:09:33 +00:00
goto_bad ;
2001-10-03 20:38:07 +00:00
2008-01-15 22:56:30 +00:00
if ( vp_new . max_lv ! = vg - > max_lv )
2007-06-28 17:33:44 +00:00
log_warn ( " WARNING: Setting maxlogicalvolumes to %d "
" (0 means unlimited) " , vg - > max_lv ) ;
2001-10-15 18:39:40 +00:00
2008-01-15 22:56:30 +00:00
if ( vp_new . max_pv ! = vg - > max_pv )
2007-06-28 17:33:44 +00:00
log_warn ( " WARNING: Setting maxphysicalvolumes to %d "
" (0 means unlimited) " , vg - > max_pv ) ;
2001-10-15 18:39:40 +00:00
2004-03-26 15:46:37 +00:00
if ( arg_count ( cmd , addtag_ARG ) ) {
2010-11-11 17:29:05 +00:00
dm_list_iterate_items ( current_group , & cmd - > arg_value_groups ) {
if ( ! grouped_arg_is_set ( current_group - > arg_values , addtag_ARG ) )
continue ;
if ( ! ( tag = grouped_arg_str_value ( current_group - > arg_values , addtag_ARG , NULL ) ) ) {
log_error ( " Failed to get tag " ) ;
goto bad ;
}
2004-03-26 15:46:37 +00:00
2010-11-11 17:29:05 +00:00
if ( ! vg_change_tag ( vg , tag , 1 ) )
goto_bad ;
}
2004-03-26 15:46:37 +00:00
}
2010-11-11 17:29:05 +00:00
if ( vg_is_clustered ( vg ) )
2008-04-08 14:22:13 +00:00
clustered_message = " Clustered " ;
2010-11-11 17:29:05 +00:00
else if ( locking_is_clustered ( ) )
clustered_message = " Non-clustered " ;
2005-03-21 22:55:12 +00:00
2009-09-14 22:47:49 +00:00
if ( ! archive ( vg ) )
goto_bad ;
2002-01-09 13:17:14 +00:00
2001-11-21 19:32:35 +00:00
/* Store VG on disk(s) */
2009-09-14 22:47:49 +00:00
if ( ! vg_write ( vg ) | | ! vg_commit ( vg ) )
goto_bad ;
2002-02-11 15:42:34 +00:00
2009-07-24 15:01:43 +00:00
unlock_vg ( cmd , VG_ORPHANS ) ;
2008-01-15 22:56:30 +00:00
unlock_vg ( cmd , vp_new . vg_name ) ;
2001-10-03 20:38:07 +00:00
2002-01-07 11:12:11 +00:00
backup ( vg ) ;
2001-12-31 21:27:39 +00:00
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 20:35:48 +01:00
log_print_unless_silent ( " %s%colume group \" %s \" successfully created " ,
clustered_message , * clustered_message ? ' v ' : ' V ' , vg - > name ) ;
2001-10-12 14:25:53 +00:00
2011-08-10 20:25:29 +00:00
release_vg ( vg ) ;
2003-10-21 22:06:07 +00:00
return ECMD_PROCESSED ;
2008-12-01 20:14:33 +00:00
bad :
2009-07-24 15:01:43 +00:00
unlock_vg ( cmd , VG_ORPHANS ) ;
bad_orphan :
2011-08-10 20:25:29 +00:00
release_vg ( vg ) ;
2008-12-01 20:14:33 +00:00
unlock_vg ( cmd , vp_new . vg_name ) ;
return ECMD_FAILED ;
2001-10-03 20:38:07 +00:00
}