Skip to contentSkip to conversation

mirroring: [patch 2 of 6] device failure tolerance

PATCH Jonathan E Brassow 1 participant 1 message Jun 30, 2005 Device mapper

lore
Share & tools
lore
#0 lore raw

This patch add device failure detection for writes. It introduces to new log functions - [sg]et_default_mirror(). These functions give the ability to tolerate a device failing and then returning after a reboot.
Before, it was possible for the following to cause incorrect results:
1) device fails
2) new writes occur
3) machine reboot
4) device is back
5) no way of knowing which device to recover from

brassow

drivers/md/dm-log.c +4 -0
diff -urN linux-2.6.12-00001/drivers/md/dm-log.c linux-2.6.12-00002/drivers/md/dm-log.c
@@ -124,6 +124,8 @@
 	 */
 	uint32_t version;
 	sector_t nr_regions;
+	int32_t default_mirror;
+	int32_t nr_mirrors;
 };
 
 struct log_c {
@@ -192,6 +194,8 @@
 	disk->magic = cpu_to_le32(core->magic);
 	disk->version = cpu_to_le32(core->version);
 	disk->nr_regions = cpu_to_le64(core->nr_regions);
+	disk->default_mirror = cpu_to_le32(core->default_mirror);
+	disk->nr_mirrors = cpu_to_le32(core->nr_mirrors);
 }
 
 static void header_from_disk(struct log_header *core, struct 

log_header *disk)
@@ -199,6 +203,8 @@
core->magic = le32_to_cpu(disk->magic); core->version = le32_to_cpu(disk->version); core->nr_regions = le64_to_cpu(disk->nr_regions);
+ core->default_mirror = le32_to_cpu(disk->default_mirror);
+ core->nr_mirrors = le32_to_cpu(disk->nr_mirrors);
}

static int read_header(struct log_c *log)
@@ -215,9 +221,13 @@

/* New log required? */
if (log->sync != DEFAULTSYNC || log->header.magic != MIRROR_MAGIC) {
+ DMERR("resetting log header.");
log->header.magic = MIRROR_MAGIC; log->header.version = MIRROR_DISK_VERSION; log->header.nr_regions = 0;
+ log->header.default_mirror = -1;
+ log->header.nr_mirrors = -1;
+
}

if (log->header.version != MIRROR_DISK_VERSION) {
@@ -514,7 +524,7 @@
lc->header.nr_regions = lc->region_count;

/* write out the log */

-	if ((r = write_bits(lc)) || (r = write_header(lc))){
+	if ((r = write_bits(lc)) || (r = write_header(lc))) {

DMERR("A write failure has occurred on a mirror log device."); fail_log_device(lc);
} else {
@@ -636,6 +646,60 @@

         return lc->sync_count;

}

+static int core_set_default_mirror(struct dirty_log *log,
+ int new_default, int nr_mirrors,
+ int unsync_regions)
+{
+ struct log_c *lc = (struct log_c *) log->context;
+ lc->header.default_mirror = new_default;
+ lc->header.nr_mirrors = nr_mirrors;
+
+ if (unsync_regions) {
+ size_t bitset_size;
+ bitset_size =
+ dm_round_up(lc->region_count,
+ sizeof(*lc->clean_bits) << BYTE_SHIFT);
+ bitset_size >>= BYTE_SHIFT;
+ memset(lc->sync_bits, 0, bitset_size);
+ memset(lc->clean_bits, 0, bitset_size);
+ lc->sync_count = 0;
+ }
+
+ /* This is core, so it is not persistent */
+ return 0;
+}
+
+static int core_get_default_mirror(struct dirty_log *log,
+ int *nr_mirrors)
+{
+ struct log_c *lc = (struct log_c *) log->context;
+ *nr_mirrors = lc->header.nr_mirrors;
+ return lc->header.default_mirror;
+}
+
+static int disk_set_default_mirror(struct dirty_log *log,
+ int new_default, int nr_mirrors,
+ int unsync_regions)
+{
+ int r = 0;
+ struct log_c *lc = (struct log_c *) log->context;
+ lc->header.default_mirror = new_default;
+ lc->header.nr_mirrors = nr_mirrors;
+
+ if (unsync_regions) {
+ size_t bitset_size;
+ bitset_size =
+ dm_round_up(lc->region_count,
+ sizeof(*lc->clean_bits) << BYTE_SHIFT);
+ bitset_size >>= BYTE_SHIFT;
+ memset(lc->sync_bits, 0, bitset_size);
+ memset(lc->clean_bits, 0, bitset_size);
+ lc->sync_count = 0;
+ r = write_bits(lc);
+ }
+ return r ? r : write_header(lc);
+}
+
#define DMEMIT_SYNC \
if (lc->sync != DEFAULTSYNC) \
DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : "")
@@ -695,6 +759,8 @@
.get_resync_work = core_get_resync_work, .complete_resync_work = core_complete_resync_work, .get_sync_count = core_get_sync_count,
+ .set_default_mirror = core_set_default_mirror,
+ .get_default_mirror = core_get_default_mirror,
.status = core_status,
};

@@ -714,6 +780,8 @@
.get_resync_work = core_get_resync_work, .complete_resync_work = core_complete_resync_work, .get_sync_count = core_get_sync_count,
+ .set_default_mirror = disk_set_default_mirror,
+ .get_default_mirror = core_get_default_mirror,
.status = disk_status,
};

drivers/md/dm-log.h +26 -0
diff -urN linux-2.6.12-00001/drivers/md/dm-log.h linux-2.6.12-00002/drivers/md/dm-log.h
@@ -103,6 +103,32 @@
         region_t (*get_sync_count)(struct dirty_log *log);
 
 	/*
+	 * If the primary mirror fails, we must have a way of
+	 * remembering which mirror is now the primary. Otherwise,
+	 * the following could happen:
+	 * 1) primary fails, but we continue (because that's what
+	 *    mirrors do)
+	 * 2) machine dies and comes back up with the failed device
+	 *    suddenly usable again.
+	 * 3) If the new primary were not recorded, we would
+	 *    choose the wrong primary by mistake, and bring about
+	 *    destruction.
+	 * These fuctions also set and get the number of mirrors,
+	 * allowing the caller to determine if a pheonix device
+	 * is present.  Allowing reads to the pheonix will be
+	 * sure to produce inconsistencies.  Once detected, the
+	 * caller should set_default_mirror w/ unsync_regions = 1
+	 * - forcing the pheonix back into sync due to recovery.
+	 * (get_default_mirror should only be called when
+	 * starting up or resuming.  Same for set w/ unsync_regions)
+	 */
+	int (*set_default_mirror)(struct dirty_log *log,
+				  int new_default, int nr_mirrors,
+				  int unsync_regions);
+	int (*get_default_mirror)(struct dirty_log *log,
+				  int *nr_mirrors);
+
+	/*
 	 * Support function for mirror status requests.
 	 */
 	int (*status)(struct dirty_log *log, status_type_t status_type,
drivers/md/dm-raid1.c +219 -26

400 lines not on this page · raw message