^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file is released under the GPL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "dm-core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "dm-rq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "dm-uevent.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.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/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/sched/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/blkpg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mempool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/dax.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/hdreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/pr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/part_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/blk-crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/keyslot-manager.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define DM_MSG_PREFIX "core"
^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) * Cookies are numeric values sent with CHANGE and REMOVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * uevents while resuming, removing or renaming the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DM_COOKIE_LENGTH 24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static const char *_name = DM_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static unsigned int major = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static unsigned int _major = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static DEFINE_IDR(_minor_idr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static DEFINE_SPINLOCK(_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static void do_deferred_remove(struct work_struct *w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static DECLARE_WORK(deferred_remove_work, do_deferred_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static struct workqueue_struct *deferred_remove_workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) atomic_t dm_global_event_nr = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) DECLARE_WAIT_QUEUE_HEAD(dm_global_eventq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void dm_issue_global_event(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) atomic_inc(&dm_global_event_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) wake_up(&dm_global_eventq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * One of these is allocated (on-stack) per original bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct clone_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct dm_table *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct dm_io *io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) sector_t sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) unsigned sector_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * One of these is allocated per clone bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define DM_TIO_MAGIC 7282014
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct dm_target_io {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) unsigned magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct dm_io *io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) unsigned target_bio_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) unsigned *len_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) bool inside_dm_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct bio clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * One of these is allocated per original bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * It contains the first clone used for that original.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define DM_IO_MAGIC 5191977
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct dm_io {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct mapped_device *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) blk_status_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) atomic_t io_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct bio *orig_bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned long start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) spinlock_t endio_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct dm_stats_aux stats_aux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* last member of dm_target_io is 'struct bio' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct dm_target_io tio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void *dm_per_bio_data(struct bio *bio, size_t data_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (!tio->inside_dm_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return (char *)bio - offsetof(struct dm_target_io, clone) - data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return (char *)bio - offsetof(struct dm_target_io, clone) - offsetof(struct dm_io, tio) - data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) EXPORT_SYMBOL_GPL(dm_per_bio_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct bio *dm_bio_from_per_bio_data(void *data, size_t data_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct dm_io *io = (struct dm_io *)((char *)data + data_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (io->magic == DM_IO_MAGIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return (struct bio *)((char *)io + offsetof(struct dm_io, tio) + offsetof(struct dm_target_io, clone));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) BUG_ON(io->magic != DM_TIO_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return (struct bio *)((char *)io + offsetof(struct dm_target_io, clone));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) EXPORT_SYMBOL_GPL(dm_bio_from_per_bio_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) unsigned dm_bio_get_target_bio_nr(const struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return container_of(bio, struct dm_target_io, clone)->target_bio_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) EXPORT_SYMBOL_GPL(dm_bio_get_target_bio_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define MINOR_ALLOCED ((void *)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * Bits for the md->flags field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define DMF_BLOCK_IO_FOR_SUSPEND 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #define DMF_SUSPENDED 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define DMF_FROZEN 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define DMF_FREEING 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define DMF_DELETING 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define DMF_NOFLUSH_SUSPENDING 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define DMF_DEFERRED_REMOVE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define DMF_SUSPENDED_INTERNALLY 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define DMF_POST_SUSPENDING 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define DM_NUMA_NODE NUMA_NO_NODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int dm_numa_node = DM_NUMA_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define DEFAULT_SWAP_BIOS (8 * 1048576 / PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int swap_bios = DEFAULT_SWAP_BIOS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int get_swap_bios(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int latch = READ_ONCE(swap_bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (unlikely(latch <= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) latch = DEFAULT_SWAP_BIOS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return latch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * For mempools pre-allocation at the table loading time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct dm_md_mempools {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct bio_set bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct bio_set io_bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct table_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) refcount_t count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct dm_dev dm_dev;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Bio-based DM's mempools' reserved IOs set by the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #define RESERVED_BIO_BASED_IOS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static unsigned reserved_bio_based_ios = RESERVED_BIO_BASED_IOS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int __dm_get_module_param_int(int *module_param, int min, int max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) int param = READ_ONCE(*module_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int modified_param = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) bool modified = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (param < min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) modified_param = min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) else if (param > max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) modified_param = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) modified = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (modified) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) (void)cmpxchg(module_param, param, modified_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) param = modified_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) unsigned __dm_get_module_param(unsigned *module_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned def, unsigned max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) unsigned param = READ_ONCE(*module_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) unsigned modified_param = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) modified_param = def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) else if (param > max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) modified_param = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (modified_param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) (void)cmpxchg(module_param, param, modified_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) param = modified_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return param;
^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) unsigned dm_get_reserved_bio_based_ios(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return __dm_get_module_param(&reserved_bio_based_ios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) RESERVED_BIO_BASED_IOS, DM_RESERVED_MAX_IOS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) EXPORT_SYMBOL_GPL(dm_get_reserved_bio_based_ios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static unsigned dm_get_numa_node(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return __dm_get_module_param_int(&dm_numa_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) DM_NUMA_NODE, num_online_nodes() - 1);
^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) static int __init local_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) r = dm_uevent_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) deferred_remove_workqueue = alloc_workqueue("kdmremove", WQ_UNBOUND, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (!deferred_remove_workqueue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) r = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) goto out_uevent_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) _major = major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) r = register_blkdev(_major, _name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) goto out_free_workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!_major)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) _major = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) out_free_workqueue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) destroy_workqueue(deferred_remove_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) out_uevent_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) dm_uevent_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static void local_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) flush_scheduled_work();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) destroy_workqueue(deferred_remove_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) unregister_blkdev(_major, _name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) dm_uevent_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) _major = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) DMINFO("cleaned up");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int (*_inits[])(void) __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) local_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) dm_target_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) dm_linear_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) dm_stripe_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) dm_io_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dm_kcopyd_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) dm_interface_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) dm_statistics_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static void (*_exits[])(void) = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) local_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) dm_target_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) dm_linear_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) dm_stripe_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) dm_io_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) dm_kcopyd_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) dm_interface_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) dm_statistics_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static int __init dm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) const int count = ARRAY_SIZE(_inits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int r, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) r = _inits[i]();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) _exits[i]();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return r;
^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) static void __exit dm_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int i = ARRAY_SIZE(_exits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) _exits[i]();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * Should be empty by this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) idr_destroy(&_minor_idr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * Block device functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int dm_deleting_md(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return test_bit(DMF_DELETING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int dm_blk_open(struct block_device *bdev, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct mapped_device *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) md = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (!md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (test_bit(DMF_FREEING, &md->flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) dm_deleting_md(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) md = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) dm_get(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) atomic_inc(&md->open_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return md ? 0 : -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static void dm_blk_close(struct gendisk *disk, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct mapped_device *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) md = disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (WARN_ON(!md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (atomic_dec_and_test(&md->open_count) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) (test_bit(DMF_DEFERRED_REMOVE, &md->flags)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) queue_work(deferred_remove_workqueue, &deferred_remove_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) dm_put(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int dm_open_count(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) return atomic_read(&md->open_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * Guarantees nothing is using the device before it's deleted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int dm_lock_for_deletion(struct mapped_device *md, bool mark_deferred, bool only_deferred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (dm_open_count(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) r = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (mark_deferred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) set_bit(DMF_DEFERRED_REMOVE, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) } else if (only_deferred && !test_bit(DMF_DEFERRED_REMOVE, &md->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) r = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) set_bit(DMF_DELETING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) int dm_cancel_deferred_remove(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (test_bit(DMF_DELETING, &md->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) r = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) clear_bit(DMF_DEFERRED_REMOVE, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static void do_deferred_remove(struct work_struct *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) dm_deferred_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct mapped_device *md = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return dm_get_geometry(md, geo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) #ifdef CONFIG_BLK_DEV_ZONED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int dm_report_zones_cb(struct blk_zone *zone, unsigned int idx, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct dm_report_zones_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) sector_t sector_diff = args->tgt->begin - args->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * Ignore zones beyond the target range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (zone->start >= args->start + args->tgt->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * Remap the start sector and write pointer position of the zone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * to match its position in the target range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) zone->start += sector_diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (zone->type != BLK_ZONE_TYPE_CONVENTIONAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (zone->cond == BLK_ZONE_COND_FULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) zone->wp = zone->start + zone->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) else if (zone->cond == BLK_ZONE_COND_EMPTY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) zone->wp = zone->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) zone->wp += sector_diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) args->next_sector = zone->start + zone->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return args->orig_cb(zone, args->zone_idx++, args->orig_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) EXPORT_SYMBOL_GPL(dm_report_zones_cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) unsigned int nr_zones, report_zones_cb cb, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct mapped_device *md = disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct dm_table *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) int srcu_idx, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct dm_report_zones_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) .next_sector = sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) .orig_data = data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) .orig_cb = cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (dm_suspended_md(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) map = dm_get_live_table(md, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (!map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct dm_target *tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) tgt = dm_table_find_target(map, args.next_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (WARN_ON_ONCE(!tgt->type->report_zones)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) args.tgt = tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) ret = tgt->type->report_zones(tgt, &args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) nr_zones - args.zone_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) } while (args.zone_idx < nr_zones &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) args.next_sector < get_capacity(disk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) ret = args.zone_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) #define dm_blk_report_zones NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) #endif /* CONFIG_BLK_DEV_ZONED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static int dm_prepare_ioctl(struct mapped_device *md, int *srcu_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct block_device **bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct dm_target *tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct dm_table *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) r = -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) map = dm_get_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (!map || !dm_table_get_size(map))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /* We only support devices that have a single target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) if (dm_table_get_num_targets(map) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) tgt = dm_table_get_target(map, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (!tgt->type->prepare_ioctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (dm_suspended_md(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) r = tgt->type->prepare_ioctl(tgt, bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (r == -ENOTCONN && !fatal_signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) dm_put_live_table(md, *srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static void dm_unprepare_ioctl(struct mapped_device *md, int srcu_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) struct mapped_device *md = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) int r, srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) r = dm_prepare_ioctl(md, &srcu_idx, &bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (r > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * Target determined this ioctl is being issued against a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * subset of the parent bdev; require extra privileges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (!capable(CAP_SYS_RAWIO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) DMDEBUG_LIMIT(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) "%s: sending ioctl %x to DM device without required privilege.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) current->comm, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) r = -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) r = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) dm_unprepare_ioctl(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) u64 dm_start_time_ns_from_clone(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct dm_io *io = tio->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) return jiffies_to_nsecs(io->start_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) EXPORT_SYMBOL_GPL(dm_start_time_ns_from_clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static void start_io_acct(struct dm_io *io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) struct mapped_device *md = io->md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct bio *bio = io->orig_bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) io->start_time = bio_start_io_acct(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (unlikely(dm_stats_used(&md->stats)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) dm_stats_account_io(&md->stats, bio_data_dir(bio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) bio->bi_iter.bi_sector, bio_sectors(bio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) false, 0, &io->stats_aux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) static void end_io_acct(struct mapped_device *md, struct bio *bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) unsigned long start_time, struct dm_stats_aux *stats_aux)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) unsigned long duration = jiffies - start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) bio_end_io_acct(bio, start_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (unlikely(dm_stats_used(&md->stats)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) dm_stats_account_io(&md->stats, bio_data_dir(bio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) bio->bi_iter.bi_sector, bio_sectors(bio),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) true, duration, stats_aux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /* nudge anyone waiting on suspend queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (unlikely(wq_has_sleeper(&md->wait)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) wake_up(&md->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) struct dm_io *io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) struct dm_target_io *tio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct bio *clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) clone = bio_alloc_bioset(GFP_NOIO, 0, &md->io_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (!clone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) tio = container_of(clone, struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) tio->inside_dm_io = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) tio->io = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) io = container_of(tio, struct dm_io, tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) io->magic = DM_IO_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) io->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) atomic_set(&io->io_count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) io->orig_bio = bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) io->md = md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) spin_lock_init(&io->endio_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) start_io_acct(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) return io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) static void free_io(struct mapped_device *md, struct dm_io *io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) bio_put(&io->tio.clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) static struct dm_target_io *alloc_tio(struct clone_info *ci, struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) unsigned target_bio_nr, gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) struct dm_target_io *tio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (!ci->io->tio.io) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) /* the dm_target_io embedded in ci->io is available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) tio = &ci->io->tio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) struct bio *clone = bio_alloc_bioset(gfp_mask, 0, &ci->io->md->bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (!clone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) tio = container_of(clone, struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) tio->inside_dm_io = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) tio->magic = DM_TIO_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) tio->io = ci->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) tio->ti = ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) tio->target_bio_nr = target_bio_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return tio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static void free_tio(struct dm_target_io *tio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (tio->inside_dm_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) bio_put(&tio->clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * Add the bio to the list of deferred io.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) static void queue_io(struct mapped_device *md, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) spin_lock_irqsave(&md->deferred_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) bio_list_add(&md->deferred, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) spin_unlock_irqrestore(&md->deferred_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) queue_work(md->wq, &md->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * Everyone (including functions in this file), should use this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * function to access the md->map field, and make sure they call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * dm_put_live_table() when finished.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) struct dm_table *dm_get_live_table(struct mapped_device *md, int *srcu_idx) __acquires(md->io_barrier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) *srcu_idx = srcu_read_lock(&md->io_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) return srcu_dereference(md->map, &md->io_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) void dm_put_live_table(struct mapped_device *md, int srcu_idx) __releases(md->io_barrier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) srcu_read_unlock(&md->io_barrier, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) void dm_sync_table(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) synchronize_srcu(&md->io_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) synchronize_rcu_expedited();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * A fast alternative to dm_get_live_table/dm_put_live_table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * The caller must not block between these two functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) static struct dm_table *dm_get_live_table_fast(struct mapped_device *md) __acquires(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return rcu_dereference(md->map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) static char *_dm_claim_ptr = "I belong to device-mapper";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * Open a table device so we can use it as a map destination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static int open_table_device(struct table_device *td, dev_t dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct block_device *bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) BUG_ON(td->dm_dev.bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) bdev = blkdev_get_by_dev(dev, td->dm_dev.mode | FMODE_EXCL, _dm_claim_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if (IS_ERR(bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return PTR_ERR(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) r = bd_link_disk_holder(bdev, dm_disk(md));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) blkdev_put(bdev, td->dm_dev.mode | FMODE_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) td->dm_dev.bdev = bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) td->dm_dev.dax_dev = dax_get_by_host(bdev->bd_disk->disk_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) * Close a table device that we've been using.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) static void close_table_device(struct table_device *td, struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (!td->dm_dev.bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) put_dax(td->dm_dev.dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) td->dm_dev.bdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) td->dm_dev.dax_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) static struct table_device *find_table_device(struct list_head *l, dev_t dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) struct table_device *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) list_for_each_entry(td, l, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) if (td->dm_dev.bdev->bd_dev == dev && td->dm_dev.mode == mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) return td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) int dm_get_table_device(struct mapped_device *md, dev_t dev, fmode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct dm_dev **result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) struct table_device *td;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) mutex_lock(&md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) td = find_table_device(&md->table_devices, dev, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (!td) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) td = kmalloc_node(sizeof(*td), GFP_KERNEL, md->numa_node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (!td) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) mutex_unlock(&md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) td->dm_dev.mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) td->dm_dev.bdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) if ((r = open_table_device(td, dev, md))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) mutex_unlock(&md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) kfree(td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) format_dev_t(td->dm_dev.name, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) refcount_set(&td->count, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) list_add(&td->list, &md->table_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) refcount_inc(&td->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) mutex_unlock(&md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) *result = &td->dm_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) EXPORT_SYMBOL_GPL(dm_get_table_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) void dm_put_table_device(struct mapped_device *md, struct dm_dev *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) struct table_device *td = container_of(d, struct table_device, dm_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) mutex_lock(&md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (refcount_dec_and_test(&td->count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) close_table_device(td, md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) list_del(&td->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) kfree(td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) mutex_unlock(&md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) EXPORT_SYMBOL(dm_put_table_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) static void free_table_devices(struct list_head *devices)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct list_head *tmp, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) list_for_each_safe(tmp, next, devices) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct table_device *td = list_entry(tmp, struct table_device, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) DMWARN("dm_destroy: %s still exists with %d references",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) td->dm_dev.name, refcount_read(&td->count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) kfree(td);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) * Get the geometry associated with a dm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) *geo = md->geometry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * Set the geometry of a device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) sector_t sz = (sector_t)geo->cylinders * geo->heads * geo->sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (geo->start > sz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) DMWARN("Start sector is beyond the geometry limits.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) md->geometry = *geo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) static int __noflush_suspending(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return test_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) * Decrements the number of outstanding ios that a bio has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) * cloned into, completing the original io if necc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) static void dec_pending(struct dm_io *io, blk_status_t error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) blk_status_t io_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) struct mapped_device *md = io->md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) unsigned long start_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) struct dm_stats_aux stats_aux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) /* Push-back supersedes any I/O errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (unlikely(error)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) spin_lock_irqsave(&io->endio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) if (!(io->status == BLK_STS_DM_REQUEUE && __noflush_suspending(md)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) io->status = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) spin_unlock_irqrestore(&io->endio_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (atomic_dec_and_test(&io->io_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (io->status == BLK_STS_DM_REQUEUE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) * Target requested pushing back the I/O.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) spin_lock_irqsave(&md->deferred_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) if (__noflush_suspending(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) /* NOTE early return due to BLK_STS_DM_REQUEUE below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) bio_list_add_head(&md->deferred, io->orig_bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) /* noflush suspend was interrupted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) io->status = BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) spin_unlock_irqrestore(&md->deferred_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) io_error = io->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) bio = io->orig_bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) start_time = io->start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) stats_aux = io->stats_aux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) free_io(md, io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) end_io_acct(md, bio, start_time, &stats_aux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) if (io_error == BLK_STS_DM_REQUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if ((bio->bi_opf & REQ_PREFLUSH) && bio->bi_iter.bi_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) * Preflush done for flush with data, reissue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) * without REQ_PREFLUSH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) bio->bi_opf &= ~REQ_PREFLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) queue_io(md, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) /* done with normal IO or empty flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (io_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) bio->bi_status = io_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) bio_endio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) void disable_discard(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) struct queue_limits *limits = dm_get_queue_limits(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) /* device doesn't really support DISCARD, disable it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) limits->max_discard_sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) blk_queue_flag_clear(QUEUE_FLAG_DISCARD, md->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) void disable_write_same(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) struct queue_limits *limits = dm_get_queue_limits(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) /* device doesn't really support WRITE SAME, disable it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) limits->max_write_same_sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) void disable_write_zeroes(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) struct queue_limits *limits = dm_get_queue_limits(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) /* device doesn't really support WRITE ZEROES, disable it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) limits->max_write_zeroes_sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) static bool swap_bios_limit(struct dm_target *ti, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) return unlikely((bio->bi_opf & REQ_SWAP) != 0) && unlikely(ti->limit_swap_bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) static void clone_endio(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) blk_status_t error = bio->bi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) struct dm_io *io = tio->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) struct mapped_device *md = tio->io->md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) dm_endio_fn endio = tio->ti->type->end_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) struct bio *orig_bio = io->orig_bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (unlikely(error == BLK_STS_TARGET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) if (bio_op(bio) == REQ_OP_DISCARD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) !bio->bi_disk->queue->limits.max_discard_sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) disable_discard(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) else if (bio_op(bio) == REQ_OP_WRITE_SAME &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) !bio->bi_disk->queue->limits.max_write_same_sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) disable_write_same(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) else if (bio_op(bio) == REQ_OP_WRITE_ZEROES &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) !bio->bi_disk->queue->limits.max_write_zeroes_sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) disable_write_zeroes(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) * For zone-append bios get offset in zone of the written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) * sector and add that to the original bio sector pos.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (bio_op(orig_bio) == REQ_OP_ZONE_APPEND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) sector_t written_sector = bio->bi_iter.bi_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) struct request_queue *q = orig_bio->bi_disk->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) u64 mask = (u64)blk_queue_zone_sectors(q) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) orig_bio->bi_iter.bi_sector += written_sector & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (endio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) int r = endio(tio->ti, bio, &error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) switch (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) case DM_ENDIO_REQUEUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) error = BLK_STS_DM_REQUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) case DM_ENDIO_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) case DM_ENDIO_INCOMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) /* The target will handle the io */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) DMWARN("unimplemented target endio return value: %d", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) if (unlikely(swap_bios_limit(tio->ti, bio))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) struct mapped_device *md = io->md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) up(&md->swap_bios_semaphore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) free_tio(tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) dec_pending(io, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) * Return maximum size of I/O possible at the supplied sector up to the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) * target boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) static inline sector_t max_io_len_target_boundary(struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) sector_t target_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) return ti->len - target_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) static sector_t max_io_len(struct dm_target *ti, sector_t sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) sector_t target_offset = dm_target_offset(ti, sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) sector_t len = max_io_len_target_boundary(ti, target_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) sector_t max_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) * Does the target need to split IO even further?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) * - varied (per target) IO splitting is a tenet of DM; this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) * explains why stacked chunk_sectors based splitting via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) * blk_max_size_offset() isn't possible here. So pass in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) * ti->max_io_len to override stacked chunk_sectors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) if (ti->max_io_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) max_len = blk_max_size_offset(ti->table->md->queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) target_offset, ti->max_io_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (len > max_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) len = max_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) int dm_set_target_max_io_len(struct dm_target *ti, sector_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (len > UINT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) DMERR("Specified maximum size of target IO (%llu) exceeds limit (%u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) (unsigned long long)len, UINT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) ti->error = "Maximum size of target IO is too large";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) ti->max_io_len = (uint32_t) len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) EXPORT_SYMBOL_GPL(dm_set_target_max_io_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static struct dm_target *dm_dax_get_live_target(struct mapped_device *md,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) sector_t sector, int *srcu_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) __acquires(md->io_barrier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) struct dm_table *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) map = dm_get_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) if (!map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) ti = dm_table_find_target(map, sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (!ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) return ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) long nr_pages, void **kaddr, pfn_t *pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) struct mapped_device *md = dax_get_private(dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) sector_t sector = pgoff * PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) long len, ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) int srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) ti = dm_dax_get_live_target(md, sector, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (!ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if (!ti->type->direct_access)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) len = max_io_len(ti, sector) / PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) if (len < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) nr_pages = min(len, nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) ret = ti->type->direct_access(ti, pgoff, nr_pages, kaddr, pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) static bool dm_dax_supported(struct dax_device *dax_dev, struct block_device *bdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) int blocksize, sector_t start, sector_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) struct mapped_device *md = dax_get_private(dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) struct dm_table *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) int srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) map = dm_get_live_table(md, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (!map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) ret = dm_table_supports_dax(map, device_not_dax_capable, &blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) static size_t dm_dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) void *addr, size_t bytes, struct iov_iter *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) struct mapped_device *md = dax_get_private(dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) sector_t sector = pgoff * PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) long ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) int srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) ti = dm_dax_get_live_target(md, sector, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (!ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) if (!ti->type->dax_copy_from_iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) ret = copy_from_iter(addr, bytes, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) ret = ti->type->dax_copy_from_iter(ti, pgoff, addr, bytes, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) static size_t dm_dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) void *addr, size_t bytes, struct iov_iter *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) struct mapped_device *md = dax_get_private(dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) sector_t sector = pgoff * PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) long ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) int srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) ti = dm_dax_get_live_target(md, sector, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (!ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) if (!ti->type->dax_copy_to_iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) ret = copy_to_iter(addr, bytes, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) ret = ti->type->dax_copy_to_iter(ti, pgoff, addr, bytes, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) static int dm_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) size_t nr_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) struct mapped_device *md = dax_get_private(dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) sector_t sector = pgoff * PAGE_SECTORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) int ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) int srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) ti = dm_dax_get_live_target(md, sector, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (!ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) if (WARN_ON(!ti->type->dax_zero_page_range)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) * ->zero_page_range() is mandatory dax operation. If we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) * here, something is wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) ret = ti->type->dax_zero_page_range(ti, pgoff, nr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) * A target may call dm_accept_partial_bio only from the map routine. It is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) * allowed for all bio types except REQ_PREFLUSH, REQ_OP_ZONE_* zone management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) * operations and REQ_OP_ZONE_APPEND (zone append writes).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) * dm_accept_partial_bio informs the dm that the target only wants to process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) * additional n_sectors sectors of the bio and the rest of the data should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) * sent in a next bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) * A diagram that explains the arithmetics:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) * +--------------------+---------------+-------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) * | 1 | 2 | 3 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) * +--------------------+---------------+-------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) * <-------------- *tio->len_ptr --------------->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) * <------- bi_size ------->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) * <-- n_sectors -->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) * Region 1 was already iterated over with bio_advance or similar function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) * (it may be empty if the target doesn't use bio_advance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) * Region 2 is the remaining bio size that the target wants to process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) * (it may be empty if region 1 is non-empty, although there is no reason
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) * to make it empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) * The target requires that region 3 is to be sent in the next bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) * If the target wants to receive multiple copies of the bio (via num_*bios, etc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) * the partially processed part (the sum of regions 1+2) must be the same for all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) * copies of the bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) unsigned bi_size = bio->bi_iter.bi_size >> SECTOR_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) BUG_ON(bio->bi_opf & REQ_PREFLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) BUG_ON(op_is_zone_mgmt(bio_op(bio)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) BUG_ON(bio_op(bio) == REQ_OP_ZONE_APPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) BUG_ON(bi_size > *tio->len_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) BUG_ON(n_sectors > bi_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) *tio->len_ptr -= bi_size - n_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) bio->bi_iter.bi_size = n_sectors << SECTOR_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) EXPORT_SYMBOL_GPL(dm_accept_partial_bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) static noinline void __set_swap_bios_limit(struct mapped_device *md, int latch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) mutex_lock(&md->swap_bios_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) while (latch < md->swap_bios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) down(&md->swap_bios_semaphore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) md->swap_bios--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) while (latch > md->swap_bios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) up(&md->swap_bios_semaphore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) md->swap_bios++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) mutex_unlock(&md->swap_bios_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) static blk_qc_t __map_bio(struct dm_target_io *tio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) sector_t sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) struct bio *clone = &tio->clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) struct dm_io *io = tio->io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) struct dm_target *ti = tio->ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) blk_qc_t ret = BLK_QC_T_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) clone->bi_end_io = clone_endio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) * Map the clone. If r == 0 we don't need to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) * anything, the target has assumed ownership of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) * this io.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) atomic_inc(&io->io_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) sector = clone->bi_iter.bi_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (unlikely(swap_bios_limit(ti, clone))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) struct mapped_device *md = io->md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) int latch = get_swap_bios();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) if (unlikely(latch != md->swap_bios))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) __set_swap_bios_limit(md, latch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) down(&md->swap_bios_semaphore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) r = ti->type->map(ti, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) switch (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) case DM_MAPIO_SUBMITTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) case DM_MAPIO_REMAPPED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) /* the bio has been remapped so dispatch it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) trace_block_bio_remap(clone->bi_disk->queue, clone,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) bio_dev(io->orig_bio), sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) ret = submit_bio_noacct(clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) case DM_MAPIO_KILL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) if (unlikely(swap_bios_limit(ti, clone))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) struct mapped_device *md = io->md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) up(&md->swap_bios_semaphore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) free_tio(tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) dec_pending(io, BLK_STS_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) case DM_MAPIO_REQUEUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) if (unlikely(swap_bios_limit(ti, clone))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) struct mapped_device *md = io->md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) up(&md->swap_bios_semaphore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) free_tio(tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) dec_pending(io, BLK_STS_DM_REQUEUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) DMWARN("unimplemented target map return value: %d", r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) static void bio_setup_sector(struct bio *bio, sector_t sector, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) bio->bi_iter.bi_sector = sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) bio->bi_iter.bi_size = to_bytes(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) * Creates a bio that consists of range of complete bvecs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) static int clone_bio(struct dm_target_io *tio, struct bio *bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) sector_t sector, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) struct bio *clone = &tio->clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) __bio_clone_fast(clone, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) r = bio_crypt_clone(clone, bio, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) if (bio_integrity(bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) if (unlikely(!dm_target_has_integrity(tio->ti->type) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) !dm_target_passes_integrity(tio->ti->type))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) DMWARN("%s: the target %s doesn't support integrity data.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) dm_device_name(tio->io->md),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) tio->ti->type->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) r = bio_integrity_clone(clone, bio, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) bio_advance(clone, to_bytes(sector - clone->bi_iter.bi_sector));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) clone->bi_iter.bi_size = to_bytes(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) if (bio_integrity(bio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) bio_integrity_trim(clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) static void alloc_multiple_bios(struct bio_list *blist, struct clone_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) struct dm_target *ti, unsigned num_bios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) struct dm_target_io *tio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) int try;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) if (!num_bios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) if (num_bios == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) tio = alloc_tio(ci, ti, 0, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) bio_list_add(blist, &tio->clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) for (try = 0; try < 2; try++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) int bio_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (try)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) mutex_lock(&ci->io->md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) for (bio_nr = 0; bio_nr < num_bios; bio_nr++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) tio = alloc_tio(ci, ti, bio_nr, try ? GFP_NOIO : GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) if (!tio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) bio_list_add(blist, &tio->clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (try)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) mutex_unlock(&ci->io->md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) if (bio_nr == num_bios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) while ((bio = bio_list_pop(blist))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) tio = container_of(bio, struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) free_tio(tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) static blk_qc_t __clone_and_map_simple_bio(struct clone_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) struct dm_target_io *tio, unsigned *len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) struct bio *clone = &tio->clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) tio->len_ptr = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) __bio_clone_fast(clone, ci->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) if (len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) bio_setup_sector(clone, ci->sector, *len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) return __map_bio(tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) static void __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) unsigned num_bios, unsigned *len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) struct bio_list blist = BIO_EMPTY_LIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) struct dm_target_io *tio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) alloc_multiple_bios(&blist, ci, ti, num_bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) while ((bio = bio_list_pop(&blist))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) tio = container_of(bio, struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) (void) __clone_and_map_simple_bio(ci, tio, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) static int __send_empty_flush(struct clone_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) unsigned target_nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) struct bio flush_bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) * Use an on-stack bio for this, it's safe since we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) * need to reference it after submit. It's just used as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) * the basis for the clone(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) bio_init(&flush_bio, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) flush_bio.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) ci->bio = &flush_bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) ci->sector_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) * Empty flush uses a statically initialized bio, as the base for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) * cloning. However, blkg association requires that a bdev is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) * associated with a gendisk, which doesn't happen until the bdev is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) * opened. So, blkg association is done at issue time of the flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) * rather than when the device is created in alloc_dev().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) bio_set_dev(ci->bio, ci->io->md->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) BUG_ON(bio_has_data(ci->bio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) while ((ti = dm_table_get_target(ci->map, target_nr++)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) __send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) bio_uninit(ci->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) static int __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) sector_t sector, unsigned *len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) struct bio *bio = ci->bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) struct dm_target_io *tio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) tio = alloc_tio(ci, ti, 0, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) tio->len_ptr = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) r = clone_bio(tio, bio, sector, *len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) free_tio(tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) (void) __map_bio(tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) static int __send_changing_extent_only(struct clone_info *ci, struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) unsigned num_bios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) unsigned len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) * Even though the device advertised support for this type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) * request, that does not mean every target supports it, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) * reconfiguration might also have changed that since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) * check was performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) if (!num_bios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) len = min_t(sector_t, ci->sector_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) max_io_len_target_boundary(ti, dm_target_offset(ti, ci->sector)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) __send_duplicate_bios(ci, ti, num_bios, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) ci->sector += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) ci->sector_count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) static bool is_abnormal_io(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) bool r = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) switch (bio_op(bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) case REQ_OP_DISCARD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) case REQ_OP_SECURE_ERASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) case REQ_OP_WRITE_SAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) case REQ_OP_WRITE_ZEROES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) r = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) int *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) struct bio *bio = ci->bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) unsigned num_bios = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) switch (bio_op(bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) case REQ_OP_DISCARD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) num_bios = ti->num_discard_bios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) case REQ_OP_SECURE_ERASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) num_bios = ti->num_secure_erase_bios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) case REQ_OP_WRITE_SAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) num_bios = ti->num_write_same_bios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) case REQ_OP_WRITE_ZEROES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) num_bios = ti->num_write_zeroes_bios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) *result = __send_changing_extent_only(ci, ti, num_bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) * Select the correct strategy for processing a non-flush bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) static int __split_and_process_non_flush(struct clone_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) unsigned len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) ti = dm_table_find_target(ci->map, ci->sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) if (!ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) if (__process_abnormal_io(ci, ti, &r))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) len = min_t(sector_t, max_io_len(ti, ci->sector), ci->sector_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) r = __clone_and_map_data_bio(ci, ti, ci->sector, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) ci->sector += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) ci->sector_count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) static void init_clone_info(struct clone_info *ci, struct mapped_device *md,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) struct dm_table *map, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) ci->map = map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) ci->io = alloc_io(md, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) ci->sector = bio->bi_iter.bi_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) #define __dm_part_stat_sub(part, field, subnd) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) (part_stat_get(part, field) -= (subnd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) * Entry point to split a bio into clones and submit them to the targets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) static blk_qc_t __split_and_process_bio(struct mapped_device *md,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) struct dm_table *map, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) struct clone_info ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) blk_qc_t ret = BLK_QC_T_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) init_clone_info(&ci, md, map, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) if (bio->bi_opf & REQ_PREFLUSH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) error = __send_empty_flush(&ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) /* dec_pending submits any data associated with flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) } else if (op_is_zone_mgmt(bio_op(bio))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) ci.bio = bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) ci.sector_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) error = __split_and_process_non_flush(&ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) ci.bio = bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) ci.sector_count = bio_sectors(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) while (ci.sector_count && !error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) error = __split_and_process_non_flush(&ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) if (current->bio_list && ci.sector_count && !error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) * Remainder must be passed to submit_bio_noacct()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) * so that it gets handled *after* bios already submitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) * have been completely processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) * We take a clone of the original to store in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) * ci.io->orig_bio to be used by end_io_acct() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) * for dec_pending to use for completion handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) struct bio *b = bio_split(bio, bio_sectors(bio) - ci.sector_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) GFP_NOIO, &md->queue->bio_split);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) ci.io->orig_bio = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) * Adjust IO stats for each split, otherwise upon queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) * reentry there will be redundant IO accounting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) * NOTE: this is a stop-gap fix, a proper fix involves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) * significant refactoring of DM core's bio splitting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) * (by eliminating DM's splitting and just using bio_split)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) part_stat_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) __dm_part_stat_sub(&dm_disk(md)->part0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) sectors[op_stat_group(bio_op(bio))], ci.sector_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) part_stat_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) bio_chain(b, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) trace_block_split(md->queue, b, bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) ret = submit_bio_noacct(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) /* drop the extra reference count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) dec_pending(ci.io, errno_to_blk_status(error));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) static blk_qc_t dm_submit_bio(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) struct mapped_device *md = bio->bi_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) blk_qc_t ret = BLK_QC_T_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) int srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) struct dm_table *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) map = dm_get_live_table(md, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) if (unlikely(!map)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) DMERR_LIMIT("%s: mapping table unavailable, erroring io",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) dm_device_name(md));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) bio_io_error(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) /* If suspended, queue this IO for later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) if (bio->bi_opf & REQ_NOWAIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) bio_wouldblock_error(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) else if (bio->bi_opf & REQ_RAHEAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) bio_io_error(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) queue_io(md, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) * Use blk_queue_split() for abnormal IO (e.g. discard, writesame, etc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) * otherwise associated queue_limits won't be imposed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) if (is_abnormal_io(bio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) blk_queue_split(&bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) ret = __split_and_process_bio(md, map, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) /*-----------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) * An IDR is used to keep track of allocated minor numbers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) static void free_minor(int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) idr_remove(&_minor_idr, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) * See if the device with a specific minor # is free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) static int specific_minor(int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) if (minor >= (1 << MINORBITS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) idr_preload(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) r = idr_alloc(&_minor_idr, MINOR_ALLOCED, minor, minor + 1, GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) idr_preload_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) return r == -ENOSPC ? -EBUSY : r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) static int next_free_minor(int *minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) idr_preload(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) r = idr_alloc(&_minor_idr, MINOR_ALLOCED, 0, 1 << MINORBITS, GFP_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) idr_preload_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) *minor = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) static const struct block_device_operations dm_blk_dops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) static const struct block_device_operations dm_rq_blk_dops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) static const struct dax_operations dm_dax_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) static void dm_wq_work(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) #ifdef CONFIG_BLK_INLINE_ENCRYPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) static void dm_queue_destroy_keyslot_manager(struct request_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) dm_destroy_keyslot_manager(q->ksm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) #else /* CONFIG_BLK_INLINE_ENCRYPTION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) static inline void dm_queue_destroy_keyslot_manager(struct request_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) #endif /* !CONFIG_BLK_INLINE_ENCRYPTION */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) static void cleanup_mapped_device(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) if (md->wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) destroy_workqueue(md->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) bioset_exit(&md->bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) bioset_exit(&md->io_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) if (md->dax_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) kill_dax(md->dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) put_dax(md->dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) md->dax_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) if (md->disk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) md->disk->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) del_gendisk(md->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) put_disk(md->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) if (md->queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) dm_queue_destroy_keyslot_manager(md->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) blk_cleanup_queue(md->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) cleanup_srcu_struct(&md->io_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) if (md->bdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) bdput(md->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) md->bdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) mutex_destroy(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) mutex_destroy(&md->type_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) mutex_destroy(&md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) mutex_destroy(&md->swap_bios_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) dm_mq_cleanup_mapped_device(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) * Allocate and initialise a blank device with a given minor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) static struct mapped_device *alloc_dev(int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) int r, numa_node_id = dm_get_numa_node();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) struct mapped_device *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) void *old_md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) md = kvzalloc_node(sizeof(*md), GFP_KERNEL, numa_node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) if (!md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) DMWARN("unable to allocate device, out of memory.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) goto bad_module_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) /* get a minor number for the dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) if (minor == DM_ANY_MINOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) r = next_free_minor(&minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) r = specific_minor(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) goto bad_minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) r = init_srcu_struct(&md->io_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) goto bad_io_barrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) md->numa_node_id = numa_node_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) md->init_tio_pdu = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) md->type = DM_TYPE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) mutex_init(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) mutex_init(&md->type_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) mutex_init(&md->table_devices_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) spin_lock_init(&md->deferred_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) atomic_set(&md->holders, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) atomic_set(&md->open_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) atomic_set(&md->event_nr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) atomic_set(&md->uevent_seq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) INIT_LIST_HEAD(&md->uevent_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) INIT_LIST_HEAD(&md->table_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) spin_lock_init(&md->uevent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) * default to bio-based until DM table is loaded and md->type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) * established. If request-based table is loaded: blk-mq will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) * override accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) md->queue = blk_alloc_queue(numa_node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) if (!md->queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) md->disk = alloc_disk_node(1, md->numa_node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) if (!md->disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) init_waitqueue_head(&md->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) INIT_WORK(&md->work, dm_wq_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) init_waitqueue_head(&md->eventq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) init_completion(&md->kobj_holder.completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) md->swap_bios = get_swap_bios();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) sema_init(&md->swap_bios_semaphore, md->swap_bios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) mutex_init(&md->swap_bios_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) md->disk->major = _major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) md->disk->first_minor = minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) md->disk->fops = &dm_blk_dops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) md->disk->queue = md->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) md->disk->private_data = md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) sprintf(md->disk->disk_name, "dm-%d", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) if (IS_ENABLED(CONFIG_DAX_DRIVER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) md->dax_dev = alloc_dax(md, md->disk->disk_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) &dm_dax_ops, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) if (IS_ERR(md->dax_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) md->dax_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) add_disk_no_queue_reg(md->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) format_dev_t(md->name, MKDEV(_major, minor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) md->wq = alloc_workqueue("kdmflush", WQ_MEM_RECLAIM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) if (!md->wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) md->bdev = bdget_disk(md->disk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if (!md->bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) dm_stats_init(&md->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) /* Populate the mapping, nobody knows we exist yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) old_md = idr_replace(&_minor_idr, md, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) BUG_ON(old_md != MINOR_ALLOCED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) return md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) cleanup_mapped_device(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) bad_io_barrier:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) free_minor(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) bad_minor:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) bad_module_get:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) kvfree(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) static void unlock_fs(struct mapped_device *md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) static void free_dev(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) int minor = MINOR(disk_devt(md->disk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) unlock_fs(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) cleanup_mapped_device(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) free_table_devices(&md->table_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) dm_stats_cleanup(&md->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) free_minor(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) kvfree(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) static int __bind_mempools(struct mapped_device *md, struct dm_table *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) struct dm_md_mempools *p = dm_table_get_md_mempools(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) if (dm_table_bio_based(t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) * The md may already have mempools that need changing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) * If so, reload bioset because front_pad may have changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) * because a different table was loaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) bioset_exit(&md->bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) bioset_exit(&md->io_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) } else if (bioset_initialized(&md->bs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) * There's no need to reload with request-based dm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) * because the size of front_pad doesn't change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) * Note for future: If you are to reload bioset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) * prep-ed requests in the queue may refer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) * to bio from the old bioset, so you must walk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) * through the queue to unprep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) BUG_ON(!p ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) bioset_initialized(&md->bs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) bioset_initialized(&md->io_bs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) ret = bioset_init_from_src(&md->bs, &p->bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) ret = bioset_init_from_src(&md->io_bs, &p->io_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) bioset_exit(&md->bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) /* mempool bind completed, no longer need any mempools in the table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) dm_table_free_md_mempools(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) * Bind a table to the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) static void event_callback(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) LIST_HEAD(uevents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) struct mapped_device *md = (struct mapped_device *) context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) spin_lock_irqsave(&md->uevent_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) list_splice_init(&md->uevent_list, &uevents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) spin_unlock_irqrestore(&md->uevent_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) atomic_inc(&md->event_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) wake_up(&md->eventq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) dm_issue_global_event();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) * Returns old map, which caller must destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) struct queue_limits *limits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) struct dm_table *old_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) struct request_queue *q = md->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) bool request_based = dm_table_request_based(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) sector_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) lockdep_assert_held(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) size = dm_table_get_size(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) * Wipe any geometry if the size of the table changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) if (size != dm_get_size(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) memset(&md->geometry, 0, sizeof(md->geometry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) set_capacity(md->disk, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) bd_set_nr_sectors(md->bdev, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) dm_table_event_callback(t, event_callback, md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) * The queue hasn't been stopped yet, if the old table type wasn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) * for request-based during suspension. So stop it to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) * I/O mapping before resume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) * This must be done before setting the queue restrictions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) * because request-based dm may be run just after the setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) if (request_based)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) dm_stop_queue(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) if (request_based) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) * Leverage the fact that request-based DM targets are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) * immutable singletons - used to optimize dm_mq_queue_rq.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) md->immutable_target = dm_table_get_immutable_target(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) ret = __bind_mempools(md, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) old_map = ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) rcu_assign_pointer(md->map, (void *)t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) md->immutable_target_type = dm_table_get_immutable_target_type(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) dm_table_set_restrictions(t, q, limits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) if (old_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) dm_sync_table(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) return old_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) * Returns unbound table for the caller to free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) static struct dm_table *__unbind(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) struct dm_table *map = rcu_dereference_protected(md->map, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) if (!map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) dm_table_event_callback(map, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) RCU_INIT_POINTER(md->map, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) dm_sync_table(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) return map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) * Constructor for a new device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) int dm_create(int minor, struct mapped_device **result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) struct mapped_device *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) md = alloc_dev(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) if (!md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) r = dm_sysfs_init(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) free_dev(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) *result = md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) * Functions to manage md->type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) * All are required to hold md->type_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) void dm_lock_md_type(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) mutex_lock(&md->type_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) void dm_unlock_md_type(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) mutex_unlock(&md->type_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) void dm_set_md_type(struct mapped_device *md, enum dm_queue_mode type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) BUG_ON(!mutex_is_locked(&md->type_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) md->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) enum dm_queue_mode dm_get_md_type(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) return md->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) struct target_type *dm_get_immutable_target_type(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) return md->immutable_target_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) * The queue_limits are only valid as long as you have a reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) * count on 'md'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) struct queue_limits *dm_get_queue_limits(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) BUG_ON(!atomic_read(&md->holders));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) return &md->queue->limits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) EXPORT_SYMBOL_GPL(dm_get_queue_limits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) * Setup the DM device's queue based on md's type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) struct queue_limits limits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) enum dm_queue_mode type = dm_get_md_type(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) case DM_TYPE_REQUEST_BASED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) md->disk->fops = &dm_rq_blk_dops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) r = dm_mq_init_request_queue(md, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) DMERR("Cannot initialize queue for request-based dm mapped device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) case DM_TYPE_BIO_BASED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) case DM_TYPE_DAX_BIO_BASED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) case DM_TYPE_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) WARN_ON_ONCE(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) r = dm_calculate_queue_limits(t, &limits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) DMERR("Cannot calculate initial queue limits");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) dm_table_set_restrictions(t, md->queue, &limits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) blk_register_queue(md->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) struct mapped_device *dm_get_md(dev_t dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) struct mapped_device *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) unsigned minor = MINOR(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) if (MAJOR(dev) != _major || minor >= (1 << MINORBITS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) md = idr_find(&_minor_idr, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) if (!md || md == MINOR_ALLOCED || (MINOR(disk_devt(dm_disk(md))) != minor) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) md = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) dm_get(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) return md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) EXPORT_SYMBOL_GPL(dm_get_md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) void *dm_get_mdptr(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) return md->interface_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) void dm_set_mdptr(struct mapped_device *md, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) md->interface_ptr = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) void dm_get(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) atomic_inc(&md->holders);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) BUG_ON(test_bit(DMF_FREEING, &md->flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) int dm_hold(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) if (test_bit(DMF_FREEING, &md->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) dm_get(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) EXPORT_SYMBOL_GPL(dm_hold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) const char *dm_device_name(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) return md->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) EXPORT_SYMBOL_GPL(dm_device_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) static void __dm_destroy(struct mapped_device *md, bool wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) struct dm_table *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) int srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) might_sleep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md))));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) set_bit(DMF_FREEING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) blk_set_queue_dying(md->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) * Take suspend_lock so that presuspend and postsuspend methods
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) * do not race with internal suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) mutex_lock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) map = dm_get_live_table(md, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) if (!dm_suspended_md(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) dm_table_presuspend_targets(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) set_bit(DMF_SUSPENDED, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) set_bit(DMF_POST_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) dm_table_postsuspend_targets(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) /* dm_put_live_table must be before msleep, otherwise deadlock is possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) * Rare, but there may be I/O requests still going to complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) * for example. Wait for all references to disappear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) * No one should increment the reference count of the mapped_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) * after the mapped_device state becomes DMF_FREEING.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) if (wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) while (atomic_read(&md->holders))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) msleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) else if (atomic_read(&md->holders))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) dm_device_name(md), atomic_read(&md->holders));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) dm_sysfs_exit(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) dm_table_destroy(__unbind(md));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) free_dev(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) void dm_destroy(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) __dm_destroy(md, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) void dm_destroy_immediate(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) __dm_destroy(md, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) void dm_put(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) atomic_dec(&md->holders);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) EXPORT_SYMBOL_GPL(dm_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) static bool md_in_flight_bios(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) struct hd_struct *part = &dm_disk(md)->part0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) long sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) sum += part_stat_local_read_cpu(part, in_flight[0], cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) sum += part_stat_local_read_cpu(part, in_flight[1], cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) return sum != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) static int dm_wait_for_bios_completion(struct mapped_device *md, long task_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) while (true) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) prepare_to_wait(&md->wait, &wait, task_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) if (!md_in_flight_bios(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) if (signal_pending_state(task_state, current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) r = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) io_schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) finish_wait(&md->wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) static int dm_wait_for_completion(struct mapped_device *md, long task_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) if (!queue_is_mq(md->queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) return dm_wait_for_bios_completion(md, task_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) while (true) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) if (!blk_mq_queue_inflight(md->queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) if (signal_pending_state(task_state, current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) r = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) msleep(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) * Process the deferred bios
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) static void dm_wq_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) struct mapped_device *md = container_of(work, struct mapped_device, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) while (!test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) spin_lock_irq(&md->deferred_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) bio = bio_list_pop(&md->deferred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) spin_unlock_irq(&md->deferred_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) if (!bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) submit_bio_noacct(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) static void dm_queue_flush(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) clear_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) queue_work(md->wq, &md->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) * Swap in a new table, returning the old one for the caller to destroy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) struct dm_table *live_map = NULL, *map = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) struct queue_limits limits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) mutex_lock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) /* device must be suspended */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) if (!dm_suspended_md(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) * If the new table has no data devices, retain the existing limits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) * This helps multipath with queue_if_no_path if all paths disappear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) * then new I/O is queued based on these limits, and then some paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) * reappear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) if (dm_table_has_no_data_devices(table)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) live_map = dm_get_live_table_fast(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) if (live_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) limits = md->queue->limits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) dm_put_live_table_fast(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) if (!live_map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) r = dm_calculate_queue_limits(table, &limits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) map = ERR_PTR(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) map = __bind(md, table, &limits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) dm_issue_global_event();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) return map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) * Functions to lock and unlock any filesystem running on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) * device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) static int lock_fs(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) WARN_ON(test_bit(DMF_FROZEN, &md->flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) r = freeze_bdev(md->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) set_bit(DMF_FROZEN, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) static void unlock_fs(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) if (!test_bit(DMF_FROZEN, &md->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) thaw_bdev(md->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) clear_bit(DMF_FROZEN, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) * @suspend_flags: DM_SUSPEND_LOCKFS_FLAG and/or DM_SUSPEND_NOFLUSH_FLAG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) * @task_state: e.g. TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) * @dmf_suspended_flag: DMF_SUSPENDED or DMF_SUSPENDED_INTERNALLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) * If __dm_suspend returns 0, the device is completely quiescent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) * now. There is no request-processing activity. All new requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) * are being added to md->deferred list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) static int __dm_suspend(struct mapped_device *md, struct dm_table *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) unsigned suspend_flags, long task_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) int dmf_suspended_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) bool do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) bool noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) lockdep_assert_held(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) * DMF_NOFLUSH_SUSPENDING must be set before presuspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) * This flag is cleared before dm_suspend returns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) if (noflush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) DMDEBUG("%s: suspending with flush", dm_device_name(md));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) * This gets reverted if there's an error later and the targets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) * provide the .presuspend_undo hook.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) dm_table_presuspend_targets(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) * Flush I/O to the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) * Any I/O submitted after lock_fs() may not be flushed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) * noflush takes precedence over do_lockfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) * (lock_fs() flushes I/Os and waits for them to complete.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) if (!noflush && do_lockfs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) r = lock_fs(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) dm_table_presuspend_undo_targets(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) * Here we must make sure that no processes are submitting requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) * to target drivers i.e. no one may be executing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) * __split_and_process_bio from dm_submit_bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) * To get all processes out of __split_and_process_bio in dm_submit_bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) * we take the write lock. To prevent any process from reentering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) * __split_and_process_bio from dm_submit_bio and quiesce the thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) * (dm_wq_work), we set DMF_BLOCK_IO_FOR_SUSPEND and call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) * flush_workqueue(md->wq).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) if (map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) synchronize_srcu(&md->io_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) * Stop md->queue before flushing md->wq in case request-based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) * dm defers requests to md->wq from md->queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) if (dm_request_based(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) dm_stop_queue(md->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) flush_workqueue(md->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) * At this point no more requests are entering target request routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) * We call dm_wait_for_completion to wait for all existing requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) * to finish.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) r = dm_wait_for_completion(md, task_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) set_bit(dmf_suspended_flag, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) if (noflush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) if (map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) synchronize_srcu(&md->io_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) /* were we interrupted ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) dm_queue_flush(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) if (dm_request_based(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) dm_start_queue(md->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) unlock_fs(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) dm_table_presuspend_undo_targets(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) /* pushback list is already flushed, so skip flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) * We need to be able to change a mapping table under a mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) * filesystem. For example we might want to move some data in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) * the background. Before the table can be swapped with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) * dm_bind_table, dm_suspend must be called to flush any in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) * flight bios and ensure that any further io gets deferred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) * Suspend mechanism in request-based dm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) * 1. Flush all I/Os by lock_fs() if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) * 2. Stop dispatching any I/O by stopping the request_queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) * 3. Wait for all in-flight I/Os to be completed or requeued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) * To abort suspend, start the request_queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) struct dm_table *map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) if (dm_suspended_md(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) if (dm_suspended_internally_md(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) /* already internally suspended, wait for internal resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) r = __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE, DMF_SUSPENDED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) set_bit(DMF_POST_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) dm_table_postsuspend_targets(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) clear_bit(DMF_POST_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) static int __dm_resume(struct mapped_device *md, struct dm_table *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) if (map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) int r = dm_table_resume_targets(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) dm_queue_flush(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) * Flushing deferred I/Os must be done after targets are resumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) * so that mapping of targets can work correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) * Request-based dm is queueing the deferred I/Os in its request_queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) if (dm_request_based(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) dm_start_queue(md->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) unlock_fs(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) int dm_resume(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) struct dm_table *map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) if (!dm_suspended_md(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) if (dm_suspended_internally_md(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) /* already internally suspended, wait for internal resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) if (!map || !dm_table_get_size(map))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) r = __dm_resume(md, map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) clear_bit(DMF_SUSPENDED, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) * Internal suspend/resume works like userspace-driven suspend. It waits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) * until all bios finish and prevents issuing new bios to the target drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) * It may be used only from the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) static void __dm_internal_suspend(struct mapped_device *md, unsigned suspend_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) struct dm_table *map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) lockdep_assert_held(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) if (md->internal_suspend_count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) return; /* nested internal suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) if (dm_suspended_md(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) set_bit(DMF_SUSPENDED_INTERNALLY, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) return; /* nest suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) * Using TASK_UNINTERRUPTIBLE because only NOFLUSH internal suspend is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) * supported. Properly supporting a TASK_INTERRUPTIBLE internal suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) * would require changing .presuspend to return an error -- avoid this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) * until there is a need for more elaborate variants of internal suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) (void) __dm_suspend(md, map, suspend_flags, TASK_UNINTERRUPTIBLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) DMF_SUSPENDED_INTERNALLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) set_bit(DMF_POST_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) dm_table_postsuspend_targets(map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) clear_bit(DMF_POST_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) static void __dm_internal_resume(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) BUG_ON(!md->internal_suspend_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) if (--md->internal_suspend_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) return; /* resume from nested internal suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) if (dm_suspended_md(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) goto done; /* resume from nested suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) * NOTE: existing callers don't need to call dm_table_resume_targets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) * (which may fail -- so best to avoid it for now by passing NULL map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) (void) __dm_resume(md, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) clear_bit(DMF_SUSPENDED_INTERNALLY, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) wake_up_bit(&md->flags, DMF_SUSPENDED_INTERNALLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) void dm_internal_suspend_noflush(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) mutex_lock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) __dm_internal_suspend(md, DM_SUSPEND_NOFLUSH_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) EXPORT_SYMBOL_GPL(dm_internal_suspend_noflush);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) void dm_internal_resume(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) mutex_lock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) __dm_internal_resume(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) EXPORT_SYMBOL_GPL(dm_internal_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) * Fast variants of internal suspend/resume hold md->suspend_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) * which prevents interaction with userspace-driven suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) void dm_internal_suspend_fast(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) mutex_lock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) if (dm_suspended_md(md) || dm_suspended_internally_md(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) synchronize_srcu(&md->io_barrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) flush_workqueue(md->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) EXPORT_SYMBOL_GPL(dm_internal_suspend_fast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) void dm_internal_resume_fast(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) if (dm_suspended_md(md) || dm_suspended_internally_md(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) dm_queue_flush(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) mutex_unlock(&md->suspend_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) EXPORT_SYMBOL_GPL(dm_internal_resume_fast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) /*-----------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) * Event notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) unsigned cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) unsigned noio_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) char udev_cookie[DM_COOKIE_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) char *envp[] = { udev_cookie, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) noio_flag = memalloc_noio_save();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) if (!cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) r = kobject_uevent(&disk_to_dev(md->disk)->kobj, action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) snprintf(udev_cookie, DM_COOKIE_LENGTH, "%s=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) DM_COOKIE_ENV_VAR_NAME, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) r = kobject_uevent_env(&disk_to_dev(md->disk)->kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) action, envp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) memalloc_noio_restore(noio_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) uint32_t dm_next_uevent_seq(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) return atomic_add_return(1, &md->uevent_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) uint32_t dm_get_event_nr(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) return atomic_read(&md->event_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) int dm_wait_event(struct mapped_device *md, int event_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) return wait_event_interruptible(md->eventq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) (event_nr != atomic_read(&md->event_nr)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) spin_lock_irqsave(&md->uevent_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) list_add(elist, &md->uevent_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) spin_unlock_irqrestore(&md->uevent_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) * The gendisk is only valid as long as you have a reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) * count on 'md'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) struct gendisk *dm_disk(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) return md->disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) EXPORT_SYMBOL_GPL(dm_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) struct kobject *dm_kobject(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) return &md->kobj_holder.kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) struct mapped_device *dm_get_from_kobject(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) struct mapped_device *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) md = container_of(kobj, struct mapped_device, kobj_holder.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) spin_lock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) if (test_bit(DMF_FREEING, &md->flags) || dm_deleting_md(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) md = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) dm_get(md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) spin_unlock(&_minor_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) return md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) int dm_suspended_md(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) return test_bit(DMF_SUSPENDED, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) static int dm_post_suspending_md(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) return test_bit(DMF_POST_SUSPENDING, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) int dm_suspended_internally_md(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) return test_bit(DMF_SUSPENDED_INTERNALLY, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) int dm_test_deferred_remove_flag(struct mapped_device *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) return test_bit(DMF_DEFERRED_REMOVE, &md->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) int dm_suspended(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) return dm_suspended_md(ti->table->md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) EXPORT_SYMBOL_GPL(dm_suspended);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) int dm_post_suspending(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) return dm_post_suspending_md(ti->table->md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) EXPORT_SYMBOL_GPL(dm_post_suspending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) int dm_noflush_suspending(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) return __noflush_suspending(ti->table->md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) EXPORT_SYMBOL_GPL(dm_noflush_suspending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) struct dm_md_mempools *dm_alloc_md_mempools(struct mapped_device *md, enum dm_queue_mode type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) unsigned integrity, unsigned per_io_data_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) unsigned min_pool_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) struct dm_md_mempools *pools = kzalloc_node(sizeof(*pools), GFP_KERNEL, md->numa_node_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) unsigned int pool_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) unsigned int front_pad, io_front_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) if (!pools)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) case DM_TYPE_BIO_BASED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) case DM_TYPE_DAX_BIO_BASED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) pool_size = max(dm_get_reserved_bio_based_ios(), min_pool_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) front_pad = roundup(per_io_data_size, __alignof__(struct dm_target_io)) + offsetof(struct dm_target_io, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) io_front_pad = roundup(front_pad, __alignof__(struct dm_io)) + offsetof(struct dm_io, tio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) ret = bioset_init(&pools->io_bs, pool_size, io_front_pad, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) if (integrity && bioset_integrity_create(&pools->io_bs, pool_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) case DM_TYPE_REQUEST_BASED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) pool_size = max(dm_get_reserved_rq_based_ios(), min_pool_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) front_pad = offsetof(struct dm_rq_clone_bio_info, clone);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) /* per_io_data_size is used for blk-mq pdu at queue allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) ret = bioset_init(&pools->bs, pool_size, front_pad, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) if (integrity && bioset_integrity_create(&pools->bs, pool_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) return pools;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) dm_free_md_mempools(pools);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) void dm_free_md_mempools(struct dm_md_mempools *pools)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) if (!pools)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) bioset_exit(&pools->bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) bioset_exit(&pools->io_bs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) kfree(pools);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) struct dm_pr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) u64 old_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) u64 new_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) bool fail_early;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) static int dm_call_pr(struct block_device *bdev, iterate_devices_callout_fn fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) struct mapped_device *md = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) struct dm_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) int ret = -ENOTTY, srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) table = dm_get_live_table(md, &srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) if (!table || !dm_table_get_size(table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) /* We only support devices that have a single target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) if (dm_table_get_num_targets(table) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) ti = dm_table_get_target(table, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) if (!ti->type->iterate_devices)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) ret = ti->type->iterate_devices(ti, fn, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) dm_put_live_table(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) * For register / unregister we need to manually call out to every path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) static int __dm_pr_register(struct dm_target *ti, struct dm_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) sector_t start, sector_t len, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) struct dm_pr *pr = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) const struct pr_ops *ops = dev->bdev->bd_disk->fops->pr_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) if (!ops || !ops->pr_register)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) return ops->pr_register(dev->bdev, pr->old_key, pr->new_key, pr->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) static int dm_pr_register(struct block_device *bdev, u64 old_key, u64 new_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) struct dm_pr pr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) .old_key = old_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) .new_key = new_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) .flags = flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) .fail_early = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) ret = dm_call_pr(bdev, __dm_pr_register, &pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) if (ret && new_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) /* unregister all paths if we failed to register any path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) pr.old_key = new_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) pr.new_key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) pr.flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) pr.fail_early = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) dm_call_pr(bdev, __dm_pr_register, &pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) static int dm_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) struct mapped_device *md = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) const struct pr_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) int r, srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) r = dm_prepare_ioctl(md, &srcu_idx, &bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) ops = bdev->bd_disk->fops->pr_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) if (ops && ops->pr_reserve)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) r = ops->pr_reserve(bdev, key, type, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) r = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) dm_unprepare_ioctl(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) static int dm_pr_release(struct block_device *bdev, u64 key, enum pr_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) struct mapped_device *md = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) const struct pr_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) int r, srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) r = dm_prepare_ioctl(md, &srcu_idx, &bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) ops = bdev->bd_disk->fops->pr_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) if (ops && ops->pr_release)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) r = ops->pr_release(bdev, key, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) r = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) dm_unprepare_ioctl(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) static int dm_pr_preempt(struct block_device *bdev, u64 old_key, u64 new_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) enum pr_type type, bool abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) struct mapped_device *md = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) const struct pr_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) int r, srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) r = dm_prepare_ioctl(md, &srcu_idx, &bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) ops = bdev->bd_disk->fops->pr_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) if (ops && ops->pr_preempt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) r = ops->pr_preempt(bdev, old_key, new_key, type, abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) r = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) dm_unprepare_ioctl(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) static int dm_pr_clear(struct block_device *bdev, u64 key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) struct mapped_device *md = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) const struct pr_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) int r, srcu_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) r = dm_prepare_ioctl(md, &srcu_idx, &bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) ops = bdev->bd_disk->fops->pr_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) if (ops && ops->pr_clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) r = ops->pr_clear(bdev, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) r = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) dm_unprepare_ioctl(md, srcu_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) static const struct pr_ops dm_pr_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) .pr_register = dm_pr_register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) .pr_reserve = dm_pr_reserve,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) .pr_release = dm_pr_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) .pr_preempt = dm_pr_preempt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) .pr_clear = dm_pr_clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) static const struct block_device_operations dm_blk_dops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) .submit_bio = dm_submit_bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) .open = dm_blk_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) .release = dm_blk_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) .ioctl = dm_blk_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) .getgeo = dm_blk_getgeo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) .report_zones = dm_blk_report_zones,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) .pr_ops = &dm_pr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) .owner = THIS_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) static const struct block_device_operations dm_rq_blk_dops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) .open = dm_blk_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) .release = dm_blk_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) .ioctl = dm_blk_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) .getgeo = dm_blk_getgeo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) .pr_ops = &dm_pr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) .owner = THIS_MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) static const struct dax_operations dm_dax_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) .direct_access = dm_dax_direct_access,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) .dax_supported = dm_dax_supported,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) .copy_from_iter = dm_dax_copy_from_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) .copy_to_iter = dm_dax_copy_to_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) .zero_page_range = dm_dax_zero_page_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) * module hooks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) module_init(dm_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) module_exit(dm_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) module_param(major, uint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) MODULE_PARM_DESC(major, "The major number of the device mapper");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) module_param(reserved_bio_based_ios, uint, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) MODULE_PARM_DESC(reserved_bio_based_ios, "Reserved IOs in bio-based mempools");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) module_param(dm_numa_node, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) MODULE_PARM_DESC(dm_numa_node, "NUMA node for DM device memory allocations");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) module_param(swap_bios, int, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) MODULE_PARM_DESC(swap_bios, "Maximum allowed inflight swap IOs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) MODULE_DESCRIPTION(DM_NAME " driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) MODULE_LICENSE("GPL");