2002-11-18 17:04:08 +03:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2002 - 2004 Sistina Software , Inc . All rights reserved .
2013-07-06 16:15:42 +04:00
* Copyright ( C ) 2004 - 2013 Red Hat , Inc . All rights reserved .
2002-11-18 17:04:08 +03:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2002-11-18 17:04:08 +03: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 .
2002-11-18 17:04:08 +03: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 ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2002-11-18 17:04:08 +03:00
*/
# include "tools.h"
int pvremove ( struct cmd_context * cmd , int argc , char * * argv )
{
2016-02-17 00:00:50 +03:00
struct processing_handle * handle ;
2016-02-19 00:38:23 +03:00
struct pvcreate_params pp ;
2016-02-17 00:00:50 +03:00
int ret ;
2002-11-18 17:04:08 +03:00
if ( ! argc ) {
log_error ( " Please enter a physical volume path " ) ;
return EINVALID_CMD_LINE ;
}
2016-02-19 00:38:23 +03:00
pvcreate_params_set_defaults ( & pp ) ;
2013-04-03 00:10:18 +04:00
2016-02-17 00:00:50 +03:00
pp . is_remove = 1 ;
pp . force = arg_count ( cmd , force_ARG ) ;
pp . yes = arg_count ( cmd , yes_ARG ) ;
pp . pv_count = argc ;
pp . pv_names = argv ;
2015-01-06 16:17:53 +03:00
2016-02-17 00:00:50 +03:00
/*
* Needed to change the set of orphan PVs .
* ( disable afterward to prevent process_each_pv from doing
* a shared global lock since it ' s already acquired it ex . )
*/
2015-03-05 23:00:44 +03:00
if ( ! lockd_gl ( cmd , " ex " , 0 ) )
return_ECMD_FAILED ;
2016-02-17 00:00:50 +03:00
cmd - > lockd_gl_disable = 1 ;
2015-03-05 23:00:44 +03:00
2016-05-31 13:24:05 +03:00
if ( ! ( handle = init_processing_handle ( cmd , NULL ) ) ) {
2016-02-17 00:00:50 +03:00
log_error ( " Failed to initialize processing handle. " ) ;
return ECMD_FAILED ;
2002-11-18 17:04:08 +03:00
}
2016-02-17 00:00:50 +03:00
/*
* pvremove uses the same toollib function as pvcreate ,
* but sets " is_remove " which changes the check function ,
* and the actual create vs remove step .
*/
if ( ! pvcreate_each_device ( cmd , handle , & pp ) )
ret = ECMD_FAILED ;
else {
/* pvcreate_each_device returns with orphans locked */
unlock_vg ( cmd , VG_ORPHANS ) ;
ret = ECMD_PROCESSED ;
}
2015-01-06 16:17:53 +03:00
2016-02-17 00:00:50 +03:00
destroy_processing_handle ( cmd , handle ) ;
return ret ;
2002-11-18 17:04:08 +03:00
}