mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chuck Ebbert <76306.1226@compuserve.com>
To: Neil Brown <neilb@suse.de>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	linux-raid <linux-raid@vger.kernel.org>
Subject: [patch] raid1: allow user to force reads from a specific disk
Date: Sun, 6 Aug 2006 20:15:15 -0400	[thread overview]
Message-ID: <200608062018_MC3-1-C74D-B4E9@compuserve.com> (raw)

Allow user to force raid1 to read all data from a given disk.
This lets users do integrity checking by comparing results
from reading different disks.  If at any time the system finds
it cannot read from the given disk it resets the disk number
to -1, the default, which means to balance reads.

Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>

---

 drivers/md/raid1.c         |   72 +++++++++++++++++++++++++++++++++++++++++++--
 include/linux/raid/raid1.h |    1 
 2 files changed, 70 insertions(+), 3 deletions(-)

--- 2.6.18-rc3-32.orig/drivers/md/raid1.c
+++ 2.6.18-rc3-32/drivers/md/raid1.c
@@ -418,19 +418,37 @@ static int raid1_end_write_request(struc
 static int read_balance(conf_t *conf, r1bio_t *r1_bio)
 {
 	const unsigned long this_sector = r1_bio->sector;
-	int new_disk = conf->last_used, disk = new_disk;
-	int wonly_disk = -1;
+	int new_disk = conf->read_from_disk, disk = conf->last_used;
+	int wonly_disk = -1, forced_read = 0;
 	const int sectors = r1_bio->sectors;
 	sector_t new_distance, current_distance;
 	mdk_rdev_t *rdev;
 
 	rcu_read_lock();
+
+	if (new_disk != -1) {
+		/* user has forced reads to one disk */
+		forced_read = 1;
+		if (new_disk >= 0 && new_disk < conf->raid_disks)
+			goto rb_out;
+	}
+
+	new_disk = conf->last_used;
 	/*
 	 * Check if we can balance. We can balance on the whole
 	 * device if no resync is going on, or below the resync window.
 	 * We take the first readable disk when above the resync window.
 	 */
  retry:
+	/*
+	 * If we reach this point and user has forced reads from one disk,
+	 * disable the forced reads because they cannot be done.  User can
+	 * check the "read_from_disk" attribute after doing IO to see if
+	 * all the reads were really done from the correct disk.
+	 */
+	if (forced_read)
+		conf->read_from_disk = -1;
+
 	if (conf->mddev->recovery_cp < MaxSector &&
 	    (this_sector + sectors >= conf->next_resync)) {
 		/* Choose the first operation device, for consistancy */
@@ -518,7 +536,6 @@ static int read_balance(conf_t *conf, r1
 
  rb_out:
 
-
 	if (new_disk >= 0) {
 		rdev = rcu_dereference(conf->mirrors[new_disk].rdev);
 		if (!rdev)
@@ -1802,6 +1819,52 @@ static sector_t sync_request(mddev_t *md
 	return nr_sectors;
 }
 
+static ssize_t
+raid1_show_read_from_disk(mddev_t *mddev, char *page)
+{
+	conf_t *conf = mddev_to_conf(mddev);
+	if (conf)
+		return sprintf(page, "%d\n", conf->read_from_disk);
+	else
+		return 0;
+}
+
+static ssize_t
+raid1_store_read_from_disk(mddev_t *mddev, const char *page, size_t len)
+{
+	conf_t *conf = mddev_to_conf(mddev);
+	char *end;
+	int new;
+
+	if (len >= PAGE_SIZE)
+		return -EINVAL;
+	if (!conf)
+		return -ENODEV;
+
+	new = simple_strtoul(page, &end, 10);
+	if (!*page || (*end && *end != '\n') )
+		return -EINVAL;
+	if (new < -1 || new >= conf->raid_disks)
+		return -EINVAL;
+	conf->read_from_disk = new;
+
+	return len;
+}
+
+static struct md_sysfs_entry
+raid1_read_from_disk = __ATTR(read_from_disk, S_IRUGO | S_IWUSR,
+				raid1_show_read_from_disk,
+				raid1_store_read_from_disk);
+
+static struct attribute *raid1_attrs[] =  {
+	&raid1_read_from_disk.attr,
+	NULL,
+};
+static struct attribute_group raid1_attrs_group = {
+	.name = NULL,
+	.attrs = raid1_attrs,
+};
+
 static int run(mddev_t *mddev)
 {
 	conf_t *conf;
@@ -1913,6 +1976,7 @@ static int run(mddev_t *mddev)
 		      !test_bit(In_sync, &conf->mirrors[j].rdev->flags)) ; j++)
 		/* nothing */;
 	conf->last_used = j;
+	conf->read_from_disk = -1; /* default: balance reads */
 
 
 	mddev->thread = md_register_thread(raid1d, mddev, "%s_raid1");
@@ -1930,6 +1994,8 @@ static int run(mddev_t *mddev)
 	/*
 	 * Ok, everything is just fine now
 	 */
+	sysfs_create_group(&mddev->kobj, &raid1_attrs_group);
+
 	mddev->array_size = mddev->size;
 
 	mddev->queue->unplug_fn = raid1_unplug;
--- 2.6.18-rc3-32.orig/include/linux/raid/raid1.h
+++ 2.6.18-rc3-32/include/linux/raid/raid1.h
@@ -32,6 +32,7 @@ struct r1_private_data_s {
 	int			raid_disks;
 	int			working_disks;
 	int			last_used;
+	int			read_from_disk;
 	sector_t		next_seq_sect;
 	spinlock_t		device_lock;
 
-- 
Chuck

             reply	other threads:[~2006-08-07  0:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-07  0:15 Chuck Ebbert [this message]
2006-08-07  0:38 ` Neil Brown
2006-08-17 15:04 ` Pavel Machek
2006-08-07  8:45 Chuck Ebbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200608062018_MC3-1-C74D-B4E9@compuserve.com \
    --to=76306.1226@compuserve.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®