mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +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.
153 lines
3.7 KiB
C
153 lines
3.7 KiB
C
/*
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
*
|
|
* 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
|
|
*/
|
|
|
|
#include "lvmpolld-common.h"
|
|
|
|
/* extract this info from autoconf/automake files */
|
|
#define LVPOLL_CMD "lvpoll"
|
|
|
|
#define MIN_ARGV_SIZE 8
|
|
|
|
static const char *const polling_ops[] = {
|
|
[PVMOVE] = LVMPD_REQ_PVMOVE,
|
|
[CONVERT] = LVMPD_REQ_CONVERT,
|
|
[MERGE] = LVMPD_REQ_MERGE,
|
|
[MERGE_THIN] = LVMPD_REQ_MERGE_THIN
|
|
};
|
|
|
|
const char *polling_op(enum poll_type type)
|
|
{
|
|
return type < POLL_TYPE_MAX ? polling_ops[type] : "<undefined>";
|
|
}
|
|
|
|
static int add_to_cmd_arr(const char ***cmdargv, const char *str, unsigned *ind)
|
|
{
|
|
const char **newargv;
|
|
|
|
if (*ind && !(*ind % MIN_ARGV_SIZE)) {
|
|
newargv = realloc(*cmdargv, (*ind / MIN_ARGV_SIZE + 1) * MIN_ARGV_SIZE * sizeof(char *));
|
|
if (!newargv)
|
|
return 0;
|
|
*cmdargv = newargv;
|
|
}
|
|
|
|
*(*cmdargv + (*ind)++) = str;
|
|
|
|
return 1;
|
|
}
|
|
|
|
const char **cmdargv_ctr(const struct lvmpolld_lv *pdlv, const char *lvm_binary, unsigned abort_polling, unsigned handle_missing_pvs)
|
|
{
|
|
unsigned i = 0;
|
|
const char **cmd_argv = malloc(MIN_ARGV_SIZE * sizeof(char *));
|
|
|
|
if (!cmd_argv)
|
|
return NULL;
|
|
|
|
/* path to lvm2 binary */
|
|
if (!add_to_cmd_arr(&cmd_argv, lvm_binary, &i))
|
|
goto err;
|
|
|
|
/* cmd to execute */
|
|
if (!add_to_cmd_arr(&cmd_argv, LVPOLL_CMD, &i))
|
|
goto err;
|
|
|
|
/* transfer internal polling interval */
|
|
if (pdlv->sinterval &&
|
|
(!add_to_cmd_arr(&cmd_argv, "--interval", &i) ||
|
|
!add_to_cmd_arr(&cmd_argv, pdlv->sinterval, &i)))
|
|
goto err;
|
|
|
|
/* pass abort param */
|
|
if (abort_polling &&
|
|
!add_to_cmd_arr(&cmd_argv, "--abort", &i))
|
|
goto err;
|
|
|
|
/* pass handle-missing-pvs. used by mirror polling operation */
|
|
if (handle_missing_pvs &&
|
|
!add_to_cmd_arr(&cmd_argv, "--handlemissingpvs", &i))
|
|
goto err;
|
|
|
|
/* one of: "convert", "pvmove", "merge", "merge_thin" */
|
|
if (!add_to_cmd_arr(&cmd_argv, "--polloperation", &i) ||
|
|
!add_to_cmd_arr(&cmd_argv, polling_ops[pdlv->type], &i))
|
|
goto err;
|
|
|
|
/* vg/lv name */
|
|
if (!add_to_cmd_arr(&cmd_argv, pdlv->lvname, &i))
|
|
goto err;
|
|
|
|
/* disable metadata backup */
|
|
if (!add_to_cmd_arr(&cmd_argv, "-An", &i))
|
|
goto err;
|
|
|
|
if (pdlv->devicesfile) {
|
|
if (!add_to_cmd_arr(&cmd_argv, "--devicesfile", &i) ||
|
|
!add_to_cmd_arr(&cmd_argv, pdlv->devicesfile, &i))
|
|
goto err;
|
|
}
|
|
|
|
/* terminating NULL */
|
|
if (!add_to_cmd_arr(&cmd_argv, NULL, &i))
|
|
goto err;
|
|
|
|
return cmd_argv;
|
|
err:
|
|
free(cmd_argv);
|
|
return NULL;
|
|
}
|
|
|
|
/* FIXME: in fact exclude should be va list */
|
|
static int copy_env(const char ***cmd_envp, unsigned *i, const char *exclude)
|
|
{
|
|
const char * const* tmp = (const char * const*) environ;
|
|
|
|
if (!tmp)
|
|
return 0;
|
|
|
|
while (*tmp) {
|
|
if (strncmp(*tmp, exclude, strlen(exclude)) && !add_to_cmd_arr(cmd_envp, *tmp, i))
|
|
return 0;
|
|
tmp++;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
const char **cmdenvp_ctr(const struct lvmpolld_lv *pdlv)
|
|
{
|
|
unsigned i = 0;
|
|
const char **cmd_envp = malloc(MIN_ARGV_SIZE * sizeof(char *));
|
|
|
|
if (!cmd_envp)
|
|
return NULL;
|
|
|
|
/* copy whole environment from lvmpolld, exclude LVM_SYSTEM_DIR if set */
|
|
if (!copy_env(&cmd_envp, &i, "LVM_SYSTEM_DIR="))
|
|
goto err;
|
|
|
|
/* Add per client LVM_SYSTEM_DIR variable if set */
|
|
if (*pdlv->lvm_system_dir_env && !add_to_cmd_arr(&cmd_envp, pdlv->lvm_system_dir_env, &i))
|
|
goto err;
|
|
|
|
/* terminating NULL */
|
|
if (!add_to_cmd_arr(&cmd_envp, NULL, &i))
|
|
goto err;
|
|
|
|
return cmd_envp;
|
|
err:
|
|
free(cmd_envp);
|
|
return NULL;
|
|
}
|