diff options
author | Benjamin Marzinski <bmarzins@redhat.com> | 2024-07-04 16:17:15 +0200 |
---|---|---|
committer | Mikulas Patocka <mpatocka@redhat.com> | 2024-07-10 13:10:06 +0200 |
commit | a21f9edb13b0d8066775cbd5efa7261e41871182 (patch) | |
tree | a3fa28a4c8452a9d94a6c06ab108dc6684e231d7 /drivers/md | |
parent | 3708c7269593b836b1d684214cd9f5d83e4ed3fd (diff) | |
download | lwn-a21f9edb13b0d8066775cbd5efa7261e41871182.tar.gz lwn-a21f9edb13b0d8066775cbd5efa7261e41871182.zip |
dm: factor out helper function from dm_get_device
Factor out a helper function, dm_devt_from_path(), from dm_get_device()
for use in dm targets.
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-table.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 33b7a1844ed4..eea41e38d87e 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -331,23 +331,15 @@ static int upgrade_mode(struct dm_dev_internal *dd, blk_mode_t new_mode, } /* - * Add a device to the list, or just increment the usage count if - * it's already present. - * * Note: the __ref annotation is because this function can call the __init * marked early_lookup_bdev when called during early boot code from dm-init.c. */ -int __ref dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode, - struct dm_dev **result) +int __ref dm_devt_from_path(const char *path, dev_t *dev_p) { int r; dev_t dev; unsigned int major, minor; char dummy; - struct dm_dev_internal *dd; - struct dm_table *t = ti->table; - - BUG_ON(!t); if (sscanf(path, "%u:%u%c", &major, &minor, &dummy) == 2) { /* Extract the major/minor numbers */ @@ -363,6 +355,29 @@ int __ref dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode, if (r) return r; } + *dev_p = dev; + return 0; +} +EXPORT_SYMBOL(dm_devt_from_path); + +/* + * Add a device to the list, or just increment the usage count if + * it's already present. + */ +int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode, + struct dm_dev **result) +{ + int r; + dev_t dev; + struct dm_dev_internal *dd; + struct dm_table *t = ti->table; + + BUG_ON(!t); + + r = dm_devt_from_path(path, &dev); + if (r) + return r; + if (dev == disk_devt(t->md->disk)) return -EINVAL; |