Skip to contentSkip to conversation

Partial Parity Log for MD RAID 5

PATCH Superseded Artur Paszkiewicz 5 participants 38 messages Dec 5, 2016 – Jan 4, 2017

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Partial Parity Log for MD RAID 5

This series of patches implements the Partial Parity Log for RAID5 arrays. The purpose of this feature is closing the RAID Write Hole. It is a solution alternative to the existing raid5-cache, but the implementation is based on it and reuses some of the code by introducing support for interchangeable policies. This allows decoupling policy from mechanism and not adding more boilerplate code in raid5.c.

The issue addressed by PPL is, that on a dirty shutdown, parity for a particular stripe may be inconsistent with data on other member disks. In degraded state, there is no way to recalculate parity, because one of the disks is missing. PPL addresses this issue and allows recalculating the parity. It stores only enough data needed for recovering from RWH and is not a true journal, like the raid5-cache implementation. It does not protect from losing in-flight data.

PPL is a distributed log - data is stored on all RAID member drives in the metadata area. It does not need a dedicated journaling drive. Performance is reduced by up to 30%-40% but it scales with the number of drives in the array and the journaling drive does not become a bottleneck.

This feature originated from Intel RSTe, which uses IMSM metadata. This patchset implements PPL for external metadata (specifically IMSM) as well as native MD v1.1 and v1.2 metadata.

v2:
- Rebased to latest md for-next.
- Fixed wrong PPL size calculation for IMSM.
- Simplified full stripe write case.
- Removed direct access to bi_io_vec.
- Handle failed bio_add_page().

Artur Paszkiewicz (12):
raid5-cache: move declarations to separate header
raid5-cache: add policy logic
raid5-cache: add a new policy
md: superblock changes for PPL
raid5-ppl: Partial Parity Log implementation
raid5-ppl: calculate partial parity
md: mddev_find_container helper function
md: expose rdev->sb_start as sysfs attribute
raid5-ppl: read PPL signature from IMSM metadata
raid5-ppl: recovery from dirty shutdown using PPL
raid5-ppl: support disk add/remove with distributed PPL
raid5-ppl: runtime PPL enabling or disabling

 drivers/md/Makefile            |    2 +-
 drivers/md/md.c                |   81 ++-
 drivers/md/md.h                |   14 +
 drivers/md/raid5-cache.c       |  275 ++++------
 drivers/md/raid5-cache.h       |  169 ++++++
 drivers/md/raid5-ppl.c         | 1153 ++++++++++++++++++++++++++++++++++++++++
 drivers/md/raid5.c             |  274 +++++++++-
 drivers/md/raid5.h             |   10 +-
 include/uapi/linux/raid/md_p.h |   18 +-
 9 files changed, 1814 insertions(+), 182 deletions(-)
 create mode 100644 drivers/md/raid5-cache.h
 create mode 100644 drivers/md/raid5-ppl.c
Signature · 1 line
2.10.1
#1 lore raw

PATCH v2 1/12 raid5-cache: move declarations to separate header

Next patches will be reusing raid5-cache structures and functions, so put them in their own header.

---
 drivers/md/raid5-cache.c | 127 +-----------------------------------------
 drivers/md/raid5-cache.h | 140 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/md/raid5.c       |   1 +
 drivers/md/raid5.h       |   9 ---
 4 files changed, 142 insertions(+), 135 deletions(-)
 create mode 100644 drivers/md/raid5-cache.h
drivers/md/raid5-cache.c +1 -126
index e786d4e..6a3f8e7 100644
@@ -23,6 +23,7 @@
 #include "md.h"
 #include "raid5.h"
 #include "bitmap.h"
+#include "raid5-cache.h"
 
 /*
  * metadata/data stored in disk with 4k size unit (a block) regardless
@@ -52,16 +53,6 @@
  */
 #define R5L_POOL_SIZE	4
 
-/*
- * r5c journal modes of the array: write-back or write-through.
- * write-through mode has identical behavior as existing log only
- * implementation.
- */
-enum r5c_journal_mode {
-	R5C_JOURNAL_MODE_WRITE_THROUGH = 0,
-	R5C_JOURNAL_MODE_WRITE_BACK = 1,
-};
-
 static char *r5c_journal_mode_str[] = {"write-through",
 				       "write-back"};
 /*
@@ -95,122 +86,6 @@ static char *r5c_journal_mode_str[] = {"write-through",
  *	- return IO for pending writes
  */
 
-struct r5l_log {
-	struct md_rdev *rdev;
-
-	u32 uuid_checksum;
-
-	sector_t device_size;		/* log device size, round to
-					 * BLOCK_SECTORS */
-	sector_t max_free_space;	/* reclaim run if free space is at
-					 * this size */
-
-	sector_t last_checkpoint;	/* log tail. where recovery scan
-					 * starts from */
-	u64 last_cp_seq;		/* log tail sequence */
-
-	sector_t log_start;		/* log head. where new data appends */
-	u64 seq;			/* log head sequence */
-
-	sector_t next_checkpoint;
-
-	struct mutex io_mutex;
-	struct r5l_io_unit *current_io;	/* current io_unit accepting new data */
-
-	spinlock_t io_list_lock;
-	struct list_head running_ios;	/* io_units which are still running,
-					 * and have not yet been completely
-					 * written to the log */
-	struct list_head io_end_ios;	/* io_units which have been completely
-					 * written to the log but not yet written
-					 * to the RAID */
-	struct list_head flushing_ios;	/* io_units which are waiting for log
-					 * cache flush */
-	struct list_head finished_ios;	/* io_units which settle down in log disk */
-	struct bio flush_bio;
-
-	struct list_head no_mem_stripes;   /* pending stripes, -ENOMEM */
-
-	struct kmem_cache *io_kc;
-	mempool_t *io_pool;
-	struct bio_set *bs;
-	mempool_t *meta_pool;
-
-	struct md_thread *reclaim_thread;
-	unsigned long reclaim_target;	/* number of space that need to be
-					 * reclaimed.  if it's 0, reclaim spaces
-					 * used by io_units which are in
-					 * IO_UNIT_STRIPE_END state (eg, reclaim
-					 * dones't wait for specific io_unit
-					 * switching to IO_UNIT_STRIPE_END
-					 * state) */
-	wait_queue_head_t iounit_wait;
-
-	struct list_head no_space_stripes; /* pending stripes, log has no space */
-	spinlock_t no_space_stripes_lock;
-
-	bool need_cache_flush;
-
-	/* for r5c_cache */
-	enum r5c_journal_mode r5c_journal_mode;
-
-	/* all stripes in r5cache, in the order of seq at sh->log_start */
-	struct list_head stripe_in_journal_list;
-
-	spinlock_t stripe_in_journal_lock;
-	atomic_t stripe_in_journal_count;
-
-	/* to submit async io_units, to fulfill ordering of flush */
-	struct work_struct deferred_io_work;
-};
-
-/*
- * an IO range starts from a meta data block and end at the next meta data
- * block. The io unit's the meta data block tracks data/parity followed it. io
- * unit is written to log disk with normal write, as we always flush log disk
- * first and then start move data to raid disks, there is no requirement to
- * write io unit with FLUSH/FUA
- */
-struct r5l_io_unit {
-	struct r5l_log *log;
-
-	struct page *meta_page;	/* store meta block */
-	int meta_offset;	/* current offset in meta_page */
-
-	struct bio *current_bio;/* current_bio accepting new data */
-
-	atomic_t pending_stripe;/* how many stripes not flushed to raid */
-	u64 seq;		/* seq number of the metablock */
-	sector_t log_start;	/* where the io_unit starts */
-	sector_t log_end;	/* where the io_unit ends */
-	struct list_head log_sibling; /* log->running_ios */
-	struct list_head stripe_list; /* stripes added to the io_unit */
-
-	int state;
-	bool need_split_bio;
-	struct bio *split_bio;
-
-	unsigned int has_flush:1;      /* include flush request */
-	unsigned int has_fua:1;        /* include fua request */
-	unsigned int has_null_flush:1; /* include empty flush request */
-	/*
-	 * io isn't sent yet, flush/fua request can only be submitted till it's
-	 * the first IO in running_ios list
-	 */
-	unsigned int io_deferred:1;
-
-	struct bio_list flush_barriers;   /* size == 0 flush bios */
-};
-
-/* r5l_io_unit state */
-enum r5l_io_unit_state {
-	IO_UNIT_RUNNING = 0,	/* accepting new IO */
-	IO_UNIT_IO_START = 1,	/* io_unit bio start writing to log,
-				 * don't accepting new bio */
-	IO_UNIT_IO_END = 2,	/* io_unit bio finish writing to log */
-	IO_UNIT_STRIPE_END = 3,	/* stripes data finished writing to raid */
-};
-
 bool r5c_is_writeback(struct r5l_log *log)
 {
 	return (log != NULL &&
drivers/md/raid5-cache.h new file +140 -0

140 lines not on this page · raw message

drivers/md/raid5.c +1 -0
index 6bf3c26..fe8c1a7 100644
@@ -61,6 +61,7 @@
 #include "raid5.h"
 #include "raid0.h"
 #include "bitmap.h"
+#include "raid5-cache.h"
 
 #define cpu_to_group(cpu) cpu_to_node(cpu)
 #define ANY_GROUP NUMA_NO_NODE
drivers/md/raid5.h +0 -9
index ed8e136..315d6ea 100644
@@ -753,15 +753,6 @@ extern sector_t raid5_compute_sector(struct r5conf *conf, sector_t r_sector,
 extern struct stripe_head *
 raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
 			int previous, int noblock, int noquiesce);
-extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev);
-extern void r5l_exit_log(struct r5l_log *log);
-extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *head_sh);
-extern void r5l_write_stripe_run(struct r5l_log *log);
-extern void r5l_flush_stripe_to_raid(struct r5l_log *log);
-extern void r5l_stripe_write_finished(struct stripe_head *sh);
-extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
-extern void r5l_quiesce(struct r5l_log *log, int state);
-extern bool r5l_log_disk_error(struct r5conf *conf);
 extern bool r5c_is_writeback(struct r5l_log *log);
 extern int
 r5c_try_caching_write(struct r5conf *conf, struct stripe_head *sh,
Signature · 1 line
2.10.1
#2 lore raw

PATCH v2 2/12 raid5-cache: add policy logic

In reply to Artur Paszkiewicz

Add a struct r5l_policy and wrapper functions for non-static functions from raid5-cache. This allows adding different policies for raid5 logging without changing the mechanism - calls from the raid5 personality stay the same.

---
 drivers/md/raid5-cache.c | 112 +++++++++++++++++++++++++++++++++++------------
 drivers/md/raid5-cache.h |  13 ++++++
 2 files changed, 98 insertions(+), 27 deletions(-)
drivers/md/raid5-cache.c +85 -27
index 6a3f8e7..74a0eda 100644
@@ -727,7 +727,7 @@ static inline void r5l_add_no_space_stripe(struct r5l_log *log,
  * running in raid5d, where reclaim could wait for raid5d too (when it flushes
  * data from log to raid disks), so we shouldn't wait for reclaim here
  */
-int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh)
+static int __r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh)
 {
 	struct r5conf *conf = sh->raid_conf;
 	int write_disks = 0;
@@ -737,8 +737,6 @@ int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh)
 	int ret = 0;
 	bool wake_reclaim = false;
 
-	if (!log)
-		return -EAGAIN;
 	/* Don't support stripe batch */
 	if (sh->log_io || !test_bit(R5_Wantwrite, &sh->dev[sh->pd_idx].flags) ||
 	    test_bit(STRIPE_SYNCING, &sh->state)) {
@@ -825,19 +823,28 @@ int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh)
 	return 0;
 }
 
-void r5l_write_stripe_run(struct r5l_log *log)
+int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh)
+{
+	if (log && log->policy->write_stripe)
+		return log->policy->write_stripe(log, sh);
+	return -EAGAIN;
+}
+
+static void __r5l_write_stripe_run(struct r5l_log *log)
 {
-	if (!log)
-		return;
 	mutex_lock(&log->io_mutex);
 	r5l_submit_current_io(log);
 	mutex_unlock(&log->io_mutex);
 }
 
-int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio)
+void r5l_write_stripe_run(struct r5l_log *log)
+{
+	if (log && log->policy->write_stripe_run)
+		log->policy->write_stripe_run(log);
+}
+
+static int __r5l_handle_flush_request(struct r5l_log *log, struct bio *bio)
 {
-	if (!log)
-		return -ENODEV;
 
 	if (log->r5c_journal_mode == R5C_JOURNAL_MODE_WRITE_THROUGH) {
 		/*
@@ -869,6 +876,13 @@ int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio)
 	return -EAGAIN;
 }
 
+int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio)
+{
+	if (log && log->policy->handle_flush_request)
+		return log->policy->handle_flush_request(log, bio);
+	return -ENODEV;
+}
+
 /* This will run after log space is reclaimed */
 static void r5l_run_no_space_stripes(struct r5l_log *log)
 {
@@ -989,8 +1003,9 @@ void r5l_stripe_write_finished(struct stripe_head *sh)
 	io = sh->log_io;
 	sh->log_io = NULL;
 
-	if (io && atomic_dec_and_test(&io->pending_stripe))
-		__r5l_stripe_write_finished(io);
+	if (io && atomic_dec_and_test(&io->pending_stripe) &&
+			io->log->policy->stripe_write_finished)
+		io->log->policy->stripe_write_finished(io);
 }
 
 static void r5l_log_flush_endio(struct bio *bio)
@@ -1024,11 +1039,11 @@ static void r5l_log_flush_endio(struct bio *bio)
  * only write stripes of an io_unit to raid disks till the io_unit is the first
  * one whose data/parity is in log.
  */
-void r5l_flush_stripe_to_raid(struct r5l_log *log)
+static void __r5l_flush_stripe_to_raid(struct r5l_log *log)
 {
 	bool do_flush;
 
-	if (!log || !log->need_cache_flush)
+	if (!log->need_cache_flush)
 		return;
 
 	spin_lock_irq(&log->io_list_lock);
@@ -1050,6 +1065,12 @@ void r5l_flush_stripe_to_raid(struct r5l_log *log)
 	submit_bio(&log->flush_bio);
 }
 
+void r5l_flush_stripe_to_raid(struct r5l_log *log)
+{
+	if (log && log->policy->flush_stripe_to_raid)
+		log->policy->flush_stripe_to_raid(log);
+}
+
 static void r5l_write_super(struct r5l_log *log, sector_t cp);
 static void r5l_write_super_and_discard_space(struct r5l_log *log,
 	sector_t end)
@@ -1304,10 +1325,10 @@ void r5l_wake_reclaim(struct r5l_log *log, sector_t space)
 	md_wakeup_thread(log->reclaim_thread);
 }
 
-void r5l_quiesce(struct r5l_log *log, int state)
+static void __r5l_quiesce(struct r5l_log *log, int state)
 {
 	struct mddev *mddev;
-	if (!log || state == 2)
+	if (state == 2)
 		return;
 	if (state == 0)
 		kthread_unpark(log->reclaim_thread->tsk);
@@ -1321,6 +1342,12 @@ void r5l_quiesce(struct r5l_log *log, int state)
 	}
 }
 
+void r5l_quiesce(struct r5l_log *log, int state)
+{
+	if (log && log->policy->quiesce)
+		log->policy->quiesce(log, state);
+}
+
 bool r5l_log_disk_error(struct r5conf *conf)
 {
 	struct r5l_log *log;
@@ -2406,11 +2433,9 @@ static int r5l_load_log(struct r5l_log *log)
 	return ret;
 }
 
-int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
+static int __r5l_init_log(struct r5l_log *log, struct r5conf *conf)
 {
-	struct request_queue *q = bdev_get_queue(rdev->bdev);
-	struct r5l_log *log;
-
+	struct request_queue *q = bdev_get_queue(log->rdev->bdev);
 	if (PAGE_SIZE != 4096)
 		return -EINVAL;
 
@@ -2429,15 +2454,11 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
 		return -EINVAL;
 	}
 
-	log = kzalloc(sizeof(*log), GFP_KERNEL);
-	if (!log)
-		return -ENOMEM;
-	log->rdev = rdev;
 
 	log->need_cache_flush = test_bit(QUEUE_FLAG_WC, &q->queue_flags) != 0;
 
-	log->uuid_checksum = crc32c_le(~0, rdev->mddev->uuid,
-				       sizeof(rdev->mddev->uuid));
+	log->uuid_checksum = crc32c_le(~0, log->rdev->mddev->uuid,
+				       sizeof(log->rdev->mddev->uuid));
 
 	mutex_init(&log->io_mutex);
 
@@ -2502,16 +2523,53 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
 io_pool:
 	kmem_cache_destroy(log->io_kc);
 io_kc:
-	kfree(log);
 	return -EINVAL;
 }
 
-void r5l_exit_log(struct r5l_log *log)
+static void __r5l_exit_log(struct r5l_log *log)
 {
 	md_unregister_thread(&log->reclaim_thread);
 	mempool_destroy(log->meta_pool);
 	bioset_free(log->bs);
 	mempool_destroy(log->io_pool);
 	kmem_cache_destroy(log->io_kc);
+}
+
+void r5l_exit_log(struct r5l_log *log)
+{
+	if (!log)
+		return;
+
+	if (log->policy->exit_log)
+		log->policy->exit_log(log);
+
 	kfree(log);
 }
+
+struct r5l_policy r5l_journal = {
+	.init_log = __r5l_init_log,
+	.exit_log = __r5l_exit_log,
+	.write_stripe = __r5l_write_stripe,
+	.write_stripe_run = __r5l_write_stripe_run,
+	.flush_stripe_to_raid = __r5l_flush_stripe_to_raid,
+	.stripe_write_finished = __r5l_stripe_write_finished,
+	.handle_flush_request = __r5l_handle_flush_request,
+	.quiesce = __r5l_quiesce,
+};
+
+int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
+{
+	int ret;
+	struct r5l_log *log = kzalloc(sizeof(*log), GFP_KERNEL);
+	if (!log)
+		return -ENOMEM;
+
+	log->rdev = rdev;
+	log->policy = &r5l_journal;
+
+	ret = log->policy->init_log(log, conf);
+	if (ret)
+		kfree(log);
+
+	return ret;
+}
drivers/md/raid5-cache.h +13 -0
index 1908d45..52cfef4 100644
@@ -78,6 +78,8 @@ struct r5l_log {
 
 	/* to submit async io_units, to fulfill ordering of flush */
 	struct work_struct deferred_io_work;
+
+	struct r5l_policy *policy;
 };
 
 /*
@@ -127,6 +129,17 @@ enum r5l_io_unit_state {
 	IO_UNIT_STRIPE_END = 3,	/* stripes data finished writing to raid */
 };
 
+struct r5l_policy {
+	int (*init_log)(struct r5l_log *log, struct r5conf *conf);
+	void (*exit_log)(struct r5l_log *log);
+	int (*write_stripe)(struct r5l_log *log, struct stripe_head *sh);
+	void (*write_stripe_run)(struct r5l_log *log);
+	void (*flush_stripe_to_raid)(struct r5l_log *log);
+	void (*stripe_write_finished)(struct r5l_io_unit *io);
+	int (*handle_flush_request)(struct r5l_log *log, struct bio *bio);
+	void (*quiesce)(struct r5l_log *log, int state);
+};
+
 extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev);
 extern void r5l_exit_log(struct r5l_log *log);
 extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh);
Signature · 1 line
2.10.1
#3 lore raw

PATCH v2 3/12 raid5-cache: add a new policy

In reply to Artur Paszkiewicz

Add a source file for the new policy implementation and allow selecting the policy based on the policy_type parameter in r5l_init_log().

Introduce a new flag for rdev state flags to allow enabling the new policy from userspace.

---
 drivers/md/Makefile      |  2 +-
 drivers/md/md.c          |  5 +++++
 drivers/md/md.h          |  3 +++
 drivers/md/raid5-cache.c | 17 +++++++++++++++--
 drivers/md/raid5-cache.h |  9 ++++++++-
 drivers/md/raid5-ppl.c   | 20 ++++++++++++++++++++
 drivers/md/raid5.c       | 42 ++++++++++++++++++++++++++++++++++++------
 7 files changed, 88 insertions(+), 10 deletions(-)
 create mode 100644 drivers/md/raid5-ppl.c
drivers/md/Makefile +1 -1
index 3cbda1a..4d48714 100644
@@ -18,7 +18,7 @@ dm-cache-cleaner-y += dm-cache-policy-cleaner.o
 dm-era-y	+= dm-era-target.o
 dm-verity-y	+= dm-verity-target.o
 md-mod-y	+= md.o bitmap.o
-raid456-y	+= raid5.o raid5-cache.o
+raid456-y	+= raid5.o raid5-cache.o raid5-ppl.o
 
 # Note: link order is important.  All raid personalities
 # and must come before md.o, as they each initialise 
drivers/md/md.c +5 -0
index c7894fb..4876687 100644
@@ -2575,6 +2575,8 @@ state_show(struct md_rdev *rdev, char *page)
 		len += sprintf(page+len, "journal%s", sep);
 	if (test_bit(WriteMostly, &flags))
 		len += sprintf(page+len, "write_mostly%s", sep);
+	if (test_bit(JournalPpl, &flags))
+		len += sprintf(page+len, "journal_ppl%s", sep);
 	if (test_bit(Blocked, &flags) ||
 	    (rdev->badblocks.unacked_exist
 	     && !test_bit(Faulty, &flags)))
@@ -2753,6 +2755,9 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
 	} else if (cmd_match(buf, "-external_bbl") && (rdev->mddev->external)) {
 		clear_bit(ExternalBbl, &rdev->flags);
 		err = 0;
+	} else if (cmd_match(buf, "journal_ppl")) {
+		set_bit(JournalPpl, &rdev->flags);
+		err = 0;
 	}
 	if (!err)
 		sysfs_notify_dirent_safe(rdev->sysfs_state);
drivers/md/md.h +3 -0
index 5c08f84..2fc75ac 100644
@@ -172,6 +172,9 @@ enum flag_bits {
 				 * Usually, this device should be faster
 				 * than other devices in the array
 				 */
+	JournalPpl,		/* This device is used for raid5
+				 * Partial Parity Log.
+				 */
 	ClusterRemove,
 	RemoveSynchronized,	/* synchronize_rcu() was called after
 				 * this device was known to be faulty,
drivers/md/raid5-cache.c +15 -2
index 74a0eda..fa82b9a 100644
@@ -2556,16 +2556,29 @@ struct r5l_policy r5l_journal = {
 	.handle_flush_request = __r5l_handle_flush_request,
 	.quiesce = __r5l_quiesce,
 };
+extern struct r5l_policy r5l_ppl;
 
-int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
+int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev, int policy_type)
 {
 	int ret;
 	struct r5l_log *log = kzalloc(sizeof(*log), GFP_KERNEL);
 	if (!log)
 		return -ENOMEM;
 
+	switch (policy_type) {
+	case RWH_POLICY_JOURNAL:
+		log->policy = &r5l_journal;
+		break;
+	case RWH_POLICY_PPL:
+		log->policy = &r5l_ppl;
+		break;
+	default:
+		kfree(log);
+		return -EINVAL;
+	}
+
 	log->rdev = rdev;
-	log->policy = &r5l_journal;
+	log->rwh_policy = policy_type;
 
 	ret = log->policy->init_log(log, conf);
 	if (ret)
drivers/md/raid5-cache.h +8 -1
index 52cfef4..4ba11d3 100644
@@ -80,6 +80,13 @@ struct r5l_log {
 	struct work_struct deferred_io_work;
 
 	struct r5l_policy *policy;
+	enum {
+		RWH_POLICY_OFF,
+		RWH_POLICY_JOURNAL,
+		RWH_POLICY_PPL,
+	} rwh_policy;
+
+	void *private;
 };
 
 /*
@@ -140,7 +147,7 @@ struct r5l_policy {
 	void (*quiesce)(struct r5l_log *log, int state);
 };
 
-extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev);
+extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev, int policy_type);
 extern void r5l_exit_log(struct r5l_log *log);
 extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh);
 extern void r5l_write_stripe_run(struct r5l_log *log);
drivers/md/raid5-ppl.c new file +20 -0
new file mode 100644
index 0000000..263fad7
@@ -0,0 +1,20 @@
+/*
+ * Partial Parity Log for closing the RAID5 write hole
+ * Copyright (c) 2016, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/blkdev.h>
+#include "raid5.h"
+#include "raid5-cache.h"
+
+struct r5l_policy r5l_ppl;
drivers/md/raid5.c +36 -6

81 lines not on this page · raw message

Signature · 1 line
2.10.1
#9 lore raw

PATCH v2 4/12 md: superblock changes for PPL

In reply to Artur Paszkiewicz

Include information about PPL location and size into mdp_superblock_1 and copy it to/from rdev. Because PPL is mutually exclusive with bitmap, put it in place of 'bitmap_offset'. Add a new flag MD_FEATURE_PPL for 'feature_map', analogically to MD_FEATURE_BITMAP_OFFSET. Add MD_HAS_PPL to mddev->flags to indicate that PPL is enabled on an array.

---
 drivers/md/md.c                | 14 ++++++++++++++
 drivers/md/md.h                |  8 ++++++++
 drivers/md/raid5.c             |  7 +++++++
 include/uapi/linux/raid/md_p.h | 18 ++++++++++++++----
 4 files changed, 43 insertions(+), 4 deletions(-)
drivers/md/md.c +14 -0
index 4876687..7028d54 100644
@@ -1524,6 +1524,11 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
 	} else if (sb->bblog_offset != 0)
 		rdev->badblocks.shift = 0;
 
+	if (le32_to_cpu(sb->feature_map) & MD_FEATURE_PPL) {
+		rdev->ppl.offset = le16_to_cpu(sb->ppl.offset);
+		rdev->ppl.size = le16_to_cpu(sb->ppl.size);
+	}
+
 	if (!refdev) {
 		ret = 1;
 	} else {
@@ -1636,6 +1641,9 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *rdev)
 
 		if (le32_to_cpu(sb->feature_map) & MD_FEATURE_JOURNAL)
 			set_bit(MD_HAS_JOURNAL, &mddev->flags);
+
+		if (le32_to_cpu(sb->feature_map) & MD_FEATURE_PPL)
+			set_bit(MD_HAS_PPL, &mddev->flags);
 	} else if (mddev->pers == NULL) {
 		/* Insist of good event counter while assembling, except for
 		 * spares (which don't need an event count) */
@@ -1849,6 +1857,12 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
 	if (test_bit(MD_HAS_JOURNAL, &mddev->flags))
 		sb->feature_map |= cpu_to_le32(MD_FEATURE_JOURNAL);
 
+	if (test_bit(MD_HAS_PPL, &mddev->flags)) {
+		sb->feature_map |= cpu_to_le32(MD_FEATURE_PPL);
+		sb->ppl.offset = cpu_to_le16(rdev->ppl.offset);
+		sb->ppl.size = cpu_to_le16(rdev->ppl.size);
+	}
+
 	rdev_for_each(rdev2, mddev) {
 		i = rdev2->desc_nr;
 		if (test_bit(Faulty, &rdev2->flags))
drivers/md/md.h +8 -0
index 2fc75ac..d1e56f8 100644
@@ -122,6 +122,13 @@ struct md_rdev {
 					   * sysfs entry */
 
 	struct badblocks badblocks;
+
+	struct {
+		unsigned int offset; /* Offset from superblock to start of PPL.
+				      * Not used by external metadata. */
+		unsigned int size;   /* Size in sectors of the PPL space */
+		sector_t sector;     /* First sector of the PPL space */
+	} ppl;
 };
 enum flag_bits {
 	Faulty,			/* device is known to have a fault */
@@ -235,6 +242,7 @@ enum mddev_flags {
 				 * never cause the array to become failed.
 				 */
 	MD_NEED_REWRITE,	/* metadata write needs to be repeated */
+	MD_HAS_PPL,		/* The raid array has PPL feature set */
 };
 #define MD_UPDATE_SB_FLAGS (BIT(MD_CHANGE_DEVS) | \
 			    BIT(MD_CHANGE_CLEAN) | \
drivers/md/raid5.c +7 -0
index 9f07769..a7e993a 100644
@@ -6849,6 +6849,10 @@ static int raid5_run(struct mddev *mddev)
 	rdev_for_each(rdev, mddev) {
 		long long diff;
 
+		if (test_bit(MD_HAS_PPL, &mddev->flags) &&
+		    test_bit(In_sync, &rdev->flags))
+			set_bit(JournalPpl, &rdev->flags);
+
 		if (test_bit(JournalPpl, &rdev->flags) &&
 		    test_bit(In_sync, &rdev->flags))
 			ppl_disks++;
@@ -6871,6 +6875,9 @@ static int raid5_run(struct mddev *mddev)
 			min_offset_diff = diff;
 	}
 
+	if (ppl_disks)
+		set_bit(MD_HAS_PPL, &mddev->flags);
+
 	if (mddev->reshape_position != MaxSector) {
 		/* Check that we can continue the reshape.
 		 * Difficulties arise if the stripe we would write to
include/uapi/linux/raid/md_p.h +14 -4
index 9930f3e..455caa8 100644
@@ -242,10 +242,18 @@ struct mdp_superblock_1 {
 
 	__le32	chunksize;	/* in 512byte sectors */
 	__le32	raid_disks;
-	__le32	bitmap_offset;	/* sectors after start of superblock that bitmap starts
-				 * NOTE: signed, so bitmap can be before superblock
-				 * only meaningful of feature_map[0] is set.
-				 */
+	union {
+		__le32	bitmap_offset;	/* sectors after start of superblock that bitmap starts
+					 * NOTE: signed, so bitmap can be before superblock
+					 * only meaningful of feature_map[0] is set.
+					 */
+
+		/* only meaningful when feature_map[MD_FEATURE_PPL] is set */
+		struct {
+			__le16 offset; /* sectors after start of superblock that ppl starts */
+			__le16 size; /* PPL size (including header) in sectors */
+		} ppl;
+	};
 
 	/* These are only valid with feature bit '4' */
 	__le32	new_level;	/* new level we are reshaping to		*/
@@ -318,6 +326,7 @@ struct mdp_superblock_1 {
 					     */
 #define MD_FEATURE_CLUSTERED		256 /* clustered MD */
 #define	MD_FEATURE_JOURNAL		512 /* support write cache */
+#define	MD_FEATURE_PPL			1024 /* support PPL */
 #define	MD_FEATURE_ALL			(MD_FEATURE_BITMAP_OFFSET	\
 					|MD_FEATURE_RECOVERY_OFFSET	\
 					|MD_FEATURE_RESHAPE_ACTIVE	\
@@ -328,6 +337,7 @@ struct mdp_superblock_1 {
 					|MD_FEATURE_RECOVERY_BITMAP	\
 					|MD_FEATURE_CLUSTERED		\
 					|MD_FEATURE_JOURNAL		\
+					|MD_FEATURE_PPL			\
 					)
 
 struct r5l_payload_header {
Signature · 1 line
2.10.1
#10 lore raw

PATCH v2 5/12 raid5-ppl: Partial Parity Log implementation

In reply to Artur Paszkiewicz

This implements the write logging functionality, using the policy logic introduced in previous patches.

PPL is a distributed log - data is stored on all RAID member drives in the metadata area. PPL is written to the parity disk of a particular stripe. Distributed log is implemented by using one r5l_log instance per each array member. They are grouped in child_logs array in struct ppl_conf, which is assigned to a common parent log. This parent log serves as a proxy and is used in raid5 personality code - it is assigned as _the_ log in r5conf->log. The child logs are where all the real work is done.

The PPL consists of a 4KB header (struct ppl_header), and at least 128KB for partial parity data. It is stored right after the array data (for IMSM) or in the bitmap area (super 1.1 and 1.2) and can be overwritten even at each array write request.

Attach a page for holding the partial parity data to each stripe_head. Allocate it only if mddev has the MD_HAS_PPL flag set.

---
 drivers/md/raid5-cache.c |  12 +-
 drivers/md/raid5-cache.h |   6 +
 drivers/md/raid5-ppl.c   | 594 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/md/raid5.c       |  15 +-
 drivers/md/raid5.h       |   1 +
 5 files changed, 620 insertions(+), 8 deletions(-)
drivers/md/raid5-cache.c +6 -6
index fa82b9a..be534d8 100644
@@ -119,8 +119,8 @@ static bool r5l_has_free_space(struct r5l_log *log, sector_t size)
 	return log->device_size > used_size + size;
 }
 
-static void __r5l_set_io_unit_state(struct r5l_io_unit *io,
-				    enum r5l_io_unit_state state)
+void __r5l_set_io_unit_state(struct r5l_io_unit *io,
+			     enum r5l_io_unit_state state)
 {
 	if (WARN_ON(io->state >= state))
 		return;
@@ -340,7 +340,7 @@ static void r5c_finish_cache_stripe(struct stripe_head *sh)
 	}
 }
 
-static void r5l_io_run_stripes(struct r5l_io_unit *io)
+void r5l_io_run_stripes(struct r5l_io_unit *io)
 {
 	struct stripe_head *sh, *next;
 
@@ -935,7 +935,7 @@ static sector_t r5l_reclaimable_space(struct r5l_log *log)
 				 r5c_calculate_new_cp(conf));
 }
 
-static void r5l_run_no_mem_stripe(struct r5l_log *log)
+void r5l_run_no_mem_stripe(struct r5l_log *log)
 {
 	struct stripe_head *sh;
 
@@ -1039,7 +1039,7 @@ static void r5l_log_flush_endio(struct bio *bio)
  * only write stripes of an io_unit to raid disks till the io_unit is the first
  * one whose data/parity is in log.
  */
-static void __r5l_flush_stripe_to_raid(struct r5l_log *log)
+void __r5l_flush_stripe_to_raid(struct r5l_log *log)
 {
 	bool do_flush;
 
@@ -1359,7 +1359,7 @@ bool r5l_log_disk_error(struct r5conf *conf)
 	if (!log)
 		ret = test_bit(MD_HAS_JOURNAL, &conf->mddev->flags);
 	else
-		ret = test_bit(Faulty, &log->rdev->flags);
+		ret = log->rdev && test_bit(Faulty, &log->rdev->flags);
 	rcu_read_unlock();
 	return ret;
 }
drivers/md/raid5-cache.h +6 -0
index 4ba11d3..0446100 100644
@@ -157,4 +157,10 @@ extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
 extern void r5l_quiesce(struct r5l_log *log, int state);
 extern bool r5l_log_disk_error(struct r5conf *conf);
 
+extern void __r5l_set_io_unit_state(struct r5l_io_unit *io,
+				    enum r5l_io_unit_state state);
+extern void r5l_io_run_stripes(struct r5l_io_unit *io);
+extern void r5l_run_no_mem_stripe(struct r5l_log *log);
+extern void __r5l_flush_stripe_to_raid(struct r5l_log *log);
+
 #endif /* _RAID5_CACHE_H */
drivers/md/raid5-ppl.c +593 -1

600 lines not on this page · raw message

drivers/md/raid5.c +14 -1
index a7e993a..77a503d3 100644
@@ -464,6 +464,11 @@ static void shrink_buffers(struct stripe_head *sh)
 		sh->dev[i].page = NULL;
 		put_page(p);
 	}
+
+	if (sh->ppl_page) {
+		put_page(sh->ppl_page);
+		sh->ppl_page = NULL;
+	}
 }
 
 static int grow_buffers(struct stripe_head *sh, gfp_t gfp)
@@ -480,6 +485,13 @@ static int grow_buffers(struct stripe_head *sh, gfp_t gfp)
 		sh->dev[i].page = page;
 		sh->dev[i].orig_page = page;
 	}
+
+	if (test_bit(MD_HAS_PPL, &sh->raid_conf->mddev->flags)) {
+		sh->ppl_page = alloc_page(gfp);
+		if (!sh->ppl_page)
+			return 1;
+	}
+
 	return 0;
 }
 
@@ -875,7 +887,8 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
 
 	might_sleep();
 
-	if (!test_bit(STRIPE_R5C_CACHING, &sh->state)) {
+	if (!test_bit(STRIPE_R5C_CACHING, &sh->state) ||
+	    test_bit(MD_HAS_PPL, &conf->mddev->flags)) {
 		/* writing out phase */
 		if (s->waiting_extra_page)
 			return;
drivers/md/raid5.h +1 -0
index 315d6ea..4a0d7b3 100644
@@ -228,6 +228,7 @@ struct stripe_head {
 	struct list_head	log_list;
 	sector_t		log_start; /* first meta block on the journal */
 	struct list_head	r5c; /* for r5c_cache->stripe_in_journal */
+	struct page		*ppl_page;
 	/**
 	 * struct stripe_operations
 	 * @target - STRIPE_OP_COMPUTE_BLK target
Signature · 1 line
2.10.1
#14 lore raw

PATCH v2 6/12 raid5-ppl: calculate partial parity

In reply to Artur Paszkiewicz

Partial parity is calculated as follows:

- reconstruct-write case:
xor data from all not updated disks in a stripe

- read-modify-write case:
xor old data and parity from all updated disks in a stripe

Implement it using the async_tx API and integrate into raid_run_ops(). It must be called when we still have access to old data, so do it when STRIPE_OP_BIODRAIN is set, but before ops_run_prexor5(). The result is stored into sh->ppl_page.

---
 drivers/md/raid5.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
drivers/md/raid5.c +75 -0
index 77a503d3..2169de5 100644
@@ -1941,6 +1941,49 @@ static void ops_run_check_pq(struct stripe_head *sh, struct raid5_percpu *percpu
 			   &sh->ops.zero_sum_result, percpu->spare_page, &submit);
 }
 
+static struct dma_async_tx_descriptor *
+ops_run_partial_parity(struct stripe_head *sh, struct raid5_percpu *percpu,
+		       struct dma_async_tx_descriptor *tx)
+{
+	int disks = sh->disks;
+	struct page **xor_srcs = flex_array_get(percpu->scribble, 0);
+	int count = 0, pd_idx = sh->pd_idx, i;
+	struct async_submit_ctl submit;
+
+	if (test_bit(STRIPE_FULL_WRITE, &sh->state))
+		return tx;
+
+	if (sh->reconstruct_state == reconstruct_state_prexor_drain_run) {
+		for (i = disks; i--;) {
+			struct r5dev *dev = &sh->dev[i];
+			if (test_bit(R5_Wantdrain, &dev->flags)
+					|| i == pd_idx)
+				xor_srcs[count++] = dev->page;
+		}
+	} else if (sh->reconstruct_state == reconstruct_state_drain_run) {
+		for (i = disks; i--;) {
+			struct r5dev *dev = &sh->dev[i];
+			if (test_bit(R5_UPTODATE, &dev->flags))
+				xor_srcs[count++] = dev->page;
+		}
+	} else {
+		return tx;
+	}
+
+	init_async_submit(&submit, ASYNC_TX_XOR_ZERO_DST, tx,
+			NULL, sh, flex_array_get(percpu->scribble, 0)
+				+ sizeof(struct page *) * (sh->disks + 2));
+
+	if (count == 1)
+		tx = async_memcpy(sh->ppl_page, xor_srcs[0], 0, 0, PAGE_SIZE,
+				&submit);
+	else
+		tx = async_xor(sh->ppl_page, xor_srcs, 0, count, PAGE_SIZE,
+				&submit);
+
+	return tx;
+}
+
 static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
 {
 	int overlap_clear = 0, i, disks = sh->disks;
@@ -1971,6 +2014,11 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
 			async_tx_ack(tx);
 	}
 
+	if (test_bit(STRIPE_OP_BIODRAIN, &ops_request) &&
+			test_bit(MD_HAS_PPL, &conf->mddev->flags) &&
+			conf->disks[sh->pd_idx].rdev)
+		tx = ops_run_partial_parity(sh, percpu, tx);
+
 	if (test_bit(STRIPE_OP_PREXOR, &ops_request)) {
 		if (level < 6)
 			tx = ops_run_prexor5(sh, percpu, tx);
@@ -3042,6 +3090,33 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx,
 	if (*bip && (*bip)->bi_iter.bi_sector < bio_end_sector(bi))
 		goto overlap;
 
+	/*
+	 * PPL does not allow writes to different disks in the same stripe when
+	 * they are not next to each other. Not really an overlap, but
+	 * wait_for_overlap can be used to handle this.
+	 */
+	if (forwrite && test_bit(MD_HAS_PPL, &conf->mddev->flags)) {
+		int i;
+		int di = 0;
+		int first = -1, last = -1;
+		int count = 0;
+		for (i = 0; i < sh->disks; i++) {
+			if (i == sh->pd_idx)
+				continue;
+
+			if (sh->dev[i].towrite || i == dd_idx) {
+				count++;
+				if (first < 0)
+					first = di;
+				last = di;
+			}
+			di++;
+		}
+
+		if (last > first && (last - first > count - 1))
+			goto overlap;
+	}
+
 	if (!forwrite || previous)
 		clear_bit(STRIPE_BATCH_READY, &sh->state);
 
Signature · 1 line
2.10.1
#15 lore raw

PATCH v2 7/12 md: mddev_find_container helper function

In reply to Artur Paszkiewicz

This allows finding the parent container of a subarray for external metadata arrays.

---
 drivers/md/md.c | 37 +++++++++++++++++++++++++++++++++++++
 drivers/md/md.h |  3 +++
 2 files changed, 40 insertions(+)
drivers/md/md.c +37 -0
index 7028d54..5a14f8e 100644
@@ -595,6 +595,43 @@ static struct mddev *mddev_find(dev_t unit)
 	goto retry;
 }
 
+struct mddev *mddev_find_container(struct mddev *subarray)
+{
+	struct mddev *mddev, *ret = NULL;
+	char *container_name;
+	int len = 0;
+	int i;
+
+	if (!subarray->external)
+		return NULL;
+
+	container_name = subarray->metadata_type + 1;
+	i = 0;
+	while (container_name[i]) {
+		if (container_name[i] == '/') {
+			len = i;
+			break;
+		}
+		i++;
+	}
+	if (len == 0)
+		return NULL;
+
+	spin_lock(&all_mddevs_lock);
+	list_for_each_entry(mddev, &all_mddevs, all_mddevs) {
+		char *name = mdname(mddev);
+		if (strlen(name) == len &&
+				strncmp(name, container_name, len) == 0) {
+			ret = mddev;
+			break;
+		}
+	}
+	spin_unlock(&all_mddevs_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(mddev_find_container);
+
 static struct attribute_group md_redundancy_group;
 
 void mddev_unlock(struct mddev *mddev)
drivers/md/md.h +3 -0
index d1e56f8..ca0b68f 100644
@@ -711,4 +711,7 @@ static inline int mddev_is_clustered(struct mddev *mddev)
 {
 	return mddev->cluster_info && mddev->bitmap_info.nodes > 1;
 }
+
+extern struct mddev *mddev_find_container(struct mddev *subarray);
+
 #endif /* _MD_MD_H */
Signature · 1 line
2.10.1
#17 lore raw

PATCH v2 8/12 md: expose rdev->sb_start as sysfs attribute

In reply to Artur Paszkiewicz

This is meant for external metadata arrays, to pass the location of the superblock to the kernel.

---
 drivers/md/md.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/md/md.c +22 -0
index 5a14f8e..7049833 100644
@@ -3204,6 +3204,27 @@ static ssize_t ubb_store(struct md_rdev *rdev, const char *page, size_t len)
 static struct rdev_sysfs_entry rdev_unack_bad_blocks =
 __ATTR(unacknowledged_bad_blocks, S_IRUGO|S_IWUSR, ubb_show, ubb_store);
 
+static ssize_t
+sb_start_show(struct md_rdev *rdev, char *page)
+{
+	return sprintf(page, "%llu\n", (unsigned long long)rdev->sb_start);
+}
+
+static ssize_t
+sb_start_store(struct md_rdev *rdev, const char *buf, size_t len)
+{
+	unsigned long long sb_start;
+	if (kstrtoull(buf, 10, &sb_start) < 0)
+		return -EINVAL;
+	if (!rdev->mddev->external)
+		return -EBUSY;
+	rdev->sb_start = sb_start;
+	return len;
+}
+
+static struct rdev_sysfs_entry rdev_sb_start =
+__ATTR(sb_start, S_IRUGO|S_IWUSR, sb_start_show, sb_start_store);
+
 static struct attribute *rdev_default_attrs[] = {
 	&rdev_state.attr,
 	&rdev_errors.attr,
@@ -3214,6 +3235,7 @@ static struct attribute *rdev_default_attrs[] = {
 	&rdev_recovery_start.attr,
 	&rdev_bad_blocks.attr,
 	&rdev_unack_bad_blocks.attr,
+	&rdev_sb_start.attr,
 	NULL,
 };
 static ssize_t
Signature · 1 line
2.10.1
#19 lore raw

PATCH v2 9/12 raid5-ppl: read PPL signature from IMSM metadata

In reply to Artur Paszkiewicz

The PPL signature is used to determine if the stored PPL is valid for a given array. With IMSM, the PPL signature should match the orig_family_num field of the superblock. To avoid passing this value from userspace, it can be read from the IMSM MPB when initializing the log.

---
 drivers/md/raid5-ppl.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 78 insertions(+), 1 deletion(-)
drivers/md/raid5-ppl.c +78 -1
index 2d4c90f..9e46497 100644
@@ -403,6 +403,75 @@ static void __ppl_stripe_write_finished(struct r5l_io_unit *io)
 	spin_unlock_irqrestore(&log->io_list_lock, flags);
 }
 
+#define IMSM_MPB_SIG "Intel Raid ISM Cfg Sig. "
+#define IMSM_MPB_ORIG_FAMILY_NUM_OFFSET 64
+
+static int ppl_find_signature_imsm(struct mddev *mddev, u32 *signature)
+{
+	struct md_rdev *rdev;
+	char *buf;
+	int ret = 0;
+	u32 orig_family_num = 0;
+	struct page *page;
+	struct mddev *container;
+
+	container = mddev_find_container(mddev);
+	if (!container || strncmp(container->metadata_type, "imsm", 4)) {
+		pr_err("Container metadata type is not imsm\n");
+		return -EINVAL;
+	}
+
+	page = alloc_page(GFP_KERNEL);
+	if (!page)
+		return -ENOMEM;
+
+	buf = page_address(page);
+
+	rdev_for_each(rdev, container) {
+		u32 tmp;
+		struct md_rdev *rdev2;
+		bool found = false;
+
+		/* only use rdevs that are both in container and mddev */
+		rdev_for_each(rdev2, mddev)
+			if (rdev2->bdev == rdev->bdev) {
+				found = true;
+				break;
+			}
+
+		if (!found)
+			continue;
+
+		if (!sync_page_io(rdev, 0,
+				queue_logical_block_size(rdev->bdev->bd_queue),
+				page, REQ_OP_READ, 0, true)) {
+			ret = -EIO;
+			goto out;
+		}
+
+		if (strncmp(buf, IMSM_MPB_SIG, strlen(IMSM_MPB_SIG)) != 0) {
+			dbg("imsm mpb signature does not match\n");
+			ret = 1;
+			goto out;
+		}
+
+		tmp = le32_to_cpu(*(u32 *)(buf + IMSM_MPB_ORIG_FAMILY_NUM_OFFSET));
+
+		if (orig_family_num && orig_family_num != tmp) {
+			dbg("orig_family_num is not the same on all disks\n");
+			ret = 1;
+			goto out;
+		}
+
+		orig_family_num = tmp;
+	}
+
+	*signature = orig_family_num;
+out:
+	__free_page(page);
+	return ret;
+}
+
 static void ppl_exit_log_child(struct r5l_log *log)
 {
 	clear_bit(JournalPpl, &log->rdev->flags);
@@ -497,9 +566,17 @@ static int __ppl_init_log(struct r5l_log *log, struct r5conf *conf)
 		return -ENOMEM;
 	log->private = ppl_conf;
 
-	if (!mddev->external)
+	if (mddev->external) {
+		ret = ppl_find_signature_imsm(mddev, &log->uuid_checksum);
+		if (ret) {
+			pr_err("Failed to read imsm signature\n");
+			ret = -EINVAL;
+			goto err;
+		}
+	} else {
 		log->uuid_checksum = crc32c_le(~0, mddev->uuid,
 					       sizeof(mddev->uuid));
+	}
 
 	if (mddev->bitmap) {
 		pr_err("PPL is not compatible with bitmap\n");
Signature · 1 line
2.10.1
#24 lore raw

PATCH v2 10/12 raid5-ppl: recovery from dirty shutdown using PPL

In reply to Artur Paszkiewicz

The recovery algorithm recalculates parity for every dirty stripe by xor-ing the partial parity and data from each updated data member disk. To verify PPL correctness a CRC is used for the PPL header. Each header entry also contains a CRC for its partial parity data. If the header is valid, recovery is performed for each entry until an invalid entry is found. If the array is not degraded and recovery using PPL fully succeeds, there is no need to resync the array because data and parity will be consistent, so in this case resync will be disabled.

Due to compatibility with IMSM implementations on other systems, we can't assume that the block size is always 4K. Writes generated by MD raid5 don't have this issue, but in other environments it is possible to have writes with the size of even a single 512-byte sector. The recovery code takes this into account and also the logical sector size of the underlying drives.

---
 drivers/md/raid5-ppl.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/md/raid5.c     |   5 +-
 2 files changed, 351 insertions(+), 1 deletion(-)
drivers/md/raid5-ppl.c +347 -0
index 9e46497..17e9803 100644
@@ -16,6 +16,7 @@
 #include <linux/blkdev.h>
 #include <linux/slab.h>
 #include <linux/crc32c.h>
+#include <linux/async_tx.h>
 #include <linux/module.h>
 #include <linux/raid/md_p.h>
 #include "md.h"
@@ -403,6 +404,346 @@ static void __ppl_stripe_write_finished(struct r5l_io_unit *io)
 	spin_unlock_irqrestore(&log->io_list_lock, flags);
 }
 
+static void ppl_xor(int size, struct page *page1, struct page *page2,
+		    struct page *page_result)
+{
+	struct async_submit_ctl submit;
+	struct dma_async_tx_descriptor *tx;
+	struct page *xor_srcs[] = { page1, page2 };
+
+	init_async_submit(&submit, ASYNC_TX_ACK|ASYNC_TX_XOR_DROP_DST,
+			  NULL, NULL, NULL, NULL);
+	tx = async_xor(page_result, xor_srcs, 0, 2, size, &submit);
+
+	async_tx_quiesce(&tx);
+}
+
+static int ppl_recover_entry(struct r5l_log *log, struct ppl_header_entry *e,
+			     sector_t ppl_sector)
+{
+	struct mddev *mddev = log->rdev->mddev;
+	struct r5conf *conf = mddev->private;
+
+	int block_size = queue_logical_block_size(mddev->queue);
+	struct page *pages;
+	struct page *page1;
+	struct page *page2;
+	sector_t r_sector_first = e->data_sector * (block_size >> 9);
+	sector_t r_sector_last = r_sector_first + (e->data_size >> 9) - 1;
+	int strip_sectors = conf->chunk_sectors;
+	int i;
+	int ret = 0;
+
+	if (e->pp_size > 0 && (e->pp_size >> 9) < strip_sectors) {
+		if (e->data_size > e->pp_size)
+			r_sector_last = r_sector_first +
+				(e->data_size / e->pp_size) * strip_sectors - 1;
+		strip_sectors = e->pp_size >> 9;
+	}
+
+	pages = alloc_pages(GFP_KERNEL, 1);
+	if (!pages)
+		return -ENOMEM;
+	page1 = pages;
+	page2 = pages + 1;
+
+	dbg("array sector first %llu, last %llu\n",
+	    (unsigned long long)r_sector_first,
+	    (unsigned long long)r_sector_last);
+
+	/* if start and end is 4k aligned, use a 4k block */
+	if (block_size == 512 &&
+			r_sector_first % (PAGE_SIZE >> 9) == 0 &&
+			(r_sector_last + 1) % (PAGE_SIZE >> 9) == 0)
+		block_size = PAGE_SIZE;
+
+	/* iterate through blocks in strip */
+	for (i = 0; i < strip_sectors; i += (block_size >> 9)) {
+		bool update_parity = false;
+		sector_t parity_sector;
+		struct md_rdev *parity_rdev;
+		struct stripe_head sh;
+		int disk;
+
+		dbg("  iter %d start\n", i);
+		memset(page_address(page1), 0, PAGE_SIZE);
+
+		/* iterate through data member disks */
+		for (disk = 0; disk < (conf->raid_disks - conf->max_degraded);
+				disk++) {
+			int dd_idx;
+			struct md_rdev *rdev;
+			sector_t sector;
+			sector_t r_sector = r_sector_first + i +
+					    (disk * conf->chunk_sectors);
+
+			dbg("    data member disk %d start\n", disk);
+			if (r_sector > r_sector_last) {
+				dbg("    array sector %llu doesn't need parity update\n",
+				    (unsigned long long)r_sector);
+				continue;
+			}
+
+			update_parity = true;
+
+			/* map raid sector to member disk */
+			sector = raid5_compute_sector(conf, r_sector, 0, &dd_idx, NULL);
+			dbg("    processing array sector %llu => data mem disk %d, sector %llu\n",
+			    (unsigned long long)r_sector, dd_idx,
+			    (unsigned long long)sector);
+
+			rdev = conf->disks[dd_idx].rdev;
+			if (!rdev) {
+				dbg("    data member disk %d missing\n", dd_idx);
+				update_parity = false;
+				break;
+			}
+
+			dbg("    reading data member disk %s sector %llu\n",
+			    rdev->bdev->bd_disk->disk_name,
+			    (unsigned long long)sector);
+			if (!sync_page_io(rdev, sector, block_size, page2,
+					REQ_OP_READ, 0, false)) {
+				md_error(mddev, rdev);
+				dbg("    read failed!\n");
+				ret = -EIO;
+				goto out;
+			}
+
+			ppl_xor(block_size, page1, page2, page1);
+		}
+
+		if (!update_parity)
+			continue;
+
+		if (e->pp_size > 0) {
+			dbg("  reading pp disk sector %llu\n",
+			    (unsigned long long)(ppl_sector + i));
+			if (!sync_page_io(log->rdev,
+					ppl_sector - log->rdev->data_offset + i,
+					block_size, page2, REQ_OP_READ, 0,
+					false)) {
+				dbg("  read failed!\n");
+				md_error(mddev, log->rdev);
+				ret = -EIO;
+				goto out;
+			}
+
+			ppl_xor(block_size, page1, page2, page1);
+		}
+
+		/* map raid sector to parity disk */
+		parity_sector = raid5_compute_sector(conf, r_sector_first + i,
+				0, &disk, &sh);
+		BUG_ON(sh.pd_idx != e->parity_disk);
+		parity_rdev = conf->disks[sh.pd_idx].rdev;
+
+		BUG_ON(parity_rdev->bdev->bd_dev != log->rdev->bdev->bd_dev);
+		dbg("  write parity at sector %llu, parity disk %s\n",
+		    (unsigned long long)parity_sector,
+		    parity_rdev->bdev->bd_disk->disk_name);
+		if (!sync_page_io(parity_rdev, parity_sector, block_size,
+				page1, REQ_OP_WRITE, 0, false)) {
+			dbg("  parity write error!\n");
+			md_error(mddev, parity_rdev);
+			ret = -EIO;
+			goto out;
+		}
+	}
+
+out:
+	__free_pages(pages, 1);
+	return ret;
+}
+
+static int ppl_recover(struct r5l_log *log, struct ppl_header *pplhdr)
+{
+	struct mddev *mddev = log->rdev->mddev;
+	sector_t ppl_sector = log->rdev->ppl.sector + (PPL_HEADER_SIZE >> 9);
+	struct page *page;
+	int i;
+	int ret = 0;
+
+	page = alloc_page(GFP_KERNEL);
+	if (!page)
+		return -ENOMEM;
+
+	/* iterate through all PPL entries saved */
+	for (i = 0; i < pplhdr->entries_count; i++) {
+		struct ppl_header_entry *e = &pplhdr->entries[i];
+		u32 size = le32_to_cpu(e->pp_size);
+		sector_t sector = ppl_sector;
+		int ppl_entry_sectors = size >> 9;
+		u32 crc, crc_stored;
+
+		dbg("disk: %d, entry: %d, ppl_sector: %llu ppl_size: %u\n",
+		    log->rdev->raid_disk, i, (unsigned long long)ppl_sector,
+		    size);
+
+		crc = ~0;
+		crc_stored = le32_to_cpu(e->checksum);
+
+		while (size) {
+			int s = size > PAGE_SIZE ? PAGE_SIZE : size;
+
+			if (!sync_page_io(log->rdev,
+					sector - log->rdev->data_offset,
+					s, page, REQ_OP_READ, 0, false)) {
+				md_error(mddev, log->rdev);
+				ret = -EIO;
+				goto out;
+			}
+
+			crc = crc32c_le(crc, page_address(page), s);
+
+			size -= s;
+			sector += s >> 9;
+		}
+
+		crc = ~crc;
+
+		if (crc != crc_stored) {
+			dbg("ppl entry crc does not match: stored: 0x%x calculated: 0x%x\n",
+			    crc_stored, crc);
+			ret++;
+		} else {
+			int ret2;
+			e->data_sector = le64_to_cpu(e->data_sector);
+			e->pp_size = le32_to_cpu(e->pp_size);
+			e->data_size = le32_to_cpu(e->data_size);
+
+			ret2 = ppl_recover_entry(log, e, ppl_sector);
+			if (ret2) {
+				ret = ret2;
+				goto out;
+			}
+		}
+
+		ppl_sector += ppl_entry_sectors;
+	}
+out:
+	__free_page(page);
+	return ret;
+}
+
+static int ppl_write_empty_header(struct r5l_log *log)
+{
+	struct page *page;
+	struct ppl_header *pplhdr;
+	int ret = 0;
+
+	dbg("disk: %d ppl_sector: %llu\n",
+	    log->rdev->raid_disk, (unsigned long long)log->rdev->ppl.sector);
+
+	page = alloc_page(GFP_KERNEL | __GFP_ZERO);
+	if (!page)
+		return -ENOMEM;
+
+	pplhdr = page_address(page);
+	memset(pplhdr->reserved, 0xff, PPL_HDR_RESERVED);
+	pplhdr->signature = cpu_to_le32(log->uuid_checksum);
+	pplhdr->checksum = cpu_to_le32(~crc32c_le(~0, pplhdr, PAGE_SIZE));
+
+	if (!sync_page_io(log->rdev, log->rdev->ppl.sector -
+			  log->rdev->data_offset, PPL_HEADER_SIZE, page,
+			  REQ_OP_WRITE, 0, false)) {
+		md_error(log->rdev->mddev, log->rdev);
+		ret = -EIO;
+	}
+
+	__free_page(page);
+	return ret;
+}
+
+static int ppl_load_distributed(struct r5l_log *log)
+{
+	struct mddev *mddev = log->rdev->mddev;
+	struct page *page;
+	struct ppl_header *pplhdr;
+	u32 crc, crc_stored;
+	int ret = 0;
+
+	dbg("disk: %d\n", log->rdev->raid_disk);
+
+	/* read PPL header */
+	page = alloc_page(GFP_KERNEL);
+	if (!page)
+		return -ENOMEM;
+
+	if (!sync_page_io(log->rdev,
+			  log->rdev->ppl.sector - log->rdev->data_offset,
+			  PAGE_SIZE, page, REQ_OP_READ, 0, false)) {
+		md_error(mddev, log->rdev);
+		ret = -EIO;
+		goto out;
+	}
+	pplhdr = page_address(page);
+
+	/* check header validity */
+	crc_stored = le32_to_cpu(pplhdr->checksum);
+	pplhdr->checksum = 0;
+	crc = ~crc32c_le(~0, pplhdr, PAGE_SIZE);
+
+	if (crc_stored != crc) {
+		dbg("ppl header crc does not match: stored: 0x%x calculated: 0x%x\n",
+		    crc_stored, crc);
+		ret = 1;
+		goto out;
+	}
+
+	pplhdr->signature = le32_to_cpu(pplhdr->signature);
+	pplhdr->generation = le64_to_cpu(pplhdr->generation);
+	pplhdr->entries_count = le32_to_cpu(pplhdr->entries_count);
+
+	if (pplhdr->signature != log->uuid_checksum) {
+		dbg("ppl header signature does not match: stored: 0x%x configured: 0x%x\n",
+		    pplhdr->signature, log->uuid_checksum);
+		ret = 1;
+		goto out;
+	}
+
+	if (mddev->recovery_cp != MaxSector)
+		ret = ppl_recover(log, pplhdr);
+out:
+	__free_page(page);
+
+	if (ret >= 0) {
+		int ret2 = ppl_write_empty_header(log);
+		if (ret2)
+			ret = ret2;
+	}
+
+	dbg("return: %d\n", ret);
+	return ret;
+}
+
+static int ppl_load(struct r5l_log *log)
+{
+	struct ppl_conf *ppl_conf = log->private;
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < ppl_conf->count; i++) {
+		struct r5l_log *log_child = ppl_conf->child_logs[i];
+		int ret2;
+
+		/* Missing drive */
+		if (!log_child)
+			continue;
+
+		ret2 = ppl_load_distributed(log_child);
+		if (ret2 < 0) {
+			ret = ret2;
+			break;
+		}
+
+		ret += ret2;
+	}
+
+	dbg("return: %d\n", ret);
+	return ret;
+}
+
 #define IMSM_MPB_SIG "Intel Raid ISM Cfg Sig. "
 #define IMSM_MPB_ORIG_FAMILY_NUM_OFFSET 64
 
@@ -634,6 +975,12 @@ static int __ppl_init_log(struct r5l_log *log, struct r5conf *conf)
 		ppl_conf->child_logs[i] = log_child;
 	}
 
+	ret = ppl_load(log);
+	if (!ret && mddev->recovery_cp == 0 && !mddev->degraded)
+		mddev->recovery_cp = MaxSector;
+	else if (ret < 0)
+		goto err;
+
 	rcu_assign_pointer(conf->log, log);
 	set_bit(MD_HAS_PPL, &mddev->flags);
 
drivers/md/raid5.c +4 -1
index 2169de5..ed340c3 100644
@@ -7160,7 +7160,10 @@ static int raid5_run(struct mddev *mddev)
 
 	if (mddev->degraded > dirty_parity_disks &&
 	    mddev->recovery_cp != MaxSector) {
-		if (mddev->ok_start_degraded)
+		if (rwh_policy)
+			pr_warn("md/raid:%s: starting dirty degraded array with journal.\n",
+				mdname(mddev));
+		else if (mddev->ok_start_degraded)
 			pr_crit("md/raid:%s: starting dirty degraded array - data corruption possible.\n",
 				mdname(mddev));
 		else {
Signature · 1 line
2.10.1
#25 lore raw

PATCH v2 11/12 raid5-ppl: support disk add/remove with distributed PPL

In reply to Artur Paszkiewicz

Add a function to modify the log by adding or removing an rdev when a drive fails or is added as a spare.

Adding a drive to the log is as simple as initializing and adding a new child log, removing a drive is more complicated because it requires stopping the child log and freeing all of its resources. In order to do that, we busy wait for any submitted log bios to complete and then manually finish and free the io_units. No new log requests will happen at this point. A new list is added to struct r5l_io_unit to have access to stripes that have been written to the log but are not completely processed yet.

---
 drivers/md/md.c          |  3 +-
 drivers/md/raid5-cache.c | 13 ++++++-
 drivers/md/raid5-cache.h |  3 ++
 drivers/md/raid5-ppl.c   | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/md/raid5.c       | 20 +++++++++++
 5 files changed, 126 insertions(+), 2 deletions(-)
drivers/md/md.c +2 -1
index 7049833..279e303 100644
@@ -8334,7 +8334,8 @@ static int remove_and_add_spares(struct mddev *mddev,
 		    !test_bit(Blocked, &rdev->flags) &&
 		    ((test_bit(RemoveSynchronized, &rdev->flags) ||
 		     (!test_bit(In_sync, &rdev->flags) &&
-		      !test_bit(Journal, &rdev->flags))) &&
+		      !test_bit(Journal, &rdev->flags) &&
+		      !test_bit(JournalPpl, &rdev->flags))) &&
 		    atomic_read(&rdev->nr_pending)==0)) {
 			if (mddev->pers->hot_remove_disk(
 				    mddev, rdev) == 0) {
drivers/md/raid5-cache.c +12 -1
index be534d8..b69a289 100644
@@ -345,7 +345,7 @@ void r5l_io_run_stripes(struct r5l_io_unit *io)
 	struct stripe_head *sh, *next;
 
 	list_for_each_entry_safe(sh, next, &io->stripe_list, log_list) {
-		list_del_init(&sh->log_list);
+		list_move_tail(&sh->log_list, &io->stripe_finished_list);
 
 		r5c_finish_cache_stripe(sh);
 
@@ -553,6 +553,7 @@ static struct r5l_io_unit *r5l_new_meta(struct r5l_log *log)
 	io->log = log;
 	INIT_LIST_HEAD(&io->log_sibling);
 	INIT_LIST_HEAD(&io->stripe_list);
+	INIT_LIST_HEAD(&io->stripe_finished_list);
 	bio_list_init(&io->flush_barriers);
 	io->state = IO_UNIT_RUNNING;
 
@@ -2546,6 +2547,16 @@ void r5l_exit_log(struct r5l_log *log)
 	kfree(log);
 }
 
+/*
+ * operation: 0 - remove rdev from log, 1 - add rdev to log
+ */
+int r5l_modify_log(struct r5l_log *log, struct md_rdev *rdev, int operation)
+{
+	if (log && log->policy->modify_log)
+		return log->policy->modify_log(log, rdev, operation);
+	return 0;
+}
+
 struct r5l_policy r5l_journal = {
 	.init_log = __r5l_init_log,
 	.exit_log = __r5l_exit_log,
drivers/md/raid5-cache.h +3 -0
index 0446100..9d5fa0df 100644
@@ -110,6 +110,7 @@ struct r5l_io_unit {
 	sector_t log_end;	/* where the io_unit ends */
 	struct list_head log_sibling; /* log->running_ios */
 	struct list_head stripe_list; /* stripes added to the io_unit */
+	struct list_head stripe_finished_list; /* stripes written to log */
 
 	int state;
 	bool need_split_bio;
@@ -139,6 +140,7 @@ enum r5l_io_unit_state {
 struct r5l_policy {
 	int (*init_log)(struct r5l_log *log, struct r5conf *conf);
 	void (*exit_log)(struct r5l_log *log);
+	int (*modify_log)(struct r5l_log *log, struct md_rdev *rdev, int op);
 	int (*write_stripe)(struct r5l_log *log, struct stripe_head *sh);
 	void (*write_stripe_run)(struct r5l_log *log);
 	void (*flush_stripe_to_raid)(struct r5l_log *log);
@@ -149,6 +151,7 @@ struct r5l_policy {
 
 extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev, int policy_type);
 extern void r5l_exit_log(struct r5l_log *log);
+extern int r5l_modify_log(struct r5l_log *log, struct md_rdev *rdev, int operation);
 extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh);
 extern void r5l_write_stripe_run(struct r5l_log *log);
 extern void r5l_flush_stripe_to_raid(struct r5l_log *log);
drivers/md/raid5-ppl.c +89 -0

107 lines not on this page · raw message

drivers/md/raid5.c +20 -0
index ed340c3..67c8dce 100644
@@ -7466,6 +7466,19 @@ static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev)
 			*rdevp = rdev;
 		}
 	}
+	if (test_bit(JournalPpl, &rdev->flags) && conf->log) {
+		int ret;
+		if (conf->log->rwh_policy != RWH_POLICY_PPL)
+			return -EINVAL;
+		ret = r5l_modify_log(conf->log, rdev, 0);
+		if (ret)
+			return ret;
+		if (p->replacement) {
+			ret = r5l_modify_log(conf->log, p->replacement, 1);
+			if (ret)
+				return ret;
+		}
+	}
 	if (p->replacement) {
 		/* We must have just cleared 'rdev' */
 		p->rdev = p->replacement;
@@ -7558,6 +7571,13 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev)
 		}
 	}
 out:
+	if (conf->log && !test_bit(Replacement, &rdev->flags) &&
+	    conf->log->rwh_policy == RWH_POLICY_PPL) {
+		int ret = r5l_modify_log(conf->log, rdev, 1);
+		if (ret)
+			return ret;
+	}
+
 	print_raid5_conf(conf);
 	return err;
 }
Signature · 1 line
2.10.1
#27 lore raw

PATCH v2 12/12 raid5-ppl: runtime PPL enabling or disabling

In reply to Artur Paszkiewicz

Introduce a sysfs attribute to get or set the current RWH policy. The raid5_reset_cache function is used to free the stripe cache and allocate it again. This is needed to allocate or free the ppl_pages for the stripes in the stripe cache.

When enabling the log at runtime it is necessary to overwrite the PPL header to avoid recovering from stale PPL data if the log had been used previously with this array.

---
 drivers/md/raid5-ppl.c |  38 ++++++++++++++---
 drivers/md/raid5.c     | 109 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+), 5 deletions(-)
drivers/md/raid5-ppl.c +33 -5
index 1a9581c..d0a25da 100644
@@ -745,6 +745,27 @@ static int ppl_load(struct r5l_log *log)
 	return ret;
 }
 
+static int ppl_invalidate(struct r5l_log *log)
+{
+	struct ppl_conf *ppl_conf = log->private;
+	int i;
+
+	for (i = 0; i < ppl_conf->count; i++) {
+		struct r5l_log *log_child = ppl_conf->child_logs[i];
+		int ret;
+
+		/* Missing drive */
+		if (!log_child)
+			continue;
+
+		ret = ppl_write_empty_header(log_child);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 #define IMSM_MPB_SIG "Intel Raid ISM Cfg Sig. "
 #define IMSM_MPB_ORIG_FAMILY_NUM_OFFSET 64
 
@@ -976,11 +997,18 @@ static int __ppl_init_log(struct r5l_log *log, struct r5conf *conf)
 		ppl_conf->child_logs[i] = log_child;
 	}
 
-	ret = ppl_load(log);
-	if (!ret && mddev->recovery_cp == 0 && !mddev->degraded)
-		mddev->recovery_cp = MaxSector;
-	else if (ret < 0)
-		goto err;
+	if (mddev->pers) {
+		dbg("Array running - invalidate PPL\n");
+		ret = ppl_invalidate(log);
+		if (ret)
+			goto err;
+	} else {
+		ret = ppl_load(log);
+		if (!ret && mddev->recovery_cp == 0 && !mddev->degraded)
+			mddev->recovery_cp = MaxSector;
+		else if (ret < 0)
+			goto err;
+	}
 
 	rcu_assign_pointer(conf->log, log);
 	set_bit(MD_HAS_PPL, &mddev->flags);
drivers/md/raid5.c +109 -0

121 lines not on this page · raw message

Signature · 1 line
2.10.1
#11 lore raw

Re: [PATCH v2 05/12] raid5-ppl: Partial Parity Log implementation

In reply to Artur Paszkiewicz
url: https://github.com/0day-ci/linux/commits/Artur-Paszkiewicz/Partial-Parity-Log-for-MD-RAID-5/20161206-081540 config: i386-randconfig-r0-201649 (attached as .config) compiler: gcc-5 (Debian…

Hi Artur,

[auto build test ERROR on next-20161205]
[cannot apply to v4.9-rc8 v4.9-rc7 v4.9-rc6 v4.9-rc8]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Artur-Paszkiewicz/Partial-Parity-Log-for-MD-RAID-5/20161206-081540
config: i386-randconfig-r0-201649 (attached as .config)
compiler: gcc-5 (Debian 5.4.1-2) 5.4.1 20160904 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

drivers/md/raid5-ppl.c: In function 'ppl_init_log_child':

>> drivers/md/raid5-ppl.c:459:2: error: too few arguments to function 'bio_init'
     bio_init(&log->flush_bio);
     ^
   In file included from include/linux/blkdev.h:19:0,
                    from drivers/md/raid5-ppl.c:16:

include/linux/bio.h:426:13: note: declared here
extern void bio_init(struct bio *bio, struct bio_vec *table,
^

vim +/bio_init +459 drivers/md/raid5-ppl.c

453 spin_lock_init(&log->io_list_lock);
454 INIT_LIST_HEAD(&log->running_ios);
455 INIT_LIST_HEAD(&log->io_end_ios);
456 INIT_LIST_HEAD(&log->flushing_ios);
457 INIT_LIST_HEAD(&log->finished_ios);
458 INIT_LIST_HEAD(&log->no_mem_stripes);

 > 459		bio_init(&log->flush_bio);

460
461 log->io_kc = log_parent->io_kc;
462 log->io_pool = log_parent->io_pool;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#28 lore raw
In reply to Artur Paszkiewicz
Quoted 15 lines · Artur Paszkiewicz

This series of patches implements the Partial Parity Log for RAID5 arrays. The purpose of this feature is closing the RAID Write Hole. It is a solution alternative to the existing raid5-cache, but the implementation is based on it and reuses some of the code by introducing support for interchangeable policies. This allows decoupling policy from mechanism and not adding more boilerplate code in raid5.c.

The issue addressed by PPL is, that on a dirty shutdown, parity for a particular stripe may be inconsistent with data on other member disks. In degraded state, there is no way to recalculate parity, because one of the disks is missing. PPL addresses this issue and allows recalculating the parity. It stores only enough data needed for recovering from RWH and is not a true journal, like the raid5-cache implementation. It does not protect from losing in-flight data.

Quoted 4 lines

PPL is a distributed log - data is stored on all RAID member drives in the metadata area. It does not need a dedicated journaling drive. Performance is reduced by up to 30%-40% but it scales with the number of drives in the array and the journaling drive does not become a bottleneck.

I would expect to see as description of what a PPL actually is and how it works here... but there is none.

The change-log for patch 06 has a tiny bit more information which is just enough to be able to start trying to understand the code, but it isn't much.
And none of this description gets into the code, or into the Documentation/. This makes it hard to review and hard to maintain.

Remember: if you want people to review you code, it is in your interest to make it easy. That means give lots of details.

NeilBrown

#4 lore raw

Re: [PATCH v2 03/12] raid5-cache: add a new policy

In reply to Artur Paszkiewicz
Quoted 5 lines · Artur Paszkiewicz

Add a source file for the new policy implementation and allow selecting the policy based on the policy_type parameter in r5l_init_log().

Introduce a new flag for rdev state flags to allow enabling the new policy from userspace.

This seems odd. Why is this a per-device flag?
It makes sense for "journal" to be a per-device flag, because only one device is the journal device and it is obviously different from the others.

But with the ppl, all devices serve as journal devices. So we would need to set journal_ppl on all devices? What happens if you set it on some, but not others? I see you get an error.

I think some sort of array-wide setting would make more sense, would it not?

And what is an RWH??? A Really Weird Handle ??

I guess it is probably a Raid5 Write Hole ? At the very least there should be a comment explaining this when you define the enum. (remember, you are trying to make it easier for reviewers).

It might almost make sense for bitmap/metadata to be used here. It can currently be "external" "internal" "clustered". Allow also "journalled" or "partial-partiy-log" ???

Maybe not ... but I'd definitely prefer a global setting, and one that didn't use an obscure abbreviation.

NeilBrown

#12 lore raw

Re: [PATCH v2 05/12] raid5-ppl: Partial Parity Log implementation

In reply to Artur Paszkiewicz
Quoted 112 lines · Artur Paszkiewicz

This implements the write logging functionality, using the policy logic introduced in previous patches.

PPL is a distributed log - data is stored on all RAID member drives in the metadata area. PPL is written to the parity disk of a particular stripe. Distributed log is implemented by using one r5l_log instance per each array member. They are grouped in child_logs array in struct ppl_conf, which is assigned to a common parent log. This parent log serves as a proxy and is used in raid5 personality code - it is assigned as _the_ log in r5conf->log. The child logs are where all the real work is done.

The PPL consists of a 4KB header (struct ppl_header), and at least 128KB for partial parity data. It is stored right after the array data (for IMSM) or in the bitmap area (super 1.1 and 1.2) and can be overwritten even at each array write request.

Attach a page for holding the partial parity data to each stripe_head. Allocate it only if mddev has the MD_HAS_PPL flag set.

---
 drivers/md/raid5-cache.c |  12 +-
 drivers/md/raid5-cache.h |   6 +
 drivers/md/raid5-ppl.c   | 594 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/md/raid5.c       |  15 +-
 drivers/md/raid5.h       |   1 +
 5 files changed, 620 insertions(+), 8 deletions(-)
drivers/md/raid5-cache.c +6 -6
index fa82b9a..be534d8 100644
@@ -119,8 +119,8 @@ static bool r5l_has_free_space(struct r5l_log *log, sector_t size)
 	return log->device_size > used_size + size;
 }
 
-static void __r5l_set_io_unit_state(struct r5l_io_unit *io,
-				    enum r5l_io_unit_state state)
+void __r5l_set_io_unit_state(struct r5l_io_unit *io,
+			     enum r5l_io_unit_state state)
 {
 	if (WARN_ON(io->state >= state))
 		return;
@@ -340,7 +340,7 @@ static void r5c_finish_cache_stripe(struct stripe_head *sh)
 	}
 }
 
-static void r5l_io_run_stripes(struct r5l_io_unit *io)
+void r5l_io_run_stripes(struct r5l_io_unit *io)
 {
 	struct stripe_head *sh, *next;
 
@@ -935,7 +935,7 @@ static sector_t r5l_reclaimable_space(struct r5l_log *log)
 				 r5c_calculate_new_cp(conf));
 }
 
-static void r5l_run_no_mem_stripe(struct r5l_log *log)
+void r5l_run_no_mem_stripe(struct r5l_log *log)
 {
 	struct stripe_head *sh;
 
@@ -1039,7 +1039,7 @@ static void r5l_log_flush_endio(struct bio *bio)
  * only write stripes of an io_unit to raid disks till the io_unit is the first
  * one whose data/parity is in log.
  */
-static void __r5l_flush_stripe_to_raid(struct r5l_log *log)
+void __r5l_flush_stripe_to_raid(struct r5l_log *log)
 {
 	bool do_flush;
 
@@ -1359,7 +1359,7 @@ bool r5l_log_disk_error(struct r5conf *conf)
 	if (!log)
 		ret = test_bit(MD_HAS_JOURNAL, &conf->mddev->flags);
 	else
-		ret = test_bit(Faulty, &log->rdev->flags);
+		ret = log->rdev && test_bit(Faulty, &log->rdev->flags);
 	rcu_read_unlock();
 	return ret;
 }
drivers/md/raid5-cache.h +6 -0
index 4ba11d3..0446100 100644
@@ -157,4 +157,10 @@ extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
 extern void r5l_quiesce(struct r5l_log *log, int state);
 extern bool r5l_log_disk_error(struct r5conf *conf);
 
+extern void __r5l_set_io_unit_state(struct r5l_io_unit *io,
+				    enum r5l_io_unit_state state);
+extern void r5l_io_run_stripes(struct r5l_io_unit *io);
+extern void r5l_run_no_mem_stripe(struct r5l_log *log);
+extern void __r5l_flush_stripe_to_raid(struct r5l_log *log);
+
 #endif /* _RAID5_CACHE_H */
drivers/md/raid5-ppl.c +5 -1
index 263fad7..2d4c90f 100644
@@ -14,7 +14,599 @@
 
 #include <linux/kernel.h>
 #include <linux/blkdev.h>
+#include <linux/slab.h>
+#include <linux/crc32c.h>
+#include <linux/module.h>
+#include <linux/raid/md_p.h>
+#include "md.h"
 #include "raid5.h"
 #include "raid5-cache.h"
 
-struct r5l_policy r5l_ppl;

drivers/md/raid5-ppl.c line 34

Quoted 10 lines
drivers/md/raid5-ppl.c +10 -0
+static bool ppl_debug;
+module_param(ppl_debug, bool, 0644);
+MODULE_PARM_DESC(ppl_debug, "Debug mode for md raid5 PPL");
+
+#define dbg(format, args...)						\
+do {									\
+	if (ppl_debug)							\
+		printk(KERN_DEBUG"[%d] %s() "format,			\
+			current->pid, __func__, ##args);		\
+} while (0)

Please don't do this. Just use pr_debug(), and use
/sys/kernel/debug/dynamic_debug/control
to turn them on and off.

drivers/md/raid5-ppl.c line 47

Quoted 13 lines
drivers/md/raid5-ppl.c +13 -0
+
+struct ppl_conf {
+	int count;
+	struct r5l_log **child_logs;
+};
+
+struct ppl_header_entry {
+	__le64 data_sector;	/* Raid sector of the new data */
+	__le32 pp_size;		/* Length of partial parity */
+	__le32 data_size;	/* Length of data */
+	__u8 parity_disk;	/* Member disk containing parity */
+	__le32 checksum;	/* Checksum of this entry */
+} __packed;

Really? "checksum" is 32bits but not aligned?
I *think* you should be using get_unaligned_le32() to access this and put_unaligned_le32() to set it.

drivers/md/raid5-ppl.c line 60

Quoted 13 lines
drivers/md/raid5-ppl.c +13 -0
+
+#define PPL_HEADER_SIZE PAGE_SIZE
+#define PPL_HDR_RESERVED 512
+#define PPL_HDR_ENTRY_SPACE \
+	(PPL_HEADER_SIZE - PPL_HDR_RESERVED - 3 * sizeof(u32) - sizeof(u64))
+#define PPL_HDR_MAX_ENTRIES \
+	(PPL_HDR_ENTRY_SPACE / sizeof(struct ppl_header_entry))
+#define PPL_ENTRY_SPACE_IMSM (128 * 1024)
+
+struct ppl_header {
+	__u8 reserved[PPL_HDR_RESERVED];/* Reserved space */
+	__le32 signature;		/* Signature (family number of volume) */
+	__le64 generation;		/* Generation number of PP Header */

This probably needs to use the 'unaligned' macros too.

drivers/md/raid5-ppl.c line 64

Quoted 4 lines
drivers/md/raid5-ppl.c +4 -0
+	__le32 entries_count;		/* Number of entries in entry array */
+	__le32 checksum;		/* Checksum of PP Header */
+	struct ppl_header_entry entries[PPL_HDR_MAX_ENTRIES];
+} __packed;

ppl_header_entry doesn't seem to be a multiple of 4 bytes long. This means all the fields in it could be unaligned...

Maybe we should make this code refuse to compile except on x86 ???

NeilBrown

#16 lore raw

Re: [PATCH v2 07/12] md: mddev_find_container helper function

In reply to Artur Paszkiewicz
Quoted 2 lines · Artur Paszkiewicz

This allows finding the parent container of a subarray for external metadata arrays.

This doesn't belong in the kernel.
If it did, there would be a detailed description here of why it is needed.
But there isn't one.

NeilBrown

#18 lore raw

Re: [PATCH v2 08/12] md: expose rdev->sb_start as sysfs attribute

In reply to Artur Paszkiewicz
Quoted 2 lines · Artur Paszkiewicz

This is meant for external metadata arrays, to pass the location of the superblock to the kernel.

The whole point of external metadata arrays is that the metadata is handled externally. The kernel doesn't need to know where it is.

Certainly the kernel needs to know where the PPL is, but that is quite a different question to knowing where the superblock is.

NeilBrown

#20 lore raw

Re: [PATCH v2 09/12] raid5-ppl: read PPL signature from IMSM metadata

In reply to Artur Paszkiewicz
Quoted 5 lines · Artur Paszkiewicz

The PPL signature is used to determine if the stored PPL is valid for a given array. With IMSM, the PPL signature should match the orig_family_num field of the superblock. To avoid passing this value from userspace, it can be read from the IMSM MPB when initializing the log.

It is up to mdadm to determine if the PPL is valid. It would only tell the kernel that a PPL exists if it is valid...

NeilBrown

#26 lore raw

Re: [PATCH v2 11/12] raid5-ppl: support disk add/remove with distributed PPL

In reply to Artur Paszkiewicz
Quoted 11 lines · Artur Paszkiewicz

Add a function to modify the log by adding or removing an rdev when a drive fails or is added as a spare.

Adding a drive to the log is as simple as initializing and adding a new child log, removing a drive is more complicated because it requires stopping the child log and freeing all of its resources. In order to do that, we busy wait for any submitted log bios to complete and then manually finish and free the io_units. No new log requests will happen at this point. A new list is added to struct r5l_io_unit to have access to stripes that have been written to the log but are not completely processed yet.

Busy-wait for IO to finish? Seriously?

At the very very least you need to cond_resched() in there, but an actual wait would be much better.

NeilBrown

#29 lore raw
In reply to NeilBrown
Quoted 4 lines · NeilBrown

I would expect to see as description of what a PPL actually is and how it works here... but there is none.

Quoted 8 lines

The change-log for patch 06 has a tiny bit more information which is just enough to be able to start trying to understand the code, but it isn't much.
And none of this description gets into the code, or into the Documentation/. This makes it hard to review and hard to maintain.

Remember: if you want people to review you code, it is in your interest to make it easy. That means give lots of details.

Hi Neil,

Thank you for taking the time to look at this and for your feedback. I didn't try to make it hard to review... Sometimes it's easy to forget how non-obvious things are after looking at them for too long :) I will improve the descriptions and address the issues that you found in the next version of the patches.

Thanks,
Artur

#5 lore raw

Re: [PATCH v2 03/12] raid5-cache: add a new policy

In reply to NeilBrown
Quoted 13 lines · NeilBrown
Quoted 5 lines · Artur Paszkiewicz

Add a source file for the new policy implementation and allow selecting the policy based on the policy_type parameter in r5l_init_log().

Introduce a new flag for rdev state flags to allow enabling the new policy from userspace.

This seems odd. Why is this a per-device flag?
It makes sense for "journal" to be a per-device flag, because only one device is the journal device and it is obviously different from the others.

Quoted 6 lines

But with the ppl, all devices serve as journal devices. So we would need to set journal_ppl on all devices? What happens if you set it on some, but not others? I see you get an error.

I think some sort of array-wide setting would make more sense, would it not?

Yes, it would. The problem exists only for external metadata, because for native there is a feature flag in the superblock and a corresponding flag in mddev->flags. Patch 12 adds a sysfs attribute to control the policy at runtime but it would have to be moved out of raid5 personality into the main md code. I didn't like the idea of adding something specific to raid5 to generic code and visible in sysfs for unrelated raid levels.

Quoted 5 lines

And what is an RWH??? A Really Weird Handle ??

I guess it is probably a Raid5 Write Hole ? At the very least there should be a comment explaining this when you define the enum. (remember, you are trying to make it easier for reviewers).

That's right, RWH stands for RAID Write Hole. I think I introduced it in the cover letter, but I'll explain it also in the code.

Quoted 6 lines

It might almost make sense for bitmap/metadata to be used here. It can currently be "external" "internal" "clustered". Allow also "journalled" or "partial-partiy-log" ???

Maybe not ... but I'd definitely prefer a global setting, and one that didn't use an obscure abbreviation.

So do you think the sysfs attribute from patch 12 ("rwh_policy") could be made global? This would simplify things but it doesn't seem right. And about the abbreviation, should it be called "write_hole_policy" or "raid5_write_hole_policy"? Maybe using bitmap/metadata is not a bad idea...

Artur

#13 lore raw

Re: [PATCH v2 05/12] raid5-ppl: Partial Parity Log implementation

In reply to NeilBrown
Quoted 171 lines · NeilBrown
Quoted 112 lines · Artur Paszkiewicz

This implements the write logging functionality, using the policy logic introduced in previous patches.

PPL is a distributed log - data is stored on all RAID member drives in the metadata area. PPL is written to the parity disk of a particular stripe. Distributed log is implemented by using one r5l_log instance per each array member. They are grouped in child_logs array in struct ppl_conf, which is assigned to a common parent log. This parent log serves as a proxy and is used in raid5 personality code - it is assigned as _the_ log in r5conf->log. The child logs are where all the real work is done.

The PPL consists of a 4KB header (struct ppl_header), and at least 128KB for partial parity data. It is stored right after the array data (for IMSM) or in the bitmap area (super 1.1 and 1.2) and can be overwritten even at each array write request.

Attach a page for holding the partial parity data to each stripe_head. Allocate it only if mddev has the MD_HAS_PPL flag set.

---
 drivers/md/raid5-cache.c |  12 +-
 drivers/md/raid5-cache.h |   6 +
 drivers/md/raid5-ppl.c   | 594 ++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/md/raid5.c       |  15 +-
 drivers/md/raid5.h       |   1 +
 5 files changed, 620 insertions(+), 8 deletions(-)
drivers/md/raid5-cache.c +6 -6
index fa82b9a..be534d8 100644
@@ -119,8 +119,8 @@ static bool r5l_has_free_space(struct r5l_log *log, sector_t size)
 	return log->device_size > used_size + size;
 }
 
-static void __r5l_set_io_unit_state(struct r5l_io_unit *io,
-				    enum r5l_io_unit_state state)
+void __r5l_set_io_unit_state(struct r5l_io_unit *io,
+			     enum r5l_io_unit_state state)
 {
 	if (WARN_ON(io->state >= state))
 		return;
@@ -340,7 +340,7 @@ static void r5c_finish_cache_stripe(struct stripe_head *sh)
 	}
 }
 
-static void r5l_io_run_stripes(struct r5l_io_unit *io)
+void r5l_io_run_stripes(struct r5l_io_unit *io)
 {
 	struct stripe_head *sh, *next;
 
@@ -935,7 +935,7 @@ static sector_t r5l_reclaimable_space(struct r5l_log *log)
 				 r5c_calculate_new_cp(conf));
 }
 
-static void r5l_run_no_mem_stripe(struct r5l_log *log)
+void r5l_run_no_mem_stripe(struct r5l_log *log)
 {
 	struct stripe_head *sh;
 
@@ -1039,7 +1039,7 @@ static void r5l_log_flush_endio(struct bio *bio)
  * only write stripes of an io_unit to raid disks till the io_unit is the first
  * one whose data/parity is in log.
  */
-static void __r5l_flush_stripe_to_raid(struct r5l_log *log)
+void __r5l_flush_stripe_to_raid(struct r5l_log *log)
 {
 	bool do_flush;
 
@@ -1359,7 +1359,7 @@ bool r5l_log_disk_error(struct r5conf *conf)
 	if (!log)
 		ret = test_bit(MD_HAS_JOURNAL, &conf->mddev->flags);
 	else
-		ret = test_bit(Faulty, &log->rdev->flags);
+		ret = log->rdev && test_bit(Faulty, &log->rdev->flags);
 	rcu_read_unlock();
 	return ret;
 }
drivers/md/raid5-cache.h +6 -0
index 4ba11d3..0446100 100644
@@ -157,4 +157,10 @@ extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
 extern void r5l_quiesce(struct r5l_log *log, int state);
 extern bool r5l_log_disk_error(struct r5conf *conf);
 
+extern void __r5l_set_io_unit_state(struct r5l_io_unit *io,
+				    enum r5l_io_unit_state state);
+extern void r5l_io_run_stripes(struct r5l_io_unit *io);
+extern void r5l_run_no_mem_stripe(struct r5l_log *log);
+extern void __r5l_flush_stripe_to_raid(struct r5l_log *log);
+
 #endif /* _RAID5_CACHE_H */
drivers/md/raid5-ppl.c +5 -1
index 263fad7..2d4c90f 100644
@@ -14,7 +14,599 @@
 
 #include <linux/kernel.h>
 #include <linux/blkdev.h>
+#include <linux/slab.h>
+#include <linux/crc32c.h>
+#include <linux/module.h>
+#include <linux/raid/md_p.h>
+#include "md.h"
 #include "raid5.h"
 #include "raid5-cache.h"
 
-struct r5l_policy r5l_ppl;

drivers/md/raid5-ppl.c line 34

Quoted 10 lines
drivers/md/raid5-ppl.c +10 -0
+static bool ppl_debug;
+module_param(ppl_debug, bool, 0644);
+MODULE_PARM_DESC(ppl_debug, "Debug mode for md raid5 PPL");
+
+#define dbg(format, args...)						\
+do {									\
+	if (ppl_debug)							\
+		printk(KERN_DEBUG"[%d] %s() "format,			\
+			current->pid, __func__, ##args);		\
+} while (0)

Please don't do this. Just use pr_debug(), and use
/sys/kernel/debug/dynamic_debug/control
to turn them on and off.

drivers/md/raid5-ppl.c line 47

Quoted 13 lines
drivers/md/raid5-ppl.c +13 -0
+
+struct ppl_conf {
+	int count;
+	struct r5l_log **child_logs;
+};
+
+struct ppl_header_entry {
+	__le64 data_sector;	/* Raid sector of the new data */
+	__le32 pp_size;		/* Length of partial parity */
+	__le32 data_size;	/* Length of data */
+	__u8 parity_disk;	/* Member disk containing parity */
+	__le32 checksum;	/* Checksum of this entry */
+} __packed;

Really? "checksum" is 32bits but not aligned?
I *think* you should be using get_unaligned_le32() to access this and put_unaligned_le32() to set it.

drivers/md/raid5-ppl.c line 60

Quoted 13 lines
drivers/md/raid5-ppl.c +13 -0
+
+#define PPL_HEADER_SIZE PAGE_SIZE
+#define PPL_HDR_RESERVED 512
+#define PPL_HDR_ENTRY_SPACE \
+	(PPL_HEADER_SIZE - PPL_HDR_RESERVED - 3 * sizeof(u32) - sizeof(u64))
+#define PPL_HDR_MAX_ENTRIES \
+	(PPL_HDR_ENTRY_SPACE / sizeof(struct ppl_header_entry))
+#define PPL_ENTRY_SPACE_IMSM (128 * 1024)
+
+struct ppl_header {
+	__u8 reserved[PPL_HDR_RESERVED];/* Reserved space */
+	__le32 signature;		/* Signature (family number of volume) */
+	__le64 generation;		/* Generation number of PP Header */

This probably needs to use the 'unaligned' macros too.

drivers/md/raid5-ppl.c line 64

Quoted 4 lines
drivers/md/raid5-ppl.c +4 -0
+	__le32 entries_count;		/* Number of entries in entry array */
+	__le32 checksum;		/* Checksum of PP Header */
+	struct ppl_header_entry entries[PPL_HDR_MAX_ENTRIES];
+} __packed;

ppl_header_entry doesn't seem to be a multiple of 4 bytes long. This means all the fields in it could be unaligned...

Quoted 1 line

Maybe we should make this code refuse to compile except on x86 ???

Oh... you are right, this is bad. I hope I can still persuade some people to fix those structures in the platform firmware, etc. Like changing "parity_disk" to 4 bytes or inserting a padding there.

Artur

#21 lore raw

Re: [PATCH v2 09/12] raid5-ppl: read PPL signature from IMSM metadata

In reply to NeilBrown
Quoted 10 lines · NeilBrown
Quoted 5 lines · Artur Paszkiewicz

The PPL signature is used to determine if the stored PPL is valid for a given array. With IMSM, the PPL signature should match the orig_family_num field of the superblock. To avoid passing this value from userspace, it can be read from the IMSM MPB when initializing the log.

It is up to mdadm to determine if the PPL is valid. It would only tell the kernel that a PPL exists if it is valid...

The kernel also has to know this value because it writes it to the PPL header. So yet another sysfs attribute just for this value? How about adding a directory similar to "bitmap" to hold all the PPL related settings?

Artur

#30 lore raw
In reply to Artur Paszkiewicz
Quoted 14 lines · Artur Paszkiewicz
Quoted 4 lines · NeilBrown

I would expect to see as description of what a PPL actually is and how it works here... but there is none.

Quoted 8 lines

The change-log for patch 06 has a tiny bit more information which is just enough to be able to start trying to understand the code, but it isn't much.
And none of this description gets into the code, or into the Documentation/. This makes it hard to review and hard to maintain.

Remember: if you want people to review you code, it is in your interest to make it easy. That means give lots of details.

Quoted 7 lines

Hi Neil,

Thank you for taking the time to look at this and for your feedback. I didn't try to make it hard to review... Sometimes it's easy to forget how non-obvious things are after looking at them for too long :) I will improve the descriptions and address the issues that you found in the next version of the patches.

Havn't looked at the patches yet, being busy recently, sorry! When you repost these, I'd like to know why we need another log for raid5 considering we already had one to fix similar issue. What's the good/bad side of this new log? There is such feature in Intel RSTe doesn't sound like a technical reason we should support this.

Thanks,
Shaohua

#6 lore raw

Re: [PATCH v2 03/12] raid5-cache: add a new policy

In reply to Artur Paszkiewicz
Quoted 42 lines · Artur Paszkiewicz
Quoted 13 lines · NeilBrown
Quoted 5 lines · Artur Paszkiewicz

Add a source file for the new policy implementation and allow selecting the policy based on the policy_type parameter in r5l_init_log().

Introduce a new flag for rdev state flags to allow enabling the new policy from userspace.

This seems odd. Why is this a per-device flag?
It makes sense for "journal" to be a per-device flag, because only one device is the journal device and it is obviously different from the others.

Quoted 6 lines

But with the ppl, all devices serve as journal devices. So we would need to set journal_ppl on all devices? What happens if you set it on some, but not others? I see you get an error.

I think some sort of array-wide setting would make more sense, would it not?

Yes, it would. The problem exists only for external metadata, because for native there is a feature flag in the superblock and a corresponding flag in mddev->flags. Patch 12 adds a sysfs attribute to control the policy at runtime but it would have to be moved out of raid5 personality into the main md code. I didn't like the idea of adding something specific to raid5 to generic code and visible in sysfs for unrelated raid levels.

Quoted 5 lines

And what is an RWH??? A Really Weird Handle ??

I guess it is probably a Raid5 Write Hole ? At the very least there should be a comment explaining this when you define the enum. (remember, you are trying to make it easier for reviewers).

That's right, RWH stands for RAID Write Hole. I think I introduced it in the cover letter, but I'll explain it also in the code.

Quoted 4 lines

It might almost make sense for bitmap/metadata to be used here. It can currently be "external" "internal" "clustered". Allow also "journalled" or "partial-partiy-log" ???

Quoted 8 lines
Quoted 2 lines

Maybe not ... but I'd definitely prefer a global setting, and one that didn't use an obscure abbreviation.

So do you think the sysfs attribute from patch 12 ("rwh_policy") could be made global? This would simplify things but it doesn't seem right. And about the abbreviation, should it be called "write_hole_policy" or "raid5_write_hole_policy"? Maybe using bitmap/metadata is not a bad idea...

How about we call it "resync_policy" which describes how to cope with unexpected shutdown. Options include:

full regenerate all redundancy info after a crash
bitmap only regenerate redundancy info indicated by bitmap
(both these suseptible to write-hole on raid456)
journal raid456 only, though could theoretically be extended
to raid1, raid10 : log transactions and replay after crash
ppl raid456 only: log partial-parity before writes.

With external metadata, this must be set explicitly. With internal metadata, it is set best on flags etc.

Thoughts? I'm not really happy with "full", but I cannot think of a better name.

Thanks,
NeilBrown

#22 lore raw

Re: [PATCH v2 09/12] raid5-ppl: read PPL signature from IMSM metadata

In reply to Artur Paszkiewicz
Quoted 9 lines · Artur Paszkiewicz
Quoted 8 lines · NeilBrown
Quoted 5 lines · Artur Paszkiewicz

The PPL signature is used to determine if the stored PPL is valid for a given array. With IMSM, the PPL signature should match the orig_family_num field of the superblock. To avoid passing this value from userspace, it can be read from the IMSM MPB when initializing the log.

Quoted 7 lines
Quoted 2 lines

It is up to mdadm to determine if the PPL is valid. It would only tell the kernel that a PPL exists if it is valid...

The kernel also has to know this value because it writes it to the PPL header. So yet another sysfs attribute just for this value? How about adding a directory similar to "bitmap" to hold all the PPL related settings?

There is only one PPL header (per device) - correct?
md can read that header, change the few fields that it knows about, and write it back out again. Does it ever need to change the PPL signature?

When a PPL is created, mdadm can write the initial header.

Am I missing something?

Thanks,
NeilBrown

#7 lore raw

Re: [PATCH v2 03/12] raid5-cache: add a new policy

In reply to NeilBrown
Quoted 63 lines · NeilBrown
Quoted 42 lines · Artur Paszkiewicz
Quoted 13 lines · NeilBrown
Quoted 5 lines · Artur Paszkiewicz

Add a source file for the new policy implementation and allow selecting the policy based on the policy_type parameter in r5l_init_log().

Introduce a new flag for rdev state flags to allow enabling the new policy from userspace.

This seems odd. Why is this a per-device flag?
It makes sense for "journal" to be a per-device flag, because only one device is the journal device and it is obviously different from the others.

Quoted 6 lines

But with the ppl, all devices serve as journal devices. So we would need to set journal_ppl on all devices? What happens if you set it on some, but not others? I see you get an error.

I think some sort of array-wide setting would make more sense, would it not?

Yes, it would. The problem exists only for external metadata, because for native there is a feature flag in the superblock and a corresponding flag in mddev->flags. Patch 12 adds a sysfs attribute to control the policy at runtime but it would have to be moved out of raid5 personality into the main md code. I didn't like the idea of adding something specific to raid5 to generic code and visible in sysfs for unrelated raid levels.

Quoted 5 lines

And what is an RWH??? A Really Weird Handle ??

I guess it is probably a Raid5 Write Hole ? At the very least there should be a comment explaining this when you define the enum. (remember, you are trying to make it easier for reviewers).

That's right, RWH stands for RAID Write Hole. I think I introduced it in the cover letter, but I'll explain it also in the code.

Quoted 4 lines

It might almost make sense for bitmap/metadata to be used here. It can currently be "external" "internal" "clustered". Allow also "journalled" or "partial-partiy-log" ???

Quoted 8 lines
Quoted 2 lines

Maybe not ... but I'd definitely prefer a global setting, and one that didn't use an obscure abbreviation.

So do you think the sysfs attribute from patch 12 ("rwh_policy") could be made global? This would simplify things but it doesn't seem right. And about the abbreviation, should it be called "write_hole_policy" or "raid5_write_hole_policy"? Maybe using bitmap/metadata is not a bad idea...

How about we call it "resync_policy" which describes how to cope with unexpected shutdown. Options include:

full regenerate all redundancy info after a crash
bitmap only regenerate redundancy info indicated by bitmap
(both these suseptible to write-hole on raid456)
journal raid456 only, though could theoretically be extended
to raid1, raid10 : log transactions and replay after crash
ppl raid456 only: log partial-parity before writes.

Quoted 5 lines

With external metadata, this must be set explicitly. With internal metadata, it is set best on flags etc.

Thoughts? I'm not really happy with "full", but I cannot think of a better name.

I'm OK with this approach. A corresponding option will also be needed in mdadm. But won't this name be a little misleading because this option is not just about unexpected shutdown (where resync applies), but also degraded array unexpected shutdown. So maybe something like "consistency_policy" and "resync" option instead of "full"?

Thanks,
Artur

#23 lore raw

Re: [PATCH v2 09/12] raid5-ppl: read PPL signature from IMSM metadata

In reply to NeilBrown
Quoted 19 lines · NeilBrown
Quoted 9 lines · Artur Paszkiewicz
Quoted 8 lines · NeilBrown
Quoted 5 lines · Artur Paszkiewicz

The PPL signature is used to determine if the stored PPL is valid for a given array. With IMSM, the PPL signature should match the orig_family_num field of the superblock. To avoid passing this value from userspace, it can be read from the IMSM MPB when initializing the log.

Quoted 7 lines
Quoted 2 lines

It is up to mdadm to determine if the PPL is valid. It would only tell the kernel that a PPL exists if it is valid...

The kernel also has to know this value because it writes it to the PPL header. So yet another sysfs attribute just for this value? How about adding a directory similar to "bitmap" to hold all the PPL related settings?

Quoted 7 lines

There is only one PPL header (per device) - correct?
md can read that header, change the few fields that it knows about, and write it back out again. Does it ever need to change the PPL signature?

When a PPL is created, mdadm can write the initial header.

Am I missing something?

Well, you are right. If mdadm takes care of validating PPL and writes the initial header, md can use the signature read from the header. Much simpler that way :) Thanks for the suggestion.

Artur

#8 lore raw

Re: [PATCH v2 03/12] raid5-cache: add a new policy

In reply to Artur Paszkiewicz
Quoted 14 lines · Artur Paszkiewicz
Quoted 14 lines

How about we call it "resync_policy" which describes how to cope with unexpected shutdown. Options include:

full regenerate all redundancy info after a crash
bitmap only regenerate redundancy info indicated by bitmap
(both these suseptible to write-hole on raid456)
journal raid456 only, though could theoretically be extended
to raid1, raid10 : log transactions and replay after crash
ppl raid456 only: log partial-parity before writes.

With external metadata, this must be set explicitly. With internal metadata, it is set best on flags etc.

Quoted 8 lines
Quoted 2 lines

Thoughts? I'm not really happy with "full", but I cannot think of a better name.

I'm OK with this approach. A corresponding option will also be needed in mdadm. But won't this name be a little misleading because this option is not just about unexpected shutdown (where resync applies), but also degraded array unexpected shutdown. So maybe something like "consistency_policy" and "resync" option instead of "full"?

"consistency_policy" and "resync" sounds good to me. Thanks.

NeilBrown

#31 lore raw
In reply to Shaohua Li
Quoted 23 lines · Shaohua Li
Quoted 14 lines · Artur Paszkiewicz
Quoted 4 lines · NeilBrown

I would expect to see as description of what a PPL actually is and how it works here... but there is none.

Quoted 8 lines

The change-log for patch 06 has a tiny bit more information which is just enough to be able to start trying to understand the code, but it isn't much.
And none of this description gets into the code, or into the Documentation/. This makes it hard to review and hard to maintain.

Remember: if you want people to review you code, it is in your interest to make it easy. That means give lots of details.

Quoted 7 lines

Hi Neil,

Thank you for taking the time to look at this and for your feedback. I didn't try to make it hard to review... Sometimes it's easy to forget how non-obvious things are after looking at them for too long :) I will improve the descriptions and address the issues that you found in the next version of the patches.

Quoted 5 lines

Havn't looked at the patches yet, being busy recently, sorry! When you repost these, I'd like to know why we need another log for raid5 considering we already had one to fix similar issue. What's the good/bad side of this new log? There is such feature in Intel RSTe doesn't sound like a technical reason we should support this.

Shaohua,

Any further thought on these patches? I am considering doing a release of mdadm early in the new year. it would be nice to include these patches if the feature is going in.

As for supporting it, if IMSM supports it and it is used in the field, then it seems legitimate for Linux to support it too. Just like we support so many other obscure pieces of hardware :)

Cheers,
Jes

#32 lore raw
Quoted 32 lines · Jes Sorensen
Quoted 23 lines · Shaohua Li
Quoted 14 lines · Artur Paszkiewicz
Quoted 4 lines · NeilBrown

I would expect to see as description of what a PPL actually is and how it works here... but there is none.

Quoted 8 lines

The change-log for patch 06 has a tiny bit more information which is just enough to be able to start trying to understand the code, but it isn't much.
And none of this description gets into the code, or into the Documentation/. This makes it hard to review and hard to maintain.

Remember: if you want people to review you code, it is in your interest to make it easy. That means give lots of details.

Quoted 7 lines

Hi Neil,

Thank you for taking the time to look at this and for your feedback. I didn't try to make it hard to review... Sometimes it's easy to forget how non-obvious things are after looking at them for too long :) I will improve the descriptions and address the issues that you found in the next version of the patches.

Quoted 5 lines

Havn't looked at the patches yet, being busy recently, sorry! When you repost these, I'd like to know why we need another log for raid5 considering we already had one to fix similar issue. What's the good/bad side of this new log? There is such feature in Intel RSTe doesn't sound like a technical reason we should support this.

Shaohua,

Quoted 7 lines

Any further thought on these patches? I am considering doing a release of mdadm early in the new year. it would be nice to include these patches if the feature is going in.

As for supporting it, if IMSM supports it and it is used in the field, then it seems legitimate for Linux to support it too. Just like we support so many other obscure pieces of hardware :)

Sure, I don't object to support it. Just need to understand how it works. Had a brief review. The ondisk format looks good. That probably is related to mdadm mostly. The disk format has alignment issue as Neil noted, which would be unfriendly for non-x86 arch. Will we stick to this disk format or change it? We'd make a decision.

For the implementation, I don't understand how the ppl works much, there aren't many details there. Two things I noted:

- The code skips the log for full stripe write. This isn't good. It would means after a unclean shutdown/recovery, one disk has arbitrary data, not the old data and new data. This breaks an assumption in filesystem, after a failed write to a sector, the sector has either old or new data. Thinking about a write to superblock. The data could be old or new superblock, but it's still a superblock, not something random.

- From the patch 6 & 10, looks PPL only help recover unwritten disks. If one disk of a stripe is dirty (eg it's written before unclean shutdown), and it's lost in recovery, what will happen? Seems the data of lost disk will be read as 0? It will break the assumption above too. If I understand the code clearly (maybe not, need clarification), this is a design flaw.

Thanks,
Shaohua

#33 lore raw
Quoted 41 lines · Shaohua Li
Quoted 32 lines · Jes Sorensen
Quoted 23 lines · Shaohua Li
Quoted 14 lines · Artur Paszkiewicz
Quoted 4 lines · NeilBrown

I would expect to see as description of what a PPL actually is and how it works here... but there is none.

Quoted 8 lines

The change-log for patch 06 has a tiny bit more information which is just enough to be able to start trying to understand the code, but it isn't much.
And none of this description gets into the code, or into the Documentation/. This makes it hard to review and hard to maintain.

Remember: if you want people to review you code, it is in your interest to make it easy. That means give lots of details.

Quoted 7 lines

Hi Neil,

Thank you for taking the time to look at this and for your feedback. I didn't try to make it hard to review... Sometimes it's easy to forget how non-obvious things are after looking at them for too long :) I will improve the descriptions and address the issues that you found in the next version of the patches.

Quoted 5 lines

Havn't looked at the patches yet, being busy recently, sorry! When you repost these, I'd like to know why we need another log for raid5 considering we already had one to fix similar issue. What's the good/bad side of this new log? There is such feature in Intel RSTe doesn't sound like a technical reason we should support this.

Shaohua,

Quoted 7 lines

Any further thought on these patches? I am considering doing a release of mdadm early in the new year. it would be nice to include these patches if the feature is going in.

As for supporting it, if IMSM supports it and it is used in the field, then it seems legitimate for Linux to support it too. Just like we support so many other obscure pieces of hardware :)

Quoted 5 lines

Sure, I don't object to support it. Just need to understand how it works. Had a brief review. The ondisk format looks good. That probably is related to mdadm mostly. The disk format has alignment issue as Neil noted, which would be unfriendly for non-x86 arch. Will we stick to this disk format or change it? We'd make a decision.

This alignment issue will be fixed by extending the 'parity_disk' field to 4 bytes. The 'checksum' field will then be properly aligned and the size of the structure will be 24 bytes, also fixing the array alignment.

Quoted 10 lines

For the implementation, I don't understand how the ppl works much, there aren't many details there. Two things I noted:

- The code skips the log for full stripe write. This isn't good. It would means after a unclean shutdown/recovery, one disk has arbitrary data, not the old data and new data. This breaks an assumption in filesystem, after a failed write to a sector, the sector has either old or new data. Thinking about a write to superblock. The data could be old or new superblock, but it's still a superblock, not something random.

Quoted 5 lines

- From the patch 6 & 10, looks PPL only help recover unwritten disks. If one disk of a stripe is dirty (eg it's written before unclean shutdown), and it's lost in recovery, what will happen? Seems the data of lost disk will be read as 0? It will break the assumption above too. If I understand the code clearly (maybe not, need clarification), this is a design flaw.

PPL is only used to update the parity for a stripe, data chunks are not modified at all during PPL recovery. The assumption was that it would protect only from silent data corruption, to eliminate the cases when data that was not touched by a write request could change. So if a dirty disk is lost, no recovery is performed for this stripe (parity is not updated). For full stripe write we only recalculate the parity after a dirty shutdown if all disks are available (like resync). So you are right that it is still possible to have arbitrary data in the written part of a stripe if that disk is lost. In such case the behavior is the same as in plain raid5.

Thanks,
Artur

#34 lore raw
Quoted 68 lines · Artur Paszkiewicz
Quoted 41 lines · Shaohua Li
Quoted 32 lines · Jes Sorensen
Quoted 23 lines · Shaohua Li
Quoted 14 lines · Artur Paszkiewicz
Quoted 4 lines · NeilBrown

I would expect to see as description of what a PPL actually is and how it works here... but there is none.

Quoted 8 lines

The change-log for patch 06 has a tiny bit more information which is just enough to be able to start trying to understand the code, but it isn't much.
And none of this description gets into the code, or into the Documentation/. This makes it hard to review and hard to maintain.

Remember: if you want people to review you code, it is in your interest to make it easy. That means give lots of details.

Quoted 7 lines

Hi Neil,

Thank you for taking the time to look at this and for your feedback. I didn't try to make it hard to review... Sometimes it's easy to forget how non-obvious things are after looking at them for too long :) I will improve the descriptions and address the issues that you found in the next version of the patches.

Quoted 5 lines

Havn't looked at the patches yet, being busy recently, sorry! When you repost these, I'd like to know why we need another log for raid5 considering we already had one to fix similar issue. What's the good/bad side of this new log? There is such feature in Intel RSTe doesn't sound like a technical reason we should support this.

Shaohua,

Quoted 7 lines

Any further thought on these patches? I am considering doing a release of mdadm early in the new year. it would be nice to include these patches if the feature is going in.

As for supporting it, if IMSM supports it and it is used in the field, then it seems legitimate for Linux to support it too. Just like we support so many other obscure pieces of hardware :)

Quoted 5 lines

Sure, I don't object to support it. Just need to understand how it works. Had a brief review. The ondisk format looks good. That probably is related to mdadm mostly. The disk format has alignment issue as Neil noted, which would be unfriendly for non-x86 arch. Will we stick to this disk format or change it? We'd make a decision.

This alignment issue will be fixed by extending the 'parity_disk' field to 4 bytes. The 'checksum' field will then be properly aligned and the size of the structure will be 24 bytes, also fixing the array alignment.

Quoted 10 lines

For the implementation, I don't understand how the ppl works much, there aren't many details there. Two things I noted:

- The code skips the log for full stripe write. This isn't good. It would means after a unclean shutdown/recovery, one disk has arbitrary data, not the old data and new data. This breaks an assumption in filesystem, after a failed write to a sector, the sector has either old or new data. Thinking about a write to superblock. The data could be old or new superblock, but it's still a superblock, not something random.

Quoted 5 lines

- From the patch 6 & 10, looks PPL only help recover unwritten disks. If one disk of a stripe is dirty (eg it's written before unclean shutdown), and it's lost in recovery, what will happen? Seems the data of lost disk will be read as 0? It will break the assumption above too. If I understand the code clearly (maybe not, need clarification), this is a design flaw.

Quoted 10 lines

PPL is only used to update the parity for a stripe, data chunks are not modified at all during PPL recovery. The assumption was that it would protect only from silent data corruption, to eliminate the cases when data that was not touched by a write request could change. So if a dirty disk is lost, no recovery is performed for this stripe (parity is not updated). For full stripe write we only recalculate the parity after a dirty shutdown if all disks are available (like resync). So you are right that it is still possible to have arbitrary data in the written part of a stripe if that disk is lost. In such case the behavior is the same as in plain raid5.

Ok, this matches my understanding. This isn't a completed solution but does help a lot. If users want to use this, there is no reason to not support it. After you fix the alignment issue and describe the solution in details, I'll look at it again.

Thanks,
Shaohua

#35 lore raw
Quoted 36 lines · Shaohua Li
Quoted 24 lines · Artur Paszkiewicz
Quoted 14 lines · Shaohua Li

For the implementation, I don't understand how the ppl works much, there aren't
many details there. Two things I noted:

- The code skips the log for full stripe write. This isn't
good. It would means
after a unclean shutdown/recovery, one disk has arbitrary data,
not the old
data and new data. This breaks an assumption in filesystem, after a failed write to a sector, the sector has either old or new data. Thinking about a write to superblock. The data could be old or new superblock,
but it's still a
superblock, not something random.

Quoted 8 lines

- From the patch 6 & 10, looks PPL only help recover unwritten disks. If one disk of a stripe is dirty (eg it's written before unclean
shutdown), and it's
lost in recovery, what will happen? Seems the data of lost disk
will be read as
0? It will break the assumption above too. If I understand the
code clearly
(maybe not, need clarification), this is a design flaw.

Quoted 10 lines

PPL is only used to update the parity for a stripe, data chunks are not modified at all during PPL recovery. The assumption was that it would protect only from silent data corruption, to eliminate the cases when data that was not touched by a write request could change. So if a dirty disk is lost, no recovery is performed for this stripe (parity is not updated). For full stripe write we only recalculate the parity after a dirty shutdown if all disks are available (like resync). So you are right that it is still possible to have arbitrary data in the written part of a stripe if that disk is lost. In such case the behavior is the same as in plain raid5.

Quoted 4 lines

Ok, this matches my understanding. This isn't a completed solution but does help a lot. If users want to use this, there is no reason to not support it. After you fix the alignment issue and describe the solution in details, I'll look at it again.

Artur,

Did you make any progress getting the alignment issue resolved?

I'd really like to get an mdadm release out the door this week, so getting this resolved would be awesome. Hint hint ;)

Cheers,
Jes

#36 lore raw
Quoted 6 lines · Jes Sorensen

Artur,

Did you make any progress getting the alignment issue resolved?

I'd really like to get an mdadm release out the door this week, so getting this resolved would be awesome. Hint hint ;)

Jes,

The alignment issue is fixed but I'm currently making changes in the kernel part after comments from Neil. This also requires modifications in mdadm, maybe even more than in the kernel. I need a few more days to finish this, I'll be sending the next version of the patches probably next week. So don't let me keep you if you want to make a release this week.

Thanks,
Artur

#37 lore raw
Quoted 8 lines · Artur Paszkiewicz
Quoted 6 lines · Jes Sorensen

Artur,

Did you make any progress getting the alignment issue resolved?

I'd really like to get an mdadm release out the door this week, so getting this resolved would be awesome. Hint hint ;)

Quoted 8 lines

Jes,

The alignment issue is fixed but I'm currently making changes in the kernel part after comments from Neil. This also requires modifications in mdadm, maybe even more than in the kernel. I need a few more days to finish this, I'll be sending the next version of the patches probably next week. So don't let me keep you if you want to make a release this week.

Artur,

Thanks for the update - it sounds like it is probably wise to let this stew a bit and let all the dust settle before we put it into an official release.

Cheers,
Jes