Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (C) 2020 Red Hat GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This file is released under the GPL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Device-mapper target to emulate smaller logical block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * size on backing devices exposing (natively) larger ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * E.g. 512 byte sector emulation on 4K native disks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "dm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/dm-bufio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define DM_MSG_PREFIX "ebs"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static void ebs_dtr(struct dm_target *ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* Emulated block size context. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct ebs_c {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct dm_dev *dev;		/* Underlying device to emulate block size on. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct dm_bufio_client *bufio;	/* Use dm-bufio for read and read-modify-write processing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct workqueue_struct *wq;	/* Workqueue for ^ processing of bios. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct work_struct ws;		/* Work item used for ^. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct bio_list bios_in;	/* Worker bios input list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	spinlock_t lock;		/* Guard bios input list above. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	sector_t start;			/* <start> table line argument, see ebs_ctr below. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	unsigned int e_bs;		/* Emulated block size in sectors exposed to upper layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	unsigned int u_bs;		/* Underlying block size in sectors retrievd from/set on lower layer device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	unsigned char block_shift;	/* bitshift sectors -> blocks used in dm-bufio API. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	bool u_bs_set:1;		/* Flag to indicate underlying block size is set on table line. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static inline sector_t __sector_to_block(struct ebs_c *ec, sector_t sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	return sector >> ec->block_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static inline sector_t __block_mod(sector_t sector, unsigned int bs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return sector & (bs - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /* Return number of blocks for a bio, accounting for misalignement of start and end sectors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static inline unsigned int __nr_blocks(struct ebs_c *ec, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	sector_t end_sector = __block_mod(bio->bi_iter.bi_sector, ec->u_bs) + bio_sectors(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return __sector_to_block(ec, end_sector) + (__block_mod(end_sector, ec->u_bs) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static inline bool __ebs_check_bs(unsigned int bs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return bs && is_power_of_2(bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * READ/WRITE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * copy blocks between bufio blocks and bio vector's (partial/overlapping) pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static int __ebs_rw_bvec(struct ebs_c *ec, int rw, struct bio_vec *bv, struct bvec_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned char *ba, *pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned int cur_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned int bv_len = bv->bv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned int buf_off = to_bytes(__block_mod(iter->bi_sector, ec->u_bs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	sector_t block = __sector_to_block(ec, iter->bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct dm_buffer *b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (unlikely(!bv->bv_page || !bv_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	pa = page_address(bv->bv_page) + bv->bv_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/* Handle overlapping page <-> blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	while (bv_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		cur_len = min(dm_bufio_get_block_size(ec->bufio) - buf_off, bv_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		/* Avoid reading for writes in case bio vector's page overwrites block completely. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if (rw == READ || buf_off || bv_len < dm_bufio_get_block_size(ec->bufio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			ba = dm_bufio_read(ec->bufio, block, &b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			ba = dm_bufio_new(ec->bufio, block, &b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		if (unlikely(IS_ERR(ba))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			 * Carry on with next buffer, if any, to issue all possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			 * data but return error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			r = PTR_ERR(ba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			/* Copy data to/from bio to buffer if read/new was successful above. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			ba += buf_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			if (rw == READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				memcpy(pa, ba, cur_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				flush_dcache_page(bv->bv_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				flush_dcache_page(bv->bv_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				memcpy(ba, pa, cur_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				dm_bufio_mark_partial_buffer_dirty(b, buf_off, buf_off + cur_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			dm_bufio_release(b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		pa += cur_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		bv_len -= cur_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		buf_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* READ/WRITE: iterate bio vector's copying between (partial) pages and bufio blocks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int __ebs_rw_bio(struct ebs_c *ec, int rw, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	int r = 0, rr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct bio_vec bv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct bvec_iter iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	bio_for_each_bvec(bv, bio, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		rr = __ebs_rw_bvec(ec, rw, &bv, &iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		if (rr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			r = rr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * Discard bio's blocks, i.e. pass discards down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * Avoid discarding partial blocks at beginning and end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * return 0 in case no blocks can be discarded as a result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int __ebs_discard_bio(struct ebs_c *ec, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	sector_t block, blocks, sector = bio->bi_iter.bi_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	block = __sector_to_block(ec, sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	blocks = __nr_blocks(ec, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 * Partial first underlying block (__nr_blocks() may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 * resulted in one block).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (__block_mod(sector, ec->u_bs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		blocks--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* Partial last underlying block if any. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (blocks && __block_mod(bio_end_sector(bio), ec->u_bs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		blocks--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return blocks ? dm_bufio_issue_discard(ec->bufio, block, blocks) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* Release blocks them from the bufio cache. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static void __ebs_forget_bio(struct ebs_c *ec, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	sector_t blocks, sector = bio->bi_iter.bi_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	blocks = __nr_blocks(ec, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	dm_bufio_forget_buffers(ec->bufio, __sector_to_block(ec, sector), blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /* Worker funtion to process incoming bios. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static void __ebs_process_bios(struct work_struct *ws)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	bool write = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	sector_t block1, block2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct ebs_c *ec = container_of(ws, struct ebs_c, ws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct bio_list bios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	bio_list_init(&bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	spin_lock_irq(&ec->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	bios = ec->bios_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	bio_list_init(&ec->bios_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	spin_unlock_irq(&ec->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	/* Prefetch all read and any mis-aligned write buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	bio_list_for_each(bio, &bios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		block1 = __sector_to_block(ec, bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		if (bio_op(bio) == REQ_OP_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			dm_bufio_prefetch(ec->bufio, block1, __nr_blocks(ec, bio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		else if (bio_op(bio) == REQ_OP_WRITE && !(bio->bi_opf & REQ_PREFLUSH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			block2 = __sector_to_block(ec, bio_end_sector(bio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			if (__block_mod(bio->bi_iter.bi_sector, ec->u_bs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				dm_bufio_prefetch(ec->bufio, block1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			if (__block_mod(bio_end_sector(bio), ec->u_bs) && block2 != block1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 				dm_bufio_prefetch(ec->bufio, block2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	bio_list_for_each(bio, &bios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		r = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (bio_op(bio) == REQ_OP_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			r = __ebs_rw_bio(ec, READ, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		else if (bio_op(bio) == REQ_OP_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			write = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			r = __ebs_rw_bio(ec, WRITE, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		} else if (bio_op(bio) == REQ_OP_DISCARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			__ebs_forget_bio(ec, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			r = __ebs_discard_bio(ec, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			bio->bi_status = errno_to_blk_status(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 * We write dirty buffers after processing I/O on them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 * but before we endio thus addressing REQ_FUA/REQ_SYNC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	r = write ? dm_bufio_write_dirty_buffers(ec->bufio) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	while ((bio = bio_list_pop(&bios))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		/* Any other request is endioed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		if (unlikely(r && bio_op(bio) == REQ_OP_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			bio_io_error(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			bio_endio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * Construct an emulated block size mapping: <dev_path> <offset> <ebs> [<ubs>]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * <dev_path>: path of the underlying device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * <offset>: offset in 512 bytes sectors into <dev_path>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * <ebs>: emulated block size in units of 512 bytes exposed to the upper layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * [<ubs>]: underlying block size in units of 512 bytes imposed on the lower layer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  * 	    optional, if not supplied, retrieve logical block size from underlying device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static int ebs_ctr(struct dm_target *ti, unsigned int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	unsigned short tmp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	unsigned long long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	char dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct ebs_c *ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (argc < 3 || argc > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		ti->error = "Invalid argument count";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	ec = ti->private = kzalloc(sizeof(*ec), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (!ec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		ti->error = "Cannot allocate ebs context";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	    tmp != (sector_t)tmp ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	    (sector_t)tmp >= ti->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		ti->error = "Invalid device offset sector";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	ec->start = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (sscanf(argv[2], "%hu%c", &tmp1, &dummy) != 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	    !__ebs_check_bs(tmp1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	    to_bytes(tmp1) > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		ti->error = "Invalid emulated block size";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	ec->e_bs = tmp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (argc > 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		if (sscanf(argv[3], "%hu%c", &tmp1, &dummy) != 1 || !__ebs_check_bs(tmp1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			ti->error = "Invalid underlying block size";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		ec->u_bs = tmp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		ec->u_bs_set = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		ec->u_bs_set = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &ec->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		ti->error = "Device lookup failed";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		ec->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (!ec->u_bs_set) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		ec->u_bs = to_sector(bdev_logical_block_size(ec->dev->bdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		if (!__ebs_check_bs(ec->u_bs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			ti->error = "Invalid retrieved underlying block size";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (!ec->u_bs_set && ec->e_bs == ec->u_bs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		DMINFO("Emulation superfluous: emulated equal to underlying block size");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (__block_mod(ec->start, ec->u_bs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		ti->error = "Device offset must be multiple of underlying block size";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	ec->bufio = dm_bufio_client_create(ec->dev->bdev, to_bytes(ec->u_bs), 1, 0, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (IS_ERR(ec->bufio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		ti->error = "Cannot create dm bufio client";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		r = PTR_ERR(ec->bufio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		ec->bufio = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	ec->wq = alloc_ordered_workqueue("dm-" DM_MSG_PREFIX, WQ_MEM_RECLAIM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (!ec->wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		ti->error = "Cannot create dm-" DM_MSG_PREFIX " workqueue";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		r = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	ec->block_shift = __ffs(ec->u_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	INIT_WORK(&ec->ws, &__ebs_process_bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	bio_list_init(&ec->bios_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	spin_lock_init(&ec->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	ti->num_flush_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	ti->num_discard_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	ti->num_secure_erase_bios = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	ti->num_write_same_bios = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	ti->num_write_zeroes_bios = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	ebs_dtr(ti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static void ebs_dtr(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct ebs_c *ec = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (ec->wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		destroy_workqueue(ec->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (ec->bufio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		dm_bufio_client_destroy(ec->bufio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (ec->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		dm_put_device(ti, ec->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	kfree(ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static int ebs_map(struct dm_target *ti, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct ebs_c *ec = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	bio_set_dev(bio, ec->dev->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	bio->bi_iter.bi_sector = ec->start + dm_target_offset(ti, bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (unlikely(bio_op(bio) == REQ_OP_FLUSH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		return DM_MAPIO_REMAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	 * Only queue for bufio processing in case of partial or overlapping buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	 * -or-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	 * emulation with ebs == ubs aiming for tests of dm-bufio overhead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (likely(__block_mod(bio->bi_iter.bi_sector, ec->u_bs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		   __block_mod(bio_end_sector(bio), ec->u_bs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		   ec->e_bs == ec->u_bs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		spin_lock_irq(&ec->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		bio_list_add(&ec->bios_in, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		spin_unlock_irq(&ec->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		queue_work(ec->wq, &ec->ws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		return DM_MAPIO_SUBMITTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/* Forget any buffer content relative to this direct backing device I/O. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	__ebs_forget_bio(ec, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	return DM_MAPIO_REMAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static void ebs_status(struct dm_target *ti, status_type_t type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		       unsigned status_flags, char *result, unsigned maxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct ebs_c *ec = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	case STATUSTYPE_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		*result = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	case STATUSTYPE_TABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		snprintf(result, maxlen, ec->u_bs_set ? "%s %llu %u %u" : "%s %llu %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			 ec->dev->name, (unsigned long long) ec->start, ec->e_bs, ec->u_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static int ebs_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct ebs_c *ec = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct dm_dev *dev = ec->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	 * Only pass ioctls through if the device sizes match exactly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	*bdev = dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	return !!(ec->start || ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static void ebs_io_hints(struct dm_target *ti, struct queue_limits *limits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	struct ebs_c *ec = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	limits->logical_block_size = to_bytes(ec->e_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	limits->physical_block_size = to_bytes(ec->u_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	limits->alignment_offset = limits->physical_block_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	blk_limits_io_min(limits, limits->logical_block_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static int ebs_iterate_devices(struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 				  iterate_devices_callout_fn fn, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	struct ebs_c *ec = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	return fn(ti, ec->dev, ec->start, ti->len, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static struct target_type ebs_target = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	.name		 = "ebs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	.version	 = {1, 0, 1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	.features	 = DM_TARGET_PASSES_INTEGRITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	.module		 = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	.ctr		 = ebs_ctr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	.dtr		 = ebs_dtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	.map		 = ebs_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	.status		 = ebs_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	.io_hints	 = ebs_io_hints,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	.prepare_ioctl	 = ebs_prepare_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	.iterate_devices = ebs_iterate_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static int __init dm_ebs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	int r = dm_register_target(&ebs_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		DMERR("register failed %d", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static void dm_ebs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	dm_unregister_target(&ebs_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) module_init(dm_ebs_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) module_exit(dm_ebs_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) MODULE_AUTHOR("Heinz Mauelshagen <dm-devel@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) MODULE_DESCRIPTION(DM_NAME " emulated block size target");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) MODULE_LICENSE("GPL");