Re: [PATCH 33/33] Try exclusive open on a spare device before it is added to another container.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is no explanation of why you try an exclusive open.
I can only imagine that you are trying to close some sort of race.

I don't think that getting an exclusive open on a member device actually
closes the race, though it might make it harder to hit.

I think the protocol that we want is that before we add or remove a device to
a container, or reassign a device within a container we take an exclusive
open on the container.
mdadm can do this to add/remove devices.
managemon can do this to assign a spare to an array.

This is the protocol that Manage_subdevs uses I think.

NeilBrown




On Mon, 5 Jul 2010 10:45:26 +0100
"Czarnowska, Anna" <anna.czarnowska@xxxxxxxxx> wrote:

> From: Marcin Labun <marcin.labun@xxxxxxxxx>
> 
> 
> 
> Signed-off-by: Marcin Labun <marcin.labun@xxxxxxxxx<mailto: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
> 
> 
> 
> ---------------------------------------------------------------------
> Intel Technology Poland sp. z o.o.
> z siedziba w Gdansku
> ul. Slowackiego 173
> 80-298 Gdansk
> 
> Sad Rejonowy Gdansk Polnoc w Gdansku, 
> VII Wydzial Gospodarczy Krajowego Rejestru Sadowego, 
> numer KRS 101882
> 
> NIP 957-07-52-316
> Kapital zakladowy 200.000 zl
> 
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.

--
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


[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux