]> sourceware.org Git - lvm2.git/commitdiff
Add activation/udev_rules config option in lvm.conf.
authorPeter Rajnoha <prajnoha@redhat.com>
Thu, 7 Jan 2010 19:54:21 +0000 (19:54 +0000)
committerPeter Rajnoha <prajnoha@redhat.com>
Thu, 7 Jan 2010 19:54:21 +0000 (19:54 +0000)
Add dm_tree_add_dev_with_udev_flags to provide wider support for udev flags.

12 files changed:
WHATS_NEW
WHATS_NEW_DM
doc/example.conf
lib/activate/dev_manager.c
lib/activate/fs.c
lib/activate/fs.h
lib/commands/toolcontext.c
lib/commands/toolcontext.h
lib/config/defaults.h
libdm/.exported_symbols
libdm/libdevmapper.h
libdm/libdm-deptree.c

index 2a75ad19a76721f013ee971c701ec095a163d52f..d2a3cf64d2810bb12927c8037e3cc44d3b0ce427 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.57 -
 ====================================
+  Add activation/udev_rules config option in lvm.conf.
   Add macro outfc() and export out_text_with_comment().
   Add macros outsize() and outhint().
   Use offsetof() macro for FIELD() macro in lib/report/report.c.
index 7a5df35ead4246e801da4bfc6b272536fa376638..7f06a2f62b4798fec71062491bcaefe40e41a265 100644 (file)
@@ -1,5 +1,6 @@
 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.
   Update code to show all fields for 'dmsetup info -c -o all'.
   Return error from dm_tree_deactivate_children().
index 0450067125528e0dfae2066351f91fd3319d4520..4b92b1f87efdf3ec2da39279c1c362f293de7e5f 100644 (file)
@@ -323,7 +323,7 @@ global {
 }
 
 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.
     # They will continue irrespective of any possible udev processing
     # 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.
     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.
     # Using "error" will make inaccessible parts of the device return
     # I/O errors on access.  You can instead use a device path, in which 
index bac0c7b527a5a66de3c44df3cb0f6d826113f24a..bf69286007cfc50c50e740cab16c5d3c4d8d719c 100644 (file)
@@ -658,6 +658,7 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
 {
        char *dlid, *name;
        struct dm_info info, info2;
+       uint16_t udev_flags = 0;
 
        if (!(name = build_dm_name(dm->mem, lv->vg->name, lv->name, layer)))
                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",
                          info.major, info.minor);
                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))
                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.
         * 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)
                        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;
index 6e4f91a9e81737ca96d80859d7c460b35fe5111c..d1691b8546c5814c9eda51e5e01cb0724ec8f4a9 100644 (file)
@@ -108,7 +108,7 @@ static void _rm_blks(const char *dir)
 }
 
 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 vg_path[PATH_MAX];
@@ -166,7 +166,7 @@ static int _mk_link(const char *dev_dir, const char *vg_name,
                        return 0;
                }
 
-               if (dm_udev_get_sync_support()) {
+               if (dm_udev_get_sync_support() && check_udev) {
                        /* Check udev created the correct link. */
                        if (!stat(link_path, &buf_lp) &&
                            !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);
                        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 "
                          "but it was not found. Falling back to "
                          "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,
-                   const char *lv_name)
+                   const char *lv_name, int check_udev)
 {
        struct stat buf;
        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)
                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 "
                         "but it is still present. Falling back to "
                         "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,
                     const char *lv_name, const char *dev,
-                    const char *old_lv_name)
+                    const char *old_lv_name, int check_udev)
 {
        switch (type) {
        case FS_ADD:
                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;
                break;
        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))
                        return_0;
                break;
                /* FIXME Use 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;
 
-               if (!_mk_link(dev_dir, vg_name, lv_name, dev))
+               if (!_mk_link(dev_dir, vg_name, lv_name, dev, check_udev))
                        stack;
        }
 
@@ -278,6 +279,7 @@ static DM_LIST_INIT(_fs_ops);
 struct fs_op_parms {
        struct dm_list list;
        fs_op_t type;
+       int check_udev;
        char *dev_dir;
        char *vg_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,
                        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;
        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;
        fsp->type = type;
+       fsp->check_udev = check_udev;
 
        _store_str(&pos, &fsp->dev_dir, dev_dir);
        _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) {
                fsp = dm_list_item(fsph, struct fs_op_parms);
                _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_free(fsp);
        }
 }
 
 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 (!_stack_fs_op(type, dev_dir, vg_name, lv_name, dev,
-                                 old_lv_name))
+                                 old_lv_name, check_udev))
                        return_0;
                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)
 {
        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)
 {
        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, 
@@ -370,12 +376,14 @@ int fs_rename_lv(struct logical_volume *lv, const char *dev,
 {
        if (strcmp(old_vgname, lv->vg->name)) {
                return
-                       (_fs_op(FS_DEL, lv->vg->cmd->dev_dir, old_vgname, old_lvname, "", "") &&
-                        _fs_op(FS_ADD, lv->vg->cmd->dev_dir, lv->vg->name, lv->name, dev, ""));
+                       (_fs_op(FS_DEL, lv->vg->cmd->dev_dir, old_vgname,
+                               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 
                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)
index 998f48fc133758364234a31be125d21228ac9c1f..28b2c73f59425e7c8ef44c034ec9d670c14eadbe 100644 (file)
  */
 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_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, 
-               const char *old_vgname, const char *old_lvname);
+                const char *old_vgname, const char *old_lvname);
 void fs_unlock(void);
 
 #endif
index bb3e5d21d252954f8b5ab25835cd5d81a052c5bd..a076e93f67cee85810afa2e5ca2ef79f5cb41d63 100644 (file)
@@ -267,6 +267,10 @@ static int _process_config(struct cmd_context *cmd)
                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,
                                                                "activation/udev_sync",
                                                                DEFAULT_UDEV_SYNC);
index 2ffc86d9de4853d6c59de51d9d0b0003f9d44b1a..eac5721790f9af36b7c97693e430fccf2a12f48c 100644 (file)
@@ -34,6 +34,7 @@ struct config_info {
        int archive;            /* should we archive ? */
        int backup;             /* should we backup ? */
        int read_ahead;         /* DM_READ_AHEAD_NONE or _AUTO */
+       int udev_rules;
        int udev_sync;
        int cache_vgmetadata;
        const char *msg_prefix;
index da13fc2b39b2a0e68b8276a7de2c326ac45d7023..94057e4d9fcb9e500f95a83b69e5380b7ed5eaf7 100644 (file)
@@ -67,6 +67,7 @@
 #define DEFAULT_PVMETADATACOPIES 1
 #define DEFAULT_LABELSECTOR UINT64_C(1)
 #define DEFAULT_READ_AHEAD "auto"
+#define DEFAULT_UDEV_RULES 1
 #define DEFAULT_UDEV_SYNC 0
 #define DEFAULT_EXTENT_SIZE 4096       /* In KB */
 #define DEFAULT_MAX_PV 0
index 554b90a91fe878728d6e7a5d1402ea16143da438..1555e422739564ab86f2acda15ba3a05ce0ea0f0 100644 (file)
@@ -50,6 +50,7 @@ dm_format_dev
 dm_tree_create
 dm_tree_free
 dm_tree_add_dev
+dm_tree_add_dev_with_udev_flags
 dm_tree_add_new_dev
 dm_tree_add_new_dev_with_udev_flags
 dm_tree_node_get_name
index c6546a63b0eef51cb534e59b609f8817b6dc901b..4c4734fd09799e2e264b9ba225809fd7dfc61397 100644 (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.
  */
 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.
index 0128217a15b44d4a248f0f77f9ff994429fe1ef1..a9836953f48a3f8b0de79b230ed313c725c8b759 100644 (file)
@@ -454,7 +454,8 @@ failed:
 
 static struct dm_tree_node *_add_dev(struct dm_tree *dtree,
                                     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_info info;
@@ -471,7 +472,7 @@ static struct dm_tree_node *_add_dev(struct dm_tree *dtree,
                        return_NULL;
 
                if (!(node = _create_dm_tree_node(dtree, name, uuid, &info,
-                                                 NULL, 0)))
+                                                 NULL, udev_flags)))
                        goto_out;
                new = 1;
        }
@@ -497,7 +498,7 @@ static struct dm_tree_node *_add_dev(struct dm_tree *dtree,
        /* Add dependencies to tree */
        for (i = 0; i < deps->count; i++)
                if (!_add_dev(dtree, node, MAJOR(deps->device[i]),
-                             MINOR(deps->device[i]))) {
+                             MINOR(deps->device[i]), udev_flags)) {
                        node = NULL;
                        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)
 {
-       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)
@@ -873,7 +880,8 @@ static int _deactivate_node(const char *name, uint32_t major, uint32_t minor,
        r = dm_task_run(dmt);
 
        /* 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? */
 
@@ -1963,7 +1971,8 @@ int dm_tree_node_add_target_area(struct dm_tree_node *node,
                }
 
                /* 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;
        }
 
This page took 0.062603 seconds and 5 git commands to generate.