Skip to content

Commit a21f9ed

Browse files
bmarzinsMikulas Patocka
authored andcommitted
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 <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]>
1 parent 3708c72 commit a21f9ed

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

drivers/md/dm-table.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,23 +331,15 @@ static int upgrade_mode(struct dm_dev_internal *dd, blk_mode_t new_mode,
331331
}
332332

333333
/*
334-
* Add a device to the list, or just increment the usage count if
335-
* it's already present.
336-
*
337334
* Note: the __ref annotation is because this function can call the __init
338335
* marked early_lookup_bdev when called during early boot code from dm-init.c.
339336
*/
340-
int __ref dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
341-
struct dm_dev **result)
337+
int __ref dm_devt_from_path(const char *path, dev_t *dev_p)
342338
{
343339
int r;
344340
dev_t dev;
345341
unsigned int major, minor;
346342
char dummy;
347-
struct dm_dev_internal *dd;
348-
struct dm_table *t = ti->table;
349-
350-
BUG_ON(!t);
351343

352344
if (sscanf(path, "%u:%u%c", &major, &minor, &dummy) == 2) {
353345
/* 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,
363355
if (r)
364356
return r;
365357
}
358+
*dev_p = dev;
359+
return 0;
360+
}
361+
EXPORT_SYMBOL(dm_devt_from_path);
362+
363+
/*
364+
* Add a device to the list, or just increment the usage count if
365+
* it's already present.
366+
*/
367+
int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
368+
struct dm_dev **result)
369+
{
370+
int r;
371+
dev_t dev;
372+
struct dm_dev_internal *dd;
373+
struct dm_table *t = ti->table;
374+
375+
BUG_ON(!t);
376+
377+
r = dm_devt_from_path(path, &dev);
378+
if (r)
379+
return r;
380+
366381
if (dev == disk_devt(t->md->disk))
367382
return -EINVAL;
368383

include/linux/device-mapper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
179179
struct dm_dev **result);
180180
void dm_put_device(struct dm_target *ti, struct dm_dev *d);
181181

182+
/*
183+
* Helper function for getting devices
184+
*/
185+
int dm_devt_from_path(const char *path, dev_t *dev_p);
186+
182187
/*
183188
* Information about a target type
184189
*/

0 commit comments

Comments
 (0)