2001-09-25 16:49:28 +04:00
/*
2013-06-12 14:08:56 +04:00
* Copyright ( C ) 2013 Red Hat , Inc . All rights reserved .
2001-09-25 16:49:28 +04:00
*
2004-03-30 23:35:44 +04:00
* This file is part of LVM2 .
2001-09-25 16:49:28 +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-09-25 16:49:28 +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 ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2001-09-25 16:49:28 +04:00
*/
2018-06-08 15:40:53 +03:00
# include "base/memory/zalloc.h"
2018-05-14 12:30:20 +03:00
# include "lib/misc/lib.h"
# include "lib/device/dev-type.h"
2018-12-14 15:10:25 +03:00
# include "lib/device/device-types.h"
2018-05-14 12:30:20 +03:00
# include "lib/mm/xlate.h"
# include "lib/config/config.h"
# include "lib/metadata/metadata.h"
# include "lib/device/bcache.h"
# include "lib/label/label.h"
2020-12-03 19:48:21 +03:00
# include "lib/commands/toolcontext.h"
2024-05-24 02:07:47 +03:00
# include "lib/activate/activate.h"
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
# include "device_mapper/misc/dm-ioctl.h"
2004-11-23 14:44:04 +03:00
2013-11-15 17:50:02 +04:00
# ifdef BLKID_WIPING_SUPPORT
2022-09-29 23:25:32 +03:00
# include <blkid/blkid.h>
2013-11-15 17:50:02 +04:00
# endif
2014-09-03 17:49:36 +04:00
# ifdef UDEV_SYNC_SUPPORT
# include <libudev.h>
2018-05-14 12:30:20 +03:00
# include "lib/device/dev-ext-udev-constants.h"
2014-09-03 17:49:36 +04:00
# endif
2018-12-14 15:10:25 +03:00
# include <libgen.h>
# include <ctype.h>
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
# include <dirent.h>
2013-06-12 14:08:56 +04:00
2020-12-03 19:48:21 +03:00
/*
* An nvme device has major number 259 ( BLKEXT ) , minor number < minor > ,
* and reading / sys / dev / block / 259 : < minor > / device / dev shows a character
* device cmajor : cminor where cmajor matches the major number of the
* nvme character device entry in / proc / devices . Checking all of that
* is excessive and unnecessary compared to just comparing / dev / name * .
*/
2024-12-07 00:02:20 +03:00
int dev_is_nvme ( struct device * dev )
2020-12-03 19:48:21 +03:00
{
2021-02-07 16:04:58 +03:00
return ( dev - > flags & DEV_IS_NVME ) ? 1 : 0 ;
2020-12-03 19:48:21 +03:00
}
2024-05-24 00:03:05 +03:00
int dev_is_lv ( struct cmd_context * cmd , struct device * dev )
2018-12-07 23:35:22 +03:00
{
2024-05-24 02:07:47 +03:00
char buffer [ 128 ] ;
2018-12-07 23:35:22 +03:00
2024-06-28 21:35:12 +03:00
if ( dev_dm_uuid ( cmd , dev , buffer , sizeof ( buffer ) ) & &
2024-05-24 02:07:47 +03:00
! strncmp ( buffer , UUID_PREFIX , sizeof ( UUID_PREFIX ) - 1 ) )
return 1 ;
2018-12-07 23:35:22 +03:00
2024-05-24 02:07:47 +03:00
return 0 ;
2018-12-07 23:35:22 +03:00
}
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
int dev_is_used_by_active_lv ( struct cmd_context * cmd , struct device * dev , int * used_by_lv_count ,
char * * used_by_dm_name , char * * used_by_vg_uuid , char * * used_by_lv_uuid )
{
char holders_path [ PATH_MAX ] ;
char dm_dev_path [ PATH_MAX ] ;
char dm_uuid [ DM_UUID_LEN ] ;
struct stat info ;
DIR * d ;
struct dirent * dirent ;
char * holder_name ;
2023-07-13 13:32:44 +03:00
unsigned dm_dev_major , dm_dev_minor ;
2024-05-26 12:30:06 +03:00
const size_t lvm_prefix_len = sizeof ( UUID_PREFIX ) - 1 ;
const size_t lvm_uuid_len = lvm_prefix_len + 2 * ID_LEN ;
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
size_t uuid_len ;
int used_count = 0 ;
char * used_name = NULL ;
char * used_vgid = NULL ;
char * used_lvid = NULL ;
/*
* An LV using this device will be listed as a " holder " in the device ' s
* sysfs " holders " dir .
*/
2024-05-28 17:17:53 +03:00
if ( dm_snprintf ( holders_path , sizeof ( holders_path ) , " %sdev/block/%u:%u/holders/ " ,
dm_sysfs_dir ( ) , MAJOR ( dev - > dev ) , MINOR ( dev - > dev ) ) < 0 ) {
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
log_error ( " %s: dm_snprintf failed for path to holders directory. " , dev_name ( dev ) ) ;
return 0 ;
}
if ( ! ( d = opendir ( holders_path ) ) )
return 0 ;
while ( ( dirent = readdir ( d ) ) ) {
if ( ! strcmp ( " . " , dirent - > d_name ) | | ! strcmp ( " .. " , dirent - > d_name ) )
continue ;
holder_name = dirent - > d_name ;
/*
* dirent - > d_name is the dev name of the holder , e . g . " dm-1 "
* from this name , create path " /dev/dm-1 " to run stat on .
*/
if ( dm_snprintf ( dm_dev_path , sizeof ( dm_dev_path ) , " %s/%s " , cmd - > dev_dir , holder_name ) < 0 )
continue ;
/*
* stat " /dev/dm-1 " which is the holder of the dev we ' re checking
* dm_dev_major : dm_dev_minor come from stat ( " /dev/dm-1 " )
*/
if ( stat ( dm_dev_path , & info ) )
continue ;
2024-05-25 23:36:18 +03:00
dm_dev_major = MAJOR ( info . st_rdev ) ;
dm_dev_minor = MINOR ( info . st_rdev ) ;
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
if ( dm_dev_major ! = cmd - > dev_types - > device_mapper_major )
continue ;
/*
* if " dm-1 " is a dm device , then check if it ' s an LVM LV
2024-05-24 02:07:47 +03:00
* by reading DM status and seeing if the uuid begins
* with UUID_PREFIX ( " LVM- " )
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
*/
2024-06-28 21:35:12 +03:00
if ( ! devno_dm_uuid ( cmd , dm_dev_major , dm_dev_minor , dm_uuid , sizeof ( dm_uuid ) ) )
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
continue ;
2024-05-26 12:30:06 +03:00
if ( ! strncmp ( dm_uuid , UUID_PREFIX , lvm_prefix_len ) )
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
used_count + + ;
if ( used_by_dm_name & & ! used_name )
used_name = dm_pool_strdup ( cmd - > mem , holder_name ) ;
if ( ! used_by_vg_uuid & & ! used_by_lv_uuid )
continue ;
/*
* UUID for LV is either " LVM-<vg_uuid><lv_uuid> " or
* " LVM-<vg_uuid><lv_uuid>-<suffix> " , where vg_uuid and lv_uuid
* has length of ID_LEN and suffix len is not restricted ( only
* restricted by whole DM UUID max len ) .
*/
uuid_len = strlen ( dm_uuid ) ;
if ( ( ( uuid_len = = lvm_uuid_len ) | |
( ( uuid_len > lvm_uuid_len ) & & ( dm_uuid [ lvm_uuid_len ] = = ' - ' ) ) ) & &
! strncmp ( dm_uuid , UUID_PREFIX , lvm_prefix_len ) ) {
if ( used_by_vg_uuid & & ! used_vgid )
used_vgid = dm_pool_strndup ( cmd - > mem , dm_uuid + lvm_prefix_len , ID_LEN ) ;
if ( used_by_lv_uuid & & ! used_lvid )
used_lvid = dm_pool_strndup ( cmd - > mem , dm_uuid + lvm_prefix_len + ID_LEN , ID_LEN ) ;
}
}
2021-07-27 16:36:48 +03:00
if ( closedir ( d ) )
log_sys_debug ( " closedir " , holders_path ) ;
skip indexing devices used by LVs in more commands
expands commit d5a06f9a7df5a43b2e2311db62ff8d3011217d74
"pvscan: skip indexing devices used by LVs"
The dev cache index is expensive and slow, so limit it
to commands that are used to observe the state of lvm.
The index is only used to print warnings about incorrect
device use by active LVs, e.g. if an LV is using a
multipath component device instead of the multipath
device. Commands that continue to use the index and
print the warnings:
fullreport, lvmdiskscan, vgs, lvs, pvs,
vgdisplay, lvdisplay, pvdisplay,
vgscan, lvscan, pvscan (excluding --cache)
A couple other commands were borrowing the DEV_USED_FOR_LV
flag to just check if a device was actively in use by LVs.
These are converted to the new dev_is_used_by_active_lv().
2021-07-08 00:59:56 +03:00
if ( used_by_lv_count )
* used_by_lv_count = used_count ;
if ( used_by_dm_name )
* used_by_dm_name = used_name ;
if ( used_by_vg_uuid )
* used_by_vg_uuid = used_vgid ;
if ( used_by_lv_uuid )
* used_by_lv_uuid = used_lvid ;
if ( used_count )
return 1 ;
return 0 ;
}
2013-06-12 14:08:56 +04:00
struct dev_types * create_dev_types ( const char * proc_dir ,
const struct dm_config_node * cn )
{
struct dev_types * dt ;
char line [ 80 ] ;
char proc_devices [ PATH_MAX ] ;
FILE * pd = NULL ;
int i , j = 0 ;
int line_maj = 0 ;
int blocksection = 0 ;
size_t dev_len = 0 ;
const struct dm_config_value * cv ;
const char * name ;
char * nl ;
2018-06-08 15:40:53 +03:00
if ( ! ( dt = zalloc ( sizeof ( struct dev_types ) ) ) ) {
2013-06-12 14:08:56 +04:00
log_error ( " Failed to allocate device type register. " ) ;
return NULL ;
}
if ( ! * proc_dir ) {
log_verbose ( " No proc filesystem found: using all block device types " ) ;
for ( i = 0 ; i < NUMBER_OF_MAJORS ; i + + )
dt - > dev_type_array [ i ] . max_partitions = 1 ;
return dt ;
}
if ( dm_snprintf ( proc_devices , sizeof ( proc_devices ) ,
" %s/devices " , proc_dir ) < 0 ) {
log_error ( " Failed to create /proc/devices string " ) ;
goto bad ;
}
if ( ! ( pd = fopen ( proc_devices , " r " ) ) ) {
log_sys_error ( " fopen " , proc_devices ) ;
goto bad ;
}
while ( fgets ( line , sizeof ( line ) , pd ) ! = NULL ) {
i = 0 ;
while ( line [ i ] = = ' ' )
i + + ;
/* If it's not a number it may be name of section */
2017-07-20 10:57:09 +03:00
line_maj = atoi ( line + i ) ;
2013-06-12 14:08:56 +04:00
if ( line_maj < 0 | | line_maj > = NUMBER_OF_MAJORS ) {
/*
* Device numbers shown in / proc / devices are actually direct
* numbers passed to registering function , however the kernel
* uses only 12 bits , so use just 12 bits for major .
*/
if ( ( nl = strchr ( line , ' \n ' ) ) ) * nl = ' \0 ' ;
log_warn ( " WARNING: /proc/devices line: %s, replacing major with %d. " ,
line , line_maj & ( NUMBER_OF_MAJORS - 1 ) ) ;
line_maj & = ( NUMBER_OF_MAJORS - 1 ) ;
}
if ( ! line_maj ) {
blocksection = ( line [ i ] = = ' B ' ) ? 1 : 0 ;
continue ;
}
/* We only want block devices ... */
if ( ! blocksection )
continue ;
/* Find the start of the device major name */
while ( line [ i ] ! = ' ' & & line [ i ] ! = ' \0 ' )
i + + ;
while ( line [ i ] = = ' ' )
i + + ;
2024-05-23 00:22:43 +03:00
/* Major is SCSI device */
if ( ! strncmp ( " sd " , line + i , 2 ) & & isspace ( * ( line + i + 2 ) ) )
dt - > dev_type_array [ line_maj ] . flags | = PARTITION_SCSI_DEVICE ;
else if ( ! strncmp ( " loop " , line + i , 4 ) & & isspace ( * ( line + i + 4 ) ) )
dt - > loop_major = line_maj ;
/* Look for device-mapper device */
/* FIXME Cope with multiple majors */
else if ( ! strncmp ( " device-mapper " , line + i , 13 ) & & isspace ( * ( line + i + 13 ) ) )
dt - > device_mapper_major = line_maj ;
2013-06-12 14:08:56 +04:00
/* Look for md device */
2024-05-23 00:22:43 +03:00
else if ( ! strncmp ( " md " , line + i , 2 ) & & isspace ( * ( line + i + 2 ) ) )
2013-06-12 14:08:56 +04:00
dt - > md_major = line_maj ;
/* Look for blkext device */
2024-05-23 00:22:43 +03:00
else if ( ! strncmp ( " blkext " , line + i , 6 ) & & isspace ( * ( line + i + 6 ) ) )
2013-06-12 14:08:56 +04:00
dt - > blkext_major = line_maj ;
/* Look for drbd device */
2024-05-23 00:22:43 +03:00
else if ( ! strncmp ( " drbd " , line + i , 4 ) & & isspace ( * ( line + i + 4 ) ) )
2013-06-12 14:08:56 +04:00
dt - > drbd_major = line_maj ;
2015-01-23 23:01:34 +03:00
/* Look for DASD */
2024-05-23 00:22:43 +03:00
else if ( ! strncmp ( " dasd " , line + i , 4 ) & & isspace ( * ( line + i + 4 ) ) )
2015-01-23 23:01:34 +03:00
dt - > dasd_major = line_maj ;
2013-06-12 14:08:56 +04:00
/* Look for EMC powerpath */
2024-05-23 00:22:43 +03:00
else if ( ! strncmp ( " emcpower " , line + i , 8 ) & & isspace ( * ( line + i + 8 ) ) )
2013-06-12 14:08:56 +04:00
dt - > emcpower_major = line_maj ;
2017-01-11 01:23:23 +03:00
/* Look for Veritas Dynamic Multipathing */
2024-05-23 00:22:43 +03:00
else if ( ! strncmp ( " VxDMP " , line + i , 5 ) & & isspace ( * ( line + i + 5 ) ) )
2017-01-11 01:23:23 +03:00
dt - > vxdmp_major = line_maj ;
2024-05-23 00:22:43 +03:00
else if ( ! strncmp ( " power2 " , line + i , 6 ) & & isspace ( * ( line + i + 6 ) ) )
2013-06-12 14:08:56 +04:00
dt - > power2_major = line_maj ;
/* Go through the valid device names and if there is a
match store max number of partitions */
for ( j = 0 ; _dev_known_types [ j ] . name [ 0 ] ; j + + ) {
dev_len = strlen ( _dev_known_types [ j ] . name ) ;
if ( dev_len < = strlen ( line + i ) & &
! strncmp ( _dev_known_types [ j ] . name , line + i , dev_len ) & &
( line_maj < NUMBER_OF_MAJORS ) ) {
dt - > dev_type_array [ line_maj ] . max_partitions =
_dev_known_types [ j ] . max_partitions ;
break ;
}
}
if ( ! cn )
continue ;
/* Check devices/types for local variations */
for ( cv = cn - > v ; cv ; cv = cv - > next ) {
if ( cv - > type ! = DM_CFG_STRING ) {
log_error ( " Expecting string in devices/types "
" in config file " ) ;
if ( fclose ( pd ) )
2021-02-07 16:06:12 +03:00
log_sys_debug ( " fclose " , proc_devices ) ;
2013-06-12 14:08:56 +04:00
goto bad ;
}
dev_len = strlen ( cv - > v . str ) ;
name = cv - > v . str ;
cv = cv - > next ;
if ( ! cv | | cv - > type ! = DM_CFG_INT ) {
log_error ( " Max partition count missing for %s "
" in devices/types in config file " ,
name ) ;
if ( fclose ( pd ) )
2021-02-07 16:06:12 +03:00
log_sys_debug ( " fclose " , proc_devices ) ;
2013-06-12 14:08:56 +04:00
goto bad ;
}
if ( ! cv - > v . i ) {
log_error ( " Zero partition count invalid for "
" %s in devices/types in config file " ,
name ) ;
if ( fclose ( pd ) )
2021-02-07 16:06:12 +03:00
log_sys_debug ( " fclose " , proc_devices ) ;
2013-06-12 14:08:56 +04:00
goto bad ;
}
if ( dev_len < = strlen ( line + i ) & &
! strncmp ( name , line + i , dev_len ) & &
( line_maj < NUMBER_OF_MAJORS ) ) {
dt - > dev_type_array [ line_maj ] . max_partitions = cv - > v . i ;
break ;
}
}
}
if ( fclose ( pd ) )
2024-05-23 01:41:57 +03:00
log_sys_debug ( " fclose " , proc_devices ) ;
2013-06-12 14:08:56 +04:00
return dt ;
bad :
2018-06-08 15:40:53 +03:00
free ( dt ) ;
2013-06-12 14:08:56 +04:00
return NULL ;
}
int dev_subsystem_part_major ( struct dev_types * dt , struct device * dev )
{
dev_t primary_dev ;
if ( MAJOR ( dev - > dev ) = = dt - > device_mapper_major )
return 1 ;
2018-05-11 22:00:19 +03:00
if ( MAJOR ( dev - > dev ) = = dt - > md_major )
return 1 ;
2013-06-12 14:08:56 +04:00
if ( MAJOR ( dev - > dev ) = = dt - > drbd_major )
return 1 ;
if ( MAJOR ( dev - > dev ) = = dt - > emcpower_major )
return 1 ;
if ( MAJOR ( dev - > dev ) = = dt - > power2_major )
return 1 ;
2004-12-21 19:10:25 +03:00
2017-01-11 01:23:23 +03:00
if ( MAJOR ( dev - > dev ) = = dt - > vxdmp_major )
return 1 ;
2013-06-12 14:08:56 +04:00
if ( ( MAJOR ( dev - > dev ) = = dt - > blkext_major ) & &
2013-06-12 16:33:28 +04:00
dev_get_primary_dev ( dt , dev , & primary_dev ) & &
2013-06-12 14:08:56 +04:00
( MAJOR ( primary_dev ) = = dt - > md_major ) )
return 1 ;
return 0 ;
}
const char * dev_subsystem_name ( struct dev_types * dt , struct device * dev )
{
2020-12-03 19:48:21 +03:00
if ( dev - > flags & DEV_IS_NVME )
return " NVME " ;
2015-04-24 22:58:58 +03:00
if ( MAJOR ( dev - > dev ) = = dt - > device_mapper_major )
return " DM " ;
2013-06-12 14:08:56 +04:00
if ( MAJOR ( dev - > dev ) = = dt - > md_major )
return " MD " ;
if ( MAJOR ( dev - > dev ) = = dt - > drbd_major )
return " DRBD " ;
2015-01-23 23:01:34 +03:00
if ( MAJOR ( dev - > dev ) = = dt - > dasd_major )
return " DASD " ;
2013-06-12 14:08:56 +04:00
if ( MAJOR ( dev - > dev ) = = dt - > emcpower_major )
return " EMCPOWER " ;
if ( MAJOR ( dev - > dev ) = = dt - > power2_major )
return " POWER2 " ;
2017-01-11 01:23:23 +03:00
if ( MAJOR ( dev - > dev ) = = dt - > vxdmp_major )
return " VXDMP " ;
2013-06-12 14:08:56 +04:00
if ( MAJOR ( dev - > dev ) = = dt - > blkext_major )
return " BLKEXT " ;
2016-06-01 17:39:47 +03:00
if ( MAJOR ( dev - > dev ) = = dt - > loop_major )
return " LOOP " ;
2013-06-12 14:08:56 +04:00
return " " ;
}
int major_max_partitions ( struct dev_types * dt , int major )
{
if ( major > = NUMBER_OF_MAJORS )
return 0 ;
return dt - > dev_type_array [ major ] . max_partitions ;
}
int major_is_scsi_device ( struct dev_types * dt , int major )
{
if ( major > = NUMBER_OF_MAJORS )
return 0 ;
return ( dt - > dev_type_array [ major ] . flags & PARTITION_SCSI_DEVICE ) ? 1 : 0 ;
}
2016-06-01 17:39:47 +03:00
static int _loop_is_with_partscan ( struct device * dev )
{
FILE * fp ;
int partscan = 0 ;
char path [ PATH_MAX ] ;
char buffer [ 64 ] ;
2024-05-28 17:17:53 +03:00
if ( dm_snprintf ( path , sizeof ( path ) , " %sdev/block/%u:%u/loop/partscan " ,
dm_sysfs_dir ( ) , MAJOR ( dev - > dev ) , MINOR ( dev - > dev ) ) < 0 ) {
2016-06-01 17:39:47 +03:00
log_warn ( " Sysfs path for partscan is too long. " ) ;
return 0 ;
}
if ( ! ( fp = fopen ( path , " r " ) ) )
return 0 ; /* not there -> no partscan */
if ( ! fgets ( buffer , sizeof ( buffer ) , fp ) ) {
log_warn ( " Failed to read %s. " , path ) ;
} else if ( sscanf ( buffer , " %d " , & partscan ) ! = 1 ) {
log_warn ( " Failed to parse %s '%s'. " , path , buffer ) ;
partscan = 0 ;
}
if ( fclose ( fp ) )
log_sys_debug ( " fclose " , path ) ;
return partscan ;
}
device usage based on devices file
The LVM devices file lists devices that lvm can use. The default
file is /etc/lvm/devices/system.devices, and the lvmdevices(8)
command is used to add or remove device entries. If the file
does not exist, or if lvm.conf includes use_devicesfile=0, then
lvm will not use a devices file. When the devices file is in use,
the regex filter is not used, and the filter settings in lvm.conf
or on the command line are ignored.
LVM records devices in the devices file using hardware-specific
IDs, such as the WWID, and attempts to use subsystem-specific
IDs for virtual device types. These device IDs are also written
in the VG metadata. When no hardware or virtual ID is available,
lvm falls back using the unstable device name as the device ID.
When devnames are used, lvm performs extra scanning to find
devices if their devname changes, e.g. after reboot.
When proper device IDs are used, an lvm command will not look
at devices outside the devices file, but when devnames are used
as a fallback, lvm will scan devices outside the devices file
to locate PVs on renamed devices. A config setting
search_for_devnames can be used to control the scanning for
renamed devname entries.
Related to the devices file, the new command option
--devices <devnames> allows a list of devices to be specified for
the command to use, overriding the devices file. The listed
devices act as a sort of devices file in terms of limiting which
devices lvm will see and use. Devices that are not listed will
appear to be missing to the lvm command.
Multiple devices files can be kept in /etc/lvm/devices, which
allows lvm to be used with different sets of devices, e.g.
system devices do not need to be exposed to a specific application,
and the application can use lvm on its own set of devices that are
not exposed to the system. The option --devicesfile <filename> is
used to select the devices file to use with the command. Without
the option set, the default system devices file is used.
Setting --devicesfile "" causes lvm to not use a devices file.
An existing, empty devices file means lvm will see no devices.
The new command vgimportdevices adds PVs from a VG to the devices
file and updates the VG metadata to include the device IDs.
vgimportdevices -a will import all VGs into the system devices file.
LVM commands run by dmeventd not use a devices file by default,
and will look at all devices on the system. A devices file can
be created for dmeventd (/etc/lvm/devices/dmeventd.devices) If
this file exists, lvm commands run by dmeventd will use it.
Internal implementaion:
- device_ids_read - read the devices file
. add struct dev_use (du) to cmd->use_devices for each devices file entry
- dev_cache_scan - get /dev entries
. add struct device (dev) to dev_cache for each device on the system
- device_ids_match - match devices file entries to /dev entries
. match each du on cmd->use_devices to a dev in dev_cache, using device ID
. on match, set du->dev, dev->id, dev->flags MATCHED_USE_ID
- label_scan - read lvm headers and metadata from devices
. filters are applied, those that do not need data from the device
. filter-deviceid skips devs without MATCHED_USE_ID, i.e.
skips /dev entries that are not listed in the devices file
. read lvm label from dev
. filters are applied, those that use data from the device
. read lvm metadata from dev
. add info/vginfo structs for PVs/VGs (info is "lvmcache")
- device_ids_find_renamed_devs - handle devices with unstable devname ID
where devname changed
. this step only needed when devs do not have proper device IDs,
and their dev names change, e.g. after reboot sdb becomes sdc.
. detect incorrect match because PVID in the devices file entry
does not match the PVID found when the device was read above
. undo incorrect match between du and dev above
. search system devices for new location of PVID
. update devices file with new devnames for PVIDs on renamed devices
. label_scan the renamed devs
- continue with command processing
2020-06-23 21:25:41 +03:00
int dev_get_partition_number ( struct device * dev , int * num )
{
char path [ PATH_MAX ] ;
char buf [ 8 ] = { 0 } ;
dev_t devt = dev - > dev ;
struct stat sb ;
if ( dev - > part ! = - 1 ) {
* num = dev - > part ;
return 1 ;
}
2024-05-28 17:17:53 +03:00
if ( dm_snprintf ( path , sizeof ( path ) , " %sdev/block/%u:%u/partition " ,
dm_sysfs_dir ( ) , MAJOR ( devt ) , MINOR ( devt ) ) < 0 ) {
device usage based on devices file
The LVM devices file lists devices that lvm can use. The default
file is /etc/lvm/devices/system.devices, and the lvmdevices(8)
command is used to add or remove device entries. If the file
does not exist, or if lvm.conf includes use_devicesfile=0, then
lvm will not use a devices file. When the devices file is in use,
the regex filter is not used, and the filter settings in lvm.conf
or on the command line are ignored.
LVM records devices in the devices file using hardware-specific
IDs, such as the WWID, and attempts to use subsystem-specific
IDs for virtual device types. These device IDs are also written
in the VG metadata. When no hardware or virtual ID is available,
lvm falls back using the unstable device name as the device ID.
When devnames are used, lvm performs extra scanning to find
devices if their devname changes, e.g. after reboot.
When proper device IDs are used, an lvm command will not look
at devices outside the devices file, but when devnames are used
as a fallback, lvm will scan devices outside the devices file
to locate PVs on renamed devices. A config setting
search_for_devnames can be used to control the scanning for
renamed devname entries.
Related to the devices file, the new command option
--devices <devnames> allows a list of devices to be specified for
the command to use, overriding the devices file. The listed
devices act as a sort of devices file in terms of limiting which
devices lvm will see and use. Devices that are not listed will
appear to be missing to the lvm command.
Multiple devices files can be kept in /etc/lvm/devices, which
allows lvm to be used with different sets of devices, e.g.
system devices do not need to be exposed to a specific application,
and the application can use lvm on its own set of devices that are
not exposed to the system. The option --devicesfile <filename> is
used to select the devices file to use with the command. Without
the option set, the default system devices file is used.
Setting --devicesfile "" causes lvm to not use a devices file.
An existing, empty devices file means lvm will see no devices.
The new command vgimportdevices adds PVs from a VG to the devices
file and updates the VG metadata to include the device IDs.
vgimportdevices -a will import all VGs into the system devices file.
LVM commands run by dmeventd not use a devices file by default,
and will look at all devices on the system. A devices file can
be created for dmeventd (/etc/lvm/devices/dmeventd.devices) If
this file exists, lvm commands run by dmeventd will use it.
Internal implementaion:
- device_ids_read - read the devices file
. add struct dev_use (du) to cmd->use_devices for each devices file entry
- dev_cache_scan - get /dev entries
. add struct device (dev) to dev_cache for each device on the system
- device_ids_match - match devices file entries to /dev entries
. match each du on cmd->use_devices to a dev in dev_cache, using device ID
. on match, set du->dev, dev->id, dev->flags MATCHED_USE_ID
- label_scan - read lvm headers and metadata from devices
. filters are applied, those that do not need data from the device
. filter-deviceid skips devs without MATCHED_USE_ID, i.e.
skips /dev entries that are not listed in the devices file
. read lvm label from dev
. filters are applied, those that use data from the device
. read lvm metadata from dev
. add info/vginfo structs for PVs/VGs (info is "lvmcache")
- device_ids_find_renamed_devs - handle devices with unstable devname ID
where devname changed
. this step only needed when devs do not have proper device IDs,
and their dev names change, e.g. after reboot sdb becomes sdc.
. detect incorrect match because PVID in the devices file entry
does not match the PVID found when the device was read above
. undo incorrect match between du and dev above
. search system devices for new location of PVID
. update devices file with new devnames for PVIDs on renamed devices
. label_scan the renamed devs
- continue with command processing
2020-06-23 21:25:41 +03:00
log_error ( " Failed to create sysfs path for %s " , dev_name ( dev ) ) ;
return 0 ;
}
if ( stat ( path , & sb ) ) {
dev - > part = 0 ;
* num = 0 ;
return 1 ;
}
if ( ! get_sysfs_value ( path , buf , sizeof ( buf ) , 0 ) ) {
log_error ( " Failed to read sysfs path for %s " , dev_name ( dev ) ) ;
return 0 ;
}
if ( ! buf [ 0 ] ) {
log_error ( " Failed to read sysfs partition value for %s " , dev_name ( dev ) ) ;
return 0 ;
}
dev - > part = atoi ( buf ) ;
* num = dev - > part ;
return 1 ;
}
2013-06-12 14:08:56 +04:00
/* See linux/genhd.h and fs/partitions/msdos */
2024-09-18 11:26:18 +03:00
# define PART_MSDOS_MAGIC 0xAA55
# define PART_MSDOS_MAGIC_OFFSET UINT64_C(0x1FE)
# define PART_MSDOS_OFFSET UINT64_C(0x1BE)
# define PART_MSDOS_TYPE_GPT_PMBR UINT8_C(0xEE)
2024-09-04 16:30:42 +03:00
# define PART_GPT_HEADER_OFFSET_LBA 0x01
# define PART_GPT_MAGIC 0x5452415020494645UL /* "EFI PART" string */
# define PART_GPT_ENTRIES_FIELDS_OFFSET UINT64_C(0x48)
2004-12-21 19:10:25 +03:00
struct partition {
2008-01-30 17:00:02 +03:00
uint8_t boot_ind ;
uint8_t head ;
uint8_t sector ;
uint8_t cyl ;
uint8_t sys_ind ; /* partition type */
uint8_t end_head ;
uint8_t end_sector ;
uint8_t end_cyl ;
uint32_t start_sect ;
uint32_t nr_sects ;
2004-12-21 19:10:25 +03:00
} __attribute__ ( ( packed ) ) ;
2004-11-23 14:44:04 +03:00
2020-12-03 19:48:21 +03:00
static int _has_sys_partition ( struct device * dev )
{
char path [ PATH_MAX ] ;
struct stat info ;
2024-05-28 17:17:53 +03:00
unsigned major = MAJOR ( dev - > dev ) ;
unsigned minor = MINOR ( dev - > dev ) ;
2020-12-03 19:48:21 +03:00
/* check if dev is a partition */
2024-05-28 17:17:53 +03:00
if ( dm_snprintf ( path , sizeof ( path ) , " %sdev/block/%u:%u/partition " ,
2020-12-03 19:48:21 +03:00
dm_sysfs_dir ( ) , major , minor ) < 0 ) {
2021-02-07 16:06:12 +03:00
log_warn ( " WARNING: %s: partition path is too long. " , dev_name ( dev ) ) ;
2020-12-03 19:48:21 +03:00
return 0 ;
}
if ( stat ( path , & info ) = = - 1 ) {
if ( errno ! = ENOENT )
2021-02-07 16:06:12 +03:00
log_sys_debug ( " stat " , path ) ;
2020-12-03 19:48:21 +03:00
return 0 ;
}
return 1 ;
}
2013-06-12 14:08:56 +04:00
static int _is_partitionable ( struct dev_types * dt , struct device * dev )
2004-11-23 14:44:04 +03:00
{
2013-06-12 14:08:56 +04:00
int parts = major_max_partitions ( dt , MAJOR ( dev - > dev ) ) ;
2004-11-23 14:44:04 +03:00
2015-01-12 16:02:57 +03:00
if ( MAJOR ( dev - > dev ) = = dt - > device_mapper_major )
return 1 ;
2009-07-10 02:50:45 +04:00
/* All MD devices are partitionable via blkext (as of 2.6.28) */
2013-06-12 14:08:56 +04:00
if ( MAJOR ( dev - > dev ) = = dt - > md_major )
2009-07-10 02:50:45 +04:00
return 1 ;
2016-06-01 17:39:47 +03:00
/* All loop devices are partitionable via blkext (as of 3.2) */
if ( ( MAJOR ( dev - > dev ) = = dt - > loop_major ) & &
_loop_is_with_partscan ( dev ) )
return 1 ;
2024-12-07 00:02:20 +03:00
if ( dev_is_nvme ( dev ) ) {
2020-12-03 19:48:21 +03:00
/* If this dev is already a partition then it's not partitionable. */
if ( _has_sys_partition ( dev ) )
return 0 ;
return 1 ;
}
2004-12-10 19:01:35 +03:00
if ( ( parts < = 1 ) | | ( MINOR ( dev - > dev ) % parts ) )
2004-11-24 23:38:05 +03:00
return 0 ;
2004-11-23 14:44:04 +03:00
2004-11-24 23:38:05 +03:00
return 1 ;
2004-11-23 14:44:04 +03:00
}
2024-09-04 16:30:42 +03:00
static int _has_gpt_partition_table ( struct device * dev )
{
unsigned int pbs , lbs ;
uint64_t entries_start ;
uint32_t nr_entries , sz_entry , i ;
struct {
uint64_t magic ;
/* skip fields we're not interested in */
uint8_t skip [ PART_GPT_ENTRIES_FIELDS_OFFSET - sizeof ( uint64_t ) ] ;
uint64_t part_entries_lba ;
uint32_t nr_part_entries ;
uint32_t sz_part_entry ;
} __attribute__ ( ( packed ) ) gpt_header ;
struct {
uint64_t part_type_guid ;
/* not interested in any other fields */
} __attribute__ ( ( packed ) ) gpt_part_entry ;
if ( ! dev_get_direct_block_sizes ( dev , & pbs , & lbs ) )
return_0 ;
if ( ! dev_read_bytes ( dev , PART_GPT_HEADER_OFFSET_LBA * lbs , sizeof ( gpt_header ) , & gpt_header ) )
return_0 ;
/* the gpt table is always written using LE on disk */
if ( le64_to_cpu ( gpt_header . magic ) ! = PART_GPT_MAGIC )
2024-10-20 01:43:42 +03:00
return 0 ;
2024-09-04 16:30:42 +03:00
entries_start = le64_to_cpu ( gpt_header . part_entries_lba ) * lbs ;
nr_entries = le32_to_cpu ( gpt_header . nr_part_entries ) ;
sz_entry = le32_to_cpu ( gpt_header . sz_part_entry ) ;
for ( i = 0 ; i < nr_entries ; i + + ) {
2024-10-25 00:26:19 +03:00
if ( ! dev_read_bytes ( dev , entries_start + ( uint64_t ) i * sz_entry ,
2024-09-04 16:30:42 +03:00
sizeof ( gpt_part_entry ) , & gpt_part_entry ) )
return_0 ;
/* just check if the guid is nonzero, no need to call le64_to_cpu here */
if ( gpt_part_entry . part_type_guid )
return 1 ;
}
return 0 ;
}
/*
* Check if there ' s a partition table present on the device dev , either msdos or gpt .
* Returns :
*
* 1 - if it has a partition table with at least one real partition defined
* ( note : the gpt ' s PMBR partition alone does not count as a real partition )
*
* 0 - if it has no partition table ,
* - or if it does have a partition table , but without any partition defined ,
* - or on error
*/
2004-11-23 14:44:04 +03:00
static int _has_partition_table ( struct device * dev )
{
int ret = 0 ;
2004-12-21 19:10:25 +03:00
unsigned p ;
2010-10-20 19:07:30 +04:00
struct {
2024-09-18 11:26:18 +03:00
uint8_t skip [ PART_MSDOS_OFFSET ] ;
2010-10-20 19:07:30 +04:00
struct partition part [ 4 ] ;
uint16_t magic ;
} __attribute__ ( ( packed ) ) buf ; /* sizeof() == SECTOR_SIZE */
2004-11-23 14:44:04 +03:00
2018-05-04 01:12:07 +03:00
if ( ! dev_read_bytes ( dev , UINT64_C ( 0 ) , sizeof ( buf ) , & buf ) )
2010-04-06 21:36:41 +04:00
return_0 ;
2004-12-21 19:10:25 +03:00
/* FIXME Check for other types of partition table too */
/* Check for msdos partition table */
2024-09-18 11:26:18 +03:00
if ( buf . magic = = xlate16 ( PART_MSDOS_MAGIC ) ) {
2010-10-20 19:07:30 +04:00
for ( p = 0 ; p < 4 ; + + p ) {
2004-12-21 19:10:25 +03:00
/* Table is invalid if boot indicator not 0 or 0x80 */
2010-10-20 19:07:30 +04:00
if ( buf . part [ p ] . boot_ind & 0x7f ) {
2004-12-21 19:10:25 +03:00
ret = 0 ;
break ;
}
/* Must have at least one non-empty partition */
2024-09-04 16:30:42 +03:00
if ( buf . part [ p ] . nr_sects ) {
/*
* If this is GPT ' s PMBR , then also
* check for gpt partition table .
*/
2024-10-03 10:38:11 +03:00
if ( buf . part [ p ] . sys_ind = = PART_MSDOS_TYPE_GPT_PMBR & & ! ret )
2024-09-04 16:30:42 +03:00
ret = _has_gpt_partition_table ( dev ) ;
else
ret = 1 ;
}
2004-12-21 19:10:25 +03:00
}
2024-09-04 16:30:42 +03:00
} else
/* Check for gpt partition table. */
ret = _has_gpt_partition_table ( dev ) ;
2004-11-23 14:44:04 +03:00
return ret ;
}
2014-09-03 17:49:36 +04:00
# ifdef UDEV_SYNC_SUPPORT
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
static int _dev_is_partitioned_udev ( struct dev_types * dt , struct device * dev )
2014-09-03 17:49:36 +04:00
{
struct dev_ext * ext ;
2016-02-02 15:28:11 +03:00
struct udev_device * device ;
const char * value ;
2014-09-03 17:49:36 +04:00
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
/*
* external_device_info_source = " udev " enables these udev checks .
* external_device_info_source = " none " disables them .
*/
2014-09-03 17:49:36 +04:00
if ( ! ( ext = dev_ext_get ( dev ) ) )
return_0 ;
2016-02-02 15:28:11 +03:00
device = ( struct udev_device * ) ext - > handle ;
if ( ! ( value = udev_device_get_property_value ( device , DEV_EXT_UDEV_BLKID_PART_TABLE_TYPE ) ) )
2014-09-03 17:49:36 +04:00
return 0 ;
2016-02-02 15:28:11 +03:00
/*
* Device - mapper devices have DEV_EXT_UDEV_BLKID_PART_TABLE_TYPE
* variable set if there ' s partition table found on whole device .
* Partitions do not have this variable set - it ' s enough to use
* only this variable to decide whether this device has partition
* table on it .
*/
if ( MAJOR ( dev - > dev ) = = dt - > device_mapper_major )
return 1 ;
2014-09-03 17:49:36 +04:00
2016-02-02 15:28:11 +03:00
/*
* Other devices have DEV_EXT_UDEV_BLKID_PART_TABLE_TYPE set for
* * both * whole device and partitions . We need to look at the
* DEV_EXT_UDEV_DEVTYPE in addition to decide - whole device
* with partition table on it has this variable set to
* DEV_EXT_UDEV_DEVTYPE_DISK .
*/
if ( ! ( value = udev_device_get_property_value ( device , DEV_EXT_UDEV_DEVTYPE ) ) )
return_0 ;
return ! strcmp ( value , DEV_EXT_UDEV_DEVTYPE_DISK ) ;
2014-09-03 17:49:36 +04:00
}
# else
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
static int _dev_is_partitioned_udev ( struct dev_types * dt , struct device * dev )
2014-09-03 17:49:36 +04:00
{
return 0 ;
}
# endif
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
static int _dev_is_partitioned_native ( struct dev_types * dt , struct device * dev )
2004-11-23 14:44:04 +03:00
{
2014-09-03 17:49:36 +04:00
int r ;
2015-01-23 23:01:34 +03:00
/* Unpartitioned DASD devices are not supported. */
2015-10-12 10:09:11 +03:00
if ( ( MAJOR ( dev - > dev ) = = dt - > dasd_major ) & & dasd_is_cdl_formatted ( dev ) )
2015-01-23 23:01:34 +03:00
return 1 ;
2014-09-03 17:49:36 +04:00
r = _has_partition_table ( dev ) ;
return r ;
}
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
int dev_is_partitioned ( struct cmd_context * cmd , struct device * dev )
2014-09-03 17:49:36 +04:00
{
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
struct dev_types * dt = cmd - > dev_types ;
2014-09-03 17:49:36 +04:00
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
if ( ! _is_partitionable ( dt , dev ) )
return 0 ;
2014-09-03 17:49:36 +04:00
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
if ( _dev_is_partitioned_native ( dt , dev ) = = 1 )
return 1 ;
if ( external_device_info_source ( ) = = DEV_EXT_UDEV ) {
if ( _dev_is_partitioned_udev ( dt , dev ) = = 1 )
return 1 ;
}
2014-09-03 17:49:36 +04:00
return 0 ;
2004-11-23 14:44:04 +03:00
}
2013-06-12 14:14:11 +04:00
/*
* Get primary dev for the dev supplied .
2013-06-12 16:33:28 +04:00
*
* We can get a primary device for a partition either by :
* A : knowing the number of partitions allowed for the dev and also
* which major : minor number represents the primary and partition device
* ( by using the dev_types - > dev_type_array )
* B : by the existence of the ' partition ' sysfs attribute
* ( / dev / block / < major > : < minor > / partition )
*
* Method A is tried first , then method B as a fallback if A fails .
*
* N . B . Method B can only do the decision based on the pure existence of
* the ' partition ' sysfs item . There ' s no direct scan for partition
* tables whatsoever !
*
2013-06-12 14:14:11 +04:00
* Returns :
2013-06-12 16:33:28 +04:00
* 0 on error
* 1 if the dev is already a primary dev , primary dev in ' result '
* 2 if the dev is a partition , primary dev in ' result '
2013-06-12 14:14:11 +04:00
*/
2013-06-12 14:08:56 +04:00
int dev_get_primary_dev ( struct dev_types * dt , struct device * dev , dev_t * result )
{
2024-05-28 17:17:53 +03:00
unsigned major = MAJOR ( dev - > dev ) ;
unsigned minor = MINOR ( dev - > dev ) ;
2014-08-19 13:35:18 +04:00
char path [ PATH_MAX ] ;
char temp_path [ PATH_MAX ] ;
2013-06-12 14:08:56 +04:00
char buffer [ 64 ] ;
2013-06-12 14:14:11 +04:00
FILE * fp = NULL ;
2013-07-19 17:26:53 +04:00
int parts , residue , size , ret = 0 ;
2013-06-12 14:14:11 +04:00
2020-12-03 19:48:21 +03:00
/*
* / dev / nvme devs don ' t use the major : minor numbering like
* block dev types that have their own major number , so
* the calculation based on minor number doesn ' t work .
*/
2024-12-07 00:02:20 +03:00
if ( dev_is_nvme ( dev ) )
2020-12-03 19:48:21 +03:00
goto sys_partition ;
2013-06-12 14:14:11 +04:00
/*
* Try to get the primary dev out of the
* list of known device types first .
*/
if ( ( parts = dt - > dev_type_array [ major ] . max_partitions ) > 1 ) {
if ( ( residue = minor % parts ) ) {
2018-11-03 19:13:10 +03:00
* result = MKDEV ( major , ( minor - residue ) ) ;
2013-06-12 16:33:28 +04:00
ret = 2 ;
2013-06-12 14:14:11 +04:00
} else {
* result = dev - > dev ;
2013-06-12 16:33:28 +04:00
ret = 1 ; /* dev is not a partition! */
2013-06-12 14:14:11 +04:00
}
goto out ;
}
2020-12-03 19:48:21 +03:00
sys_partition :
2013-06-12 14:14:11 +04:00
/*
* If we can ' t get the primary dev out of the list of known device
* types , try to look at sysfs directly then . This is more complex
* way and it also requires certain sysfs layout to be present
* which might not be there in old kernels !
*/
2020-12-03 19:48:21 +03:00
if ( ! _has_sys_partition ( dev ) ) {
2013-06-12 14:14:11 +04:00
* result = dev - > dev ;
2013-07-19 17:26:53 +04:00
ret = 1 ;
goto out ; /* dev is not a partition! */
2013-06-12 14:08:56 +04:00
}
/*
* extract parent ' s path from the partition ' s symlink , e . g . :
* - readlink / sys / dev / block / 259 : 0 = . . / . . / block / md0 / md0p1
* - dirname . . / . . / block / md0 / md0p1 = . . / . . / block / md0
* - basename . . / . . / block / md0 / md0 = md0
* Parent ' s ' dev ' sysfs attribute = / sys / block / md0 / dev
*/
2024-05-28 17:17:53 +03:00
if ( dm_snprintf ( path , sizeof ( path ) , " %sdev/block/%u:%u " ,
2021-02-09 18:47:08 +03:00
dm_sysfs_dir ( ) , major , minor ) < 0 ) {
log_warn ( " WARNING: %s: major:minor sysfs path is too long. " , dev_name ( dev ) ) ;
return 0 ;
}
if ( ( size = readlink ( path , temp_path , sizeof ( temp_path ) - 1 ) ) < 0 ) {
2021-02-07 16:06:12 +03:00
log_warn ( " WARNING: Readlink of %s failed. " , path ) ;
2013-06-12 14:14:11 +04:00
goto out ;
2013-06-12 14:08:56 +04:00
}
temp_path [ size ] = ' \0 ' ;
2022-08-10 16:09:34 +03:00
if ( dm_snprintf ( path , sizeof ( path ) , " %sblock/%s/dev " ,
2021-02-07 16:06:12 +03:00
dm_sysfs_dir ( ) , basename ( dirname ( temp_path ) ) ) < 0 ) {
log_warn ( " WARNING: sysfs path for %s is too long. " ,
basename ( dirname ( temp_path ) ) ) ;
2013-06-12 14:14:11 +04:00
goto out ;
2013-06-12 14:08:56 +04:00
}
/* finally, parse 'dev' attribute and create corresponding dev_t */
2015-11-08 19:15:24 +03:00
if ( ! ( fp = fopen ( path , " r " ) ) ) {
2013-06-12 14:08:56 +04:00
if ( errno = = ENOENT )
2021-02-07 16:06:12 +03:00
log_debug ( " sysfs file %s does not exist. " , path ) ;
2013-06-12 14:08:56 +04:00
else
2021-02-07 16:06:12 +03:00
log_sys_debug ( " fopen " , path ) ;
2013-06-12 14:14:11 +04:00
goto out ;
2013-06-12 14:08:56 +04:00
}
if ( ! fgets ( buffer , sizeof ( buffer ) , fp ) ) {
log_sys_error ( " fgets " , path ) ;
goto out ;
}
2013-06-12 14:14:11 +04:00
if ( sscanf ( buffer , " %d:%d " , & major , & minor ) ! = 2 ) {
2021-02-07 16:06:12 +03:00
log_warn ( " WARNING: sysfs file %s not in expected MAJ:MIN format: %s " ,
2013-06-12 14:08:56 +04:00
path , buffer ) ;
goto out ;
}
2018-11-03 19:13:10 +03:00
* result = MKDEV ( major , minor ) ;
2013-06-23 13:14:34 +04:00
ret = 2 ;
2013-06-12 14:08:56 +04:00
out :
2013-06-12 14:14:11 +04:00
if ( fp & & fclose ( fp ) )
2021-02-07 16:06:12 +03:00
log_sys_debug ( " fclose " , path ) ;
2013-06-12 14:08:56 +04:00
return ret ;
}
2019-11-21 01:07:27 +03:00
# ifdef BLKID_WIPING_SUPPORT
2022-09-09 23:16:56 +03:00
int fs_block_size_and_type ( const char * pathname , uint32_t * fs_block_size_bytes , char * fstype , int * nofs )
2019-11-21 01:07:27 +03:00
{
2022-09-09 23:16:56 +03:00
blkid_probe probe = NULL ;
const char * type_str = NULL , * size_str = NULL ;
2023-04-26 15:15:21 +03:00
size_t len = 0 ;
2022-09-09 23:16:56 +03:00
int ret = 1 ;
int rc ;
if ( ! ( probe = blkid_new_probe_from_filename ( pathname ) ) ) {
log_error ( " Failed libblkid probe setup for %s " , pathname ) ;
return 0 ;
}
2019-11-21 01:07:27 +03:00
2022-09-09 23:16:56 +03:00
blkid_probe_enable_superblocks ( probe , 1 ) ;
blkid_probe_set_superblocks_flags ( probe ,
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_LABELRAW |
BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW |
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
2022-09-29 23:25:32 +03:00
# ifdef BLKID_SUBLKS_FSINFO
BLKID_SUBLKS_FSINFO |
# endif
2022-09-10 00:14:27 +03:00
BLKID_SUBLKS_MAGIC ) ;
2022-09-09 23:16:56 +03:00
rc = blkid_do_safeprobe ( probe ) ;
if ( rc < 0 ) {
log_debug ( " Failed libblkid probe for %s " , pathname ) ;
ret = 0 ;
goto out ;
} else if ( rc = = 1 ) {
/* no file system on the device */
log_debug ( " No file system found on %s. " , pathname ) ;
if ( nofs )
* nofs = 1 ;
goto out ;
}
if ( ! blkid_probe_lookup_value ( probe , " TYPE " , & type_str , & len ) & & len & & type_str ) {
if ( fstype )
strncpy ( fstype , type_str , FSTYPE_MAX ) ;
2020-06-11 20:43:07 +03:00
} else {
2022-09-09 23:16:56 +03:00
/* any difference from blkid_do_safeprobe rc=1? */
log_debug ( " No file system type on %s. " , pathname ) ;
if ( nofs )
* nofs = 1 ;
goto out ;
}
if ( fs_block_size_bytes ) {
if ( ! blkid_probe_lookup_value ( probe , " BLOCK_SIZE " , & size_str , & len ) & & len & & size_str )
* fs_block_size_bytes = atoi ( size_str ) ;
else
* fs_block_size_bytes = 0 ;
2019-11-21 01:07:27 +03:00
}
2022-09-09 23:16:56 +03:00
log_debug ( " Found blkid fstype %s fsblocksize %s on %s " ,
type_str ? : " none " , size_str ? : " unused " , pathname ) ;
out :
blkid_free_probe ( probe ) ;
return ret ;
2019-11-21 01:07:27 +03:00
}
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
int fs_get_blkid ( const char * pathname , struct fs_info * fsi )
{
blkid_probe probe = NULL ;
2023-04-26 15:15:21 +03:00
const char * str = " " ;
size_t len = 0 ;
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
uint64_t fslastblock = 0 ;
2024-09-19 13:39:46 +03:00
uint64_t fssize = 0 ;
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
unsigned int fsblocksize = 0 ;
int rc ;
if ( ! ( probe = blkid_new_probe_from_filename ( pathname ) ) ) {
log_error ( " Failed libblkid probe setup for %s " , pathname ) ;
return 0 ;
}
blkid_probe_enable_superblocks ( probe , 1 ) ;
blkid_probe_set_superblocks_flags ( probe ,
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_LABELRAW |
BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW |
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
2022-09-29 23:25:32 +03:00
# ifdef BLKID_SUBLKS_FSINFO
BLKID_SUBLKS_FSINFO |
# endif
BLKID_SUBLKS_MAGIC ) ;
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
rc = blkid_do_safeprobe ( probe ) ;
if ( rc < 0 ) {
log_error ( " Failed libblkid probe for %s " , pathname ) ;
blkid_free_probe ( probe ) ;
return 0 ;
} else if ( rc = = 1 ) {
/* no file system on the device */
2023-04-26 15:40:11 +03:00
log_print_unless_silent ( " No file system found on %s. " , pathname ) ;
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
fsi - > nofs = 1 ;
blkid_free_probe ( probe ) ;
return 1 ;
}
if ( ! blkid_probe_lookup_value ( probe , " TYPE " , & str , & len ) & & len )
strncpy ( fsi - > fstype , str , sizeof ( fsi - > fstype ) - 1 ) ;
else {
/* any difference from blkid_do_safeprobe rc=1? */
2023-04-26 15:40:11 +03:00
log_print_unless_silent ( " No file system type on %s. " , pathname ) ;
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
fsi - > nofs = 1 ;
blkid_free_probe ( probe ) ;
return 1 ;
}
if ( ! blkid_probe_lookup_value ( probe , " BLOCK_SIZE " , & str , & len ) & & len )
fsi - > fs_block_size_bytes = atoi ( str ) ;
if ( ! blkid_probe_lookup_value ( probe , " FSLASTBLOCK " , & str , & len ) & & len )
fslastblock = strtoull ( str , NULL , 0 ) ;
if ( ! blkid_probe_lookup_value ( probe , " FSBLOCKSIZE " , & str , & len ) & & len )
fsblocksize = ( unsigned int ) atoi ( str ) ;
2024-09-19 13:39:46 +03:00
if ( ! blkid_probe_lookup_value ( probe , " FSSIZE " , & str , & len ) & & len )
fssize = strtoull ( str , NULL , 0 ) ;
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
blkid_free_probe ( probe ) ;
if ( fslastblock & & fsblocksize )
fsi - > fs_last_byte = fslastblock * fsblocksize ;
2024-09-19 13:39:46 +03:00
else if ( fssize ) {
fsi - > fs_last_byte = fssize ;
/*
2024-10-25 13:47:26 +03:00
* For swap , FSLASTBLOCK is reported by blkid since v2 .41 so use that directly .
* Otherwise , we do have FSSIZE reported since v2 .39 . Then . then last block is calculated as :
2024-09-19 13:39:46 +03:00
* FSSIZE ( = = size of the usable swap area ) + FSBLOCKSIZE ( = = size of the swap header )
*/
if ( ! strcmp ( fsi - > fstype , " swap " ) )
fsi - > fs_last_byte + = fsblocksize ;
}
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
log_debug ( " libblkid TYPE %s BLOCK_SIZE %d FSLASTBLOCK %llu FSBLOCKSIZE %u fs_last_byte %llu " ,
fsi - > fstype , fsi - > fs_block_size_bytes , ( unsigned long long ) fslastblock , fsblocksize ,
( unsigned long long ) fsi - > fs_last_byte ) ;
return 1 ;
}
2019-11-21 01:07:27 +03:00
# else
2022-09-09 23:16:56 +03:00
int fs_block_size_and_type ( const char * pathname , uint32_t * fs_block_size_bytes , char * fstype , int * nofs )
2019-11-21 01:07:27 +03:00
{
2020-06-11 20:43:07 +03:00
log_debug ( " Disabled blkid BLOCK_SIZE for fs. " ) ;
2019-11-21 01:07:27 +03:00
return 0 ;
}
lvresize: add new options and defaults for fs handling
The new option "--fs String" for lvresize/lvreduce/lvextend
controls the handling of file systems before/after resizing
the LV. --resizefs is the same as --fs resize.
The new option "--fsmode String" can be used to control
mounting and unmounting of the fs during resizing.
Possible --fs values:
checksize
Only applies to reducing size; does nothing for extend.
Check the fs size and reduce the LV if the fs is not using
the affected space, i.e. the fs does not need to be shrunk.
Fail the command without reducing the fs or LV if the fs is
using the affected space.
resize
Resize the fs using the fs-specific resize command.
This may include mounting, unmounting, or running fsck.
See --fsmode to control mounting behavior, and --nofsck to
disable fsck.
resize_fsadm
Use the old method of calling fsadm to handle the fs
(deprecated.) Warning: this option does not prevent lvreduce
from destroying file systems that are unmounted (or mounted
if prompts are skipped.)
ignore
Resize the LV without checking for or handling a file system.
Warning: using ignore when reducing the LV size may destroy the
file system.
Possible --fsmode values:
manage
Mount or unmount the fs as needed to resize the fs,
and attempt to restore the original mount state at the end.
nochange
Do not mount or unmount the fs. If mounting or unmounting
is required to resize the fs, then do not resize the fs or
the LV and fail the command.
offline
Unmount the fs if it is mounted, and resize the fs while it
is unmounted. If mounting is required to resize the fs,
then do not resize the fs or the LV and fail the command.
Notes on lvreduce:
When no --fs or --resizefs option is specified:
. lvextend default behavior is fs ignore.
. lvreduce default behavior is fs checksize
(includes activating the LV.)
With the exception of --fs resize_fsadm|ignore, lvreduce requires
the recent libblkid fields FSLASTBLOCK and FSBLOCKSIZE.
FSLASTBLOCK*FSBLOCKSIZE is the last byte used by the fs on the LV,
which determines if reducing the fs is necessary.
2022-06-14 23:20:21 +03:00
int fs_get_blkid ( const char * pathname , struct fs_info * fsi )
{
log_debug ( " Disabled blkid for fs info. " ) ;
return 0 ;
}
2019-11-21 01:07:27 +03:00
# endif
2013-11-15 17:50:02 +04:00
# ifdef BLKID_WIPING_SUPPORT
2014-02-10 16:28:13 +04:00
static inline int _type_in_flag_list ( const char * type , uint32_t flag_list )
{
return ( ( ( flag_list & TYPE_LVM2_MEMBER ) & & ! strcmp ( type , " LVM2_member " ) ) | |
( ( flag_list & TYPE_LVM1_MEMBER ) & & ! strcmp ( type , " LVM1_member " ) ) | |
( ( flag_list & TYPE_DM_SNAPSHOT_COW ) & & ! strcmp ( type , " DM_snapshot_cow " ) ) ) ;
}
2015-07-21 11:34:04 +03:00
# define MSG_FAILED_SIG_OFFSET "Failed to get offset of the %s signature on %s."
# define MSG_FAILED_SIG_LENGTH "Failed to get length of the %s signature on %s."
2015-07-21 12:00:43 +03:00
# define MSG_WIPING_SKIPPED " Wiping skipped."
2015-07-21 11:34:04 +03:00
2013-11-28 16:14:46 +04:00
static int _blkid_wipe ( blkid_probe probe , struct device * dev , const char * name ,
2014-02-10 16:28:13 +04:00
uint32_t types_to_exclude , uint32_t types_no_prompt ,
int yes , force_t force )
2013-11-15 17:50:02 +04:00
{
2014-09-22 17:51:49 +04:00
static const char _msg_wiping [ ] = " Wiping %s signature on %s. " ;
2013-11-15 17:50:02 +04:00
const char * offset = NULL , * type = NULL , * magic = NULL ,
* usage = NULL , * label = NULL , * uuid = NULL ;
loff_t offset_value ;
2021-07-27 23:39:16 +03:00
size_t len = 0 ;
2013-11-15 17:50:02 +04:00
if ( ! blkid_probe_lookup_value ( probe , " TYPE " , & type , NULL ) ) {
2014-02-10 16:28:13 +04:00
if ( _type_in_flag_list ( type , types_to_exclude ) )
2015-02-19 15:20:01 +03:00
return 2 ;
2014-01-22 19:26:49 +04:00
if ( blkid_probe_lookup_value ( probe , " SBMAGIC_OFFSET " , & offset , NULL ) ) {
2015-07-21 11:34:04 +03:00
if ( force < DONT_PROMPT ) {
log_error ( MSG_FAILED_SIG_OFFSET , type , name ) ;
return 0 ;
}
2017-07-19 17:16:12 +03:00
2021-02-07 16:06:12 +03:00
log_warn ( " WARNING: " MSG_FAILED_SIG_OFFSET MSG_WIPING_SKIPPED , type , name ) ;
2017-07-19 17:16:12 +03:00
return 2 ;
2014-01-22 19:26:49 +04:00
}
if ( blkid_probe_lookup_value ( probe , " SBMAGIC " , & magic , & len ) ) {
2015-07-21 11:34:04 +03:00
if ( force < DONT_PROMPT ) {
log_error ( MSG_FAILED_SIG_LENGTH , type , name ) ;
return 0 ;
}
2017-07-19 17:16:12 +03:00
log_warn ( " WARNING: " MSG_FAILED_SIG_LENGTH MSG_WIPING_SKIPPED , type , name ) ;
return 2 ;
2014-01-22 19:26:49 +04:00
}
2013-11-15 17:50:02 +04:00
} else if ( ! blkid_probe_lookup_value ( probe , " PTTYPE " , & type , NULL ) ) {
2014-01-22 19:26:49 +04:00
if ( blkid_probe_lookup_value ( probe , " PTMAGIC_OFFSET " , & offset , NULL ) ) {
2015-07-21 11:34:04 +03:00
if ( force < DONT_PROMPT ) {
log_error ( MSG_FAILED_SIG_OFFSET , type , name ) ;
return 0 ;
}
2017-07-19 17:16:12 +03:00
log_warn ( " WARNING: " MSG_FAILED_SIG_OFFSET MSG_WIPING_SKIPPED , type , name ) ;
return 2 ;
2014-01-22 19:26:49 +04:00
}
if ( blkid_probe_lookup_value ( probe , " PTMAGIC " , & magic , & len ) ) {
2015-07-21 11:34:04 +03:00
if ( force < DONT_PROMPT ) {
log_error ( MSG_FAILED_SIG_LENGTH , type , name ) ;
return 0 ;
}
2017-07-19 17:16:12 +03:00
log_warn ( " WARNING: " MSG_FAILED_SIG_LENGTH MSG_WIPING_SKIPPED , type , name ) ;
return 2 ;
2014-01-22 19:26:49 +04:00
}
2013-11-15 17:50:02 +04:00
usage = " partition table " ;
} else
return_0 ;
offset_value = strtoll ( offset , NULL , 10 ) ;
if ( ! usage )
2014-05-07 13:22:14 +04:00
( void ) blkid_probe_lookup_value ( probe , " USAGE " , & usage , NULL ) ;
( void ) blkid_probe_lookup_value ( probe , " LABEL " , & label , NULL ) ;
( void ) blkid_probe_lookup_value ( probe , " UUID " , & uuid , NULL ) ;
/* Return values ignored here, in the worst case we print NULL */
2013-11-15 17:50:02 +04:00
log_verbose ( " Found existing signature on %s at offset %s: LABEL= \" %s \" "
" UUID= \" %s \" TYPE= \" %s \" USAGE= \" %s \" " ,
name , offset , label , uuid , type , usage ) ;
2014-02-10 16:28:13 +04:00
if ( ! _type_in_flag_list ( type , types_no_prompt ) ) {
if ( ! yes & & ( force = = PROMPT ) & &
yes_no_prompt ( " WARNING: %s signature detected on %s at offset %s. "
2014-07-03 14:15:19 +04:00
" Wipe it? [y/n]: " , type , name , offset ) = = ' n ' ) {
log_error ( " Aborted wiping of %s. " , type ) ;
return 0 ;
}
2014-02-10 00:33:36 +04:00
log_print_unless_silent ( _msg_wiping , type , name ) ;
2014-02-10 16:28:13 +04:00
} else
2014-02-10 00:33:36 +04:00
log_verbose ( _msg_wiping , type , name ) ;
2013-11-15 17:50:02 +04:00
2018-02-27 20:26:04 +03:00
if ( ! dev_write_zeros ( dev , offset_value , len ) ) {
2013-11-15 17:50:02 +04:00
log_error ( " Failed to wipe %s signature on %s. " , type , name ) ;
return 0 ;
}
return 1 ;
}
static int _wipe_known_signatures_with_blkid ( struct device * dev , const char * name ,
2014-02-10 16:28:13 +04:00
uint32_t types_to_exclude ,
uint32_t types_no_prompt ,
2015-02-17 11:46:34 +03:00
int yes , force_t force , int * wiped )
2013-11-15 17:50:02 +04:00
{
blkid_probe probe = NULL ;
2015-02-17 11:46:34 +03:00
int found = 0 , left = 0 , wiped_tmp ;
2015-02-19 15:20:01 +03:00
int r_wipe ;
2013-11-15 17:50:02 +04:00
int r = 0 ;
2015-02-17 11:46:34 +03:00
if ( ! wiped )
wiped = & wiped_tmp ;
* wiped = 0 ;
2013-11-15 17:50:02 +04:00
/* TODO: Should we check for valid dev - _dev_is_valid(dev)? */
2022-02-23 00:03:11 +03:00
if ( dm_list_empty ( & dev - > aliases ) )
goto_out ;
2013-11-15 17:50:02 +04:00
if ( ! ( probe = blkid_new_probe_from_filename ( dev_name ( dev ) ) ) ) {
log_error ( " Failed to create a new blkid probe for device %s. " , dev_name ( dev ) ) ;
goto out ;
}
blkid_probe_enable_partitions ( probe , 1 ) ;
blkid_probe_set_partitions_flags ( probe , BLKID_PARTS_MAGIC ) ;
blkid_probe_enable_superblocks ( probe , 1 ) ;
blkid_probe_set_superblocks_flags ( probe , BLKID_SUBLKS_LABEL |
BLKID_SUBLKS_UUID |
BLKID_SUBLKS_TYPE |
BLKID_SUBLKS_USAGE |
BLKID_SUBLKS_VERSION |
BLKID_SUBLKS_MAGIC |
BLKID_SUBLKS_BADCSUM ) ;
while ( ! blkid_do_probe ( probe ) ) {
2015-10-13 13:18:04 +03:00
if ( ( r_wipe = _blkid_wipe ( probe , dev , name , types_to_exclude , types_no_prompt , yes , force ) ) = = 1 ) {
2015-02-17 11:46:34 +03:00
( * wiped ) + + ;
2015-10-13 13:18:04 +03:00
if ( blkid_probe_step_back ( probe ) ) {
log_error ( " Failed to step back blkid probe to check just wiped signature. " ) ;
goto out ;
}
}
2015-02-19 15:20:01 +03:00
/* do not count excluded types */
if ( r_wipe ! = 2 )
found + + ;
2013-11-15 17:50:02 +04:00
}
if ( ! found )
r = 1 ;
2015-02-17 11:46:34 +03:00
left = found - * wiped ;
2013-11-15 17:50:02 +04:00
if ( ! left )
r = 1 ;
else
log_warn ( " %d existing signature%s left on the device. " ,
left , left > 1 ? " s " : " " ) ;
out :
if ( probe )
blkid_free_probe ( probe ) ;
return r ;
}
# endif /* BLKID_WIPING_SUPPORT */
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
static int _wipe_signature ( struct cmd_context * cmd , struct device * dev , const char * type , const char * name ,
2015-02-17 11:46:34 +03:00
int wipe_len , int yes , force_t force , int * wiped ,
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
int ( * signature_detection_fn ) ( struct cmd_context * cmd , struct device * dev , uint64_t * offset_found , int full ) )
2013-11-06 18:09:29 +04:00
{
int wipe ;
2021-03-09 17:58:48 +03:00
uint64_t offset_found = 0 ;
2013-11-06 18:09:29 +04:00
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
wipe = signature_detection_fn ( cmd , dev , & offset_found , 1 ) ;
2013-11-06 18:09:29 +04:00
if ( wipe = = - 1 ) {
log_error ( " Fatal error while trying to detect %s on %s. " ,
type , name ) ;
return 0 ;
}
if ( wipe = = 0 )
return 1 ;
/* Specifying --yes => do not ask. */
if ( ! yes & & ( force = = PROMPT ) & &
2014-07-03 14:15:19 +04:00
yes_no_prompt ( " WARNING: %s detected on %s. Wipe it? [y/n]: " ,
type , name ) = = ' n ' ) {
log_error ( " Aborted wiping of %s. " , type ) ;
return 0 ;
}
2013-11-06 18:09:29 +04:00
log_print_unless_silent ( " Wiping %s on %s. " , type , name ) ;
2018-02-27 20:26:04 +03:00
if ( ! dev_write_zeros ( dev , offset_found , wipe_len ) ) {
2013-11-06 18:09:29 +04:00
log_error ( " Failed to wipe %s on %s. " , type , name ) ;
return 0 ;
}
2015-02-17 11:46:34 +03:00
( * wiped ) + + ;
2013-11-06 18:09:29 +04:00
return 1 ;
}
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
static int _wipe_known_signatures_with_lvm ( struct cmd_context * cmd , struct device * dev , const char * name ,
2014-02-10 16:28:13 +04:00
uint32_t types_to_exclude __attribute__ ( ( unused ) ) ,
uint32_t types_no_prompt __attribute__ ( ( unused ) ) ,
2015-02-17 11:46:34 +03:00
int yes , force_t force , int * wiped )
2013-11-06 18:09:29 +04:00
{
2015-02-17 11:46:34 +03:00
int wiped_tmp ;
if ( ! wiped )
wiped = & wiped_tmp ;
* wiped = 0 ;
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
if ( ! _wipe_signature ( cmd , dev , " software RAID md superblock " , name , 4 , yes , force , wiped , dev_is_md_component ) | |
! _wipe_signature ( cmd , dev , " swap signature " , name , 10 , yes , force , wiped , dev_is_swap ) | |
! _wipe_signature ( cmd , dev , " LUKS signature " , name , 8 , yes , force , wiped , dev_is_luks ) )
2013-11-06 18:09:29 +04:00
return 0 ;
return 1 ;
}
2013-11-15 17:50:02 +04:00
int wipe_known_signatures ( struct cmd_context * cmd , struct device * dev ,
2014-02-10 16:28:13 +04:00
const char * name , uint32_t types_to_exclude ,
2015-02-17 11:46:34 +03:00
uint32_t types_no_prompt , int yes , force_t force ,
int * wiped )
2013-11-15 17:50:02 +04:00
{
2015-09-22 12:11:26 +03:00
int blkid_wiping_enabled = find_config_tree_bool ( cmd , allocation_use_blkid_wiping_CFG , NULL ) ;
2013-11-15 17:50:02 +04:00
# ifdef BLKID_WIPING_SUPPORT
2015-09-22 12:11:26 +03:00
if ( blkid_wiping_enabled )
2013-11-28 16:14:46 +04:00
return _wipe_known_signatures_with_blkid ( dev , name ,
2014-02-10 16:28:13 +04:00
types_to_exclude ,
types_no_prompt ,
2015-02-17 11:46:34 +03:00
yes , force , wiped ) ;
2013-11-15 17:50:02 +04:00
# endif
2015-09-22 12:11:26 +03:00
if ( blkid_wiping_enabled ) {
2021-02-07 16:06:12 +03:00
log_warn ( " WARNING: allocation/use_blkid_wiping=1 configuration setting is set "
2015-09-22 12:11:26 +03:00
" while LVM is not compiled with blkid wiping support. " ) ;
2021-02-07 16:06:12 +03:00
log_warn ( " WARNING: Falling back to native LVM signature detection. " ) ;
2015-09-22 12:11:26 +03:00
}
devices: rework libudev usage
related to config settings:
obtain_device_info_from_udev (controls if lvm gets
a list of devices from readdir /dev or from libudev)
external_device_info_source (controls if lvm asks
libudev for device information)
. Make the obtain_device_list_from_udev setting
affect only the choice of readdir /dev vs libudev.
The setting no longer controls if udev is used for
device type checks.
. Change obtain_device_list_from_udev default to 0.
This helps avoid boot timeouts due to slow libudev
queries, avoids reported failures from
udev_enumerate_scan_devices, and avoids delays from
"device not initialized in udev database" errors.
Even without errors, for a system booting with 1024 PVs,
lvm2-pvscan times improve from about 100 sec to 15 sec,
and the pvscan command from about 64 sec to about 4 sec.
. For external_device_info_source="none", remove all
libudev device info queries, and use only lvm
native device info.
. For external_device_info_source="udev", first check
lvm native device info, then check libudev info.
. Remove sleep/retry loop when attempting libudev
queries for device info. udev info will simply
be skipped if it's not immediately available.
. Only set up a libdev connection if it will be used by
obtain_device_list_from_udev/external_device_info_source.
. For native multipath component detection, use
/etc/multipath/wwids. If a device has a wwid
matching an entry in the wwids file, then it's
considered a multipath component. This is
necessary to natively detect multipath
components when the mpath device is not set up.
2021-06-09 01:12:09 +03:00
return _wipe_known_signatures_with_lvm ( cmd , dev , name ,
2014-02-10 16:28:13 +04:00
types_to_exclude ,
types_no_prompt ,
2015-02-17 11:46:34 +03:00
yes , force , wiped ) ;
2013-11-15 17:50:02 +04:00
}
2013-11-13 17:56:29 +04:00
# ifdef __linux__
2009-08-01 21:07:36 +04:00
2013-11-22 15:57:35 +04:00
static int _snprintf_attr ( char * buf , size_t buf_size , const char * sysfs_dir ,
const char * attribute , dev_t dev )
{
2024-05-28 17:17:53 +03:00
if ( dm_snprintf ( buf , buf_size , " %sdev/block/%u:%u/%s " , sysfs_dir ,
MAJOR ( dev ) , MINOR ( dev ) , attribute ) < 0 ) {
2021-02-07 16:06:12 +03:00
log_warn ( " WARNING: sysfs path for %s attribute is too long. " , attribute ) ;
2013-11-22 15:57:35 +04:00
return 0 ;
}
return 1 ;
}
2021-02-09 02:43:13 +03:00
static int _dev_sysfs_block_attribute ( struct dev_types * dt ,
const char * attribute ,
struct device * dev ,
unsigned long * value )
2009-08-01 21:07:36 +04:00
{
2013-06-12 13:38:48 +04:00
const char * sysfs_dir = dm_sysfs_dir ( ) ;
2013-11-22 15:57:35 +04:00
char path [ PATH_MAX ] , buffer [ 64 ] ;
2009-08-01 21:07:36 +04:00
FILE * fp ;
2021-02-07 16:07:17 +03:00
dev_t primary = 0 ;
2021-02-09 02:43:13 +03:00
int ret = 0 ;
2009-08-01 21:07:36 +04:00
if ( ! attribute | | ! * attribute )
2014-09-16 03:44:25 +04:00
goto_out ;
2009-08-01 21:07:36 +04:00
if ( ! sysfs_dir | | ! * sysfs_dir )
2014-09-16 03:44:25 +04:00
goto_out ;
2009-08-01 21:07:36 +04:00
2013-11-22 15:57:35 +04:00
if ( ! _snprintf_attr ( path , sizeof ( path ) , sysfs_dir , attribute , dev - > dev ) )
2021-02-09 02:43:13 +03:00
goto_out ;
2009-08-01 21:07:36 +04:00
2009-08-01 21:08:43 +04:00
/*
* check if the desired sysfs attribute exists
* - if not : either the kernel doesn ' t have topology support
* or the device could be a partition
*/
2021-02-07 16:07:17 +03:00
if ( ! ( fp = fopen ( path , " r " ) ) ) {
2009-08-01 21:14:52 +04:00
if ( errno ! = ENOENT ) {
2021-02-07 16:07:17 +03:00
log_sys_debug ( " fopen " , path ) ;
2014-09-16 03:44:25 +04:00
goto out ;
2009-08-01 21:14:52 +04:00
}
2013-06-12 16:33:28 +04:00
if ( ! dev_get_primary_dev ( dt , dev , & primary ) )
2014-09-16 03:44:25 +04:00
goto out ;
2009-08-01 21:08:43 +04:00
/* get attribute from partition's primary device */
2013-11-22 15:57:35 +04:00
if ( ! _snprintf_attr ( path , sizeof ( path ) , sysfs_dir , attribute , primary ) )
2014-09-16 03:44:25 +04:00
goto_out ;
2013-11-22 15:57:35 +04:00
2021-02-07 16:07:17 +03:00
if ( ! ( fp = fopen ( path , " r " ) ) ) {
2009-08-01 21:14:52 +04:00
if ( errno ! = ENOENT )
2021-02-07 16:07:17 +03:00
log_sys_debug ( " fopen " , path ) ;
2014-09-16 03:44:25 +04:00
goto out ;
2009-08-01 21:14:52 +04:00
}
2009-08-01 21:08:43 +04:00
}
2009-08-01 21:07:36 +04:00
if ( ! fgets ( buffer , sizeof ( buffer ) , fp ) ) {
2014-07-03 14:03:16 +04:00
log_sys_debug ( " fgets " , path ) ;
2014-09-16 03:44:25 +04:00
goto out_close ;
2009-08-01 21:07:36 +04:00
}
2021-02-09 02:43:13 +03:00
if ( sscanf ( buffer , " %lu " , value ) ! = 1 ) {
2021-02-07 16:07:17 +03:00
log_warn ( " WARNING: sysfs file %s not in expected format: %s " , path , buffer ) ;
2014-09-16 03:44:25 +04:00
goto out_close ;
2009-08-01 21:07:36 +04:00
}
2021-02-09 02:43:13 +03:00
ret = 1 ;
2016-03-03 22:53:08 +03:00
2014-09-16 03:44:25 +04:00
out_close :
2009-08-01 21:07:36 +04:00
if ( fclose ( fp ) )
2014-07-03 14:03:16 +04:00
log_sys_debug ( " fclose " , path ) ;
2009-08-01 21:07:36 +04:00
2014-09-16 03:44:25 +04:00
out :
2021-02-09 02:43:13 +03:00
return ret ;
}
static unsigned long _dev_topology_attribute ( struct dev_types * dt ,
const char * attribute ,
struct device * dev ,
unsigned long default_value )
{
unsigned long result = default_value ;
unsigned long value = 0UL ;
if ( _dev_sysfs_block_attribute ( dt , attribute , dev , & value ) ) {
log_very_verbose ( " Device %s: %s is %lu%s. " ,
dev_name ( dev ) , attribute , value , default_value ? " " : " bytes " ) ;
result = value > > SECTOR_SHIFT ;
if ( ! result & & value ) {
log_warn ( " WARNING: Device %s: %s is %lu and is unexpectedly less than sector. " ,
dev_name ( dev ) , attribute , value ) ;
result = 1 ;
}
}
2014-09-16 03:44:25 +04:00
return result ;
2009-08-01 21:07:36 +04:00
}
2013-06-12 14:08:56 +04:00
unsigned long dev_alignment_offset ( struct dev_types * dt , struct device * dev )
2009-08-01 21:07:36 +04:00
{
2014-09-16 03:44:25 +04:00
return _dev_topology_attribute ( dt , " alignment_offset " , dev , 0UL ) ;
2009-08-01 21:07:36 +04:00
}
2013-06-12 14:08:56 +04:00
unsigned long dev_minimum_io_size ( struct dev_types * dt , struct device * dev )
2009-08-01 21:08:43 +04:00
{
2014-09-16 03:44:25 +04:00
return _dev_topology_attribute ( dt , " queue/minimum_io_size " , dev , 0UL ) ;
2009-08-01 21:08:43 +04:00
}
2013-06-12 14:08:56 +04:00
unsigned long dev_optimal_io_size ( struct dev_types * dt , struct device * dev )
2009-08-01 21:08:43 +04:00
{
2014-09-16 03:44:25 +04:00
return _dev_topology_attribute ( dt , " queue/optimal_io_size " , dev , 0UL ) ;
2009-08-01 21:08:43 +04:00
}
2013-06-12 14:08:56 +04:00
unsigned long dev_discard_max_bytes ( struct dev_types * dt , struct device * dev )
2011-04-13 01:59:01 +04:00
{
2014-09-16 03:44:25 +04:00
return _dev_topology_attribute ( dt , " queue/discard_max_bytes " , dev , 0UL ) ;
2011-04-13 01:59:01 +04:00
}
2013-06-12 14:08:56 +04:00
unsigned long dev_discard_granularity ( struct dev_types * dt , struct device * dev )
2011-04-13 01:59:01 +04:00
{
2014-09-16 03:44:25 +04:00
return _dev_topology_attribute ( dt , " queue/discard_granularity " , dev , 0UL ) ;
2011-04-13 01:59:01 +04:00
}
2014-09-16 03:44:25 +04:00
int dev_is_rotational ( struct dev_types * dt , struct device * dev )
{
2021-02-09 02:43:13 +03:00
unsigned long value ;
return _dev_sysfs_block_attribute ( dt , " queue/rotational " , dev , & value ) ? ( int ) value : 1 ;
2014-09-16 03:44:25 +04:00
}
2021-02-07 17:03:13 +03:00
/* dev is pmem if /sys/dev/block/<major>:<minor>/queue/dax is 1 */
int dev_is_pmem ( struct dev_types * dt , struct device * dev )
{
2021-02-09 02:43:13 +03:00
unsigned long value ;
return _dev_sysfs_block_attribute ( dt , " queue/dax " , dev , & value ) ? ( int ) value : 0 ;
2021-02-07 17:03:13 +03:00
}
2009-08-01 21:07:36 +04:00
# else
2013-06-17 17:17:15 +04:00
int dev_get_primary_dev ( struct dev_types * dt , struct device * dev , dev_t * result )
2009-08-01 21:11:02 +04:00
{
return 0 ;
}
2013-06-12 14:08:56 +04:00
unsigned long dev_alignment_offset ( struct dev_types * dt , struct device * dev )
2009-08-01 21:07:36 +04:00
{
return 0UL ;
}
2013-06-12 14:08:56 +04:00
unsigned long dev_minimum_io_size ( struct dev_types * dt , struct device * dev )
2009-08-01 21:08:43 +04:00
{
return 0UL ;
}
2013-06-12 14:08:56 +04:00
unsigned long dev_optimal_io_size ( struct dev_types * dt , struct device * dev )
2009-08-01 21:08:43 +04:00
{
return 0UL ;
}
2013-06-12 14:08:56 +04:00
unsigned long dev_discard_max_bytes ( struct dev_types * dt , struct device * dev )
2011-04-13 01:59:01 +04:00
{
return 0UL ;
}
2013-06-12 14:08:56 +04:00
unsigned long dev_discard_granularity ( struct dev_types * dt , struct device * dev )
2011-04-13 01:59:01 +04:00
{
return 0UL ;
}
2014-09-16 03:44:25 +04:00
int dev_is_rotational ( struct dev_types * dt , struct device * dev )
{
return 1 ;
}
2021-02-07 17:03:13 +03:00
int dev_is_pmem ( struct dev_types * dt , struct device * dev )
{
return 0 ;
}
2009-08-01 21:07:36 +04:00
# endif
2016-09-05 13:13:10 +03:00