2013-06-12 14:08:56 +04:00
/*
* Copyright ( C ) 2013 Red Hat , Inc . All rights reserved .
*
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v .2 .1 .
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2013-06-12 14:08:56 +04:00
*/
# ifndef _LVM_DEV_TYPE_H
# define _LVM_DEV_TYPE_H
2018-05-14 12:30:20 +03:00
# include "lib/device/device.h"
# include "lib/display/display.h"
# include "lib/label/label.h"
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
# include "lib/device/filesystem.h"
2013-06-12 14:08:56 +04:00
# define NUMBER_OF_MAJORS 4096
2013-11-13 17:56:29 +04:00
# ifdef __linux__
2018-05-14 12:30:20 +03:00
# include "libdm / misc / kdev_t.h"
2013-06-12 14:08:56 +04:00
# else
# define MAJOR(x) major((x))
# define MINOR(x) minor((x))
# define MKDEV(x,y) makedev((x),(y))
# endif
# define PARTITION_SCSI_DEVICE (1 << 0)
struct dev_type_def {
int max_partitions ; /* 0 means LVM won't use this major number. */
int flags ;
} ;
struct dev_types {
2023-07-13 13:32:44 +03:00
unsigned md_major ;
unsigned blkext_major ;
unsigned drbd_major ;
unsigned device_mapper_major ;
unsigned emcpower_major ;
unsigned vxdmp_major ;
unsigned power2_major ;
unsigned dasd_major ;
unsigned loop_major ;
2013-06-12 14:08:56 +04:00
struct dev_type_def dev_type_array [ NUMBER_OF_MAJORS ] ;
} ;
struct dev_types * create_dev_types ( const char * proc_dir , const struct dm_config_node * cn ) ;
/* Subsystems */
int dev_subsystem_part_major ( struct dev_types * dt , struct device * dev ) ;
const char * dev_subsystem_name ( struct dev_types * dt , struct device * dev ) ;
int major_is_scsi_device ( struct dev_types * dt , int major ) ;
/* Signature/superblock recognition with position returned where found. */
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_md_component ( struct cmd_context * cmd , struct device * dev , uint64_t * sb , int full ) ;
2022-03-30 01:18:45 +03:00
int dev_is_mpath_component ( struct cmd_context * cmd , struct device * dev , dev_t * mpath_devno ) ;
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_swap ( struct cmd_context * cmd , struct device * dev , uint64_t * signature , int full ) ;
int dev_is_luks ( struct cmd_context * cmd , struct device * dev , uint64_t * signature , int full ) ;
2015-10-12 10:09:11 +03:00
int dasd_is_cdl_formatted ( struct device * dev ) ;
2013-06-12 14:08:56 +04:00
2021-11-18 02:10:45 +03:00
const char * dev_mpath_component_wwid ( struct cmd_context * cmd , struct device * dev ) ;
2018-05-01 22:32:15 +03:00
int dev_is_lvm1 ( struct device * dev , char * buf , int buflen ) ;
int dev_is_pool ( struct device * dev , char * buf , int buflen ) ;
2013-11-06 18:09:29 +04:00
/* Signature wiping. */
2014-02-10 16:28:13 +04:00
# define TYPE_LVM1_MEMBER 0x001
# define TYPE_LVM2_MEMBER 0x002
# define TYPE_DM_SNAPSHOT_COW 0x004
2013-11-28 16:14:46 +04:00
int wipe_known_signatures ( struct cmd_context * cmd , 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-06 18:09:29 +04:00
2013-06-12 14:08:56 +04:00
/* Type-specific device properties */
unsigned long dev_md_stripe_width ( struct dev_types * dt , struct device * dev ) ;
2018-06-15 19:42:10 +03:00
int dev_is_md_with_end_superblock ( struct dev_types * dt , struct device * dev ) ;
2013-06-12 14:08:56 +04:00
/* Partitioning */
int major_max_partitions ( struct dev_types * dt , int major ) ;
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 ) ;
2013-06-12 14:08:56 +04:00
int dev_get_primary_dev ( struct dev_types * dt , struct device * dev , dev_t * result ) ;
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 ) ;
2013-06-12 14:08:56 +04:00
/* Various device properties */
unsigned long dev_alignment_offset ( struct dev_types * dt , struct device * dev ) ;
unsigned long dev_minimum_io_size ( struct dev_types * dt , struct device * dev ) ;
unsigned long dev_optimal_io_size ( struct dev_types * dt , struct device * dev ) ;
unsigned long dev_discard_max_bytes ( struct dev_types * dt , struct device * dev ) ;
unsigned long dev_discard_granularity ( struct dev_types * dt , struct device * dev ) ;
2014-09-16 03:44:25 +04:00
int dev_is_rotational ( struct dev_types * dt , struct device * dev ) ;
2021-02-07 17:03:13 +03:00
int dev_is_pmem ( struct dev_types * dt , struct device * dev ) ;
2018-08-27 22:53:09 +03:00
2024-12-07 00:02:20 +03:00
int dev_is_nvme ( struct device * dev ) ;
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
2022-09-09 23:16:56 +03:00
# define FSTYPE_MAX 16
int fs_block_size_and_type ( const char * pathname , uint32_t * fs_block_size_bytes , char * fstype , int * nofs ) ;
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 ) ;
2019-11-21 01:07:27 +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 ) ;
2013-06-12 14:08:56 +04:00
# endif