aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm-ioctl.c4
-rw-r--r--drivers/md/dm-table.c71
-rw-r--r--drivers/md/dm.h7
3 files changed, 43 insertions, 39 deletions
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index b262c0042de3..90e19f13f269 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1131,7 +1131,7 @@ static void retrieve_deps(struct dm_table *table,
1131 unsigned int count = 0; 1131 unsigned int count = 0;
1132 struct list_head *tmp; 1132 struct list_head *tmp;
1133 size_t len, needed; 1133 size_t len, needed;
1134 struct dm_dev *dd; 1134 struct dm_dev_internal *dd;
1135 struct dm_target_deps *deps; 1135 struct dm_target_deps *deps;
1136 1136
1137 deps = get_result_buffer(param, param_size, &len); 1137 deps = get_result_buffer(param, param_size, &len);
@@ -1157,7 +1157,7 @@ static void retrieve_deps(struct dm_table *table,
1157 deps->count = count; 1157 deps->count = count;
1158 count = 0; 1158 count = 0;
1159 list_for_each_entry (dd, dm_table_get_devices(table), list) 1159 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);
1161 1161
1162 param->data_size = param->data_start + needed; 1162 param->data_size = param->data_start + needed;
1163} 1163}
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 61f441409234..5dd32b8a57ac 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -250,7 +250,8 @@ static void free_devices(struct list_head *devices)
250 struct list_head *tmp, *next; 250 struct list_head *tmp, *next;
251 251
252 list_for_each_safe(tmp, next, devices) { 252 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);
254 kfree(dd); 255 kfree(dd);
255 } 256 }
256} 257}
@@ -327,12 +328,12 @@ static int lookup_device(const char *path, dev_t *dev)
327/* 328/*
328 * See if we've already got a device in the list. 329 * See if we've already got a device in the list.
329 */ 330 */
330static struct dm_dev *find_device(struct list_head *l, dev_t dev) 331static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
331{ 332{
332 struct dm_dev *dd; 333 struct dm_dev_internal *dd;
333 334
334 list_for_each_entry (dd, l, list) 335 list_for_each_entry (dd, l, list)
335 if (dd->bdev->bd_dev == dev) 336 if (dd->dm_dev.bdev->bd_dev == dev)
336 return dd; 337 return dd;
337 338
338 return NULL; 339 return NULL;
@@ -341,45 +342,47 @@ static struct dm_dev *find_device(struct list_head *l, dev_t dev)
341/* 342/*
342 * Open a device so we can use it as a map destination. 343 * Open a device so we can use it as a map destination.
343 */ 344 */
344static int open_dev(struct dm_dev *d, dev_t dev, struct mapped_device *md) 345static int open_dev(struct dm_dev_internal *d, dev_t dev,
346 struct mapped_device *md)
345{ 347{
346 static char *_claim_ptr = "I belong to device-mapper"; 348 static char *_claim_ptr = "I belong to device-mapper";
347 struct block_device *bdev; 349 struct block_device *bdev;
348 350
349 int r; 351 int r;
350 352
351 BUG_ON(d->bdev); 353 BUG_ON(d->dm_dev.bdev);
352 354
353 bdev = open_by_devnum(dev, d->mode); 355 bdev = open_by_devnum(dev, d->dm_dev.mode);
354 if (IS_ERR(bdev)) 356 if (IS_ERR(bdev))
355 return PTR_ERR(bdev); 357 return PTR_ERR(bdev);
356 r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md)); 358 r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md));
357 if (r) 359 if (r)
358 blkdev_put(bdev); 360 blkdev_put(bdev);
359 else 361 else
360 d->bdev = bdev; 362 d->dm_dev.bdev = bdev;
361 return r; 363 return r;
362} 364}
363 365
364/* 366/*
365 * Close a device that we've been using. 367 * Close a device that we've been using.
366 */ 368 */
367static void close_dev(struct dm_dev *d, struct mapped_device *md) 369static void close_dev(struct dm_dev_internal *d, struct mapped_device *md)
368{ 370{
369 if (!d->bdev) 371 if (!d->dm_dev.bdev)
370 return; 372 return;
371 373
372 bd_release_from_disk(d->bdev, dm_disk(md)); 374 bd_release_from_disk(d->dm_dev.bdev, dm_disk(md));
373 blkdev_put(d->bdev); 375 blkdev_put(d->dm_dev.bdev);
374 d->bdev = NULL; 376 d->dm_dev.bdev = NULL;
375} 377}
376 378
377/* 379/*
378 * If possible, this checks an area of a destination device is valid. 380 * If possible, this checks an area of a destination device is valid.
379 */ 381 */
380static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len) 382static int check_device_area(struct dm_dev_internal *dd, sector_t start,
383 sector_t len)
381{ 384{
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;
383 386
384 if (!dev_size) 387 if (!dev_size)
385 return 1; 388 return 1;
@@ -392,16 +395,17 @@ static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len)
392 * careful to leave things as they were if we fail to reopen the 395 * careful to leave things as they were if we fail to reopen the
393 * device. 396 * device.
394 */ 397 */
395static int upgrade_mode(struct dm_dev *dd, int new_mode, struct mapped_device *md) 398static int upgrade_mode(struct dm_dev_internal *dd, int new_mode,
399 struct mapped_device *md)
396{ 400{
397 int r; 401 int r;
398 struct dm_dev dd_copy; 402 struct dm_dev_internal dd_copy;
399 dev_t dev = dd->bdev->bd_dev; 403 dev_t dev = dd->dm_dev.bdev->bd_dev;
400 404
401 dd_copy = *dd; 405 dd_copy = *dd;
402 406
403 dd->mode |= new_mode; 407 dd->dm_dev.mode |= new_mode;
404 dd->bdev = NULL; 408 dd->dm_dev.bdev = NULL;
405 r = open_dev(dd, dev, md); 409 r = open_dev(dd, dev, md);
406 if (!r) 410 if (!r)
407 close_dev(&dd_copy, md); 411 close_dev(&dd_copy, md);
@@ -421,7 +425,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
421{ 425{
422 int r; 426 int r;
423 dev_t uninitialized_var(dev); 427 dev_t uninitialized_var(dev);
424 struct dm_dev *dd; 428 struct dm_dev_internal *dd;
425 unsigned int major, minor; 429 unsigned int major, minor;
426 430
427 BUG_ON(!t); 431 BUG_ON(!t);
@@ -443,20 +447,20 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
443 if (!dd) 447 if (!dd)
444 return -ENOMEM; 448 return -ENOMEM;
445 449
446 dd->mode = mode; 450 dd->dm_dev.mode = mode;
447 dd->bdev = NULL; 451 dd->dm_dev.bdev = NULL;
448 452
449 if ((r = open_dev(dd, dev, t->md))) { 453 if ((r = open_dev(dd, dev, t->md))) {
450 kfree(dd); 454 kfree(dd);
451 return r; 455 return r;
452 } 456 }
453 457
454 format_dev_t(dd->name, dev); 458 format_dev_t(dd->dm_dev.name, dev);
455 459
456 atomic_set(&dd->count, 0); 460 atomic_set(&dd->count, 0);
457 list_add(&dd->list, &t->devices); 461 list_add(&dd->list, &t->devices);
458 462
459 } else if (dd->mode != (mode | dd->mode)) { 463 } else if (dd->dm_dev.mode != (mode | dd->dm_dev.mode)) {
460 r = upgrade_mode(dd, mode, t->md); 464 r = upgrade_mode(dd, mode, t->md);
461 if (r) 465 if (r)
462 return r; 466 return r;
@@ -465,11 +469,11 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
465 469
466 if (!check_device_area(dd, start, len)) { 470 if (!check_device_area(dd, start, len)) {
467 DMWARN("device %s too small for target", path); 471 DMWARN("device %s too small for target", path);
468 dm_put_device(ti, dd); 472 dm_put_device(ti, &dd->dm_dev);
469 return -EINVAL; 473 return -EINVAL;
470 } 474 }
471 475
472 *result = dd; 476 *result = &dd->dm_dev;
473 477
474 return 0; 478 return 0;
475} 479}
@@ -540,8 +544,11 @@ int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
540/* 544/*
541 * Decrement a devices use count and remove it if necessary. 545 * Decrement a devices use count and remove it if necessary.
542 */ 546 */
543void dm_put_device(struct dm_target *ti, struct dm_dev *dd) 547void dm_put_device(struct dm_target *ti, struct dm_dev *d)
544{ 548{
549 struct dm_dev_internal *dd = container_of(d, struct dm_dev_internal,
550 dm_dev);
551
545 if (atomic_dec_and_test(&dd->count)) { 552 if (atomic_dec_and_test(&dd->count)) {
546 close_dev(dd, ti->table->md); 553 close_dev(dd, ti->table->md);
547 list_del(&dd->list); 554 list_del(&dd->list);
@@ -937,12 +944,12 @@ int dm_table_resume_targets(struct dm_table *t)
937 944
938int dm_table_any_congested(struct dm_table *t, int bdi_bits) 945int dm_table_any_congested(struct dm_table *t, int bdi_bits)
939{ 946{
940 struct dm_dev *dd; 947 struct dm_dev_internal *dd;
941 struct list_head *devices = dm_table_get_devices(t); 948 struct list_head *devices = dm_table_get_devices(t);
942 int r = 0; 949 int r = 0;
943 950
944 list_for_each_entry(dd, devices, list) { 951 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);
946 r |= bdi_congested(&q->backing_dev_info, bdi_bits); 953 r |= bdi_congested(&q->backing_dev_info, bdi_bits);
947 } 954 }
948 955
@@ -951,11 +958,11 @@ int dm_table_any_congested(struct dm_table *t, int bdi_bits)
951 958
952void dm_table_unplug_all(struct dm_table *t) 959void dm_table_unplug_all(struct dm_table *t)
953{ 960{
954 struct dm_dev *dd; 961 struct dm_dev_internal *dd;
955 struct list_head *devices = dm_table_get_devices(t); 962 struct list_head *devices = dm_table_get_devices(t);
956 963
957 list_for_each_entry(dd, devices, list) { 964 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);
959 966
960 blk_unplug(q); 967 blk_unplug(q);
961 } 968 }
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 1e59a0b0a78a..65f2f562220e 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -25,13 +25,10 @@
25/* 25/*
26 * List of devices that a metadevice uses and should open/close. 26 * List of devices that a metadevice uses and should open/close.
27 */ 27 */
28struct dm_dev { 28struct dm_dev_internal {
29 struct list_head list; 29 struct list_head list;
30
31 atomic_t count; 30 atomic_t count;
32 int mode; 31 struct dm_dev dm_dev;
33 struct block_device *bdev;
34 char name[16];
35}; 32};
36 33
37struct dm_table; 34struct dm_table;