Skip to content

Commit 809b1e4

Browse files
hreineckesnitm
authored andcommitted
dm: avoid filesystem lookup in dm_get_dev_t()
This reverts commit 644bda6 ("dm table: fall back to getting device using name_to_dev_t()") dm_get_dev_t() is just used to convert an arbitrary 'path' string into a dev_t. It doesn't presume that the device is present; that check will be done later, as the only caller is dm_get_device(), which does a dm_get_table_device() later on, which will properly open the device. So if the path string already _is_ in major:minor representation we can convert it directly, avoiding a recursion into the filesystem to lookup the block device. This avoids a hang in multipath_message() when the filesystem is inaccessible. Fixes: 644bda6 ("dm table: fall back to getting device using name_to_dev_t()") Cc: stable@vger.kernel.org Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Martin Wilck <mwilck@suse.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent 004b8ae commit 809b1e4

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

drivers/md/dm-table.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,23 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
363363
{
364364
int r;
365365
dev_t dev;
366+
unsigned int major, minor;
367+
char dummy;
366368
struct dm_dev_internal *dd;
367369
struct dm_table *t = ti->table;
368370

369371
BUG_ON(!t);
370372

371-
dev = dm_get_dev_t(path);
372-
if (!dev)
373-
return -ENODEV;
373+
if (sscanf(path, "%u:%u%c", &major, &minor, &dummy) == 2) {
374+
/* Extract the major/minor numbers */
375+
dev = MKDEV(major, minor);
376+
if (MAJOR(dev) != major || MINOR(dev) != minor)
377+
return -EOVERFLOW;
378+
} else {
379+
dev = dm_get_dev_t(path);
380+
if (!dev)
381+
return -ENODEV;
382+
}
374383

375384
dd = find_device(&t->devices, dev);
376385
if (!dd) {

0 commit comments

Comments
 (0)