From: Czarnowska, Anna Sent: Monday, July 05, 2010 11:45 AM To: Neil Brown Cc: linux-raid@xxxxxxxxxxxxxxx; Czarnowska, Anna; Hawrylewicz Czarnowski, Przemyslaw; Labun, Marcin; Neubauer, Wojciech; Williams, Dan J; Ciechanowski, Ed; dledford@xxxxxxxxxx Subject: [PATCH 33/33] Try exclusive open on a spare device before it is added to another container. From: Marcin Labun <marcin.labun@xxxxxxxxx> Signed-off-by: Marcin Labun <marcin.labun@xxxxxxxxx> --- Monitor.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Monitor.c b/Monitor.c index 932a2bc..a1ae67f 100644 --- a/Monitor.c +++ b/Monitor.c @@ -534,8 +534,9 @@ int Monitor(mddev_dev_t devlist, return 0; } -static int move_spare(struct state *st2, struct state *st1, int i, char *mailaddr, - char *mailfrom, char *alert_cmd, int dosyslog) +static int move_spare(struct state *st2, struct state *st1, int i, + char *mailaddr, char *mailfrom, char *alert_cmd, + int dosyslog) { struct mddev_dev_s devlist; @@ -570,20 +571,41 @@ static int move_spare(struct state *st2, struct state *st1, int i, char *mailadd devlist.disposition = 'r'; if (Manage_subdevs(st2->devname, from_fd, &devlist, -1) == 0) { - devlist.disposition = 'a'; - if (Manage_subdevs(st1->devname, to_fd, &devlist, -1) == 0) { - st2->devid[i] = 0; - ping_manager(st2->devname); - ping_manager(st1->devname); - alert("MoveSpare", st1->devname, st2->devname, mailaddr, - mailfrom, alert_cmd, dosyslog); - close(from_fd); - close(to_fd); - return 1; + int dfd; + dfd = open(dv, O_RDWR|O_EXCL); + if (dfd < 0) { + fprintf(stderr, + "Error: Exclusive open on device %s failed\n", + dv); + devlist.disposition = 'a'; + if (Manage_subdevs(st2->devname, from_fd, &devlist, + -1) != 0) + fprintf(stderr, + "Error: Adding back spare device %s" + "to container %s failed!\n", + st2->devname, dv); } else { - Manage_subdevs(st2->devname, from_fd, &devlist, -1); + close(dfd); + devlist.disposition = 'a'; + if (Manage_subdevs(st1->devname, to_fd, &devlist, + -1) == 0) { + st2->devid[i] = 0; + ping_manager(st2->devname); + ping_manager(st1->devname); + alert("MoveSpare", st1->devname, st2->devname, + mailaddr, mailfrom, alert_cmd, dosyslog); + close(from_fd); + close(to_fd); + return 1; + } else if (Manage_subdevs(st2->devname, from_fd, + &devlist, -1) != 0) + fprintf(stderr, + "Error: Adding back spare device" + "%s to container %s failed!\n", + st2->devname, dv); } } + /* Failed to add spare to new container */ close(from_fd); close(to_fd); return 0; -- 1.6.4.2 -- To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html