1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Add activation/udev_rules config option in lvm.conf.

Add dm_tree_add_dev_with_udev_flags to provide wider support for udev flags.
This commit is contained in:
Peter Rajnoha 2010-01-07 19:54:21 +00:00
parent 4998a0041f
commit cda69e17ef
12 changed files with 88 additions and 33 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.57 - Version 2.02.57 -
==================================== ====================================
Add activation/udev_rules config option in lvm.conf.
Add macro outfc() and export out_text_with_comment(). Add macro outfc() and export out_text_with_comment().
Add macros outsize() and outhint(). Add macros outsize() and outhint().
Use offsetof() macro for FIELD() macro in lib/report/report.c. Use offsetof() macro for FIELD() macro in lib/report/report.c.

View File

@ -1,5 +1,6 @@
Version 1.02.41 - Version 1.02.41 -
==================================== ====================================
Add dm_tree_add_dev_with_udev_flags to provide wider support for udev flags.
Add --noudevrules option for dmsetup to disable /dev node management by udev. Add --noudevrules option for dmsetup to disable /dev node management by udev.
Update code to show all fields for 'dmsetup info -c -o all'. Update code to show all fields for 'dmsetup info -c -o all'.
Return error from dm_tree_deactivate_children(). Return error from dm_tree_deactivate_children().

View File

@ -323,7 +323,7 @@ global {
} }
activation { activation {
# Set to 0 to disable udev syncronisation (if compiled into the binaries). # Set to 0 to disable udev synchronisation (if compiled into the binaries).
# Processes will not wait for notification from udev. # Processes will not wait for notification from udev.
# They will continue irrespective of any possible udev processing # They will continue irrespective of any possible udev processing
# in the background. You should only use this if udev is not running # in the background. You should only use this if udev is not running
@ -333,6 +333,13 @@ activation {
# waiting for udev, run 'dmsetup udevcomplete_all' manually to wake them up. # waiting for udev, run 'dmsetup udevcomplete_all' manually to wake them up.
udev_sync = 1 udev_sync = 1
# Set to 0 to disable the udev rules installed by LVM2 (if built with
# --enable-udev_rules). LVM2 will then manage the /dev nodes and symlinks
# for active logical volumes directly itself.
# N.B. Manual intervention may be required if this setting is changed
# while any logical volumes are active.
udev_rules = 1
# How to fill in missing stripes if activating an incomplete volume. # How to fill in missing stripes if activating an incomplete volume.
# Using "error" will make inaccessible parts of the device return # Using "error" will make inaccessible parts of the device return
# I/O errors on access. You can instead use a device path, in which # I/O errors on access. You can instead use a device path, in which

View File

@ -658,6 +658,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
{ {
char *dlid, *name; char *dlid, *name;
struct dm_info info, info2; struct dm_info info, info2;
uint16_t udev_flags = 0;
if (!(name = build_dm_name(dm->mem, lv->vg->name, lv->name, layer))) if (!(name = build_dm_name(dm->mem, lv->vg->name, lv->name, layer)))
return_0; return_0;
@ -695,7 +696,20 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
} }
} }
if (info.exists && !dm_tree_add_dev(dtree, info.major, info.minor)) { if (layer || !lv_is_visible(lv))
udev_flags |= DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG |
DM_UDEV_DISABLE_DISK_RULES_FLAG |
DM_UDEV_DISABLE_OTHER_RULES_FLAG;
if (lv_is_cow(lv))
udev_flags |= DM_UDEV_LOW_PRIORITY_FLAG;
if (!dm->cmd->current_settings.udev_rules)
udev_flags |= DM_UDEV_DISABLE_DM_RULES_FLAG |
DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG;
if (info.exists && !dm_tree_add_dev_with_udev_flags(dtree, info.major,
info.minor, udev_flags)) {
log_error("Failed to add device (%" PRIu32 ":%" PRIu32") to dtree", log_error("Failed to add device (%" PRIu32 ":%" PRIu32") to dtree",
info.major, info.minor); info.major, info.minor);
return 0; return 0;
@ -1034,6 +1048,10 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
if (lv_is_cow(lv)) if (lv_is_cow(lv))
udev_flags |= DM_UDEV_LOW_PRIORITY_FLAG; udev_flags |= DM_UDEV_LOW_PRIORITY_FLAG;
if (!dm->cmd->current_settings.udev_rules)
udev_flags |= DM_UDEV_DISABLE_DM_RULES_FLAG |
DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG;
/* /*
* Add LV to dtree. * Add LV to dtree.
* If we're working with precommitted metadata, clear any * If we're working with precommitted metadata, clear any
@ -1151,7 +1169,8 @@ static int _remove_lv_symlinks(struct dev_manager *dm, struct dm_tree_node *root
if (*layer) if (*layer)
continue; continue;
fs_del_lv_byname(dm->cmd->dev_dir, vgname, lvname); fs_del_lv_byname(dm->cmd->dev_dir, vgname, lvname,
dm->cmd->current_settings.udev_rules);
} }
return r; return r;

View File

@ -108,7 +108,7 @@ static void _rm_blks(const char *dir)
} }
static int _mk_link(const char *dev_dir, const char *vg_name, static int _mk_link(const char *dev_dir, const char *vg_name,
const char *lv_name, const char *dev) const char *lv_name, const char *dev, int check_udev)
{ {
char lv_path[PATH_MAX], link_path[PATH_MAX], lvm1_group_path[PATH_MAX]; char lv_path[PATH_MAX], link_path[PATH_MAX], lvm1_group_path[PATH_MAX];
char vg_path[PATH_MAX]; char vg_path[PATH_MAX];
@ -166,7 +166,7 @@ static int _mk_link(const char *dev_dir, const char *vg_name,
return 0; return 0;
} }
if (dm_udev_get_sync_support()) { if (dm_udev_get_sync_support() && check_udev) {
/* Check udev created the correct link. */ /* Check udev created the correct link. */
if (!stat(link_path, &buf_lp) && if (!stat(link_path, &buf_lp) &&
!stat(lv_path, &buf)) { !stat(lv_path, &buf)) {
@ -190,7 +190,7 @@ static int _mk_link(const char *dev_dir, const char *vg_name,
log_sys_error("unlink", lv_path); log_sys_error("unlink", lv_path);
return 0; return 0;
} }
} else if (dm_udev_get_sync_support()) } else if (dm_udev_get_sync_support() && check_udev)
log_warn("The link %s should had been created by udev " log_warn("The link %s should had been created by udev "
"but it was not found. Falling back to " "but it was not found. Falling back to "
"direct link creation.", lv_path); "direct link creation.", lv_path);
@ -208,7 +208,7 @@ static int _mk_link(const char *dev_dir, const char *vg_name,
} }
static int _rm_link(const char *dev_dir, const char *vg_name, static int _rm_link(const char *dev_dir, const char *vg_name,
const char *lv_name) const char *lv_name, int check_udev)
{ {
struct stat buf; struct stat buf;
char lv_path[PATH_MAX]; char lv_path[PATH_MAX];
@ -221,7 +221,7 @@ static int _rm_link(const char *dev_dir, const char *vg_name,
if (lstat(lv_path, &buf) && errno == ENOENT) if (lstat(lv_path, &buf) && errno == ENOENT)
return 1; return 1;
else if (dm_udev_get_sync_support()) else if (dm_udev_get_sync_support() && check_udev)
log_warn("The link %s should have been removed by udev " log_warn("The link %s should have been removed by udev "
"but it is still present. Falling back to " "but it is still present. Falling back to "
"direct link removal.", lv_path); "direct link removal.", lv_path);
@ -248,25 +248,26 @@ typedef enum {
static int _do_fs_op(fs_op_t type, const char *dev_dir, const char *vg_name, static int _do_fs_op(fs_op_t type, const char *dev_dir, const char *vg_name,
const char *lv_name, const char *dev, const char *lv_name, const char *dev,
const char *old_lv_name) const char *old_lv_name, int check_udev)
{ {
switch (type) { switch (type) {
case FS_ADD: case FS_ADD:
if (!_mk_dir(dev_dir, vg_name) || if (!_mk_dir(dev_dir, vg_name) ||
!_mk_link(dev_dir, vg_name, lv_name, dev)) !_mk_link(dev_dir, vg_name, lv_name, dev, check_udev))
return_0; return_0;
break; break;
case FS_DEL: case FS_DEL:
if (!_rm_link(dev_dir, vg_name, lv_name) || if (!_rm_link(dev_dir, vg_name, lv_name, check_udev) ||
!_rm_dir(dev_dir, vg_name)) !_rm_dir(dev_dir, vg_name))
return_0; return_0;
break; break;
/* FIXME Use rename() */ /* FIXME Use rename() */
case FS_RENAME: case FS_RENAME:
if (old_lv_name && !_rm_link(dev_dir, vg_name, old_lv_name)) if (old_lv_name && !_rm_link(dev_dir, vg_name, old_lv_name,
check_udev))
stack; stack;
if (!_mk_link(dev_dir, vg_name, lv_name, dev)) if (!_mk_link(dev_dir, vg_name, lv_name, dev, check_udev))
stack; stack;
} }
@ -278,6 +279,7 @@ static DM_LIST_INIT(_fs_ops);
struct fs_op_parms { struct fs_op_parms {
struct dm_list list; struct dm_list list;
fs_op_t type; fs_op_t type;
int check_udev;
char *dev_dir; char *dev_dir;
char *vg_name; char *vg_name;
char *lv_name; char *lv_name;
@ -295,7 +297,7 @@ static void _store_str(char **pos, char **ptr, const char *str)
static int _stack_fs_op(fs_op_t type, const char *dev_dir, const char *vg_name, static int _stack_fs_op(fs_op_t type, const char *dev_dir, const char *vg_name,
const char *lv_name, const char *dev, const char *lv_name, const char *dev,
const char *old_lv_name) const char *old_lv_name, int check_udev)
{ {
struct fs_op_parms *fsp; struct fs_op_parms *fsp;
size_t len = strlen(dev_dir) + strlen(vg_name) + strlen(lv_name) + size_t len = strlen(dev_dir) + strlen(vg_name) + strlen(lv_name) +
@ -309,6 +311,7 @@ static int _stack_fs_op(fs_op_t type, const char *dev_dir, const char *vg_name,
pos = fsp->names; pos = fsp->names;
fsp->type = type; fsp->type = type;
fsp->check_udev = check_udev;
_store_str(&pos, &fsp->dev_dir, dev_dir); _store_str(&pos, &fsp->dev_dir, dev_dir);
_store_str(&pos, &fsp->vg_name, vg_name); _store_str(&pos, &fsp->vg_name, vg_name);
@ -329,40 +332,43 @@ static void _pop_fs_ops(void)
dm_list_iterate_safe(fsph, fspht, &_fs_ops) { dm_list_iterate_safe(fsph, fspht, &_fs_ops) {
fsp = dm_list_item(fsph, struct fs_op_parms); fsp = dm_list_item(fsph, struct fs_op_parms);
_do_fs_op(fsp->type, fsp->dev_dir, fsp->vg_name, fsp->lv_name, _do_fs_op(fsp->type, fsp->dev_dir, fsp->vg_name, fsp->lv_name,
fsp->dev, fsp->old_lv_name); fsp->dev, fsp->old_lv_name, fsp->check_udev);
dm_list_del(&fsp->list); dm_list_del(&fsp->list);
dm_free(fsp); dm_free(fsp);
} }
} }
static int _fs_op(fs_op_t type, const char *dev_dir, const char *vg_name, static int _fs_op(fs_op_t type, const char *dev_dir, const char *vg_name,
const char *lv_name, const char *dev, const char *old_lv_name) const char *lv_name, const char *dev, const char *old_lv_name,
int check_udev)
{ {
if (memlock()) { if (memlock()) {
if (!_stack_fs_op(type, dev_dir, vg_name, lv_name, dev, if (!_stack_fs_op(type, dev_dir, vg_name, lv_name, dev,
old_lv_name)) old_lv_name, check_udev))
return_0; return_0;
return 1; return 1;
} }
return _do_fs_op(type, dev_dir, vg_name, lv_name, dev, old_lv_name); return _do_fs_op(type, dev_dir, vg_name, lv_name, dev,
old_lv_name, check_udev);
} }
int fs_add_lv(const struct logical_volume *lv, const char *dev) int fs_add_lv(const struct logical_volume *lv, const char *dev)
{ {
return _fs_op(FS_ADD, lv->vg->cmd->dev_dir, lv->vg->name, lv->name, return _fs_op(FS_ADD, lv->vg->cmd->dev_dir, lv->vg->name, lv->name,
dev, ""); dev, "", lv->vg->cmd->current_settings.udev_rules);
} }
int fs_del_lv(const struct logical_volume *lv) int fs_del_lv(const struct logical_volume *lv)
{ {
return _fs_op(FS_DEL, lv->vg->cmd->dev_dir, lv->vg->name, lv->name, return _fs_op(FS_DEL, lv->vg->cmd->dev_dir, lv->vg->name, lv->name,
"", ""); "", "", lv->vg->cmd->current_settings.udev_rules);
} }
int fs_del_lv_byname(const char *dev_dir, const char *vg_name, const char *lv_name) int fs_del_lv_byname(const char *dev_dir, const char *vg_name,
const char *lv_name, int check_udev)
{ {
return _fs_op(FS_DEL, dev_dir, vg_name, lv_name, "", ""); return _fs_op(FS_DEL, dev_dir, vg_name, lv_name, "", "", check_udev);
} }
int fs_rename_lv(struct logical_volume *lv, const char *dev, int fs_rename_lv(struct logical_volume *lv, const char *dev,
@ -370,12 +376,14 @@ int fs_rename_lv(struct logical_volume *lv, const char *dev,
{ {
if (strcmp(old_vgname, lv->vg->name)) { if (strcmp(old_vgname, lv->vg->name)) {
return return
(_fs_op(FS_DEL, lv->vg->cmd->dev_dir, old_vgname, old_lvname, "", "") && (_fs_op(FS_DEL, lv->vg->cmd->dev_dir, old_vgname,
_fs_op(FS_ADD, lv->vg->cmd->dev_dir, lv->vg->name, lv->name, dev, "")); old_lvname, "", "", lv->vg->cmd->current_settings.udev_rules) &&
_fs_op(FS_ADD, lv->vg->cmd->dev_dir, lv->vg->name,
lv->name, dev, "", lv->vg->cmd->current_settings.udev_rules));
} }
else else
return _fs_op(FS_RENAME, lv->vg->cmd->dev_dir, lv->vg->name, lv->name, return _fs_op(FS_RENAME, lv->vg->cmd->dev_dir, lv->vg->name, lv->name,
dev, old_lvname); dev, old_lvname, lv->vg->cmd->current_settings.udev_rules);
} }
void fs_unlock(void) void fs_unlock(void)

View File

@ -25,9 +25,10 @@
*/ */
int fs_add_lv(const struct logical_volume *lv, const char *dev); int fs_add_lv(const struct logical_volume *lv, const char *dev);
int fs_del_lv(const struct logical_volume *lv); int fs_del_lv(const struct logical_volume *lv);
int fs_del_lv_byname(const char *dev_dir, const char *vg_name, const char *lv_name); int fs_del_lv_byname(const char *dev_dir, const char *vg_name,
const char *lv_name, int check_udev);
int fs_rename_lv(struct logical_volume *lv, const char *dev, int fs_rename_lv(struct logical_volume *lv, const char *dev,
const char *old_vgname, const char *old_lvname); const char *old_vgname, const char *old_lvname);
void fs_unlock(void); void fs_unlock(void);
#endif #endif

View File

@ -267,6 +267,10 @@ static int _process_config(struct cmd_context *cmd)
return 0; return 0;
} }
cmd->default_settings.udev_rules = find_config_tree_int(cmd,
"activation/udev_rules",
DEFAULT_UDEV_RULES);
cmd->default_settings.udev_sync = find_config_tree_int(cmd, cmd->default_settings.udev_sync = find_config_tree_int(cmd,
"activation/udev_sync", "activation/udev_sync",
DEFAULT_UDEV_SYNC); DEFAULT_UDEV_SYNC);

View File

@ -34,6 +34,7 @@ struct config_info {
int archive; /* should we archive ? */ int archive; /* should we archive ? */
int backup; /* should we backup ? */ int backup; /* should we backup ? */
int read_ahead; /* DM_READ_AHEAD_NONE or _AUTO */ int read_ahead; /* DM_READ_AHEAD_NONE or _AUTO */
int udev_rules;
int udev_sync; int udev_sync;
int cache_vgmetadata; int cache_vgmetadata;
const char *msg_prefix; const char *msg_prefix;

View File

@ -67,6 +67,7 @@
#define DEFAULT_PVMETADATACOPIES 1 #define DEFAULT_PVMETADATACOPIES 1
#define DEFAULT_LABELSECTOR UINT64_C(1) #define DEFAULT_LABELSECTOR UINT64_C(1)
#define DEFAULT_READ_AHEAD "auto" #define DEFAULT_READ_AHEAD "auto"
#define DEFAULT_UDEV_RULES 1
#define DEFAULT_UDEV_SYNC 0 #define DEFAULT_UDEV_SYNC 0
#define DEFAULT_EXTENT_SIZE 4096 /* In KB */ #define DEFAULT_EXTENT_SIZE 4096 /* In KB */
#define DEFAULT_MAX_PV 0 #define DEFAULT_MAX_PV 0

View File

@ -50,6 +50,7 @@ dm_format_dev
dm_tree_create dm_tree_create
dm_tree_free dm_tree_free
dm_tree_add_dev dm_tree_add_dev
dm_tree_add_dev_with_udev_flags
dm_tree_add_new_dev dm_tree_add_new_dev
dm_tree_add_new_dev_with_udev_flags dm_tree_add_new_dev_with_udev_flags
dm_tree_node_get_name dm_tree_node_get_name

View File

@ -267,6 +267,8 @@ void dm_tree_free(struct dm_tree *tree);
* Add nodes to the tree for a given device and all the devices it uses. * Add nodes to the tree for a given device and all the devices it uses.
*/ */
int dm_tree_add_dev(struct dm_tree *tree, uint32_t major, uint32_t minor); int dm_tree_add_dev(struct dm_tree *tree, uint32_t major, uint32_t minor);
int dm_tree_add_dev_with_udev_flags(struct dm_tree *tree, uint32_t major,
uint32_t minor, uint16_t udev_flags);
/* /*
* Add a new node to the tree if it doesn't already exist. * Add a new node to the tree if it doesn't already exist.

View File

@ -454,7 +454,8 @@ failed:
static struct dm_tree_node *_add_dev(struct dm_tree *dtree, static struct dm_tree_node *_add_dev(struct dm_tree *dtree,
struct dm_tree_node *parent, struct dm_tree_node *parent,
uint32_t major, uint32_t minor) uint32_t major, uint32_t minor,
uint16_t udev_flags)
{ {
struct dm_task *dmt = NULL; struct dm_task *dmt = NULL;
struct dm_info info; struct dm_info info;
@ -471,7 +472,7 @@ static struct dm_tree_node *_add_dev(struct dm_tree *dtree,
return_NULL; return_NULL;
if (!(node = _create_dm_tree_node(dtree, name, uuid, &info, if (!(node = _create_dm_tree_node(dtree, name, uuid, &info,
NULL, 0))) NULL, udev_flags)))
goto_out; goto_out;
new = 1; new = 1;
} }
@ -497,7 +498,7 @@ static struct dm_tree_node *_add_dev(struct dm_tree *dtree,
/* Add dependencies to tree */ /* Add dependencies to tree */
for (i = 0; i < deps->count; i++) for (i = 0; i < deps->count; i++)
if (!_add_dev(dtree, node, MAJOR(deps->device[i]), if (!_add_dev(dtree, node, MAJOR(deps->device[i]),
MINOR(deps->device[i]))) { MINOR(deps->device[i]), udev_flags)) {
node = NULL; node = NULL;
goto_out; goto_out;
} }
@ -652,7 +653,13 @@ void dm_tree_node_set_read_ahead(struct dm_tree_node *dnode,
int dm_tree_add_dev(struct dm_tree *dtree, uint32_t major, uint32_t minor) int dm_tree_add_dev(struct dm_tree *dtree, uint32_t major, uint32_t minor)
{ {
return _add_dev(dtree, &dtree->root, major, minor) ? 1 : 0; return _add_dev(dtree, &dtree->root, major, minor, 0) ? 1 : 0;
}
int dm_tree_add_dev_with_udev_flags(struct dm_tree *dtree, uint32_t major,
uint32_t minor, uint16_t udev_flags)
{
return _add_dev(dtree, &dtree->root, major, minor, udev_flags) ? 1 : 0;
} }
const char *dm_tree_node_get_name(struct dm_tree_node *node) const char *dm_tree_node_get_name(struct dm_tree_node *node)
@ -873,7 +880,8 @@ static int _deactivate_node(const char *name, uint32_t major, uint32_t minor,
r = dm_task_run(dmt); r = dm_task_run(dmt);
/* FIXME Until kernel returns actual name so dm-ioctl.c can handle it */ /* FIXME Until kernel returns actual name so dm-ioctl.c can handle it */
rm_dev_node(name, dmt->cookie_set); rm_dev_node(name, dmt->cookie_set &&
!(udev_flags & DM_UDEV_DISABLE_DM_RULES_FLAG));
/* FIXME Remove node from tree or mark invalid? */ /* FIXME Remove node from tree or mark invalid? */
@ -1963,7 +1971,8 @@ int dm_tree_node_add_target_area(struct dm_tree_node *node,
} }
/* FIXME Check correct macro use */ /* FIXME Check correct macro use */
if (!(dev_node = _add_dev(node->dtree, node, MAJOR(info.st_rdev), MINOR(info.st_rdev)))) if (!(dev_node = _add_dev(node->dtree, node, MAJOR(info.st_rdev),
MINOR(info.st_rdev), 0)))
return_0; return_0;
} }