Lines Matching full:ec

37 static inline sector_t __sector_to_block(struct ebs_c *ec, sector_t sector)  in __sector_to_block()  argument
39 return sector >> ec->block_shift; in __sector_to_block()
48 static inline unsigned int __nr_blocks(struct ebs_c *ec, struct bio *bio) in __nr_blocks() argument
50 sector_t end_sector = __block_mod(bio->bi_iter.bi_sector, ec->u_bs) + bio_sectors(bio); in __nr_blocks()
52 return __sector_to_block(ec, end_sector) + (__block_mod(end_sector, ec->u_bs) ? 1 : 0); in __nr_blocks()
65 static int __ebs_rw_bvec(struct ebs_c *ec, enum req_op op, struct bio_vec *bv, in __ebs_rw_bvec() argument
72 unsigned int buf_off = to_bytes(__block_mod(iter->bi_sector, ec->u_bs)); in __ebs_rw_bvec()
73 sector_t block = __sector_to_block(ec, iter->bi_sector); in __ebs_rw_bvec()
83 cur_len = min(dm_bufio_get_block_size(ec->bufio) - buf_off, bv_len); in __ebs_rw_bvec()
86 if (op == REQ_OP_READ || buf_off || bv_len < dm_bufio_get_block_size(ec->bufio)) in __ebs_rw_bvec()
87 ba = dm_bufio_read(ec->bufio, block, &b); in __ebs_rw_bvec()
89 ba = dm_bufio_new(ec->bufio, block, &b); in __ebs_rw_bvec()
122 static int __ebs_rw_bio(struct ebs_c *ec, enum req_op op, struct bio *bio) in __ebs_rw_bio() argument
129 rr = __ebs_rw_bvec(ec, op, &bv, &iter); in __ebs_rw_bio()
143 static int __ebs_discard_bio(struct ebs_c *ec, struct bio *bio) in __ebs_discard_bio() argument
147 block = __sector_to_block(ec, sector); in __ebs_discard_bio()
148 blocks = __nr_blocks(ec, bio); in __ebs_discard_bio()
154 if (__block_mod(sector, ec->u_bs)) { in __ebs_discard_bio()
160 if (blocks && __block_mod(bio_end_sector(bio), ec->u_bs)) in __ebs_discard_bio()
163 return blocks ? dm_bufio_issue_discard(ec->bufio, block, blocks) : 0; in __ebs_discard_bio()
167 static void __ebs_forget_bio(struct ebs_c *ec, struct bio *bio) in __ebs_forget_bio() argument
171 blocks = __nr_blocks(ec, bio); in __ebs_forget_bio()
173 dm_bufio_forget_buffers(ec->bufio, __sector_to_block(ec, sector), blocks); in __ebs_forget_bio()
182 struct ebs_c *ec = container_of(ws, struct ebs_c, ws); in __ebs_process_bios() local
188 spin_lock_irq(&ec->lock); in __ebs_process_bios()
189 bios = ec->bios_in; in __ebs_process_bios()
190 bio_list_init(&ec->bios_in); in __ebs_process_bios()
191 spin_unlock_irq(&ec->lock); in __ebs_process_bios()
195 block1 = __sector_to_block(ec, bio->bi_iter.bi_sector); in __ebs_process_bios()
197 dm_bufio_prefetch(ec->bufio, block1, __nr_blocks(ec, bio)); in __ebs_process_bios()
199 block2 = __sector_to_block(ec, bio_end_sector(bio)); in __ebs_process_bios()
200 if (__block_mod(bio->bi_iter.bi_sector, ec->u_bs)) in __ebs_process_bios()
201 dm_bufio_prefetch(ec->bufio, block1, 1); in __ebs_process_bios()
202 if (__block_mod(bio_end_sector(bio), ec->u_bs) && block2 != block1) in __ebs_process_bios()
203 dm_bufio_prefetch(ec->bufio, block2, 1); in __ebs_process_bios()
210 r = __ebs_rw_bio(ec, REQ_OP_READ, bio); in __ebs_process_bios()
213 r = __ebs_rw_bio(ec, REQ_OP_WRITE, bio); in __ebs_process_bios()
215 __ebs_forget_bio(ec, bio); in __ebs_process_bios()
216 r = __ebs_discard_bio(ec, bio); in __ebs_process_bios()
227 r = write ? dm_bufio_write_dirty_buffers(ec->bufio) : 0; in __ebs_process_bios()
253 struct ebs_c *ec; in ebs_ctr() local
260 ec = ti->private = kzalloc(sizeof(*ec), GFP_KERNEL); in ebs_ctr()
261 if (!ec) { in ebs_ctr()
273 ec->start = tmp; in ebs_ctr()
281 ec->e_bs = tmp1; in ebs_ctr()
288 ec->u_bs = tmp1; in ebs_ctr()
289 ec->u_bs_set = true; in ebs_ctr()
291 ec->u_bs_set = false; in ebs_ctr()
293 r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &ec->dev); in ebs_ctr()
296 ec->dev = NULL; in ebs_ctr()
301 if (!ec->u_bs_set) { in ebs_ctr()
302 ec->u_bs = to_sector(bdev_logical_block_size(ec->dev->bdev)); in ebs_ctr()
303 if (!__ebs_check_bs(ec->u_bs)) { in ebs_ctr()
309 if (!ec->u_bs_set && ec->e_bs == ec->u_bs) in ebs_ctr()
312 if (__block_mod(ec->start, ec->u_bs)) { in ebs_ctr()
317 ec->bufio = dm_bufio_client_create(ec->dev->bdev, to_bytes(ec->u_bs), 1, in ebs_ctr()
319 if (IS_ERR(ec->bufio)) { in ebs_ctr()
321 r = PTR_ERR(ec->bufio); in ebs_ctr()
322 ec->bufio = NULL; in ebs_ctr()
326 ec->wq = alloc_ordered_workqueue("dm-" DM_MSG_PREFIX, WQ_MEM_RECLAIM); in ebs_ctr()
327 if (!ec->wq) { in ebs_ctr()
333 ec->block_shift = __ffs(ec->u_bs); in ebs_ctr()
334 INIT_WORK(&ec->ws, &__ebs_process_bios); in ebs_ctr()
335 bio_list_init(&ec->bios_in); in ebs_ctr()
336 spin_lock_init(&ec->lock); in ebs_ctr()
350 struct ebs_c *ec = ti->private; in ebs_dtr() local
352 if (ec->wq) in ebs_dtr()
353 destroy_workqueue(ec->wq); in ebs_dtr()
354 if (ec->bufio) in ebs_dtr()
355 dm_bufio_client_destroy(ec->bufio); in ebs_dtr()
356 if (ec->dev) in ebs_dtr()
357 dm_put_device(ti, ec->dev); in ebs_dtr()
358 kfree(ec); in ebs_dtr()
363 struct ebs_c *ec = ti->private; in ebs_map() local
365 bio_set_dev(bio, ec->dev->bdev); in ebs_map()
366 bio->bi_iter.bi_sector = ec->start + dm_target_offset(ti, bio->bi_iter.bi_sector); in ebs_map()
375 if (likely(__block_mod(bio->bi_iter.bi_sector, ec->u_bs) || in ebs_map()
376 __block_mod(bio_end_sector(bio), ec->u_bs) || in ebs_map()
377 ec->e_bs == ec->u_bs)) { in ebs_map()
378 spin_lock_irq(&ec->lock); in ebs_map()
379 bio_list_add(&ec->bios_in, bio); in ebs_map()
380 spin_unlock_irq(&ec->lock); in ebs_map()
382 queue_work(ec->wq, &ec->ws); in ebs_map()
388 __ebs_forget_bio(ec, bio); in ebs_map()
396 struct ebs_c *ec = ti->private; in ebs_status() local
403 snprintf(result, maxlen, ec->u_bs_set ? "%s %llu %u %u" : "%s %llu %u", in ebs_status()
404 ec->dev->name, (unsigned long long) ec->start, ec->e_bs, ec->u_bs); in ebs_status()
414 struct ebs_c *ec = ti->private; in ebs_prepare_ioctl() local
415 struct dm_dev *dev = ec->dev; in ebs_prepare_ioctl()
421 return !!(ec->start || ti->len != bdev_nr_sectors(dev->bdev)); in ebs_prepare_ioctl()
426 struct ebs_c *ec = ti->private; in ebs_io_hints() local
428 limits->logical_block_size = to_bytes(ec->e_bs); in ebs_io_hints()
429 limits->physical_block_size = to_bytes(ec->u_bs); in ebs_io_hints()
437 struct ebs_c *ec = ti->private; in ebs_iterate_devices() local
439 return fn(ti, ec->dev, ec->start, ti->len, data); in ebs_iterate_devices()