Commit 7bc3447b692185c5ea78bee93d0ef1dee2fd7ce7

Authored by Milan Broz
Committed by Alasdair G Kergon
1 parent f6fccb1213

dm: linear add merge

This patch implements biovec merge function for linear target.

If the underlying device has merge function defined, call it.
If not, keep precomputed value.

Signed-off-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

Showing 1 changed file with 33 additions and 5 deletions Side-by-side Diff

drivers/md/dm-linear.c
... ... @@ -69,14 +69,26 @@
69 69 kfree(lc);
70 70 }
71 71  
72   -static int linear_map(struct dm_target *ti, struct bio *bio,
73   - union map_info *map_context)
  72 +static sector_t linear_map_sector(struct dm_target *ti, sector_t bi_sector)
74 73 {
75   - struct linear_c *lc = (struct linear_c *) ti->private;
  74 + struct linear_c *lc = ti->private;
76 75  
  76 + return lc->start + (bi_sector - ti->begin);
  77 +}
  78 +
  79 +static void linear_map_bio(struct dm_target *ti, struct bio *bio)
  80 +{
  81 + struct linear_c *lc = ti->private;
  82 +
77 83 bio->bi_bdev = lc->dev->bdev;
78   - bio->bi_sector = lc->start + (bio->bi_sector - ti->begin);
  84 + bio->bi_sector = linear_map_sector(ti, bio->bi_sector);
  85 +}
79 86  
  87 +static int linear_map(struct dm_target *ti, struct bio *bio,
  88 + union map_info *map_context)
  89 +{
  90 + linear_map_bio(ti, bio);
  91 +
80 92 return DM_MAPIO_REMAPPED;
81 93 }
82 94  
83 95  
84 96  
... ... @@ -114,15 +126,31 @@
114 126 return blkdev_driver_ioctl(bdev->bd_inode, &fake_file, bdev->bd_disk, cmd, arg);
115 127 }
116 128  
  129 +static int linear_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
  130 + struct bio_vec *biovec, int max_size)
  131 +{
  132 + struct linear_c *lc = ti->private;
  133 + struct request_queue *q = bdev_get_queue(lc->dev->bdev);
  134 +
  135 + if (!q->merge_bvec_fn)
  136 + return max_size;
  137 +
  138 + bvm->bi_bdev = lc->dev->bdev;
  139 + bvm->bi_sector = linear_map_sector(ti, bvm->bi_sector);
  140 +
  141 + return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
  142 +}
  143 +
117 144 static struct target_type linear_target = {
118 145 .name = "linear",
119   - .version= {1, 0, 2},
  146 + .version= {1, 0, 3},
120 147 .module = THIS_MODULE,
121 148 .ctr = linear_ctr,
122 149 .dtr = linear_dtr,
123 150 .map = linear_map,
124 151 .status = linear_status,
125 152 .ioctl = linear_ioctl,
  153 + .merge = linear_merge,
126 154 };
127 155  
128 156 int __init dm_linear_init(void)