2001-10-09 16:05:34 +00:00
/*
2004-03-30 19:35:44 +00:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
* Copyright ( C ) 2004 Red Hat , Inc . All rights reserved .
2001-10-09 16:05:34 +00:00
*
2004-03-30 19:35:44 +00:00
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
* of the GNU General Public License v .2 .
*
* You should have received a copy of the GNU General Public License
* 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-09 16:05:34 +00:00
*/
2002-11-18 14:01:16 +00:00
# include "lib.h"
2001-10-16 16:25:28 +00:00
# include "metadata.h"
2001-10-09 16:05:34 +00:00
# include "activate.h"
2003-07-04 22:34:56 +00:00
# include "memlock.h"
2001-11-15 14:27:51 +00:00
# include "display.h"
2001-11-12 12:20:58 +00:00
# include "fs.h"
2004-04-08 15:23:23 +00:00
# include "lvm-file.h"
2001-12-31 19:09:51 +00:00
# include "lvm-string.h"
2002-02-25 12:56:16 +00:00
# include "pool.h"
# include "toolcontext.h"
2002-02-26 11:49:17 +00:00
# include "dev_manager.h"
2004-03-08 18:13:22 +00:00
# include "str_list.h"
2004-05-04 21:25:57 +00:00
# include "config.h"
2002-01-21 11:06:32 +00:00
# include <limits.h>
2002-02-18 15:52:48 +00:00
# include <fcntl.h>
2003-07-04 22:34:56 +00:00
# include <unistd.h>
2002-01-21 11:06:32 +00:00
2002-02-11 15:48:34 +00:00
# define _skip(fmt, args...) log_very_verbose("Skipping: " fmt , ## args)
2001-10-09 16:05:34 +00:00
2004-04-08 15:23:23 +00:00
int lvm1_present ( struct cmd_context * cmd )
{
char path [ PATH_MAX ] ;
if ( lvm_snprintf ( path , sizeof ( path ) , " %s/lvm/global " , cmd - > proc_dir )
< 0 ) {
log_error ( " LVM1 proc global snprintf failed " ) ;
return 0 ;
}
if ( path_exists ( path ) )
return 1 ;
else
return 0 ;
}
2003-01-08 22:44:07 +00:00
# ifndef DEVMAPPER_SUPPORT
void set_activation ( int act )
{
2004-03-19 16:26:46 +00:00
static int warned = 0 ;
if ( warned | | ! act )
return ;
log_error ( " Compiled without libdevmapper support. "
" Can't enable activation. " ) ;
warned = 1 ;
2003-01-08 22:44:07 +00:00
}
int activation ( void )
{
return 0 ;
}
int library_version ( char * version , size_t size )
{
return 0 ;
}
int driver_version ( char * version , size_t size )
{
return 0 ;
}
2004-03-26 19:52:09 +00:00
int target_present ( const char * target_name )
{
return 0 ;
}
2005-01-12 22:58:21 +00:00
int lv_info ( const struct logical_volume * lv , struct lvinfo * info ,
int with_open_count )
2003-01-08 22:44:07 +00:00
{
return 0 ;
}
2004-03-26 15:35:01 +00:00
int lv_info_by_lvid ( struct cmd_context * cmd , const char * lvid_s ,
2005-01-12 22:58:21 +00:00
struct lvinfo * info , int with_open_count )
2004-03-26 15:35:01 +00:00
{
return 0 ;
}
2003-01-08 22:44:07 +00:00
int lv_snapshot_percent ( struct logical_volume * lv , float * percent )
{
return 0 ;
}
2003-07-04 22:34:56 +00:00
int lv_mirror_percent ( struct logical_volume * lv , int wait , float * percent ,
uint32_t * event_nr )
2003-04-30 15:26:25 +00:00
{
return 0 ;
}
2003-01-08 22:44:07 +00:00
int lvs_in_vg_activated ( struct volume_group * vg )
{
return 0 ;
}
int lvs_in_vg_opened ( struct volume_group * vg )
{
return 0 ;
}
2004-03-08 18:54:13 +00:00
int lv_suspend ( struct cmd_context * cmd , const char * lvid_s )
{
return 1 ;
}
2003-01-08 22:44:07 +00:00
int lv_suspend_if_active ( struct cmd_context * cmd , const char * lvid_s )
{
return 1 ;
}
2004-03-08 18:54:13 +00:00
int lv_resume ( struct cmd_context * cmd , const char * lvid_s )
{
return 1 ;
}
2003-01-08 22:44:07 +00:00
int lv_resume_if_active ( struct cmd_context * cmd , const char * lvid_s )
{
return 1 ;
}
int lv_deactivate ( struct cmd_context * cmd , const char * lvid_s )
{
return 1 ;
}
2004-03-08 18:54:13 +00:00
int lv_activation_filter ( struct cmd_context * cmd , const char * lvid_s ,
int * activate_lv )
{
return 1 ;
}
2003-01-08 22:44:07 +00:00
int lv_activate ( struct cmd_context * cmd , const char * lvid_s )
{
return 1 ;
}
2004-03-08 18:54:13 +00:00
int lv_activate_with_filter ( struct cmd_context * cmd , const char * lvid_s )
{
return 1 ;
}
2003-11-12 19:16:48 +00:00
int lv_mknodes ( struct cmd_context * cmd , const struct logical_volume * lv )
{
return 1 ;
}
2003-07-04 22:34:56 +00:00
void activation_exit ( void )
{
return ;
}
2003-01-08 22:44:07 +00:00
# else /* DEVMAPPER_SUPPORT */
2002-11-18 14:01:16 +00:00
static int _activation = 1 ;
2002-12-19 23:25:55 +00:00
void set_activation ( int act )
2002-11-18 14:01:16 +00:00
{
2002-12-19 23:25:55 +00:00
if ( act = = _activation )
2002-11-18 14:01:16 +00:00
return ;
2002-12-19 23:25:55 +00:00
_activation = act ;
2002-11-18 14:01:16 +00:00
if ( _activation )
log_verbose ( " Activation enabled. Device-mapper kernel "
" driver will be used. " ) ;
else
log_verbose ( " Activation disabled. No device-mapper "
" interaction will be attempted. " ) ;
}
2002-12-19 23:25:55 +00:00
int activation ( void )
2002-11-18 14:01:16 +00:00
{
return _activation ;
}
2004-03-08 18:13:22 +00:00
static int _passes_activation_filter ( struct cmd_context * cmd ,
struct logical_volume * lv )
{
2004-05-04 18:28:15 +00:00
const struct config_node * cn ;
2004-03-08 18:13:22 +00:00
struct config_value * cv ;
char * str ;
char path [ PATH_MAX ] ;
2004-03-08 18:28:45 +00:00
if ( ! ( cn = find_config_node ( cmd - > cft - > root , " activation/volume_list " ) ) ) {
2004-05-04 18:28:15 +00:00
/* If no host tags defined, activate */
2004-03-08 18:13:22 +00:00
if ( list_empty ( & cmd - > tags ) )
return 1 ;
/* If any host tag matches any LV or VG tag, activate */
if ( str_list_match_list ( & cmd - > tags , & lv - > tags ) | |
str_list_match_list ( & cmd - > tags , & lv - > vg - > tags ) )
return 1 ;
/* Don't activate */
return 0 ;
}
for ( cv = cn - > v ; cv ; cv = cv - > next ) {
if ( cv - > type ! = CFG_STRING ) {
log_error ( " Ignoring invalid string in config file "
" activation/volume_list " ) ;
continue ;
}
str = cv - > v . str ;
if ( ! * str ) {
log_error ( " Ignoring empty string in config file "
" activation/volume_list " ) ;
continue ;
}
/* Tag? */
if ( * str = = ' @ ' ) {
str + + ;
if ( ! * str ) {
log_error ( " Ignoring empty tag in config file "
" activation/volume_list " ) ;
continue ;
}
/* If any host tag matches any LV or VG tag, activate */
if ( ! strcmp ( str , " * " ) ) {
if ( str_list_match_list ( & cmd - > tags , & lv - > tags )
| | str_list_match_list ( & cmd - > tags ,
& lv - > vg - > tags ) )
return 1 ;
else
continue ;
}
/* If supplied tag matches LV or VG tag, activate */
if ( str_list_match_item ( & lv - > tags , str ) | |
str_list_match_item ( & lv - > vg - > tags , str ) )
return 1 ;
else
continue ;
}
if ( ! index ( str , ' / ' ) ) {
/* vgname supplied */
if ( ! strcmp ( str , lv - > vg - > name ) )
return 1 ;
else
continue ;
}
/* vgname/lvname */
if ( lvm_snprintf ( path , sizeof ( path ) , " %s/%s " , lv - > vg - > name ,
lv - > name ) < 0 ) {
log_error ( " lvm_snprintf error from %s/%s " , lv - > vg - > name ,
lv - > name ) ;
continue ;
}
if ( ! strcmp ( path , str ) )
return 1 ;
}
return 0 ;
}
2002-01-17 16:39:24 +00:00
int library_version ( char * version , size_t size )
{
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 0 ;
2002-01-17 16:39:24 +00:00
if ( ! dm_get_library_version ( version , size ) )
return 0 ;
return 1 ;
}
int driver_version ( char * version , size_t size )
{
int r = 0 ;
struct dm_task * dmt ;
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 0 ;
2002-01-17 16:39:24 +00:00
log_very_verbose ( " Getting driver version " ) ;
if ( ! ( dmt = dm_task_create ( DM_DEVICE_VERSION ) ) ) {
stack ;
return 0 ;
}
if ( ! dm_task_run ( dmt ) )
log_error ( " Failed to get driver version " ) ;
if ( ! dm_task_get_driver_version ( dmt , version , size ) )
goto out ;
r = 1 ;
2002-03-18 23:25:50 +00:00
out :
2002-01-17 16:39:24 +00:00
dm_task_destroy ( dmt ) ;
return r ;
}
2004-03-26 19:52:09 +00:00
int target_present ( const char * target_name )
{
int r = 0 ;
struct dm_task * dmt ;
struct dm_versions * target , * last_target ;
if ( ! activation ( ) )
return 0 ;
log_very_verbose ( " Getting target version for %s " , target_name ) ;
if ( ! ( dmt = dm_task_create ( DM_DEVICE_LIST_VERSIONS ) ) ) {
stack ;
return 0 ;
}
if ( ! dm_task_run ( dmt ) ) {
log_debug ( " Failed to get %s target version " , target_name ) ;
/* Assume this was because LIST_VERSIONS isn't supported */
return 1 ;
}
target = dm_task_get_versions ( dmt ) ;
do {
last_target = target ;
if ( ! strcmp ( target_name , target - > name ) ) {
r = 1 ;
goto out ;
}
target = ( void * ) target + target - > next ;
} while ( last_target ! = target ) ;
out :
dm_task_destroy ( dmt ) ;
return r ;
}
2002-02-26 11:49:17 +00:00
/*
* Returns 1 if info structure populated , else 0 on failure .
*/
2003-11-13 14:11:41 +00:00
static int _lv_info ( const struct logical_volume * lv , int mknodes ,
2005-01-12 22:58:21 +00:00
struct lvinfo * info , int with_open_count )
2001-11-07 11:51:42 +00:00
{
2002-02-26 11:49:17 +00:00
int r ;
struct dev_manager * dm ;
2003-01-08 22:44:07 +00:00
struct dm_info dminfo ;
2002-01-10 23:21:07 +00:00
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 0 ;
2004-05-04 21:25:57 +00:00
if ( ! ( dm = dev_manager_create ( lv - > vg - > cmd , lv - > vg - > name ) ) ) {
2002-01-21 11:06:32 +00:00
stack ;
2002-02-26 11:49:17 +00:00
return 0 ;
2002-01-21 11:06:32 +00:00
}
2002-01-10 23:21:07 +00:00
2005-01-12 22:58:21 +00:00
if ( ! ( r = dev_manager_info ( dm , lv , mknodes , with_open_count , & dminfo ) ) )
2002-02-26 11:49:17 +00:00
stack ;
2002-01-10 23:21:07 +00:00
2003-01-08 22:44:07 +00:00
info - > exists = dminfo . exists ;
info - > suspended = dminfo . suspended ;
info - > open_count = dminfo . open_count ;
info - > major = dminfo . major ;
info - > minor = dminfo . minor ;
info - > read_only = dminfo . read_only ;
2002-02-26 11:49:17 +00:00
dev_manager_destroy ( dm ) ;
return r ;
}
2002-02-11 17:42:02 +00:00
2005-01-12 22:58:21 +00:00
int lv_info ( const struct logical_volume * lv , struct lvinfo * info ,
int with_open_count )
2003-11-13 14:11:41 +00:00
{
2005-01-12 22:58:21 +00:00
return _lv_info ( lv , 0 , info , with_open_count ) ;
2003-11-13 14:11:41 +00:00
}
2004-03-26 15:35:01 +00:00
int lv_info_by_lvid ( struct cmd_context * cmd , const char * lvid_s ,
2005-01-12 22:58:21 +00:00
struct lvinfo * info , int with_open_count )
2004-03-26 15:35:01 +00:00
{
struct logical_volume * lv ;
if ( ! ( lv = lv_from_lvid ( cmd , lvid_s ) ) )
return 0 ;
2005-01-12 22:58:21 +00:00
return _lv_info ( lv , 0 , info , with_open_count ) ;
2004-03-26 15:35:01 +00:00
}
2002-05-09 21:17:57 +00:00
/*
* Returns 1 if percent set , else 0 on failure .
*/
2002-05-22 14:03:45 +00:00
int lv_snapshot_percent ( struct logical_volume * lv , float * percent )
2002-05-09 21:17:57 +00:00
{
int r ;
struct dev_manager * dm ;
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 0 ;
2004-05-04 21:25:57 +00:00
if ( ! ( dm = dev_manager_create ( lv - > vg - > cmd , lv - > vg - > name ) ) ) {
2002-05-09 21:17:57 +00:00
stack ;
return 0 ;
}
2002-05-22 14:03:45 +00:00
if ( ! ( r = dev_manager_snapshot_percent ( dm , lv , percent ) ) )
2002-05-09 21:17:57 +00:00
stack ;
2002-05-22 14:03:45 +00:00
2002-05-09 21:17:57 +00:00
dev_manager_destroy ( dm ) ;
return r ;
}
2003-04-30 15:26:25 +00:00
/* FIXME Merge with snapshot_percent */
int lv_mirror_percent ( struct logical_volume * lv , int wait , float * percent ,
uint32_t * event_nr )
{
int r ;
struct dev_manager * dm ;
2004-03-26 19:10:48 +00:00
struct lvinfo info ;
2003-04-30 15:26:25 +00:00
if ( ! activation ( ) )
return 0 ;
2005-01-12 22:58:21 +00:00
if ( ! lv_info ( lv , & info , 0 ) ) {
2004-03-26 19:10:48 +00:00
stack ;
return 0 ;
}
if ( ! info . exists )
return 0 ;
2004-05-04 21:25:57 +00:00
if ( ! ( dm = dev_manager_create ( lv - > vg - > cmd , lv - > vg - > name ) ) ) {
2003-04-30 15:26:25 +00:00
stack ;
return 0 ;
}
if ( ! ( r = dev_manager_mirror_percent ( dm , lv , wait , percent , event_nr ) ) )
stack ;
dev_manager_destroy ( dm ) ;
return r ;
}
2002-03-11 19:02:28 +00:00
static int _lv_active ( struct logical_volume * lv )
2001-11-07 15:02:07 +00:00
{
2003-01-08 22:44:07 +00:00
struct lvinfo info ;
2001-11-07 15:02:07 +00:00
2005-01-12 22:58:21 +00:00
if ( ! lv_info ( lv , & info , 0 ) ) {
2001-11-07 15:02:07 +00:00
stack ;
2002-02-26 11:49:17 +00:00
return - 1 ;
2001-11-07 15:02:07 +00:00
}
2002-02-26 11:49:17 +00:00
return info . exists ;
2001-11-07 15:02:07 +00:00
}
2002-03-11 19:02:28 +00:00
static int _lv_open_count ( struct logical_volume * lv )
2002-02-18 15:52:48 +00:00
{
2003-01-08 22:44:07 +00:00
struct lvinfo info ;
2002-02-18 15:52:48 +00:00
2005-01-12 22:58:21 +00:00
if ( ! lv_info ( lv , & info , 1 ) ) {
2002-02-18 15:52:48 +00:00
stack ;
2002-02-26 11:49:17 +00:00
return - 1 ;
2002-02-18 15:52:48 +00:00
}
2002-02-26 11:49:17 +00:00
return info . open_count ;
2002-02-18 15:52:48 +00:00
}
2002-03-01 19:08:11 +00:00
/* FIXME Need to detect and handle an lv rename */
2004-03-08 18:54:13 +00:00
static int _lv_activate_lv ( struct logical_volume * lv )
2001-10-09 16:05:34 +00:00
{
2002-02-11 15:48:34 +00:00
int r ;
2002-02-26 11:49:17 +00:00
struct dev_manager * dm ;
2001-10-09 16:05:34 +00:00
2004-05-04 21:25:57 +00:00
if ( ! ( dm = dev_manager_create ( lv - > vg - > cmd , lv - > vg - > name ) ) ) {
2002-02-11 15:48:34 +00:00
stack ;
return 0 ;
2001-11-02 13:45:05 +00:00
}
2002-03-07 16:48:46 +00:00
if ( ! ( r = dev_manager_activate ( dm , lv ) ) )
2002-02-11 15:48:34 +00:00
stack ;
2001-11-02 13:45:05 +00:00
2002-02-26 11:49:17 +00:00
dev_manager_destroy ( dm ) ;
2001-11-02 13:45:05 +00:00
return r ;
2001-10-09 16:05:34 +00:00
}
2001-10-16 16:25:28 +00:00
2002-03-11 15:08:39 +00:00
static int _lv_deactivate ( struct logical_volume * lv )
2001-10-31 17:59:52 +00:00
{
2002-02-26 11:49:17 +00:00
int r ;
struct dev_manager * dm ;
2001-11-07 11:51:42 +00:00
2004-05-04 21:25:57 +00:00
if ( ! ( dm = dev_manager_create ( lv - > vg - > cmd , lv - > vg - > name ) ) ) {
2002-02-11 15:48:34 +00:00
stack ;
return 0 ;
}
2001-11-07 11:51:42 +00:00
2002-02-26 11:49:17 +00:00
if ( ! ( r = dev_manager_deactivate ( dm , lv ) ) )
2001-11-07 11:51:42 +00:00
stack ;
2002-02-26 11:49:17 +00:00
dev_manager_destroy ( dm ) ;
return r ;
2001-11-07 11:51:42 +00:00
}
2004-03-08 18:54:13 +00:00
static int _lv_suspend_lv ( struct logical_volume * lv )
2002-01-10 23:21:07 +00:00
{
2002-03-14 15:36:07 +00:00
int r ;
struct dev_manager * dm ;
2001-11-28 18:03:11 +00:00
2004-05-04 21:25:57 +00:00
if ( ! ( dm = dev_manager_create ( lv - > vg - > cmd , lv - > vg - > name ) ) ) {
2001-11-07 11:51:42 +00:00
stack ;
return 0 ;
}
2001-10-31 17:59:52 +00:00
2002-03-14 15:36:07 +00:00
if ( ! ( r = dev_manager_suspend ( dm , lv ) ) )
2001-11-07 11:51:42 +00:00
stack ;
2001-10-31 17:59:52 +00:00
2002-03-14 15:36:07 +00:00
dev_manager_destroy ( dm ) ;
return r ;
2002-02-11 15:48:34 +00:00
}
2002-01-10 23:21:07 +00:00
2002-03-01 19:08:11 +00:00
/*
2004-05-11 18:18:14 +00:00
* These two functions return the number of visible LVs in the state ,
2002-03-01 19:08:11 +00:00
* or - 1 on error .
*/
2001-11-02 16:28:04 +00:00
int lvs_in_vg_activated ( struct volume_group * vg )
{
2005-06-01 16:51:55 +00:00
struct lv_list * lvl ;
2001-11-08 16:15:58 +00:00
int count = 0 ;
2001-11-07 11:51:42 +00:00
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 0 ;
2005-06-01 16:51:55 +00:00
list_iterate_items ( lvl , & vg - > lvs ) {
if ( lvl - > lv - > status & VISIBLE_LV )
count + = ( _lv_active ( lvl - > lv ) = = 1 ) ;
2001-11-07 11:51:42 +00:00
}
return count ;
2001-11-02 16:28:04 +00:00
}
2001-11-07 15:02:07 +00:00
int lvs_in_vg_opened ( struct volume_group * vg )
{
2005-06-01 16:51:55 +00:00
struct lv_list * lvl ;
2001-11-08 16:15:58 +00:00
int count = 0 ;
2001-11-07 15:02:07 +00:00
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 0 ;
2005-06-01 16:51:55 +00:00
list_iterate_items ( lvl , & vg - > lvs ) {
if ( lvl - > lv - > status & VISIBLE_LV )
count + = ( _lv_open_count ( lvl - > lv ) > 0 ) ;
2001-11-07 15:02:07 +00:00
}
return count ;
}
2002-02-25 12:56:16 +00:00
2004-03-08 18:54:13 +00:00
static int _lv_suspend ( struct cmd_context * cmd , const char * lvid_s ,
int error_if_not_suspended )
2002-02-25 12:56:16 +00:00
{
struct logical_volume * lv ;
2003-01-08 22:44:07 +00:00
struct lvinfo info ;
2002-02-25 12:56:16 +00:00
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 1 ;
if ( ! ( lv = lv_from_lvid ( cmd , lvid_s ) ) )
2002-02-25 12:56:16 +00:00
return 0 ;
2002-03-14 15:36:07 +00:00
if ( test_mode ( ) ) {
_skip ( " Suspending '%s'. " , lv - > name ) ;
2003-01-17 20:16:23 +00:00
return 1 ;
2002-03-14 15:36:07 +00:00
}
2005-01-12 22:58:21 +00:00
if ( ! lv_info ( lv , & info , 0 ) ) {
2002-03-18 23:25:50 +00:00
stack ;
return 0 ;
}
2002-03-11 19:02:28 +00:00
2003-07-04 22:34:56 +00:00
if ( ! info . exists | | info . suspended )
2004-03-08 18:54:13 +00:00
return error_if_not_suspended ? 0 : 1 ;
2003-07-04 22:34:56 +00:00
memlock_inc ( ) ;
2004-03-08 18:54:13 +00:00
if ( ! _lv_suspend_lv ( lv ) ) {
2003-07-04 22:34:56 +00:00
memlock_dec ( ) ;
fs_unlock ( ) ;
return 0 ;
}
2002-03-01 19:08:11 +00:00
2002-02-25 12:56:16 +00:00
return 1 ;
}
2004-03-08 18:54:13 +00:00
/* Returns success if the device is not active */
int lv_suspend_if_active ( struct cmd_context * cmd , const char * lvid_s )
{
return _lv_suspend ( cmd , lvid_s , 0 ) ;
}
int lv_suspend ( struct cmd_context * cmd , const char * lvid_s )
{
return _lv_suspend ( cmd , lvid_s , 1 ) ;
}
static int _lv_resume ( struct cmd_context * cmd , const char * lvid_s ,
int error_if_not_active )
2002-02-25 12:56:16 +00:00
{
struct logical_volume * lv ;
2003-01-08 22:44:07 +00:00
struct lvinfo info ;
2002-02-25 12:56:16 +00:00
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 1 ;
if ( ! ( lv = lv_from_lvid ( cmd , lvid_s ) ) )
2002-02-25 12:56:16 +00:00
return 0 ;
2002-03-14 15:36:07 +00:00
if ( test_mode ( ) ) {
_skip ( " Resuming '%s'. " , lv - > name ) ;
2003-01-17 20:16:23 +00:00
return 1 ;
2002-03-14 15:36:07 +00:00
}
2005-01-12 22:58:21 +00:00
if ( ! lv_info ( lv , & info , 0 ) ) {
2002-03-18 23:25:50 +00:00
stack ;
return 0 ;
}
2002-03-11 19:02:28 +00:00
2003-07-04 22:34:56 +00:00
if ( ! info . exists | | ! info . suspended )
2004-03-08 18:54:13 +00:00
return error_if_not_active ? 0 : 1 ;
2003-07-04 22:34:56 +00:00
2004-03-08 18:54:13 +00:00
if ( ! _lv_activate_lv ( lv ) )
2003-07-04 22:34:56 +00:00
return 0 ;
memlock_dec ( ) ;
fs_unlock ( ) ;
2002-02-25 12:56:16 +00:00
return 1 ;
}
2004-03-08 18:54:13 +00:00
/* Returns success if the device is not active */
int lv_resume_if_active ( struct cmd_context * cmd , const char * lvid_s )
{
return _lv_resume ( cmd , lvid_s , 0 ) ;
}
int lv_resume ( struct cmd_context * cmd , const char * lvid_s )
{
return _lv_resume ( cmd , lvid_s , 1 ) ;
}
2002-03-11 15:08:39 +00:00
int lv_deactivate ( struct cmd_context * cmd , const char * lvid_s )
2002-02-27 12:26:41 +00:00
{
struct logical_volume * lv ;
2003-01-08 22:44:07 +00:00
struct lvinfo info ;
2003-07-04 22:34:56 +00:00
int r ;
2002-02-27 12:26:41 +00:00
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 1 ;
if ( ! ( lv = lv_from_lvid ( cmd , lvid_s ) ) )
2002-02-27 12:26:41 +00:00
return 0 ;
2002-03-14 15:36:07 +00:00
if ( test_mode ( ) ) {
_skip ( " Deactivating '%s'. " , lv - > name ) ;
2003-01-17 20:16:23 +00:00
return 1 ;
2002-03-14 15:36:07 +00:00
}
2005-01-12 22:58:21 +00:00
if ( ! lv_info ( lv , & info , 1 ) ) {
2002-03-18 23:25:50 +00:00
stack ;
return 0 ;
}
2002-03-11 19:02:28 +00:00
2003-07-04 22:34:56 +00:00
if ( ! info . exists )
return 1 ;
2002-02-27 12:26:41 +00:00
2004-03-26 19:13:39 +00:00
if ( info . open_count & & ( lv - > status & VISIBLE_LV ) ) {
2003-10-21 22:00:36 +00:00
log_error ( " LV %s/%s in use: not removing " , lv - > vg - > name ,
lv - > name ) ;
return 0 ;
}
2003-07-04 22:34:56 +00:00
memlock_inc ( ) ;
r = _lv_deactivate ( lv ) ;
memlock_dec ( ) ;
fs_unlock ( ) ;
return r ;
2002-02-27 12:26:41 +00:00
}
2004-03-08 18:54:13 +00:00
/* Test if LV passes filter */
int lv_activation_filter ( struct cmd_context * cmd , const char * lvid_s ,
int * activate_lv )
{
struct logical_volume * lv ;
if ( ! activation ( ) )
goto activate ;
if ( ! ( lv = lv_from_lvid ( cmd , lvid_s ) ) )
return 0 ;
if ( ! _passes_activation_filter ( cmd , lv ) ) {
log_verbose ( " Not activating %s/%s due to config file settings " ,
lv - > vg - > name , lv - > name ) ;
* activate_lv = 0 ;
return 1 ;
}
activate :
* activate_lv = 1 ;
return 1 ;
}
static int _lv_activate ( struct cmd_context * cmd , const char * lvid_s , int filter )
2002-02-27 12:26:41 +00:00
{
struct logical_volume * lv ;
2003-01-08 22:44:07 +00:00
struct lvinfo info ;
2003-07-04 22:34:56 +00:00
int r ;
2002-02-27 12:26:41 +00:00
2002-11-18 14:01:16 +00:00
if ( ! activation ( ) )
return 1 ;
if ( ! ( lv = lv_from_lvid ( cmd , lvid_s ) ) )
2002-02-27 12:26:41 +00:00
return 0 ;
2004-03-08 18:54:13 +00:00
if ( filter & & ! _passes_activation_filter ( cmd , lv ) ) {
2004-03-08 18:13:22 +00:00
log_verbose ( " Not activating %s/%s due to config file settings " ,
lv - > vg - > name , lv - > name ) ;
return 0 ;
}
2002-03-14 15:36:07 +00:00
if ( test_mode ( ) ) {
_skip ( " Activating '%s'. " , lv - > name ) ;
2003-01-17 20:16:23 +00:00
return 1 ;
2002-03-14 15:36:07 +00:00
}
2005-01-12 22:58:21 +00:00
if ( ! lv_info ( lv , & info , 0 ) ) {
2002-03-18 23:25:50 +00:00
stack ;
return 0 ;
}
2002-03-01 19:08:11 +00:00
2003-07-04 22:34:56 +00:00
if ( info . exists & & ! info . suspended )
return 1 ;
2002-02-27 12:26:41 +00:00
2003-07-04 22:34:56 +00:00
memlock_inc ( ) ;
2004-03-08 18:54:13 +00:00
r = _lv_activate_lv ( lv ) ;
2003-07-04 22:34:56 +00:00
memlock_dec ( ) ;
fs_unlock ( ) ;
return r ;
2002-02-27 12:26:41 +00:00
}
2003-01-08 22:44:07 +00:00
2004-03-08 18:54:13 +00:00
/* Activate LV */
int lv_activate ( struct cmd_context * cmd , const char * lvid_s )
{
return _lv_activate ( cmd , lvid_s , 0 ) ;
}
/* Activate LV only if it passes filter */
int lv_activate_with_filter ( struct cmd_context * cmd , const char * lvid_s )
{
return _lv_activate ( cmd , lvid_s , 1 ) ;
}
2003-11-12 19:16:48 +00:00
int lv_mknodes ( struct cmd_context * cmd , const struct logical_volume * lv )
{
struct lvinfo info ;
int r = 1 ;
2004-03-30 14:40:03 +00:00
if ( ! lv ) {
r = dev_manager_mknodes ( ) ;
fs_unlock ( ) ;
return r ;
}
2005-01-12 22:58:21 +00:00
if ( ! _lv_info ( lv , 1 , & info , 0 ) ) {
2003-11-12 19:16:48 +00:00
stack ;
return 0 ;
}
if ( info . exists )
2004-03-30 14:38:57 +00:00
r = dev_manager_lv_mknodes ( lv ) ;
2003-11-12 19:16:48 +00:00
else
2004-03-30 14:38:57 +00:00
r = dev_manager_lv_rmnodes ( lv ) ;
2003-11-12 19:16:48 +00:00
fs_unlock ( ) ;
return r ;
}
2003-07-04 22:34:56 +00:00
void activation_exit ( void )
{
dev_manager_exit ( ) ;
}
2003-01-08 22:44:07 +00:00
# endif