mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
83fe6e720f
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
218 lines
5.6 KiB
C
218 lines
5.6 KiB
C
/*
|
|
* Copyright (C) 2014-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
|
|
*/
|
|
|
|
#ifndef _LVM_LVMPOLLD_DATA_UTILS_H
|
|
#define _LVM_LVMPOLLD_DATA_UTILS_H
|
|
|
|
#include <pthread.h>
|
|
|
|
struct buffer;
|
|
struct lvmpolld_state;
|
|
|
|
enum poll_type {
|
|
PVMOVE = 0,
|
|
CONVERT,
|
|
MERGE,
|
|
MERGE_THIN,
|
|
POLL_TYPE_MAX
|
|
};
|
|
|
|
struct lvmpolld_cmd_stat {
|
|
int retcode;
|
|
int signal;
|
|
};
|
|
|
|
struct lvmpolld_store {
|
|
pthread_mutex_t lock;
|
|
void *store;
|
|
const char *name;
|
|
unsigned active_polling_count;
|
|
};
|
|
|
|
struct lvmpolld_lv {
|
|
/*
|
|
* accessing following vars doesn't
|
|
* require struct lvmpolld_lv lock
|
|
*/
|
|
struct lvmpolld_state *const ls;
|
|
const enum poll_type type;
|
|
const char *const lvid;
|
|
const char *const lvmpolld_id;
|
|
const char *const devicesfile;
|
|
const char *const lvname; /* full vg/lv name */
|
|
const unsigned pdtimeout; /* in seconds */
|
|
const char *const sinterval;
|
|
const char *const lvm_system_dir_env;
|
|
struct lvmpolld_store *const pdst;
|
|
const char *const *cmdargv;
|
|
const char *const *cmdenvp;
|
|
|
|
/* only used by write */
|
|
pid_t cmd_pid;
|
|
pthread_t tid;
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
/* block of shared variables protected by lock */
|
|
struct lvmpolld_cmd_stat cmd_state;
|
|
unsigned init_rq_count; /* for debuging purposes only */
|
|
unsigned polling_finished:1; /* no more updates */
|
|
unsigned error:1; /* unrecoverable error occured in lvmpolld */
|
|
};
|
|
|
|
typedef void (*lvmpolld_parse_output_fn_t) (struct lvmpolld_lv *pdlv, const char *line);
|
|
|
|
/* TODO: replace with configuration option */
|
|
#define MIN_POLLING_TIMEOUT 60
|
|
|
|
struct lvmpolld_lv_state {
|
|
unsigned error:1;
|
|
unsigned polling_finished:1;
|
|
struct lvmpolld_cmd_stat cmd_state;
|
|
};
|
|
|
|
struct lvmpolld_thread_data {
|
|
char *line;
|
|
size_t line_size;
|
|
int outpipe[2];
|
|
int errpipe[2];
|
|
FILE *fout;
|
|
FILE *ferr;
|
|
char buf[1024];
|
|
struct lvmpolld_lv *pdlv;
|
|
};
|
|
|
|
char *construct_id(const char *sysdir, const char *lvid);
|
|
|
|
/* LVMPOLLD_LV_T section */
|
|
|
|
/* only call with appropriate struct lvmpolld_store lock held */
|
|
struct lvmpolld_lv *pdlv_create(struct lvmpolld_state *ls, const char *id,
|
|
const char *vgname, const char *lvname,
|
|
const char *sysdir, enum poll_type type,
|
|
const char *sinterval, unsigned pdtimeout,
|
|
struct lvmpolld_store *pdst,
|
|
const char *devicesfile);
|
|
|
|
/* only call with appropriate struct lvmpolld_store lock held */
|
|
void pdlv_destroy(struct lvmpolld_lv *pdlv);
|
|
|
|
static inline void pdlv_lock(struct lvmpolld_lv *pdlv)
|
|
{
|
|
pthread_mutex_lock(&pdlv->lock);
|
|
}
|
|
|
|
static inline void pdlv_unlock(struct lvmpolld_lv *pdlv)
|
|
{
|
|
pthread_mutex_unlock(&pdlv->lock);
|
|
}
|
|
|
|
/*
|
|
* no struct lvmpolld_lv lock required section
|
|
*/
|
|
static inline int pdlv_is_type(const struct lvmpolld_lv *pdlv, enum poll_type type)
|
|
{
|
|
return pdlv->type == type;
|
|
}
|
|
|
|
static inline unsigned pdlv_get_timeout(const struct lvmpolld_lv *pdlv)
|
|
{
|
|
return pdlv->pdtimeout;
|
|
}
|
|
|
|
static inline enum poll_type pdlv_get_type(const struct lvmpolld_lv *pdlv)
|
|
{
|
|
return pdlv->type;
|
|
}
|
|
|
|
unsigned pdlv_get_polling_finished(struct lvmpolld_lv *pdlv);
|
|
struct lvmpolld_lv_state pdlv_get_status(struct lvmpolld_lv *pdlv);
|
|
void pdlv_set_cmd_state(struct lvmpolld_lv *pdlv, const struct lvmpolld_cmd_stat *cmd_state);
|
|
void pdlv_set_error(struct lvmpolld_lv *pdlv, unsigned error);
|
|
void pdlv_set_polling_finished(struct lvmpolld_lv *pdlv, unsigned finished);
|
|
|
|
/*
|
|
* struct lvmpolld_lv lock required section
|
|
*/
|
|
static inline struct lvmpolld_cmd_stat pdlv_locked_cmd_state(const struct lvmpolld_lv *pdlv)
|
|
{
|
|
return pdlv->cmd_state;
|
|
}
|
|
|
|
static inline int pdlv_locked_polling_finished(const struct lvmpolld_lv *pdlv)
|
|
{
|
|
return pdlv->polling_finished;
|
|
}
|
|
|
|
static inline unsigned pdlv_locked_error(const struct lvmpolld_lv *pdlv)
|
|
{
|
|
return pdlv->error;
|
|
}
|
|
|
|
/* struct lvmpolld_store manipulation routines */
|
|
|
|
struct lvmpolld_store *pdst_init(const char *name);
|
|
void pdst_destroy(struct lvmpolld_store *pdst);
|
|
|
|
void pdst_locked_dump(const struct lvmpolld_store *pdst, struct buffer *buff);
|
|
void pdst_locked_lock_all_pdlvs(const struct lvmpolld_store *pdst);
|
|
void pdst_locked_unlock_all_pdlvs(const struct lvmpolld_store *pdst);
|
|
void pdst_locked_destroy_all_pdlvs(const struct lvmpolld_store *pdst);
|
|
void pdst_locked_send_cancel(const struct lvmpolld_store *pdst);
|
|
|
|
static inline void pdst_lock(struct lvmpolld_store *pdst)
|
|
{
|
|
pthread_mutex_lock(&pdst->lock);
|
|
}
|
|
|
|
static inline void pdst_unlock(struct lvmpolld_store *pdst)
|
|
{
|
|
pthread_mutex_unlock(&pdst->lock);
|
|
}
|
|
|
|
static inline void pdst_locked_inc(struct lvmpolld_store *pdst)
|
|
{
|
|
pdst->active_polling_count++;
|
|
}
|
|
|
|
static inline void pdst_locked_dec(struct lvmpolld_store *pdst)
|
|
{
|
|
pdst->active_polling_count--;
|
|
}
|
|
|
|
static inline unsigned pdst_locked_get_active_count(const struct lvmpolld_store *pdst)
|
|
{
|
|
return pdst->active_polling_count;
|
|
}
|
|
|
|
static inline int pdst_locked_insert(struct lvmpolld_store *pdst, const char *key, struct lvmpolld_lv *pdlv)
|
|
{
|
|
return dm_hash_insert(pdst->store, key, pdlv);
|
|
}
|
|
|
|
static inline struct lvmpolld_lv *pdst_locked_lookup(struct lvmpolld_store *pdst, const char *key)
|
|
{
|
|
return dm_hash_lookup(pdst->store, key);
|
|
}
|
|
|
|
static inline void pdst_locked_remove(struct lvmpolld_store *pdst, const char *key)
|
|
{
|
|
dm_hash_remove(pdst->store, key);
|
|
}
|
|
|
|
struct lvmpolld_thread_data *lvmpolld_thread_data_constructor(struct lvmpolld_lv *pdlv);
|
|
void lvmpolld_thread_data_destroy(void *thread_private);
|
|
|
|
#endif /* _LVM_LVMPOLLD_DATA_UTILS_H */
|