patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / md / dm-table.c
1 /*
2  * Copyright (C) 2001 Sistina Software (UK) Limited.
3  *
4  * This file is released under the GPL.
5  */
6
7 #include "dm.h"
8
9 #include <linux/module.h>
10 #include <linux/vmalloc.h>
11 #include <linux/blkdev.h>
12 #include <linux/namei.h>
13 #include <linux/ctype.h>
14 #include <linux/slab.h>
15 #include <linux/interrupt.h>
16 #include <asm/atomic.h>
17
18 #define MAX_DEPTH 16
19 #define NODE_SIZE L1_CACHE_BYTES
20 #define KEYS_PER_NODE (NODE_SIZE / sizeof(sector_t))
21 #define CHILDREN_PER_NODE (KEYS_PER_NODE + 1)
22
23 struct dm_table {
24         atomic_t holders;
25
26         /* btree table */
27         unsigned int depth;
28         unsigned int counts[MAX_DEPTH]; /* in nodes */
29         sector_t *index[MAX_DEPTH];
30
31         unsigned int num_targets;
32         unsigned int num_allocated;
33         sector_t *highs;
34         struct dm_target *targets;
35
36         /*
37          * Indicates the rw permissions for the new logical
38          * device.  This should be a combination of FMODE_READ
39          * and FMODE_WRITE.
40          */
41         int mode;
42
43         /* a list of devices used by this table */
44         struct list_head devices;
45
46         /*
47          * These are optimistic limits taken from all the
48          * targets, some targets will need smaller limits.
49          */
50         struct io_restrictions limits;
51
52         /* events get handed up using this callback */
53         void (*event_fn)(void *);
54         void *event_context;
55 };
56
57 /*
58  * Similar to ceiling(log_size(n))
59  */
60 static unsigned int int_log(unsigned long n, unsigned long base)
61 {
62         int result = 0;
63
64         while (n > 1) {
65                 n = dm_div_up(n, base);
66                 result++;
67         }
68
69         return result;
70 }
71
72 /*
73  * Returns the minimum that is _not_ zero, unless both are zero.
74  */
75 #define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
76
77 /*
78  * Combine two io_restrictions, always taking the lower value.
79  */
80 static void combine_restrictions_low(struct io_restrictions *lhs,
81                                      struct io_restrictions *rhs)
82 {
83         lhs->max_sectors =
84                 min_not_zero(lhs->max_sectors, rhs->max_sectors);
85
86         lhs->max_phys_segments =
87                 min_not_zero(lhs->max_phys_segments, rhs->max_phys_segments);
88
89         lhs->max_hw_segments =
90                 min_not_zero(lhs->max_hw_segments, rhs->max_hw_segments);
91
92         lhs->hardsect_size = max(lhs->hardsect_size, rhs->hardsect_size);
93
94         lhs->max_segment_size =
95                 min_not_zero(lhs->max_segment_size, rhs->max_segment_size);
96
97         lhs->seg_boundary_mask =
98                 min_not_zero(lhs->seg_boundary_mask, rhs->seg_boundary_mask);
99 }
100
101 /*
102  * Calculate the index of the child node of the n'th node k'th key.
103  */
104 static inline unsigned int get_child(unsigned int n, unsigned int k)
105 {
106         return (n * CHILDREN_PER_NODE) + k;
107 }
108
109 /*
110  * Return the n'th node of level l from table t.
111  */
112 static inline sector_t *get_node(struct dm_table *t,
113                                  unsigned int l, unsigned int n)
114 {
115         return t->index[l] + (n * KEYS_PER_NODE);
116 }
117
118 /*
119  * Return the highest key that you could lookup from the n'th
120  * node on level l of the btree.
121  */
122 static sector_t high(struct dm_table *t, unsigned int l, unsigned int n)
123 {
124         for (; l < t->depth - 1; l++)
125                 n = get_child(n, CHILDREN_PER_NODE - 1);
126
127         if (n >= t->counts[l])
128                 return (sector_t) - 1;
129
130         return get_node(t, l, n)[KEYS_PER_NODE - 1];
131 }
132
133 /*
134  * Fills in a level of the btree based on the highs of the level
135  * below it.
136  */
137 static int setup_btree_index(unsigned int l, struct dm_table *t)
138 {
139         unsigned int n, k;
140         sector_t *node;
141
142         for (n = 0U; n < t->counts[l]; n++) {
143                 node = get_node(t, l, n);
144
145                 for (k = 0U; k < KEYS_PER_NODE; k++)
146                         node[k] = high(t, l + 1, get_child(n, k));
147         }
148
149         return 0;
150 }
151
152 void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size)
153 {
154         unsigned long size;
155         void *addr;
156
157         /*
158          * Check that we're not going to overflow.
159          */
160         if (nmemb > (ULONG_MAX / elem_size))
161                 return NULL;
162
163         size = nmemb * elem_size;
164         addr = vmalloc(size);
165         if (addr)
166                 memset(addr, 0, size);
167
168         return addr;
169 }
170
171 /*
172  * highs, and targets are managed as dynamic arrays during a
173  * table load.
174  */
175 static int alloc_targets(struct dm_table *t, unsigned int num)
176 {
177         sector_t *n_highs;
178         struct dm_target *n_targets;
179         int n = t->num_targets;
180
181         /*
182          * Allocate both the target array and offset array at once.
183          */
184         n_highs = (sector_t *) dm_vcalloc(num, sizeof(struct dm_target) +
185                                           sizeof(sector_t));
186         if (!n_highs)
187                 return -ENOMEM;
188
189         n_targets = (struct dm_target *) (n_highs + num);
190
191         if (n) {
192                 memcpy(n_highs, t->highs, sizeof(*n_highs) * n);
193                 memcpy(n_targets, t->targets, sizeof(*n_targets) * n);
194         }
195
196         memset(n_highs + n, -1, sizeof(*n_highs) * (num - n));
197         vfree(t->highs);
198
199         t->num_allocated = num;
200         t->highs = n_highs;
201         t->targets = n_targets;
202
203         return 0;
204 }
205
206 int dm_table_create(struct dm_table **result, int mode, unsigned num_targets)
207 {
208         struct dm_table *t = kmalloc(sizeof(*t), GFP_KERNEL);
209
210         if (!t)
211                 return -ENOMEM;
212
213         memset(t, 0, sizeof(*t));
214         INIT_LIST_HEAD(&t->devices);
215         atomic_set(&t->holders, 1);
216
217         if (!num_targets)
218                 num_targets = KEYS_PER_NODE;
219
220         num_targets = dm_round_up(num_targets, KEYS_PER_NODE);
221
222         if (alloc_targets(t, num_targets)) {
223                 kfree(t);
224                 t = NULL;
225                 return -ENOMEM;
226         }
227
228         t->mode = mode;
229         *result = t;
230         return 0;
231 }
232
233 static void free_devices(struct list_head *devices)
234 {
235         struct list_head *tmp, *next;
236
237         for (tmp = devices->next; tmp != devices; tmp = next) {
238                 struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
239                 next = tmp->next;
240                 kfree(dd);
241         }
242 }
243
244 void table_destroy(struct dm_table *t)
245 {
246         unsigned int i;
247
248         /* free the indexes (see dm_table_complete) */
249         if (t->depth >= 2)
250                 vfree(t->index[t->depth - 2]);
251
252         /* free the targets */
253         for (i = 0; i < t->num_targets; i++) {
254                 struct dm_target *tgt = t->targets + i;
255
256                 if (tgt->type->dtr)
257                         tgt->type->dtr(tgt);
258
259                 dm_put_target_type(tgt->type);
260         }
261
262         vfree(t->highs);
263
264         /* free the device list */
265         if (t->devices.next != &t->devices) {
266                 DMWARN("devices still present during destroy: "
267                        "dm_table_remove_device calls missing");
268
269                 free_devices(&t->devices);
270         }
271
272         kfree(t);
273 }
274
275 void dm_table_get(struct dm_table *t)
276 {
277         atomic_inc(&t->holders);
278 }
279
280 void dm_table_put(struct dm_table *t)
281 {
282         if (!t)
283                 return;
284
285         if (atomic_dec_and_test(&t->holders))
286                 table_destroy(t);
287 }
288
289 /*
290  * Checks to see if we need to extend highs or targets.
291  */
292 static inline int check_space(struct dm_table *t)
293 {
294         if (t->num_targets >= t->num_allocated)
295                 return alloc_targets(t, t->num_allocated * 2);
296
297         return 0;
298 }
299
300 /*
301  * Convert a device path to a dev_t.
302  */
303 static int lookup_device(const char *path, dev_t *dev)
304 {
305         int r;
306         struct nameidata nd;
307         struct inode *inode;
308
309         if ((r = path_lookup(path, LOOKUP_FOLLOW, &nd)))
310                 return r;
311
312         inode = nd.dentry->d_inode;
313         if (!inode) {
314                 r = -ENOENT;
315                 goto out;
316         }
317
318         if (!S_ISBLK(inode->i_mode)) {
319                 r = -ENOTBLK;
320                 goto out;
321         }
322
323         *dev = inode->i_rdev;
324
325  out:
326         path_release(&nd);
327         return r;
328 }
329
330 /*
331  * See if we've already got a device in the list.
332  */
333 static struct dm_dev *find_device(struct list_head *l, dev_t dev)
334 {
335         struct dm_dev *dd;
336
337         list_for_each_entry (dd, l, list)
338                 if (dd->bdev->bd_dev == dev)
339                         return dd;
340
341         return NULL;
342 }
343
344 /*
345  * Open a device so we can use it as a map destination.
346  */
347 static int open_dev(struct dm_dev *d, dev_t dev)
348 {
349         static char *_claim_ptr = "I belong to device-mapper";
350         struct block_device *bdev;
351
352         int r;
353
354         if (d->bdev)
355                 BUG();
356
357         bdev = open_by_devnum(dev, d->mode);
358         if (IS_ERR(bdev))
359                 return PTR_ERR(bdev);
360         r = bd_claim(bdev, _claim_ptr);
361         if (r)
362                 blkdev_put(bdev);
363         else
364                 d->bdev = bdev;
365         return r;
366 }
367
368 /*
369  * Close a device that we've been using.
370  */
371 static void close_dev(struct dm_dev *d)
372 {
373         if (!d->bdev)
374                 return;
375
376         bd_release(d->bdev);
377         blkdev_put(d->bdev);
378         d->bdev = NULL;
379 }
380
381 /*
382  * If possible (ie. blk_size[major] is set), this checks an area
383  * of a destination device is valid.
384  */
385 static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len)
386 {
387         sector_t dev_size;
388         dev_size = dd->bdev->bd_inode->i_size >> SECTOR_SHIFT;
389         return ((start < dev_size) && (len <= (dev_size - start)));
390 }
391
392 /*
393  * This upgrades the mode on an already open dm_dev.  Being
394  * careful to leave things as they were if we fail to reopen the
395  * device.
396  */
397 static int upgrade_mode(struct dm_dev *dd, int new_mode)
398 {
399         int r;
400         struct dm_dev dd_copy;
401         dev_t dev = dd->bdev->bd_dev;
402
403         memcpy(&dd_copy, dd, sizeof(dd_copy));
404
405         dd->mode |= new_mode;
406         dd->bdev = NULL;
407         r = open_dev(dd, dev);
408         if (!r)
409                 close_dev(&dd_copy);
410         else
411                 memcpy(dd, &dd_copy, sizeof(dd_copy));
412
413         return r;
414 }
415
416 /*
417  * Add a device to the list, or just increment the usage count if
418  * it's already present.
419  */
420 static int __table_get_device(struct dm_table *t, struct dm_target *ti,
421                               const char *path, sector_t start, sector_t len,
422                               int mode, struct dm_dev **result)
423 {
424         int r;
425         dev_t dev;
426         struct dm_dev *dd;
427         unsigned int major, minor;
428
429         if (!t)
430                 BUG();
431
432         if (sscanf(path, "%u:%u", &major, &minor) == 2) {
433                 /* Extract the major/minor numbers */
434                 dev = MKDEV(major, minor);
435                 if (MAJOR(dev) != major || MINOR(dev) != minor)
436                         return -EOVERFLOW;
437         } else {
438                 /* convert the path to a device */
439                 if ((r = lookup_device(path, &dev)))
440                         return r;
441         }
442
443         dd = find_device(&t->devices, dev);
444         if (!dd) {
445                 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
446                 if (!dd)
447                         return -ENOMEM;
448
449                 dd->mode = mode;
450                 dd->bdev = NULL;
451
452                 if ((r = open_dev(dd, dev))) {
453                         kfree(dd);
454                         return r;
455                 }
456
457                 atomic_set(&dd->count, 0);
458                 list_add(&dd->list, &t->devices);
459
460         } else if (dd->mode != (mode | dd->mode)) {
461                 r = upgrade_mode(dd, mode);
462                 if (r)
463                         return r;
464         }
465         atomic_inc(&dd->count);
466
467         if (!check_device_area(dd, start, len)) {
468                 DMWARN("device %s too small for target", path);
469                 dm_put_device(ti, dd);
470                 return -EINVAL;
471         }
472
473         *result = dd;
474
475         return 0;
476 }
477
478
479 int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
480                   sector_t len, int mode, struct dm_dev **result)
481 {
482         int r = __table_get_device(ti->table, ti, path,
483                                    start, len, mode, result);
484         if (!r) {
485                 request_queue_t *q = bdev_get_queue((*result)->bdev);
486                 struct io_restrictions *rs = &ti->limits;
487
488                 /*
489                  * Combine the device limits low.
490                  *
491                  * FIXME: if we move an io_restriction struct
492                  *        into q this would just be a call to
493                  *        combine_restrictions_low()
494                  */
495                 rs->max_sectors =
496                         min_not_zero(rs->max_sectors, q->max_sectors);
497
498                 /* FIXME: Device-Mapper on top of RAID-0 breaks because DM
499                  *        currently doesn't honor MD's merge_bvec_fn routine.
500                  *        In this case, we'll force DM to use PAGE_SIZE or
501                  *        smaller I/O, just to be safe. A better fix is in the
502                  *        works, but add this for the time being so it will at
503                  *        least operate correctly.
504                  */
505                 if (q->merge_bvec_fn)
506                         rs->max_sectors =
507                                 min_not_zero(rs->max_sectors,
508                                              (unsigned short)(PAGE_SIZE >> 9));
509
510                 rs->max_phys_segments =
511                         min_not_zero(rs->max_phys_segments,
512                                      q->max_phys_segments);
513
514                 rs->max_hw_segments =
515                         min_not_zero(rs->max_hw_segments, q->max_hw_segments);
516
517                 rs->hardsect_size = max(rs->hardsect_size, q->hardsect_size);
518
519                 rs->max_segment_size =
520                         min_not_zero(rs->max_segment_size, q->max_segment_size);
521
522                 rs->seg_boundary_mask =
523                         min_not_zero(rs->seg_boundary_mask,
524                                      q->seg_boundary_mask);
525         }
526
527         return r;
528 }
529
530 /*
531  * Decrement a devices use count and remove it if necessary.
532  */
533 void dm_put_device(struct dm_target *ti, struct dm_dev *dd)
534 {
535         if (atomic_dec_and_test(&dd->count)) {
536                 close_dev(dd);
537                 list_del(&dd->list);
538                 kfree(dd);
539         }
540 }
541
542 /*
543  * Checks to see if the target joins onto the end of the table.
544  */
545 static int adjoin(struct dm_table *table, struct dm_target *ti)
546 {
547         struct dm_target *prev;
548
549         if (!table->num_targets)
550                 return !ti->begin;
551
552         prev = &table->targets[table->num_targets - 1];
553         return (ti->begin == (prev->begin + prev->len));
554 }
555
556 /*
557  * Used to dynamically allocate the arg array.
558  */
559 static char **realloc_argv(unsigned *array_size, char **old_argv)
560 {
561         char **argv;
562         unsigned new_size;
563
564         new_size = *array_size ? *array_size * 2 : 64;
565         argv = kmalloc(new_size * sizeof(*argv), GFP_KERNEL);
566         if (argv) {
567                 memcpy(argv, old_argv, *array_size * sizeof(*argv));
568                 *array_size = new_size;
569         }
570
571         kfree(old_argv);
572         return argv;
573 }
574
575 /*
576  * Destructively splits up the argument list to pass to ctr.
577  */
578 static int split_args(int *argc, char ***argvp, char *input)
579 {
580         char *start, *end = input, *out, **argv = NULL;
581         unsigned array_size = 0;
582
583         *argc = 0;
584         argv = realloc_argv(&array_size, argv);
585         if (!argv)
586                 return -ENOMEM;
587
588         while (1) {
589                 start = end;
590
591                 /* Skip whitespace */
592                 while (*start && isspace(*start))
593                         start++;
594
595                 if (!*start)
596                         break;  /* success, we hit the end */
597
598                 /* 'out' is used to remove any back-quotes */
599                 end = out = start;
600                 while (*end) {
601                         /* Everything apart from '\0' can be quoted */
602                         if (*end == '\\' && *(end + 1)) {
603                                 *out++ = *(end + 1);
604                                 end += 2;
605                                 continue;
606                         }
607
608                         if (isspace(*end))
609                                 break;  /* end of token */
610
611                         *out++ = *end++;
612                 }
613
614                 /* have we already filled the array ? */
615                 if ((*argc + 1) > array_size) {
616                         argv = realloc_argv(&array_size, argv);
617                         if (!argv)
618                                 return -ENOMEM;
619                 }
620
621                 /* we know this is whitespace */
622                 if (*end)
623                         end++;
624
625                 /* terminate the string and put it in the array */
626                 *out = '\0';
627                 argv[*argc] = start;
628                 (*argc)++;
629         }
630
631         *argvp = argv;
632         return 0;
633 }
634
635 static void check_for_valid_limits(struct io_restrictions *rs)
636 {
637         if (!rs->max_sectors)
638                 rs->max_sectors = MAX_SECTORS;
639         if (!rs->max_phys_segments)
640                 rs->max_phys_segments = MAX_PHYS_SEGMENTS;
641         if (!rs->max_hw_segments)
642                 rs->max_hw_segments = MAX_HW_SEGMENTS;
643         if (!rs->hardsect_size)
644                 rs->hardsect_size = 1 << SECTOR_SHIFT;
645         if (!rs->max_segment_size)
646                 rs->max_segment_size = MAX_SEGMENT_SIZE;
647         if (!rs->seg_boundary_mask)
648                 rs->seg_boundary_mask = -1;
649 }
650
651 int dm_table_add_target(struct dm_table *t, const char *type,
652                         sector_t start, sector_t len, char *params)
653 {
654         int r = -EINVAL, argc;
655         char **argv;
656         struct dm_target *tgt;
657
658         if ((r = check_space(t)))
659                 return r;
660
661         tgt = t->targets + t->num_targets;
662         memset(tgt, 0, sizeof(*tgt));
663
664         if (!len) {
665                 tgt->error = "zero-length target";
666                 DMERR(": %s\n", tgt->error);
667                 return -EINVAL;
668         }
669
670         tgt->type = dm_get_target_type(type);
671         if (!tgt->type) {
672                 tgt->error = "unknown target type";
673                 DMERR(": %s\n", tgt->error);
674                 return -EINVAL;
675         }
676
677         tgt->table = t;
678         tgt->begin = start;
679         tgt->len = len;
680         tgt->error = "Unknown error";
681
682         /*
683          * Does this target adjoin the previous one ?
684          */
685         if (!adjoin(t, tgt)) {
686                 tgt->error = "Gap in table";
687                 r = -EINVAL;
688                 goto bad;
689         }
690
691         r = split_args(&argc, &argv, params);
692         if (r) {
693                 tgt->error = "couldn't split parameters (insufficient memory)";
694                 goto bad;
695         }
696
697         r = tgt->type->ctr(tgt, argc, argv);
698         kfree(argv);
699         if (r)
700                 goto bad;
701
702         t->highs[t->num_targets++] = tgt->begin + tgt->len - 1;
703
704         /* FIXME: the plan is to combine high here and then have
705          * the merge fn apply the target level restrictions. */
706         combine_restrictions_low(&t->limits, &tgt->limits);
707         return 0;
708
709  bad:
710         DMERR(": %s\n", tgt->error);
711         dm_put_target_type(tgt->type);
712         return r;
713 }
714
715 static int setup_indexes(struct dm_table *t)
716 {
717         int i;
718         unsigned int total = 0;
719         sector_t *indexes;
720
721         /* allocate the space for *all* the indexes */
722         for (i = t->depth - 2; i >= 0; i--) {
723                 t->counts[i] = dm_div_up(t->counts[i + 1], CHILDREN_PER_NODE);
724                 total += t->counts[i];
725         }
726
727         indexes = (sector_t *) dm_vcalloc(total, (unsigned long) NODE_SIZE);
728         if (!indexes)
729                 return -ENOMEM;
730
731         /* set up internal nodes, bottom-up */
732         for (i = t->depth - 2, total = 0; i >= 0; i--) {
733                 t->index[i] = indexes;
734                 indexes += (KEYS_PER_NODE * t->counts[i]);
735                 setup_btree_index(i, t);
736         }
737
738         return 0;
739 }
740
741 /*
742  * Builds the btree to index the map.
743  */
744 int dm_table_complete(struct dm_table *t)
745 {
746         int r = 0;
747         unsigned int leaf_nodes;
748
749         check_for_valid_limits(&t->limits);
750
751         /* how many indexes will the btree have ? */
752         leaf_nodes = dm_div_up(t->num_targets, KEYS_PER_NODE);
753         t->depth = 1 + int_log(leaf_nodes, CHILDREN_PER_NODE);
754
755         /* leaf layer has already been set up */
756         t->counts[t->depth - 1] = leaf_nodes;
757         t->index[t->depth - 1] = t->highs;
758
759         if (t->depth >= 2)
760                 r = setup_indexes(t);
761
762         return r;
763 }
764
765 static DECLARE_MUTEX(_event_lock);
766 void dm_table_event_callback(struct dm_table *t,
767                              void (*fn)(void *), void *context)
768 {
769         down(&_event_lock);
770         t->event_fn = fn;
771         t->event_context = context;
772         up(&_event_lock);
773 }
774
775 void dm_table_event(struct dm_table *t)
776 {
777         /*
778          * You can no longer call dm_table_event() from interrupt
779          * context, use a bottom half instead.
780          */
781         BUG_ON(in_interrupt());
782
783         down(&_event_lock);
784         if (t->event_fn)
785                 t->event_fn(t->event_context);
786         up(&_event_lock);
787 }
788
789 sector_t dm_table_get_size(struct dm_table *t)
790 {
791         return t->num_targets ? (t->highs[t->num_targets - 1] + 1) : 0;
792 }
793
794 struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index)
795 {
796         if (index > t->num_targets)
797                 return NULL;
798
799         return t->targets + index;
800 }
801
802 /*
803  * Search the btree for the correct target.
804  */
805 struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector)
806 {
807         unsigned int l, n = 0, k = 0;
808         sector_t *node;
809
810         for (l = 0; l < t->depth; l++) {
811                 n = get_child(n, k);
812                 node = get_node(t, l, n);
813
814                 for (k = 0; k < KEYS_PER_NODE; k++)
815                         if (node[k] >= sector)
816                                 break;
817         }
818
819         return &t->targets[(KEYS_PER_NODE * n) + k];
820 }
821
822 void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q)
823 {
824         /*
825          * Make sure we obey the optimistic sub devices
826          * restrictions.
827          */
828         q->max_sectors = t->limits.max_sectors;
829         q->max_phys_segments = t->limits.max_phys_segments;
830         q->max_hw_segments = t->limits.max_hw_segments;
831         q->hardsect_size = t->limits.hardsect_size;
832         q->max_segment_size = t->limits.max_segment_size;
833         q->seg_boundary_mask = t->limits.seg_boundary_mask;
834 }
835
836 unsigned int dm_table_get_num_targets(struct dm_table *t)
837 {
838         return t->num_targets;
839 }
840
841 struct list_head *dm_table_get_devices(struct dm_table *t)
842 {
843         return &t->devices;
844 }
845
846 int dm_table_get_mode(struct dm_table *t)
847 {
848         return t->mode;
849 }
850
851 void dm_table_suspend_targets(struct dm_table *t)
852 {
853         int i;
854
855         for (i = 0; i < t->num_targets; i++) {
856                 struct dm_target *ti = t->targets + i;
857
858                 if (ti->type->suspend)
859                         ti->type->suspend(ti);
860         }
861 }
862
863 void dm_table_resume_targets(struct dm_table *t)
864 {
865         int i;
866
867         for (i = 0; i < t->num_targets; i++) {
868                 struct dm_target *ti = t->targets + i;
869
870                 if (ti->type->resume)
871                         ti->type->resume(ti);
872         }
873 }
874
875 int dm_table_any_congested(struct dm_table *t, int bdi_bits)
876 {
877         struct list_head *d, *devices;
878         int r = 0;
879
880         devices = dm_table_get_devices(t);
881         for (d = devices->next; d != devices; d = d->next) {
882                 struct dm_dev *dd = list_entry(d, struct dm_dev, list);
883                 request_queue_t *q = bdev_get_queue(dd->bdev);
884                 r |= bdi_congested(&q->backing_dev_info, bdi_bits);
885         }
886
887         return r;
888 }
889
890 void dm_table_unplug_all(struct dm_table *t)
891 {
892         struct list_head *d, *devices = dm_table_get_devices(t);
893
894         for (d = devices->next; d != devices; d = d->next) {
895                 struct dm_dev *dd = list_entry(d, struct dm_dev, list);
896                 request_queue_t *q = bdev_get_queue(dd->bdev);
897
898                 if (q->unplug_fn)
899                         q->unplug_fn(q);
900         }
901 }
902
903 EXPORT_SYMBOL(dm_vcalloc);
904 EXPORT_SYMBOL(dm_get_device);
905 EXPORT_SYMBOL(dm_put_device);
906 EXPORT_SYMBOL(dm_table_event);
907 EXPORT_SYMBOL(dm_table_get_mode);
908 EXPORT_SYMBOL(dm_table_put);
909 EXPORT_SYMBOL(dm_table_get);
910 EXPORT_SYMBOL(dm_table_unplug_all);