2008-10-30 20:39:00 +03:00
/*
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
* Copyright ( C ) 2004 - 2007 Red Hat , Inc . All rights reserved .
*
* 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 Lesser General Public License v .2 .1 .
*
* You should have received a copy of the GNU Lesser General Public License
* 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
2008-10-30 20:39:00 +03:00
*/
# include "lib.h"
# include "device.h"
# include "lvm-string.h"
# include "defaults.h"
2011-02-18 17:11:22 +03:00
# include "metadata-exported.h"
2008-10-30 20:39:00 +03:00
# include <stdarg.h>
static int _verbose_level = VERBOSE_BASE_LEVEL ;
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
static int _silent = 0 ;
2008-10-30 20:39:00 +03:00
static int _test = 0 ;
static int _md_filtering = 0 ;
2016-05-25 21:57:33 +03:00
static int _internal_filtering = 0 ;
filters: add firmware RAID filter
Just like MD filtering that detects components of software RAID (md),
add detection for firmware RAID.
We're not adding any native code to detect this - there are lots of
firmware RAIDs out there which is just out of LVM scope. However,
with current changes with which we're able to get device info from
external sources (e.g. external_device_info_source="udev"), we can
do this easily if the external device status source has this kind
of information - which is the case of "udev" source where the results
of blkid scans are stored.
This detection should cover all firmware RAIDs that blkid can detect and
which are identified as:
ID_FS_TYPE = {adaptec,ddf,hpt45x,hpt37x,isw,jmicron,lsi_mega,nvidia,promise_fasttrack,silicon_medley,via}_raid_member
2014-09-09 17:05:57 +04:00
static int _fwraid_filtering = 0 ;
2008-10-30 20:39:00 +03:00
static int _pvmove = 0 ;
static int _full_scan_done = 0 ; /* Restrict to one full scan during each cmd */
2011-04-22 16:05:32 +04:00
static int _obtain_device_list_from_udev = DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV ;
2015-11-07 19:17:37 +03:00
static enum dev_ext_e _external_device_info_source = DEV_EXT_NONE ;
2008-10-30 20:39:00 +03:00
static int _trust_cache = 0 ; /* Don't scan when incomplete VGs encountered */
static int _debug_level = 0 ;
2015-07-08 12:22:24 +03:00
static int _debug_classes_logged = 0 ;
2008-10-30 20:39:00 +03:00
static int _log_cmd_name = 0 ;
static int _ignorelockingfailure = 0 ;
static int _security_level = SECURITY_LEVEL ;
static char _cmd_name [ 30 ] = " " ;
static int _mirror_in_sync = 0 ;
static int _dmeventd_monitor = DEFAULT_DMEVENTD_MONITOR ;
2015-10-23 11:48:01 +03:00
/* When set, disables update of _dmeventd_monitor & _ignore_suspended_devices */
static int _disable_dmeventd_monitoring = 0 ;
2010-01-05 23:56:51 +03:00
static int _background_polling = DEFAULT_BACKGROUND_POLLING ;
2008-10-30 20:39:00 +03:00
static int _ignore_suspended_devices = 0 ;
Mirror: Fix hangs and lock-ups caused by attempting label reads of mirrors
There is a problem with the way mirrors have been designed to handle
failures that is resulting in stuck LVM processes and hung I/O. When
mirrors encounter a write failure, they block I/O and notify userspace
to reconfigure the mirror to remove failed devices. This process is
open to a couple races:
1) Any LVM process other than the one that is meant to deal with the
mirror failure can attempt to read the mirror, fail, and block other
LVM commands (including the repair command) from proceeding due to
holding a lock on the volume group.
2) If there are multiple mirrors that suffer a failure in the same
volume group, a repair can block while attempting to read the LVM
label from one mirror while trying to repair the other.
Mitigation of these races has been attempted by disallowing label reading
of mirrors that are either suspended or are indicated as blocking by
the kernel. While this has closed the window of opportunity for hitting
the above problems considerably, it hasn't closed it completely. This is
because it is still possible to start an LVM command, read the status of
the mirror as healthy, and then perform the read for the label at the
moment after a the failure is discovered by the kernel.
I can see two solutions to this problem:
1) Allow users to configure whether mirrors can be candidates for LVM
labels (i.e. whether PVs can be created on mirror LVs). If the user
chooses to allow label scanning of mirror LVs, it will be at the expense
of a possible hang in I/O or LVM processes.
2) Instrument a way to allow asynchronous label reading - allowing
blocked label reads to be ignored while continuing to process the LVM
command. This would action would allow LVM commands to continue even
though they would have otherwise blocked trying to read a mirror. They
can then release their lock and allow a repair command to commence. In
the event of #2 above, the repair command already in progress can continue
and repair the failed mirror.
This patch brings solution #1. If solution #2 is developed later on, the
configuration option created in #1 can be negated - allowing mirrors to
be scanned for labels by default once again.
2013-10-23 04:14:33 +04:00
static int _ignore_lvm_mirrors = DEFAULT_IGNORE_LVM_MIRRORS ;
2008-10-30 20:39:00 +03:00
static int _error_message_produced = 0 ;
2008-12-18 08:27:17 +03:00
static unsigned _is_static = 0 ;
2010-01-11 18:40:03 +03:00
static int _udev_checking = 1 ;
2011-09-22 21:39:56 +04:00
static int _retry_deactivation = DEFAULT_RETRY_DEACTIVATION ;
2011-07-01 18:09:19 +04:00
static int _activation_checks = 0 ;
2010-08-11 16:14:23 +04:00
static char _sysfs_dir_path [ PATH_MAX ] = " " ;
2010-10-13 19:40:38 +04:00
static int _dev_disable_after_error_count = DEFAULT_DISABLE_AFTER_ERROR_COUNT ;
2011-02-18 17:11:22 +03:00
static uint64_t _pv_min_size = ( DEFAULT_PV_MIN_SIZE_KB * 1024L > > SECTOR_SHIFT ) ;
2011-08-11 21:46:13 +04:00
static int _detect_internal_vg_cache_corruption =
DEFAULT_DETECT_INTERNAL_VG_CACHE_CORRUPTION ;
2016-02-29 22:38:31 +03:00
static const char * _unknown_device_name = DEFAULT_UNKNOWN_DEVICE_NAME ;
2008-10-30 20:39:00 +03:00
void init_verbose ( int level )
{
_verbose_level = level ;
}
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
void init_silent ( int silent )
{
_silent = silent ;
}
2008-10-30 20:39:00 +03:00
void init_test ( int level )
{
if ( ! _test & & level )
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_warn ( " TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated. " ) ;
2008-10-30 20:39:00 +03:00
_test = level ;
}
void init_md_filtering ( int level )
{
_md_filtering = level ;
}
2016-05-25 21:57:33 +03:00
void init_internal_filtering ( int level )
{
_internal_filtering = level ;
}
filters: add firmware RAID filter
Just like MD filtering that detects components of software RAID (md),
add detection for firmware RAID.
We're not adding any native code to detect this - there are lots of
firmware RAIDs out there which is just out of LVM scope. However,
with current changes with which we're able to get device info from
external sources (e.g. external_device_info_source="udev"), we can
do this easily if the external device status source has this kind
of information - which is the case of "udev" source where the results
of blkid scans are stored.
This detection should cover all firmware RAIDs that blkid can detect and
which are identified as:
ID_FS_TYPE = {adaptec,ddf,hpt45x,hpt37x,isw,jmicron,lsi_mega,nvidia,promise_fasttrack,silicon_medley,via}_raid_member
2014-09-09 17:05:57 +04:00
void init_fwraid_filtering ( int level )
{
_fwraid_filtering = level ;
}
2008-10-30 20:39:00 +03:00
void init_pvmove ( int level )
{
_pvmove = level ;
}
void init_full_scan_done ( int level )
{
_full_scan_done = level ;
}
2011-04-22 16:05:32 +04:00
void init_obtain_device_list_from_udev ( int device_list_from_udev )
{
_obtain_device_list_from_udev = device_list_from_udev ;
}
2015-11-07 19:17:37 +03:00
void init_external_device_info_source ( enum dev_ext_e src )
2014-12-15 18:27:33 +03:00
{
_external_device_info_source = src ;
}
2008-10-30 20:39:00 +03:00
void init_trust_cache ( int trustcache )
{
_trust_cache = trustcache ;
}
void init_ignorelockingfailure ( int level )
{
_ignorelockingfailure = level ;
}
void init_security_level ( int level )
{
_security_level = level ;
}
void init_mirror_in_sync ( int in_sync )
{
_mirror_in_sync = in_sync ;
}
void init_dmeventd_monitor ( int reg )
{
2015-10-23 11:48:01 +03:00
if ( ! _disable_dmeventd_monitoring )
2015-10-22 11:44:38 +03:00
_dmeventd_monitor = reg ;
2008-10-30 20:39:00 +03:00
}
2015-10-23 11:48:01 +03:00
void init_disable_dmeventd_monitoring ( int reg )
{
_disable_dmeventd_monitoring = reg ;
}
2010-01-05 23:56:51 +03:00
void init_background_polling ( int polling )
{
_background_polling = polling ;
}
2008-10-30 20:39:00 +03:00
void init_ignore_suspended_devices ( int ignore )
{
2015-10-23 11:48:01 +03:00
if ( ! _disable_dmeventd_monitoring )
2015-10-22 11:44:38 +03:00
_ignore_suspended_devices = ignore ;
2008-10-30 20:39:00 +03:00
}
Mirror: Fix hangs and lock-ups caused by attempting label reads of mirrors
There is a problem with the way mirrors have been designed to handle
failures that is resulting in stuck LVM processes and hung I/O. When
mirrors encounter a write failure, they block I/O and notify userspace
to reconfigure the mirror to remove failed devices. This process is
open to a couple races:
1) Any LVM process other than the one that is meant to deal with the
mirror failure can attempt to read the mirror, fail, and block other
LVM commands (including the repair command) from proceeding due to
holding a lock on the volume group.
2) If there are multiple mirrors that suffer a failure in the same
volume group, a repair can block while attempting to read the LVM
label from one mirror while trying to repair the other.
Mitigation of these races has been attempted by disallowing label reading
of mirrors that are either suspended or are indicated as blocking by
the kernel. While this has closed the window of opportunity for hitting
the above problems considerably, it hasn't closed it completely. This is
because it is still possible to start an LVM command, read the status of
the mirror as healthy, and then perform the read for the label at the
moment after a the failure is discovered by the kernel.
I can see two solutions to this problem:
1) Allow users to configure whether mirrors can be candidates for LVM
labels (i.e. whether PVs can be created on mirror LVs). If the user
chooses to allow label scanning of mirror LVs, it will be at the expense
of a possible hang in I/O or LVM processes.
2) Instrument a way to allow asynchronous label reading - allowing
blocked label reads to be ignored while continuing to process the LVM
command. This would action would allow LVM commands to continue even
though they would have otherwise blocked trying to read a mirror. They
can then release their lock and allow a repair command to commence. In
the event of #2 above, the repair command already in progress can continue
and repair the failed mirror.
This patch brings solution #1. If solution #2 is developed later on, the
configuration option created in #1 can be negated - allowing mirrors to
be scanned for labels by default once again.
2013-10-23 04:14:33 +04:00
void init_ignore_lvm_mirrors ( int scan )
{
_ignore_lvm_mirrors = scan ;
}
2008-10-30 20:39:00 +03:00
void init_cmd_name ( int status )
{
_log_cmd_name = status ;
}
2008-12-18 08:27:17 +03:00
void init_is_static ( unsigned value )
{
_is_static = value ;
}
2010-01-11 18:40:03 +03:00
void init_udev_checking ( int checking )
{
if ( ( _udev_checking = checking ) )
2013-01-08 02:30:29 +04:00
log_debug_activation ( " LVM udev checking enabled " ) ;
2010-01-11 18:40:03 +03:00
else
2013-01-08 02:30:29 +04:00
log_debug_activation ( " LVM udev checking disabled " ) ;
2010-01-11 18:40:03 +03:00
}
2011-09-22 21:39:56 +04:00
void init_retry_deactivation ( int retry )
{
_retry_deactivation = retry ;
}
2011-07-01 18:09:19 +04:00
void init_activation_checks ( int checks )
{
if ( ( _activation_checks = checks ) )
2013-01-08 02:30:29 +04:00
log_debug_activation ( " LVM activation checks enabled " ) ;
2011-07-01 18:09:19 +04:00
else
2013-01-08 02:30:29 +04:00
log_debug_activation ( " LVM activation checks disabled " ) ;
2011-07-01 18:09:19 +04:00
}
2010-10-13 19:40:38 +04:00
void init_dev_disable_after_error_count ( int value )
{
_dev_disable_after_error_count = value ;
}
2011-02-18 17:11:22 +03:00
void init_pv_min_size ( uint64_t sectors )
{
_pv_min_size = sectors ;
}
2011-08-11 21:46:13 +04:00
void init_detect_internal_vg_cache_corruption ( int detect )
{
_detect_internal_vg_cache_corruption = detect ;
}
2008-10-30 20:39:00 +03:00
void set_cmd_name ( const char * cmd )
{
2018-03-02 18:25:37 +03:00
( void ) dm_strncpy ( _cmd_name , cmd , sizeof ( _cmd_name ) ) ;
2008-10-30 20:39:00 +03:00
}
2015-06-16 23:13:10 +03:00
const char * get_cmd_name ( void )
{
return _cmd_name ;
}
2010-08-11 16:14:23 +04:00
void set_sysfs_dir_path ( const char * path )
{
2018-03-02 18:25:37 +03:00
( void ) dm_strncpy ( _sysfs_dir_path , path , sizeof ( _sysfs_dir_path ) ) ;
2010-08-11 16:14:23 +04:00
}
2011-03-30 00:30:05 +04:00
const char * log_command_name ( void )
2008-10-30 20:39:00 +03:00
{
if ( ! _log_cmd_name )
return " " ;
return _cmd_name ;
}
void init_error_message_produced ( int value )
{
_error_message_produced = value ;
}
int error_message_produced ( void )
{
return _error_message_produced ;
}
2011-03-30 00:30:05 +04:00
int test_mode ( void )
2008-10-30 20:39:00 +03:00
{
return _test ;
}
2011-03-30 00:30:05 +04:00
int md_filtering ( void )
2008-10-30 20:39:00 +03:00
{
return _md_filtering ;
}
2016-05-25 21:57:33 +03:00
int internal_filtering ( void )
{
return _internal_filtering ;
}
filters: add firmware RAID filter
Just like MD filtering that detects components of software RAID (md),
add detection for firmware RAID.
We're not adding any native code to detect this - there are lots of
firmware RAIDs out there which is just out of LVM scope. However,
with current changes with which we're able to get device info from
external sources (e.g. external_device_info_source="udev"), we can
do this easily if the external device status source has this kind
of information - which is the case of "udev" source where the results
of blkid scans are stored.
This detection should cover all firmware RAIDs that blkid can detect and
which are identified as:
ID_FS_TYPE = {adaptec,ddf,hpt45x,hpt37x,isw,jmicron,lsi_mega,nvidia,promise_fasttrack,silicon_medley,via}_raid_member
2014-09-09 17:05:57 +04:00
int fwraid_filtering ( void )
{
return _fwraid_filtering ;
}
2011-03-30 00:30:05 +04:00
int pvmove_mode ( void )
2008-10-30 20:39:00 +03:00
{
return _pvmove ;
}
2011-03-30 00:30:05 +04:00
int full_scan_done ( void )
2008-10-30 20:39:00 +03:00
{
return _full_scan_done ;
}
2011-09-01 17:30:11 +04:00
int obtain_device_list_from_udev ( void )
2011-04-22 16:05:32 +04:00
{
return _obtain_device_list_from_udev ;
}
2015-11-07 19:17:37 +03:00
enum dev_ext_e external_device_info_source ( void )
2014-12-15 18:27:33 +03:00
{
return _external_device_info_source ;
}
2011-03-30 00:30:05 +04:00
int trust_cache ( void )
2008-10-30 20:39:00 +03:00
{
return _trust_cache ;
}
2011-03-30 00:30:05 +04:00
int background_polling ( void )
2010-01-05 23:56:51 +03:00
{
return _background_polling ;
}
2011-03-30 00:30:05 +04:00
int ignorelockingfailure ( void )
2008-10-30 20:39:00 +03:00
{
return _ignorelockingfailure ;
}
2011-03-30 00:30:05 +04:00
int security_level ( void )
2008-10-30 20:39:00 +03:00
{
return _security_level ;
}
int mirror_in_sync ( void )
{
return _mirror_in_sync ;
}
int dmeventd_monitor_mode ( void )
{
return _dmeventd_monitor ;
}
int ignore_suspended_devices ( void )
{
return _ignore_suspended_devices ;
}
Mirror: Fix hangs and lock-ups caused by attempting label reads of mirrors
There is a problem with the way mirrors have been designed to handle
failures that is resulting in stuck LVM processes and hung I/O. When
mirrors encounter a write failure, they block I/O and notify userspace
to reconfigure the mirror to remove failed devices. This process is
open to a couple races:
1) Any LVM process other than the one that is meant to deal with the
mirror failure can attempt to read the mirror, fail, and block other
LVM commands (including the repair command) from proceeding due to
holding a lock on the volume group.
2) If there are multiple mirrors that suffer a failure in the same
volume group, a repair can block while attempting to read the LVM
label from one mirror while trying to repair the other.
Mitigation of these races has been attempted by disallowing label reading
of mirrors that are either suspended or are indicated as blocking by
the kernel. While this has closed the window of opportunity for hitting
the above problems considerably, it hasn't closed it completely. This is
because it is still possible to start an LVM command, read the status of
the mirror as healthy, and then perform the read for the label at the
moment after a the failure is discovered by the kernel.
I can see two solutions to this problem:
1) Allow users to configure whether mirrors can be candidates for LVM
labels (i.e. whether PVs can be created on mirror LVs). If the user
chooses to allow label scanning of mirror LVs, it will be at the expense
of a possible hang in I/O or LVM processes.
2) Instrument a way to allow asynchronous label reading - allowing
blocked label reads to be ignored while continuing to process the LVM
command. This would action would allow LVM commands to continue even
though they would have otherwise blocked trying to read a mirror. They
can then release their lock and allow a repair command to commence. In
the event of #2 above, the repair command already in progress can continue
and repair the failed mirror.
This patch brings solution #1. If solution #2 is developed later on, the
configuration option created in #1 can be negated - allowing mirrors to
be scanned for labels by default once again.
2013-10-23 04:14:33 +04:00
int ignore_lvm_mirrors ( void )
{
return _ignore_lvm_mirrors ;
}
2008-10-30 20:39:00 +03:00
void init_debug ( int level )
{
_debug_level = level ;
}
2013-01-08 02:25:19 +04:00
void init_debug_classes_logged ( int classes )
{
_debug_classes_logged = classes ;
}
int debug_class_is_logged ( int class )
{
/* If no class given, log it */
if ( ! class )
return 1 ;
return ( _debug_classes_logged & class ) ? 1 : 0 ;
}
2011-03-30 00:30:05 +04:00
int verbose_level ( void )
2008-10-30 20:39:00 +03:00
{
return _verbose_level ;
}
2011-03-30 00:30:05 +04:00
int debug_level ( void )
2008-10-30 20:39:00 +03:00
{
return _debug_level ;
}
2008-12-18 08:27:17 +03: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 23:35:48 +04:00
int silent_mode ( void )
{
return _silent ;
}
2008-12-18 08:27:17 +03:00
unsigned is_static ( void )
{
return _is_static ;
}
2010-01-11 18:40:03 +03:00
int udev_checking ( void )
{
return _udev_checking ;
}
2010-08-11 16:14:23 +04:00
2011-09-22 21:39:56 +04:00
int retry_deactivation ( void )
{
return _retry_deactivation ;
}
2011-07-01 18:09:19 +04:00
int activation_checks ( void )
{
return _activation_checks ;
}
2011-03-30 00:30:05 +04:00
const char * sysfs_dir_path ( void )
2010-08-11 16:14:23 +04:00
{
return _sysfs_dir_path ;
}
2010-10-13 19:40:38 +04:00
int dev_disable_after_error_count ( void )
{
return _dev_disable_after_error_count ;
}
2011-02-18 17:11:22 +03:00
uint64_t pv_min_size ( void )
{
return _pv_min_size ;
}
2011-08-11 21:46:13 +04:00
int detect_internal_vg_cache_corruption ( void )
{
return _detect_internal_vg_cache_corruption ;
}
2016-02-29 22:38:31 +03:00
const char * unknown_device_name ( void )
{
return _unknown_device_name ;
}
void init_unknown_device_name ( const char * name )
{
_unknown_device_name = name ;
}