^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (C) 2001-2003 Sistina Software (UK) Limited.
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "dm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/dax.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/device-mapper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define DM_MSG_PREFIX "linear"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Linear: maps a linear range of a device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct linear_c {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct dm_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) sector_t start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Construct a linear mapping: <dev_path> <offset>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct linear_c *lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned long long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) char dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (argc != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ti->error = "Invalid argument count";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return -EINVAL;
^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) lc = kmalloc(sizeof(*lc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (lc == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ti->error = "Cannot allocate linear context";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1 || tmp != (sector_t)tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ti->error = "Invalid device sector";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) lc->start = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ti->error = "Device lookup failed";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) goto bad;
^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) ti->num_flush_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ti->num_discard_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ti->num_secure_erase_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ti->num_write_same_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ti->num_write_zeroes_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ti->private = lc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) kfree(lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static void linear_dtr(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct linear_c *lc = (struct linear_c *) ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) dm_put_device(ti, lc->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) kfree(lc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static sector_t linear_map_sector(struct dm_target *ti, sector_t bi_sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct linear_c *lc = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return lc->start + dm_target_offset(ti, bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static void linear_map_bio(struct dm_target *ti, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct linear_c *lc = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) bio_set_dev(bio, lc->dev->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (bio_sectors(bio) || op_is_zone_mgmt(bio_op(bio)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) bio->bi_iter.bi_sector =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) linear_map_sector(ti, bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static int linear_map(struct dm_target *ti, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) linear_map_bio(ti, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return DM_MAPIO_REMAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void linear_status(struct dm_target *ti, status_type_t type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned status_flags, char *result, unsigned maxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct linear_c *lc = (struct linear_c *) ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) case STATUSTYPE_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) result[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case STATUSTYPE_TABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) snprintf(result, maxlen, "%s %llu", lc->dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) (unsigned long long)lc->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int linear_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct linear_c *lc = (struct linear_c *) ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct dm_dev *dev = lc->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *bdev = dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * Only pass ioctls through if the device sizes match exactly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (lc->start ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #ifdef CONFIG_BLK_DEV_ZONED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static int linear_report_zones(struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct dm_report_zones_args *args, unsigned int nr_zones)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct linear_c *lc = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) sector_t sector = linear_map_sector(ti, args->next_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) args->start = lc->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return blkdev_report_zones(lc->dev->bdev, sector, nr_zones,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) dm_report_zones_cb, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int linear_iterate_devices(struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) iterate_devices_callout_fn fn, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct linear_c *lc = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return fn(ti, lc->dev, lc->start, ti->len, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #if IS_ENABLED(CONFIG_DAX_DRIVER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) long nr_pages, void **kaddr, pfn_t *pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct linear_c *lc = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct block_device *bdev = lc->dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct dax_device *dax_dev = lc->dev->dax_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) dev_sector = linear_map_sector(ti, sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages * PAGE_SIZE, &pgoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static size_t linear_dax_copy_from_iter(struct dm_target *ti, pgoff_t pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) void *addr, size_t bytes, struct iov_iter *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct linear_c *lc = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct block_device *bdev = lc->dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct dax_device *dax_dev = lc->dev->dax_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) dev_sector = linear_map_sector(ti, sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static size_t linear_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) void *addr, size_t bytes, struct iov_iter *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct linear_c *lc = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct block_device *bdev = lc->dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct dax_device *dax_dev = lc->dev->dax_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) dev_sector = linear_map_sector(ti, sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
^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) static int linear_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) size_t nr_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct linear_c *lc = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct block_device *bdev = lc->dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct dax_device *dax_dev = lc->dev->dax_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) dev_sector = linear_map_sector(ti, sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages << PAGE_SHIFT, &pgoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return dax_zero_page_range(dax_dev, pgoff, nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define linear_dax_direct_access NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define linear_dax_copy_from_iter NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define linear_dax_copy_to_iter NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #define linear_dax_zero_page_range NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static struct target_type linear_target = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .name = "linear",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .version = {1, 4, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #ifdef CONFIG_BLK_DEV_ZONED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .report_zones = linear_report_zones,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) DM_TARGET_PASSES_CRYPTO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .ctr = linear_ctr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .dtr = linear_dtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .map = linear_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .status = linear_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .prepare_ioctl = linear_prepare_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .iterate_devices = linear_iterate_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .direct_access = linear_dax_direct_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .dax_copy_from_iter = linear_dax_copy_from_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .dax_copy_to_iter = linear_dax_copy_to_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .dax_zero_page_range = linear_dax_zero_page_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int __init dm_linear_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int r = dm_register_target(&linear_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) DMERR("register failed %d", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) void dm_linear_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) dm_unregister_target(&linear_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }