^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (C) 2003 Sistina Software Limited.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2005-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-bio-record.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mempool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/device-mapper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/dm-io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/dm-dirty-log.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/dm-kcopyd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/dm-region-hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DM_MSG_PREFIX "raid1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define MAX_RECOVERY 1 /* Maximum number of regions recovered in parallel. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define MAX_NR_MIRRORS (DM_KCOPYD_MAX_REGIONS + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define DM_RAID1_HANDLE_ERRORS 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define DM_RAID1_KEEP_LOG 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define errors_handled(p) ((p)->features & DM_RAID1_HANDLE_ERRORS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define keep_log(p) ((p)->features & DM_RAID1_KEEP_LOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static DECLARE_WAIT_QUEUE_HEAD(_kmirrord_recovery_stopped);
^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) * Mirror set structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) enum dm_raid1_error {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) DM_RAID1_WRITE_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) DM_RAID1_FLUSH_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) DM_RAID1_SYNC_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) DM_RAID1_READ_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct mirror {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct mirror_set *ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) atomic_t error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) unsigned long error_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct dm_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) sector_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct mirror_set {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct dm_target *ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) uint64_t features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) spinlock_t lock; /* protects the lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct bio_list reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct bio_list writes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct bio_list failures;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct bio_list holds; /* bios are waiting until suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct dm_region_hash *rh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct dm_kcopyd_client *kcopyd_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct dm_io_client *io_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) region_t nr_regions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int in_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int log_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int leg_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) atomic_t suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) atomic_t default_mirror; /* Default mirror */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct workqueue_struct *kmirrord_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct work_struct kmirrord_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) unsigned long timer_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct work_struct trigger_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) unsigned nr_mirrors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct mirror mirror[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(raid1_resync_throttle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) "A percentage of time allocated for raid resynchronization");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void wakeup_mirrord(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct mirror_set *ms = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) queue_work(ms->kmirrord_wq, &ms->kmirrord_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static void delayed_wake_fn(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct mirror_set *ms = from_timer(ms, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) clear_bit(0, &ms->timer_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) wakeup_mirrord(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static void delayed_wake(struct mirror_set *ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (test_and_set_bit(0, &ms->timer_pending))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ms->timer.expires = jiffies + HZ / 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) add_timer(&ms->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static void wakeup_all_recovery_waiters(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) wake_up_all(&_kmirrord_recovery_stopped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int should_wake = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct bio_list *bl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) bl = (rw == WRITE) ? &ms->writes : &ms->reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) spin_lock_irqsave(&ms->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) should_wake = !(bl->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) bio_list_add(bl, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) spin_unlock_irqrestore(&ms->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (should_wake)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) wakeup_mirrord(ms);
^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) static void dispatch_bios(void *context, struct bio_list *bio_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct mirror_set *ms = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) while ((bio = bio_list_pop(bio_list)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) queue_bio(ms, bio, WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct dm_raid1_bio_record {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct mirror *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* if details->bi_disk == NULL, details were not saved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct dm_bio_details details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) region_t write_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * Every mirror should look like this one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define DEFAULT_MIRROR 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * This is yucky. We squirrel the mirror struct away inside
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * bi_next for read/write buffers. This is safe since the bh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * doesn't get submitted to the lower levels of block layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static struct mirror *bio_get_m(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return (struct mirror *) bio->bi_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static void bio_set_m(struct bio *bio, struct mirror *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) bio->bi_next = (struct bio *) m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static struct mirror *get_default_mirror(struct mirror_set *ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return &ms->mirror[atomic_read(&ms->default_mirror)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void set_default_mirror(struct mirror *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct mirror_set *ms = m->ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct mirror *m0 = &(ms->mirror[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) atomic_set(&ms->default_mirror, m - m0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static struct mirror *get_valid_mirror(struct mirror_set *ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct mirror *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (!atomic_read(&m->error_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* fail_mirror
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * @m: mirror device to fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * @error_type: one of the enum's, DM_RAID1_*_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * If errors are being handled, record the type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * error encountered for this device. If this type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * of error has already been recorded, we can return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * otherwise, we must signal userspace by triggering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * an event. Additionally, if the device is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * primary device, we must choose a new primary, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * only if the mirror is in-sync.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * This function must not block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct mirror_set *ms = m->ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct mirror *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ms->leg_failure = 1;
^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) * error_count is used for nothing more than a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * simple way to tell if a device has encountered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) atomic_inc(&m->error_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (test_and_set_bit(error_type, &m->error_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (!errors_handled(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (m != get_default_mirror(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (!ms->in_sync && !keep_log(ms)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * Better to issue requests to same failing device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * than to risk returning corrupt data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) DMERR("Primary mirror (%s) failed while out-of-sync: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) "Reads may fail.", m->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) new = get_valid_mirror(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) set_default_mirror(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) DMWARN("All sides of mirror have failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) schedule_work(&ms->trigger_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int mirror_flush(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct mirror_set *ms = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) unsigned long error_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct dm_io_region io[MAX_NR_MIRRORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct mirror *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct dm_io_request io_req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .bi_op = REQ_OP_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .bi_op_flags = REQ_PREFLUSH | REQ_SYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .mem.type = DM_IO_KMEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .mem.ptr.addr = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .client = ms->io_client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) io[i].bdev = m->dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) io[i].sector = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) io[i].count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) error_bits = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) dm_io(&io_req, ms->nr_mirrors, io, &error_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (unlikely(error_bits != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) for (i = 0; i < ms->nr_mirrors; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (test_bit(i, &error_bits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) fail_mirror(ms->mirror + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) DM_RAID1_FLUSH_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /*-----------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * Recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * When a mirror is first activated we may find that some regions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * are in the no-sync state. We have to recover these by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * recopying from the default mirror to all the others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void recovery_complete(int read_err, unsigned long write_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct dm_region *reg = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct mirror_set *ms = dm_rh_region_context(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int m, bit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (read_err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /* Read error means the failure of default mirror. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) DMERR_LIMIT("Unable to read primary mirror during recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) fail_mirror(get_default_mirror(ms), DM_RAID1_SYNC_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (write_err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) DMERR_LIMIT("Write error during recovery (error = 0x%lx)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) write_err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * Bits correspond to devices (excluding default mirror).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * The default mirror cannot change during recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) for (m = 0; m < ms->nr_mirrors; m++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (&ms->mirror[m] == get_default_mirror(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (test_bit(bit, &write_err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) fail_mirror(ms->mirror + m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) DM_RAID1_SYNC_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) bit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) dm_rh_recovery_end(reg, !(read_err || write_err));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static void recover(struct mirror_set *ms, struct dm_region *reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct dm_io_region from, to[DM_KCOPYD_MAX_REGIONS], *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct mirror *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) unsigned long flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) region_t key = dm_rh_get_region_key(reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) sector_t region_size = dm_rh_get_region_size(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /* fill in the source */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) m = get_default_mirror(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) from.bdev = m->dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) from.sector = m->offset + dm_rh_region_to_sector(ms->rh, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (key == (ms->nr_regions - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * The final region may be smaller than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * region_size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) from.count = ms->ti->len & (region_size - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (!from.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) from.count = region_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) from.count = region_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* fill in the destinations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) for (i = 0, dest = to; i < ms->nr_mirrors; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (&ms->mirror[i] == get_default_mirror(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) m = ms->mirror + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) dest->bdev = m->dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) dest->sector = m->offset + dm_rh_region_to_sector(ms->rh, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) dest->count = from.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) dest++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* hand to kcopyd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (!errors_handled(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) set_bit(DM_KCOPYD_IGNORE_ERROR, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) flags, recovery_complete, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static void reset_ms_flags(struct mirror_set *ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) unsigned int m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ms->leg_failure = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) for (m = 0; m < ms->nr_mirrors; m++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) atomic_set(&(ms->mirror[m].error_count), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ms->mirror[m].error_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static void do_recovery(struct mirror_set *ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct dm_region *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * Start quiescing some regions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) dm_rh_recovery_prepare(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * Copy any already quiesced regions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) while ((reg = dm_rh_recovery_start(ms->rh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) recover(ms, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * Update the in sync flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (!ms->in_sync &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) (log->type->get_sync_count(log) == ms->nr_regions)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* the sync is complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) dm_table_event(ms->ti->table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) ms->in_sync = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) reset_ms_flags(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) /*-----------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * Reads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct mirror *m = get_default_mirror(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (likely(!atomic_read(&m->error_count)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (m-- == ms->mirror)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) m += ms->nr_mirrors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) } while (m != get_default_mirror(ms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static int default_ok(struct mirror *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct mirror *default_mirror = get_default_mirror(m->ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return !atomic_read(&default_mirror->error_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static int mirror_available(struct mirror_set *ms, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) region_t region = dm_rh_bio_to_region(ms->rh, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (log->type->in_sync(log, region, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return choose_mirror(ms, bio->bi_iter.bi_sector) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * remap a buffer to a particular mirror.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static sector_t map_sector(struct mirror *m, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (unlikely(!bio->bi_iter.bi_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return m->offset + dm_target_offset(m->ms->ti, bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static void map_bio(struct mirror *m, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) bio_set_dev(bio, m->dev->bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) bio->bi_iter.bi_sector = map_sector(m, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static void map_region(struct dm_io_region *io, struct mirror *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) io->bdev = m->dev->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) io->sector = map_sector(m, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) io->count = bio_sectors(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static void hold_bio(struct mirror_set *ms, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * Lock is required to avoid race condition during suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) spin_lock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (atomic_read(&ms->suspend)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) spin_unlock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * If device is suspended, complete the bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (dm_noflush_suspending(ms->ti))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) bio->bi_status = BLK_STS_DM_REQUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) bio->bi_status = BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) bio_endio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * Hold bio until the suspend is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) bio_list_add(&ms->holds, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) spin_unlock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /*-----------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * Reads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static void read_callback(unsigned long error, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct bio *bio = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct mirror *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) m = bio_get_m(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) bio_set_m(bio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (likely(!error)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) bio_endio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) fail_mirror(m, DM_RAID1_READ_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (likely(default_ok(m)) || mirror_available(m->ms, bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) DMWARN_LIMIT("Read failure on mirror device %s. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) "Trying alternative device.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) m->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) queue_bio(m->ms, bio, bio_data_dir(bio));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) DMERR_LIMIT("Read failure on mirror device %s. Failing I/O.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) m->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) bio_io_error(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /* Asynchronous read. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static void read_async_bio(struct mirror *m, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct dm_io_region io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct dm_io_request io_req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) .bi_op = REQ_OP_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) .bi_op_flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) .mem.type = DM_IO_BIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) .mem.ptr.bio = bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .notify.fn = read_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .notify.context = bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) .client = m->ms->io_client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) map_region(&io, m, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) bio_set_m(bio, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) BUG_ON(dm_io(&io_req, 1, &io, NULL));
^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) static inline int region_in_sync(struct mirror_set *ms, region_t region,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) int may_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) int state = dm_rh_get_state(ms->rh, region, may_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return state == DM_RH_CLEAN || state == DM_RH_DIRTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) static void do_reads(struct mirror_set *ms, struct bio_list *reads)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) region_t region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) struct mirror *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) while ((bio = bio_list_pop(reads))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) region = dm_rh_bio_to_region(ms->rh, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) m = get_default_mirror(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * We can only read balance if the region is in sync.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (likely(region_in_sync(ms, region, 1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) m = choose_mirror(ms, bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) else if (m && atomic_read(&m->error_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) m = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (likely(m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) read_async_bio(m, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) bio_io_error(bio);
^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) /*-----------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * Writes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * We do different things with the write io depending on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * state of the region that it's in:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * SYNC: increment pending, use kcopyd to write to *all* mirrors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * RECOVERING: delay the io until recovery completes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * NOSYNC: increment pending, just write to the default mirror
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static void write_callback(unsigned long error, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct bio *bio = (struct bio *) context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct mirror_set *ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) int should_wake = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) ms = bio_get_m(bio)->ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) bio_set_m(bio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) * NOTE: We don't decrement the pending count here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * instead it is done by the targets endio function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * This way we handle both writes to SYNC and NOSYNC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) * regions with the same code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (likely(!error)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) bio_endio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * If the bio is discard, return an error, but do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * degrade the array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (bio_op(bio) == REQ_OP_DISCARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) bio->bi_status = BLK_STS_NOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) bio_endio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) return;
^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) for (i = 0; i < ms->nr_mirrors; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (test_bit(i, &error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) fail_mirror(ms->mirror + i, DM_RAID1_WRITE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * Need to raise event. Since raising
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) * events can block, we need to do it in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * the main thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) spin_lock_irqsave(&ms->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (!ms->failures.head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) should_wake = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) bio_list_add(&ms->failures, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) spin_unlock_irqrestore(&ms->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (should_wake)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) wakeup_mirrord(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static void do_write(struct mirror_set *ms, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) struct dm_io_region io[MAX_NR_MIRRORS], *dest = io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) struct mirror *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) struct dm_io_request io_req = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) .bi_op = REQ_OP_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) .bi_op_flags = bio->bi_opf & (REQ_FUA | REQ_PREFLUSH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) .mem.type = DM_IO_BIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) .mem.ptr.bio = bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) .notify.fn = write_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) .notify.context = bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) .client = ms->io_client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (bio_op(bio) == REQ_OP_DISCARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) io_req.bi_op = REQ_OP_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) io_req.mem.type = DM_IO_KMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) io_req.mem.ptr.addr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) map_region(dest++, m, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * Use default mirror because we only need it to retrieve the reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * to the mirror set in write_callback().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) bio_set_m(bio, get_default_mirror(ms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) BUG_ON(dm_io(&io_req, ms->nr_mirrors, io, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) static void do_writes(struct mirror_set *ms, struct bio_list *writes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) struct bio_list sync, nosync, recover, *this_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) struct bio_list requeue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) region_t region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (!writes->head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return;
^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) * Classify each write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) bio_list_init(&sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) bio_list_init(&nosync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) bio_list_init(&recover);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) bio_list_init(&requeue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) while ((bio = bio_list_pop(writes))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if ((bio->bi_opf & REQ_PREFLUSH) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) (bio_op(bio) == REQ_OP_DISCARD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) bio_list_add(&sync, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) continue;
^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) region = dm_rh_bio_to_region(ms->rh, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (log->type->is_remote_recovering &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) log->type->is_remote_recovering(log, region)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) bio_list_add(&requeue, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) state = dm_rh_get_state(ms->rh, region, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) case DM_RH_CLEAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) case DM_RH_DIRTY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) this_list = &sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) case DM_RH_NOSYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) this_list = &nosync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) case DM_RH_RECOVERING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) this_list = &recover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) bio_list_add(this_list, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * Add bios that are delayed due to remote recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * back on to the write queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) if (unlikely(requeue.head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) spin_lock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) bio_list_merge(&ms->writes, &requeue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) spin_unlock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) delayed_wake(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * Increment the pending counts for any regions that will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * be written to (writes to recover regions are going to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * be delayed).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) dm_rh_inc_pending(ms->rh, &sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) dm_rh_inc_pending(ms->rh, &nosync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) * If the flush fails on a previous call and succeeds here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) * we must not reset the log_failure variable. We need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * userspace interaction to do that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) ms->log_failure = dm_rh_flush(ms->rh) ? 1 : ms->log_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * Dispatch io.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (unlikely(ms->log_failure) && errors_handled(ms)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) spin_lock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) bio_list_merge(&ms->failures, &sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) spin_unlock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) wakeup_mirrord(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) while ((bio = bio_list_pop(&sync)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) do_write(ms, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) while ((bio = bio_list_pop(&recover)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) dm_rh_delay(ms->rh, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) while ((bio = bio_list_pop(&nosync))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (unlikely(ms->leg_failure) && errors_handled(ms) && !keep_log(ms)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) spin_lock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) bio_list_add(&ms->failures, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) spin_unlock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) wakeup_mirrord(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) map_bio(get_default_mirror(ms), bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) submit_bio_noacct(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) }
^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 void do_failures(struct mirror_set *ms, struct bio_list *failures)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) if (likely(!failures->head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * If the log has failed, unattempted writes are being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * put on the holds list. We can't issue those writes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * until a log has been marked, so we must store them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * If a 'noflush' suspend is in progress, we can requeue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * the I/O's to the core. This give userspace a chance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * to reconfigure the mirror, at which point the core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) * will reissue the writes. If the 'noflush' flag is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) * not set, we have no choice but to return errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) * Some writes on the failures list may have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) * submitted before the log failure and represent a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * failure to write to one of the devices. It is ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * for us to treat them the same and requeue them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) while ((bio = bio_list_pop(failures))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (!ms->log_failure) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) ms->in_sync = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) dm_rh_mark_nosync(ms->rh, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * If all the legs are dead, fail the I/O.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * If the device has failed and keep_log is enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * fail the I/O.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * If we have been told to handle errors, and keep_log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * isn't enabled, hold the bio and wait for userspace to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) * deal with the problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) * Otherwise pretend that the I/O succeeded. (This would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) * be wrong if the failed leg returned after reboot and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) * got replicated back to the good legs.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (unlikely(!get_valid_mirror(ms) || (keep_log(ms) && ms->log_failure)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) bio_io_error(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) else if (errors_handled(ms) && !keep_log(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) hold_bio(ms, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) bio_endio(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) static void trigger_event(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) struct mirror_set *ms =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) container_of(work, struct mirror_set, trigger_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) dm_table_event(ms->ti->table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /*-----------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) * kmirrord
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) static void do_mirror(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct mirror_set *ms = container_of(work, struct mirror_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) kmirrord_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct bio_list reads, writes, failures;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) spin_lock_irqsave(&ms->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) reads = ms->reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) writes = ms->writes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) failures = ms->failures;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) bio_list_init(&ms->reads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) bio_list_init(&ms->writes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) bio_list_init(&ms->failures);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) spin_unlock_irqrestore(&ms->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) dm_rh_update_states(ms->rh, errors_handled(ms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) do_recovery(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) do_reads(ms, &reads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) do_writes(ms, &writes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) do_failures(ms, &failures);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^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) * Target functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) *---------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) static struct mirror_set *alloc_context(unsigned int nr_mirrors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) uint32_t region_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) struct dm_dirty_log *dl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) struct mirror_set *ms =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) kzalloc(struct_size(ms, mirror, nr_mirrors), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (!ms) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) ti->error = "Cannot allocate mirror context";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) spin_lock_init(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) bio_list_init(&ms->reads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) bio_list_init(&ms->writes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) bio_list_init(&ms->failures);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) bio_list_init(&ms->holds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) ms->ti = ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) ms->nr_mirrors = nr_mirrors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) ms->nr_regions = dm_sector_div_up(ti->len, region_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) ms->in_sync = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) ms->log_failure = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) ms->leg_failure = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) atomic_set(&ms->suspend, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) atomic_set(&ms->default_mirror, DEFAULT_MIRROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) ms->io_client = dm_io_client_create();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (IS_ERR(ms->io_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) ti->error = "Error creating dm_io client";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) kfree(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) ms->rh = dm_region_hash_create(ms, dispatch_bios, wakeup_mirrord,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) wakeup_all_recovery_waiters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ms->ti->begin, MAX_RECOVERY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) dl, region_size, ms->nr_regions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) if (IS_ERR(ms->rh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) ti->error = "Error creating dirty region hash";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) dm_io_client_destroy(ms->io_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) kfree(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) static void free_context(struct mirror_set *ms, struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) unsigned int m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) while (m--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) dm_put_device(ti, ms->mirror[m].dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) dm_io_client_destroy(ms->io_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) dm_region_hash_destroy(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) kfree(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) unsigned int mirror, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) unsigned long long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) char dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) if (sscanf(argv[1], "%llu%c", &offset, &dummy) != 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) offset != (sector_t)offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) ti->error = "Invalid offset";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) &ms->mirror[mirror].dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) ti->error = "Device lookup failure";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) return ret;
^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) ms->mirror[mirror].ms = ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) atomic_set(&(ms->mirror[mirror].error_count), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) ms->mirror[mirror].error_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) ms->mirror[mirror].offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) * Create dirty log: log_type #log_params <log_params>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) static struct dm_dirty_log *create_dirty_log(struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) unsigned argc, char **argv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) unsigned *args_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) unsigned param_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) struct dm_dirty_log *dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) char dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) if (argc < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) ti->error = "Insufficient mirror log arguments";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (sscanf(argv[1], "%u%c", ¶m_count, &dummy) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) ti->error = "Invalid mirror log argument count";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) *args_used = 2 + param_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) if (argc < *args_used) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) ti->error = "Insufficient mirror log arguments";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) dl = dm_dirty_log_create(argv[0], ti, mirror_flush, param_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) argv + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) if (!dl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) ti->error = "Error creating mirror dirty log";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) static int parse_features(struct mirror_set *ms, unsigned argc, char **argv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) unsigned *args_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) unsigned num_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) struct dm_target *ti = ms->ti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) char dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) *args_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (!argc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) if (sscanf(argv[0], "%u%c", &num_features, &dummy) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) ti->error = "Invalid number of features";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) argc--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) argv++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) (*args_used)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) if (num_features > argc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) ti->error = "Not enough arguments to support feature count";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) for (i = 0; i < num_features; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (!strcmp("handle_errors", argv[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) ms->features |= DM_RAID1_HANDLE_ERRORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) else if (!strcmp("keep_log", argv[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) ms->features |= DM_RAID1_KEEP_LOG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) ti->error = "Unrecognised feature requested";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) argc--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) argv++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) (*args_used)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (!errors_handled(ms) && keep_log(ms)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) ti->error = "keep_log feature requires the handle_errors feature";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return -EINVAL;
^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 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) * Construct a mirror mapping:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) * log_type #log_params <log_params>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) * #mirrors [mirror_path offset]{2,}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) * [#features <features>]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) * log_type is "core" or "disk"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) * #log_params is between 1 and 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * If present, supported features are "handle_errors" and "keep_log".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) unsigned int nr_mirrors, m, args_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) struct mirror_set *ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) struct dm_dirty_log *dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) char dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) dl = create_dirty_log(ti, argc, argv, &args_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) if (!dl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) argv += args_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) argc -= args_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) if (!argc || sscanf(argv[0], "%u%c", &nr_mirrors, &dummy) != 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) nr_mirrors < 2 || nr_mirrors > MAX_NR_MIRRORS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) ti->error = "Invalid number of mirrors";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) dm_dirty_log_destroy(dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) argv++, argc--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) if (argc < nr_mirrors * 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) ti->error = "Too few mirror arguments";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) dm_dirty_log_destroy(dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) ms = alloc_context(nr_mirrors, dl->type->get_region_size(dl), ti, dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (!ms) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) dm_dirty_log_destroy(dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) /* Get the mirror parameter sets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) for (m = 0; m < nr_mirrors; m++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) r = get_mirror(ms, ti, m, argv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) free_context(ms, ti, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) argv += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) argc -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) ti->private = ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) r = dm_set_target_max_io_len(ti, dm_rh_get_region_size(ms->rh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) goto err_free_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) ti->num_flush_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) ti->num_discard_bios = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) ti->per_io_data_size = sizeof(struct dm_raid1_bio_record);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) ms->kmirrord_wq = alloc_workqueue("kmirrord", WQ_MEM_RECLAIM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) if (!ms->kmirrord_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) DMERR("couldn't start kmirrord");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) r = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) goto err_free_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) INIT_WORK(&ms->kmirrord_work, do_mirror);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) timer_setup(&ms->timer, delayed_wake_fn, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) ms->timer_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) INIT_WORK(&ms->trigger_event, trigger_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) r = parse_features(ms, argc, argv, &args_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) goto err_destroy_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) argv += args_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) argc -= args_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) * Any read-balancing addition depends on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) * DM_RAID1_HANDLE_ERRORS flag being present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) * This is because the decision to balance depends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) * on the sync state of a region. If the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * flag is not present, we ignore errors; and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) * the sync state may be inaccurate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (argc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) ti->error = "Too many mirror arguments";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) r = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) goto err_destroy_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) ms->kcopyd_client = dm_kcopyd_client_create(&dm_kcopyd_throttle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) if (IS_ERR(ms->kcopyd_client)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) r = PTR_ERR(ms->kcopyd_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) goto err_destroy_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) wakeup_mirrord(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) err_destroy_wq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) destroy_workqueue(ms->kmirrord_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) err_free_context:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) free_context(ms, ti, ms->nr_mirrors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) static void mirror_dtr(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) struct mirror_set *ms = (struct mirror_set *) ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) del_timer_sync(&ms->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) flush_workqueue(ms->kmirrord_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) flush_work(&ms->trigger_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) dm_kcopyd_client_destroy(ms->kcopyd_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) destroy_workqueue(ms->kmirrord_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) free_context(ms, ti, ms->nr_mirrors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) * Mirror mapping function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) static int mirror_map(struct dm_target *ti, struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) int r, rw = bio_data_dir(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) struct mirror *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) struct mirror_set *ms = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) struct dm_raid1_bio_record *bio_record =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) bio_record->details.bi_disk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (rw == WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) /* Save region for mirror_end_io() handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) queue_bio(ms, bio, rw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) return DM_MAPIO_SUBMITTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) r = log->type->in_sync(log, dm_rh_bio_to_region(ms->rh, bio), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (r < 0 && r != -EWOULDBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) return DM_MAPIO_KILL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) * If region is not in-sync queue the bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) if (!r || (r == -EWOULDBLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) if (bio->bi_opf & REQ_RAHEAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) return DM_MAPIO_KILL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) queue_bio(ms, bio, rw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) return DM_MAPIO_SUBMITTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) * The region is in-sync and we can perform reads directly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) * Store enough information so we can retry if it fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) m = choose_mirror(ms, bio->bi_iter.bi_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) if (unlikely(!m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return DM_MAPIO_KILL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) dm_bio_record(&bio_record->details, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) bio_record->m = m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) map_bio(m, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) return DM_MAPIO_REMAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) static int mirror_end_io(struct dm_target *ti, struct bio *bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) blk_status_t *error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) int rw = bio_data_dir(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) struct mirror_set *ms = (struct mirror_set *) ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) struct mirror *m = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) struct dm_bio_details *bd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) struct dm_raid1_bio_record *bio_record =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) * We need to dec pending if this was a write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) if (rw == WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (!(bio->bi_opf & REQ_PREFLUSH) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) bio_op(bio) != REQ_OP_DISCARD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) dm_rh_dec(ms->rh, bio_record->write_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) return DM_ENDIO_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) if (*error == BLK_STS_NOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) if (bio->bi_opf & REQ_RAHEAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) if (unlikely(*error)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (!bio_record->details.bi_disk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) * There wasn't enough memory to record necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) * information for a retry or there was no other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) * mirror in-sync.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) DMERR_LIMIT("Mirror read failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) return DM_ENDIO_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) m = bio_record->m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) DMERR("Mirror read failed from %s. Trying alternative device.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) m->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) fail_mirror(m, DM_RAID1_READ_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) * A failed read is requeued for another attempt using an intact
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) * mirror.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) if (default_ok(m) || mirror_available(ms, bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) bd = &bio_record->details;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) dm_bio_restore(bd, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) bio_record->details.bi_disk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) bio->bi_status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) queue_bio(ms, bio, rw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return DM_ENDIO_INCOMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) DMERR("All replicated volumes dead, failing I/O");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) bio_record->details.bi_disk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) return DM_ENDIO_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) static void mirror_presuspend(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) struct mirror_set *ms = (struct mirror_set *) ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) struct bio_list holds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) atomic_set(&ms->suspend, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) * Process bios in the hold list to start recovery waiting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) * for bios in the hold list. After the process, no bio has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) * a chance to be added in the hold list because ms->suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) * is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) spin_lock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) holds = ms->holds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) bio_list_init(&ms->holds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) spin_unlock_irq(&ms->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) while ((bio = bio_list_pop(&holds)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) hold_bio(ms, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) * We must finish up all the work that we've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) * generated (i.e. recovery work).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) dm_rh_stop_recovery(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) wait_event(_kmirrord_recovery_stopped,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) !dm_rh_recovery_in_flight(ms->rh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) if (log->type->presuspend && log->type->presuspend(log))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) /* FIXME: need better error handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) DMWARN("log presuspend failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) * Now that recovery is complete/stopped and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) * delayed bios are queued, we need to wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) * the worker thread to complete. This way,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) * we know that all of our I/O has been pushed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) flush_workqueue(ms->kmirrord_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) static void mirror_postsuspend(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) struct mirror_set *ms = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) if (log->type->postsuspend && log->type->postsuspend(log))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) /* FIXME: need better error handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) DMWARN("log postsuspend failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) static void mirror_resume(struct dm_target *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) struct mirror_set *ms = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) atomic_set(&ms->suspend, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) if (log->type->resume && log->type->resume(log))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) /* FIXME: need better error handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) DMWARN("log resume failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) dm_rh_start_recovery(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) * device_status_char
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) * @m: mirror device/leg we want the status of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) * We return one character representing the most severe error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) * we have encountered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) * A => Alive - No failures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) * D => Dead - A write failure occurred leaving mirror out-of-sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) * S => Sync - A sychronization failure occurred, mirror out-of-sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) * R => Read - A read failure occurred, mirror data unaffected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) * Returns: <char>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) static char device_status_char(struct mirror *m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) if (!atomic_read(&(m->error_count)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) return 'A';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) (test_bit(DM_RAID1_SYNC_ERROR, &(m->error_type))) ? 'S' :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) (test_bit(DM_RAID1_READ_ERROR, &(m->error_type))) ? 'R' : 'U';
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) static void mirror_status(struct dm_target *ti, status_type_t type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) unsigned status_flags, char *result, unsigned maxlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) unsigned int m, sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) int num_feature_args = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) struct mirror_set *ms = (struct mirror_set *) ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) char buffer[MAX_NR_MIRRORS + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) case STATUSTYPE_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) DMEMIT("%d ", ms->nr_mirrors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) for (m = 0; m < ms->nr_mirrors; m++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) DMEMIT("%s ", ms->mirror[m].dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) buffer[m] = device_status_char(&(ms->mirror[m]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) buffer[m] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) DMEMIT("%llu/%llu 1 %s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) (unsigned long long)log->type->get_sync_count(log),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) (unsigned long long)ms->nr_regions, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) sz += log->type->status(log, type, result+sz, maxlen-sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) case STATUSTYPE_TABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) sz = log->type->status(log, type, result, maxlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) DMEMIT("%d", ms->nr_mirrors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) for (m = 0; m < ms->nr_mirrors; m++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) DMEMIT(" %s %llu", ms->mirror[m].dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) (unsigned long long)ms->mirror[m].offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) num_feature_args += !!errors_handled(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) num_feature_args += !!keep_log(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (num_feature_args) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) DMEMIT(" %d", num_feature_args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) if (errors_handled(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) DMEMIT(" handle_errors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) if (keep_log(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) DMEMIT(" keep_log");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) break;
^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 int mirror_iterate_devices(struct dm_target *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) iterate_devices_callout_fn fn, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) struct mirror_set *ms = ti->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) for (i = 0; !ret && i < ms->nr_mirrors; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) ret = fn(ti, ms->mirror[i].dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) ms->mirror[i].offset, ti->len, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) return ret;
^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 struct target_type mirror_target = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) .name = "mirror",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) .version = {1, 14, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) .ctr = mirror_ctr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) .dtr = mirror_dtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) .map = mirror_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) .end_io = mirror_end_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) .presuspend = mirror_presuspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) .postsuspend = mirror_postsuspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) .resume = mirror_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) .status = mirror_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) .iterate_devices = mirror_iterate_devices,
^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 __init dm_mirror_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) r = dm_register_target(&mirror_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) DMERR("Failed to register mirror target");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) goto bad_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) bad_target:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) static void __exit dm_mirror_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) dm_unregister_target(&mirror_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) /* Module hooks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) module_init(dm_mirror_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) module_exit(dm_mirror_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) MODULE_DESCRIPTION(DM_NAME " mirror target");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) MODULE_AUTHOR("Joe Thornber");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) MODULE_LICENSE("GPL");