Commit 644bda6f authored by Dan Ehrenberg's avatar Dan Ehrenberg Committed by Mike Snitzer

dm table: fall back to getting device using name_to_dev_t()

If a device is used as the root filesystem, it can't be built
off of devices which are within the root filesystem (just like
command line arguments to root=).  For this reason, Linux has a
pseudo-filesystem for root= and MD initialization (based on the
function name_to_dev_t) which handles different ways of specifying
devices including PARTUUID and major:minor.

Switch to using name_to_dev_t() in dm_get_device().  Rather than
having DM assume that all things which are not major:minor are paths in
an already-mounted filesystem, change dm_get_device() to first attempt
to look up the device in the filesystem, and if not found it will fall
back to using name_to_dev_t().

In terms of backwards compatibility, there are some cases where
behavior will be different:
- If you have a file in the current working directory named 1:2 and
  you initialze DM there, then it will try to use that file rather
  than the disk with that major:minor pair as a backing device.
- Similarly for other bdev types which name_to_dev_t() knows how to
  interpret, the previous behavior was to repeatedly check for the
  existence of the file (e.g., while waiting for rootfs to come up)
  but the new behavior is to use the name_to_dev_t() interpretation.
  For example, if you have a file named /dev/ubiblock0_0 which is
  a symlink to /dev/sda3, but it is not yet present when DM starts
  to initialize, then the name_to_dev_t() interpretation will take
  precedence.

These incompatibilities would only show up in really strange setups
with bad practices so we shouldn't have to worry about them.
Signed-off-by: default avatarDan Ehrenberg <dehrenberg@chromium.org>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent 283e7ad0
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/atomic.h> #include <linux/atomic.h>
#include <linux/blk-mq.h> #include <linux/blk-mq.h>
#include <linux/mount.h>
#define DM_MSG_PREFIX "table" #define DM_MSG_PREFIX "table"
...@@ -373,23 +374,18 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode, ...@@ -373,23 +374,18 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
int r; int r;
dev_t uninitialized_var(dev); dev_t uninitialized_var(dev);
struct dm_dev_internal *dd; struct dm_dev_internal *dd;
unsigned int major, minor;
struct dm_table *t = ti->table; struct dm_table *t = ti->table;
char dummy; struct block_device *bdev;
BUG_ON(!t); BUG_ON(!t);
if (sscanf(path, "%u:%u%c", &major, &minor, &dummy) == 2) { /* convert the path to a device */
/* Extract the major/minor numbers */ bdev = lookup_bdev(path);
dev = MKDEV(major, minor); if (IS_ERR(bdev)) {
if (MAJOR(dev) != major || MINOR(dev) != minor) dev = name_to_dev_t(path);
return -EOVERFLOW; if (!dev)
return -ENODEV;
} else { } else {
/* convert the path to a device */
struct block_device *bdev = lookup_bdev(path);
if (IS_ERR(bdev))
return PTR_ERR(bdev);
dev = bdev->bd_dev; dev = bdev->bd_dev;
bdput(bdev); bdput(bdev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment