qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liu Yuan <namei.unix@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2 1/7] md: add support for simultaneous disk failure on the same node
Date: Fri, 29 Mar 2013 13:42:18 +0800	[thread overview]
Message-ID: <1364535744-8707-2-git-send-email-namei.unix@gmail.com> (raw)
In-Reply-To: <1364535744-8707-1-git-send-email-namei.unix@gmail.com>

From: Liu Yuan <tailai.ly@taobao.com>

Don't panic out, instead we simply remove this disk for this nested disk
failures.

Signed-off-by: Liu Yuan <tailai.ly@taobao.com>
---
 sheep/md.c |   66 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 48 insertions(+), 18 deletions(-)

diff --git a/sheep/md.c b/sheep/md.c
index ed474c8..821a391 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -154,40 +154,77 @@ static inline void calculate_vdisks(struct disk *disks, int nr_disks,
 #define MDNAME	"user.md.size"
 #define MDSIZE	sizeof(uint64_t)
 
+/*
+ * If path is broken during initilization or not support xattr return 0. We can
+ * safely use 0 to represent failure case  because 0 space path can be
+ * considered as broken path.
+ */
 static uint64_t init_path_space(char *path)
 {
 	struct statvfs fs;
 	uint64_t size;
 
+	if (!is_xattr_enabled(path)) {
+		sd_iprintf("multi-disk support need xattr feature");
+		goto broken_path;
+	}
+
 	if (getxattr(path, MDNAME, &size, MDSIZE) < 0) {
-		if (errno == ENODATA)
+		if (errno == ENODATA) {
 			goto create;
-		else
-			panic("%s, %m", path);
+		} else {
+			sd_eprintf("%s, %m", path);
+			goto broken_path;
+		}
 	}
 
 	return size;
 create:
-	if (statvfs(path, &fs) < 0)
-		panic("get disk %s space failed %m", path);
+	if (statvfs(path, &fs) < 0) {
+		sd_eprintf("get disk %s space failed %m", path);
+		goto broken_path;
+	}
 	size = (int64_t)fs.f_frsize * fs.f_bfree;
-	if (setxattr(path, MDNAME, &size, MDSIZE, 0) < 0)
-		panic("%s, %m", path);
+	if (setxattr(path, MDNAME, &size, MDSIZE, 0) < 0) {
+		sd_eprintf("%s, %m", path);
+		goto broken_path;
+	}
 	return size;
+broken_path:
+	return 0;
+}
+
+static inline void remove_disk(int idx)
+{
+	int i;
+
+	sd_iprintf("%s from multi-disk array", md_disks[idx].path);
+	/*
+	 * We need to keep last disk path to generate EIO when all disks are
+	 * broken
+	 */
+	for (i = idx; i < md_nr_disks - 1; i++)
+		md_disks[i] = md_disks[i + 1];
+
+	md_nr_disks--;
 }
 
 uint64_t md_init_space(void)
 {
-	uint64_t total = 0;
+	uint64_t total;
 	int i;
 
+reinit:
 	if (!md_nr_disks)
 		return 0;
+	total = 0;
 
 	for (i = 0; i < md_nr_disks; i++) {
-		if (!is_xattr_enabled(md_disks[i].path))
-			panic("multi-disk support need xattr feature");
 		md_disks[i].space = init_path_space(md_disks[i].path);
+		if (!md_disks[i].space) {
+			remove_disk(i);
+			goto reinit;
+		}
 		total += md_disks[i].space;
 	}
 	calculate_vdisks(md_disks, md_nr_disks, total);
@@ -329,15 +366,8 @@ static inline void kick_recover(void)
 
 static void unplug_disk(int idx)
 {
-	int i;
 
-	/*
-	 * We need to keep last disk path to generate EIO when all disks are
-	 * broken
-	 */
-	for (i = idx; i < md_nr_disks - 1; i++)
-		md_disks[i] = md_disks[i + 1];
-	md_nr_disks--;
+	remove_disk(idx);
 	sys->disk_space = md_init_space();
 	if (md_nr_disks > 0)
 		kick_recover();
-- 
1.7.9.5

  reply	other threads:[~2013-03-29  5:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-29  5:42 [Qemu-devel] [PATCH v2 0/7] md: add hot-plug and hot-unplug support Liu Yuan
2013-03-29  5:42 ` Liu Yuan [this message]
2013-03-29  5:42 ` [Qemu-devel] [PATCH v2 2/7] tests/055: test simultaneous multiple disk failures on the same node Liu Yuan
2013-03-29  5:42 ` [Qemu-devel] [PATCH v2 3/7] net: enlarge connect_to_addr() scope Liu Yuan
2013-03-29  5:42 ` [Qemu-devel] [PATCH v2 4/7] md: add hot-plug and hot-unplug support Liu Yuan
2013-03-29  5:42 ` [Qemu-devel] [PATCH v2 5/7] collie: add new commands to manipulate multi-disks Liu Yuan
2013-03-29  5:42 ` [Qemu-devel] [PATCH v2 6/7] sheep: remove duplicate recovery complete notification Liu Yuan
2013-03-29  5:42 ` [Qemu-devel] [PATCH v2 7/7] tsets: add 057 to test md hot-plug and hot-unplug Liu Yuan
2013-03-29  5:46 ` [Qemu-devel] [PATCH v2 0/7] md: add hot-plug and hot-unplug support Liu Yuan

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=1364535744-8707-2-git-send-email-namei.unix@gmail.com \
    --to=namei.unix@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).