The DRBD driver
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / block / drbd / drbd_wrappers.h
1 #ifndef _DRBD_WRAPPERS_H
2 #define _DRBD_WRAPPERS_H
3
4 #include <linux/ctype.h>
5 #include <linux/mm.h>
6
7 /* see get_sb_bdev and bd_claim */
8 extern char *drbd_sec_holder;
9
10 /* sets the number of 512 byte sectors of our virtual device */
11 static inline void drbd_set_my_capacity(struct drbd_conf *mdev,
12 sector_t size)
13 {
14 /* set_capacity(mdev->this_bdev->bd_disk, size); */
15 set_capacity(mdev->vdisk, size);
16 mdev->this_bdev->bd_inode->i_size = (loff_t)size << 9;
17 }
18
19 #define drbd_bio_uptodate(bio) bio_flagged(bio, BIO_UPTODATE)
20
21 static inline int drbd_bio_has_active_page(struct bio *bio)
22 {
23 struct bio_vec *bvec;
24 int i;
25
26 __bio_for_each_segment(bvec, bio, i, 0) {
27 if (page_count(bvec->bv_page) > 1)
28 return 1;
29 }
30
31 return 0;
32 }
33
34 /* bi_end_io handlers */
35 extern void drbd_md_io_complete(struct bio *bio, int error);
36 extern void drbd_endio_read_sec(struct bio *bio, int error);
37 extern void drbd_endio_write_sec(struct bio *bio, int error);
38 extern void drbd_endio_pri(struct bio *bio, int error);
39
40 /*
41 * used to submit our private bio
42 */
43 static inline void drbd_generic_make_request(struct drbd_conf *mdev,
44 int fault_type, struct bio *bio)
45 {
46 __release(local);
47 if (!bio->bi_bdev) {
48 printk(KERN_ERR "drbd%d: drbd_generic_make_request: "
49 "bio->bi_bdev == NULL\n",
50 mdev_to_minor(mdev));
51 dump_stack();
52 bio_endio(bio, -ENODEV);
53 return;
54 }
55
56 if (FAULT_ACTIVE(mdev, fault_type))
57 bio_endio(bio, -EIO);
58 else
59 generic_make_request(bio);
60 }
61
62 static inline void drbd_plug_device(struct drbd_conf *mdev)
63 {
64 struct request_queue *q;
65 q = bdev_get_queue(mdev->this_bdev);
66
67 spin_lock_irq(q->queue_lock);
68
69 /* XXX the check on !blk_queue_plugged is redundant,
70 * implicitly checked in blk_plug_device */
71
72 if (!blk_queue_plugged(q)) {
73 blk_plug_device(q);
74 del_timer(&q->unplug_timer);
75 /* unplugging should not happen automatically... */
76 }
77 spin_unlock_irq(q->queue_lock);
78 }
79
80 static inline int drbd_crypto_is_hash(struct crypto_tfm *tfm)
81 {
82 return (crypto_tfm_alg_type(tfm) & CRYPTO_ALG_TYPE_HASH_MASK)
83 == CRYPTO_ALG_TYPE_HASH;
84 }
85
86 #ifndef __CHECKER__
87 # undef __cond_lock
88 # define __cond_lock(x,c) (c)
89 #endif
90
91 #endif