mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-05 13:18:20 +03:00
ef96186add
The devices file /etc/lvm/devices/system.devices is a list of devices that lvm can use. This is the default system devices file, which is specified in lvm.conf devices/devicesfile. The command option --devicesfile <filename> allows lvm to be used with a different set of devices. This allows different applications to use lvm on different sets of devices, e.g. system devices do not need to be exposed to an application using lvm on its own devices, and application devices do not need to be exposed to the system. In most cases (with limited exceptions), lvm will not read or use a device not listed in the devices file. When the devices file is used, the regex filter is not used, and the filter settings in lvm.conf are ignored. filter-deviceid is used when the devices file is enabled, and rejects any device that does not match an entry in the devices file. Set use_devicesfile=0 in lvm.conf or set --devicesfile "" on the command line to disable the use of a devices file. When disabled, lvm will see and use any device on the system that passes the regex filter (and other standard filters.) A device ID, e.g. wwid or serial number from sysfs, is a unique ID that identifies a device. The device ID is generally independent of the device content, and lvm can get the device ID without reading the device. The device ID is used in the devices file as the primary method of identifying device entries, and is also included in VG metadata for PVs. Each device_id has a device_id_type which indicates where the device_id comes from, e.g. "sys_wwid" means the device_id comes from the sysfs wwid file. Others are sys_serial, mpath_uuid, loop_file, md_uuid, devname. (devname is the device path, which is a fallback when no other proper device_id_type is available.) filter-deviceid permits lvm to use only devices on the system that have a device_id matching a devices file entry. Using the device_id, lvm can determine the set of devices to use without reading any devices, so the devices file will constrain lvm in two ways: 1. it limits the devices that lvm will read. 2. it limits the devices that lvm will use. In some uncommon cases, e.g. when devices have no unique ID and device_id has to fall back to using the devname, lvm may need to read all devices on the system to determine which ones correspond to the devices file entries. In this case, the devices file does not limit the devices that lvm reads, but it does limit the devices that lvm uses. pvcreate/vgcreate/vgextend are not constrained by the devices file, and will look outside it to find the new PV. They assign the new PV a device_id and add it to the devices file. It is also possible to explicitly add new PVs to the devices file before using them in pvcreate/etc, in which case these commands would not need to look outside the devices file for the new device. vgimportdevices VG looks at all devices on the system to find an existing VG and add its devices to the devices file. The command is not limited by an existing devices file. The command will also add device_ids to the VG metadata if the VG does not yet include device_ids. vgimportdevices -a imports devices for all accessible VGs. Since vgimportdevices does not limit itself to devices in an existing devices file, the lvm.conf regex filter applies. Adding --foreign will import devices for foreign VGs, but device_ids are not added to foreign VGs. Incomplete VGs are not imported. The lvmdevices command manages the devices file. The primary purpose is to edit the devices file, but it will read PV headers to find/check PVIDs. (It does not read, process or modify VG metadata.) lvmdevices . Displays devices file entries. lvmdevices --check . Checks devices file entries. lvmdevices --update . Updates devices file entries. lvmdevices --adddev <devname> . Adds devices_file entry (reads pv header). lvmdevices --deldev <devname> . Removes devices file entry. lvmdevices --addpvid <pvid> . Reads pv header of all devices to find <pvid>, and if found adds devices file entry. lvmdevices --delpvid <pvid> . Removes devices file entry. The vgimportclone command has a new option --importdevices that does the equivalent of vgimportdevices with the cloned devices that are being imported. The devices are "uncloned" (new vgname and pvids) while at the same time adding the devices to the devices file. This allows cloned PVs to be imported without duplicate PVs ever appearing on the system. The command option --devices <devnames> allows a specific list of devices to be exposed to the lvm command, overriding the devices file.
200 lines
6.4 KiB
C
200 lines
6.4 KiB
C
/*
|
|
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
|
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
|
|
*
|
|
* This file is part of LVM2.
|
|
*
|
|
* This copyrighted material is made available to anyone wishing to use,
|
|
* modify, copy, or redistribute it subject to the terms and conditions
|
|
* of the GNU Lesser General Public License v.2.1.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef _LVM_DEVICE_H
|
|
#define _LVM_DEVICE_H
|
|
|
|
#include "lib/uuid/uuid.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
#define DEV_REGULAR 0x00000002 /* Regular file? */
|
|
#define DEV_ALLOCED 0x00000004 /* malloc used */
|
|
#define DEV_OPENED_RW 0x00000008 /* Opened RW */
|
|
#define DEV_OPENED_EXCL 0x00000010 /* Opened EXCL */
|
|
#define DEV_O_DIRECT 0x00000020 /* Use O_DIRECT */
|
|
#define DEV_O_DIRECT_TESTED 0x00000040 /* DEV_O_DIRECT is reliable */
|
|
#define DEV_OPEN_FAILURE 0x00000080 /* Has last open failed? */
|
|
#define DEV_USED_FOR_LV 0x00000100 /* Is device used for an LV */
|
|
#define DEV_ASSUMED_FOR_LV 0x00000200 /* Is device assumed for an LV */
|
|
#define DEV_NOT_O_NOATIME 0x00000400 /* Don't use O_NOATIME */
|
|
#define DEV_IN_BCACHE 0x00000800 /* dev fd is open and used in bcache */
|
|
#define DEV_BCACHE_EXCL 0x00001000 /* bcache_fd should be open EXCL */
|
|
#define DEV_FILTER_AFTER_SCAN 0x00002000 /* apply filter after bcache has data */
|
|
#define DEV_FILTER_OUT_SCAN 0x00004000 /* filtered out during label scan */
|
|
#define DEV_BCACHE_WRITE 0x00008000 /* bcache_fd is open with RDWR */
|
|
#define DEV_SCAN_FOUND_LABEL 0x00010000 /* label scan read dev and found label */
|
|
#define DEV_IS_MD_COMPONENT 0x00020000 /* device is an md component */
|
|
#define DEV_UDEV_INFO_MISSING 0x00040000 /* we have no udev info for this device */
|
|
#define DEV_IS_NVME 0x00080000 /* set if dev is nvme */
|
|
#define DEV_MATCHED_USE_ID 0x00100000 /* matched an entry from cmd->use_devices */
|
|
|
|
/*
|
|
* Support for external device info.
|
|
* Any new external device info source needs to be
|
|
* registered using EXT_REGISTER macro in dev-ext.c.
|
|
*/
|
|
typedef enum dev_ext_e {
|
|
DEV_EXT_NONE,
|
|
DEV_EXT_UDEV,
|
|
DEV_EXT_NUM
|
|
} dev_ext_t;
|
|
|
|
struct dev_ext {
|
|
int enabled;
|
|
dev_ext_t src;
|
|
void *handle;
|
|
};
|
|
|
|
#define DEV_ID_TYPE_SYS_WWID 0x0001
|
|
#define DEV_ID_TYPE_SYS_SERIAL 0x0002
|
|
#define DEV_ID_TYPE_MPATH_UUID 0x0003
|
|
#define DEV_ID_TYPE_MD_UUID 0x0004
|
|
#define DEV_ID_TYPE_LOOP_FILE 0x0005
|
|
#define DEV_ID_TYPE_CRYPT_UUID 0x0006
|
|
#define DEV_ID_TYPE_LVMLV_UUID 0x0007
|
|
#define DEV_ID_TYPE_DEVNAME 0x0008
|
|
|
|
/* A device ID of a certain type for a device. */
|
|
|
|
struct dev_id {
|
|
struct dm_list list;
|
|
struct device *dev;
|
|
uint16_t idtype;
|
|
char *idname;
|
|
};
|
|
|
|
/* A device listed in devices file that lvm should use. */
|
|
|
|
struct dev_use {
|
|
struct dm_list list;
|
|
struct device *dev;
|
|
int part;
|
|
uint16_t idtype;
|
|
char *idname;
|
|
char *devname;
|
|
char *pvid;
|
|
};
|
|
|
|
/*
|
|
* All devices in LVM will be represented by one of these.
|
|
* pointer comparisons are valid.
|
|
*/
|
|
struct device {
|
|
struct dm_list aliases; /* struct dm_str_list */
|
|
struct dm_list ids; /* struct dev_id, different entries for different idtypes */
|
|
struct dev_id *id; /* points to the the ids entry being used for this dev */
|
|
dev_t dev;
|
|
|
|
/* private */
|
|
int fd;
|
|
int open_count;
|
|
int physical_block_size; /* From BLKPBSZGET: lowest possible sector size that the hardware can operate on without reverting to read-modify-write operations */
|
|
int logical_block_size; /* From BLKSSZGET: lowest possible block size that the storage device can address */
|
|
int read_ahead;
|
|
int bcache_fd;
|
|
int bcache_di;
|
|
int part; /* partition number */
|
|
uint32_t flags;
|
|
uint32_t filtered_flags;
|
|
unsigned size_seqno;
|
|
uint64_t size;
|
|
uint64_t end;
|
|
struct dev_ext ext;
|
|
const char *duplicate_prefer_reason;
|
|
|
|
const char *vgid; /* if device is an LV */
|
|
const char *lvid; /* if device is an LV */
|
|
|
|
char pvid[ID_LEN + 1]; /* if device is a PV */
|
|
char _padding[7];
|
|
};
|
|
|
|
/*
|
|
* All I/O is annotated with the reason it is performed.
|
|
*/
|
|
typedef enum dev_io_reason {
|
|
DEV_IO_SIGNATURES = 0, /* Scanning device signatures */
|
|
DEV_IO_LABEL, /* LVM PV disk label */
|
|
DEV_IO_MDA_HEADER, /* Text format metadata area header */
|
|
DEV_IO_MDA_CONTENT, /* Text format metadata area content */
|
|
DEV_IO_MDA_EXTRA_HEADER, /* Header of any extra metadata areas on device */
|
|
DEV_IO_MDA_EXTRA_CONTENT, /* Content of any extra metadata areas on device */
|
|
DEV_IO_FMT1, /* Original LVM1 metadata format */
|
|
DEV_IO_POOL, /* Pool metadata format */
|
|
DEV_IO_LV, /* Content written to an LV */
|
|
DEV_IO_LOG /* Logging messages */
|
|
} dev_io_reason_t;
|
|
|
|
struct device_list {
|
|
struct dm_list list;
|
|
struct device *dev;
|
|
};
|
|
|
|
struct device_area {
|
|
struct device *dev;
|
|
uint64_t start; /* Bytes */
|
|
uint64_t size; /* Bytes */
|
|
};
|
|
|
|
/*
|
|
* Support for external device info.
|
|
*/
|
|
const char *dev_ext_name(struct device *dev);
|
|
int dev_ext_enable(struct device *dev, dev_ext_t src);
|
|
int dev_ext_disable(struct device *dev);
|
|
struct dev_ext *dev_ext_get(struct device *dev);
|
|
int dev_ext_release(struct device *dev);
|
|
|
|
/*
|
|
* Increment current dev_size_seqno.
|
|
* This is used to control lifetime
|
|
* of cached device size.
|
|
*/
|
|
void dev_size_seqno_inc(void);
|
|
|
|
/*
|
|
* All io should use these routines.
|
|
*/
|
|
int dev_get_direct_block_sizes(struct device *dev, unsigned int *physical_block_size,
|
|
unsigned int *logical_block_size);
|
|
int dev_get_size(struct device *dev, uint64_t *size);
|
|
int dev_get_read_ahead(struct device *dev, uint32_t *read_ahead);
|
|
int dev_discard_blocks(struct device *dev, uint64_t offset_bytes, uint64_t size_bytes);
|
|
|
|
/* Use quiet version if device number could change e.g. when opening LV */
|
|
int dev_open(struct device *dev);
|
|
int dev_open_quiet(struct device *dev);
|
|
int dev_open_flags(struct device *dev, int flags, int direct, int quiet);
|
|
int dev_open_readonly(struct device *dev);
|
|
int dev_open_readonly_buffered(struct device *dev);
|
|
int dev_open_readonly_quiet(struct device *dev);
|
|
int dev_close(struct device *dev);
|
|
int dev_close_immediate(struct device *dev);
|
|
|
|
int dev_fd(struct device *dev);
|
|
const char *dev_name(const struct device *dev);
|
|
|
|
void dev_flush(struct device *dev);
|
|
|
|
struct device *dev_create_file(const char *filename, struct device *dev,
|
|
struct dm_str_list *alias, int use_malloc);
|
|
void dev_destroy_file(struct device *dev);
|
|
|
|
/* Return a valid device name from the alias list; NULL otherwise */
|
|
const char *dev_name_confirmed(struct device *dev, int quiet);
|
|
|
|
#endif
|