Skip to content

Commit 82b1519

Browse files
Mikulas Patockakergon
authored andcommitted
dm: export struct dm_dev
Split struct dm_dev in two and publish the part that other targets need in include/linux/device-mapper.h. Signed-off-by: Mikulas Patocka <[email protected]> Signed-off-by: Alasdair G Kergon <[email protected]>
1 parent 933f01d commit 82b1519

File tree

4 files changed

+49
-40
lines changed

4 files changed

+49
-40
lines changed

drivers/md/dm-ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ static void retrieve_deps(struct dm_table *table,
11311131
unsigned int count = 0;
11321132
struct list_head *tmp;
11331133
size_t len, needed;
1134-
struct dm_dev *dd;
1134+
struct dm_dev_internal *dd;
11351135
struct dm_target_deps *deps;
11361136

11371137
deps = get_result_buffer(param, param_size, &len);
@@ -1157,7 +1157,7 @@ static void retrieve_deps(struct dm_table *table,
11571157
deps->count = count;
11581158
count = 0;
11591159
list_for_each_entry (dd, dm_table_get_devices(table), list)
1160-
deps->dev[count++] = huge_encode_dev(dd->bdev->bd_dev);
1160+
deps->dev[count++] = huge_encode_dev(dd->dm_dev.bdev->bd_dev);
11611161

11621162
param->data_size = param->data_start + needed;
11631163
}

drivers/md/dm-table.c

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ static void free_devices(struct list_head *devices)
250250
struct list_head *tmp, *next;
251251

252252
list_for_each_safe(tmp, next, devices) {
253-
struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
253+
struct dm_dev_internal *dd =
254+
list_entry(tmp, struct dm_dev_internal, list);
254255
kfree(dd);
255256
}
256257
}
@@ -327,12 +328,12 @@ static int lookup_device(const char *path, dev_t *dev)
327328
/*
328329
* See if we've already got a device in the list.
329330
*/
330-
static struct dm_dev *find_device(struct list_head *l, dev_t dev)
331+
static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
331332
{
332-
struct dm_dev *dd;
333+
struct dm_dev_internal *dd;
333334

334335
list_for_each_entry (dd, l, list)
335-
if (dd->bdev->bd_dev == dev)
336+
if (dd->dm_dev.bdev->bd_dev == dev)
336337
return dd;
337338

338339
return NULL;
@@ -341,45 +342,47 @@ static struct dm_dev *find_device(struct list_head *l, dev_t dev)
341342
/*
342343
* Open a device so we can use it as a map destination.
343344
*/
344-
static int open_dev(struct dm_dev *d, dev_t dev, struct mapped_device *md)
345+
static int open_dev(struct dm_dev_internal *d, dev_t dev,
346+
struct mapped_device *md)
345347
{
346348
static char *_claim_ptr = "I belong to device-mapper";
347349
struct block_device *bdev;
348350

349351
int r;
350352

351-
BUG_ON(d->bdev);
353+
BUG_ON(d->dm_dev.bdev);
352354

353-
bdev = open_by_devnum(dev, d->mode);
355+
bdev = open_by_devnum(dev, d->dm_dev.mode);
354356
if (IS_ERR(bdev))
355357
return PTR_ERR(bdev);
356358
r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md));
357359
if (r)
358360
blkdev_put(bdev);
359361
else
360-
d->bdev = bdev;
362+
d->dm_dev.bdev = bdev;
361363
return r;
362364
}
363365

364366
/*
365367
* Close a device that we've been using.
366368
*/
367-
static void close_dev(struct dm_dev *d, struct mapped_device *md)
369+
static void close_dev(struct dm_dev_internal *d, struct mapped_device *md)
368370
{
369-
if (!d->bdev)
371+
if (!d->dm_dev.bdev)
370372
return;
371373

372-
bd_release_from_disk(d->bdev, dm_disk(md));
373-
blkdev_put(d->bdev);
374-
d->bdev = NULL;
374+
bd_release_from_disk(d->dm_dev.bdev, dm_disk(md));
375+
blkdev_put(d->dm_dev.bdev);
376+
d->dm_dev.bdev = NULL;
375377
}
376378

377379
/*
378380
* If possible, this checks an area of a destination device is valid.
379381
*/
380-
static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len)
382+
static int check_device_area(struct dm_dev_internal *dd, sector_t start,
383+
sector_t len)
381384
{
382-
sector_t dev_size = dd->bdev->bd_inode->i_size >> SECTOR_SHIFT;
385+
sector_t dev_size = dd->dm_dev.bdev->bd_inode->i_size >> SECTOR_SHIFT;
383386

384387
if (!dev_size)
385388
return 1;
@@ -392,16 +395,17 @@ static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len)
392395
* careful to leave things as they were if we fail to reopen the
393396
* device.
394397
*/
395-
static int upgrade_mode(struct dm_dev *dd, int new_mode, struct mapped_device *md)
398+
static int upgrade_mode(struct dm_dev_internal *dd, int new_mode,
399+
struct mapped_device *md)
396400
{
397401
int r;
398-
struct dm_dev dd_copy;
399-
dev_t dev = dd->bdev->bd_dev;
402+
struct dm_dev_internal dd_copy;
403+
dev_t dev = dd->dm_dev.bdev->bd_dev;
400404

401405
dd_copy = *dd;
402406

403-
dd->mode |= new_mode;
404-
dd->bdev = NULL;
407+
dd->dm_dev.mode |= new_mode;
408+
dd->dm_dev.bdev = NULL;
405409
r = open_dev(dd, dev, md);
406410
if (!r)
407411
close_dev(&dd_copy, md);
@@ -421,7 +425,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
421425
{
422426
int r;
423427
dev_t uninitialized_var(dev);
424-
struct dm_dev *dd;
428+
struct dm_dev_internal *dd;
425429
unsigned int major, minor;
426430

427431
BUG_ON(!t);
@@ -443,20 +447,20 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
443447
if (!dd)
444448
return -ENOMEM;
445449

446-
dd->mode = mode;
447-
dd->bdev = NULL;
450+
dd->dm_dev.mode = mode;
451+
dd->dm_dev.bdev = NULL;
448452

449453
if ((r = open_dev(dd, dev, t->md))) {
450454
kfree(dd);
451455
return r;
452456
}
453457

454-
format_dev_t(dd->name, dev);
458+
format_dev_t(dd->dm_dev.name, dev);
455459

456460
atomic_set(&dd->count, 0);
457461
list_add(&dd->list, &t->devices);
458462

459-
} else if (dd->mode != (mode | dd->mode)) {
463+
} else if (dd->dm_dev.mode != (mode | dd->dm_dev.mode)) {
460464
r = upgrade_mode(dd, mode, t->md);
461465
if (r)
462466
return r;
@@ -465,11 +469,11 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
465469

466470
if (!check_device_area(dd, start, len)) {
467471
DMWARN("device %s too small for target", path);
468-
dm_put_device(ti, dd);
472+
dm_put_device(ti, &dd->dm_dev);
469473
return -EINVAL;
470474
}
471475

472-
*result = dd;
476+
*result = &dd->dm_dev;
473477

474478
return 0;
475479
}
@@ -540,8 +544,11 @@ int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
540544
/*
541545
* Decrement a devices use count and remove it if necessary.
542546
*/
543-
void dm_put_device(struct dm_target *ti, struct dm_dev *dd)
547+
void dm_put_device(struct dm_target *ti, struct dm_dev *d)
544548
{
549+
struct dm_dev_internal *dd = container_of(d, struct dm_dev_internal,
550+
dm_dev);
551+
545552
if (atomic_dec_and_test(&dd->count)) {
546553
close_dev(dd, ti->table->md);
547554
list_del(&dd->list);
@@ -937,12 +944,12 @@ int dm_table_resume_targets(struct dm_table *t)
937944

938945
int dm_table_any_congested(struct dm_table *t, int bdi_bits)
939946
{
940-
struct dm_dev *dd;
947+
struct dm_dev_internal *dd;
941948
struct list_head *devices = dm_table_get_devices(t);
942949
int r = 0;
943950

944951
list_for_each_entry(dd, devices, list) {
945-
struct request_queue *q = bdev_get_queue(dd->bdev);
952+
struct request_queue *q = bdev_get_queue(dd->dm_dev.bdev);
946953
r |= bdi_congested(&q->backing_dev_info, bdi_bits);
947954
}
948955

@@ -951,11 +958,11 @@ int dm_table_any_congested(struct dm_table *t, int bdi_bits)
951958

952959
void dm_table_unplug_all(struct dm_table *t)
953960
{
954-
struct dm_dev *dd;
961+
struct dm_dev_internal *dd;
955962
struct list_head *devices = dm_table_get_devices(t);
956963

957964
list_for_each_entry(dd, devices, list) {
958-
struct request_queue *q = bdev_get_queue(dd->bdev);
965+
struct request_queue *q = bdev_get_queue(dd->dm_dev.bdev);
959966

960967
blk_unplug(q);
961968
}

drivers/md/dm.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@
2525
/*
2626
* List of devices that a metadevice uses and should open/close.
2727
*/
28-
struct dm_dev {
28+
struct dm_dev_internal {
2929
struct list_head list;
30-
3130
atomic_t count;
32-
int mode;
33-
struct block_device *bdev;
34-
char name[16];
31+
struct dm_dev dm_dev;
3532
};
3633

3734
struct dm_table;

include/linux/device-mapper.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
struct dm_target;
1515
struct dm_table;
16-
struct dm_dev;
1716
struct mapped_device;
1817
struct bio_vec;
1918

@@ -84,6 +83,12 @@ void dm_error(const char *message);
8483
*/
8584
void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
8685

86+
struct dm_dev {
87+
struct block_device *bdev;
88+
int mode;
89+
char name[16];
90+
};
91+
8792
/*
8893
* Constructors should call these functions to ensure destination devices
8994
* are opened/closed correctly.

0 commit comments

Comments
 (0)