From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1agbSw-0003K0-27 for mharc-grub-devel@gnu.org; Thu, 17 Mar 2016 13:12:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agbSq-000376-Ts for grub-devel@gnu.org; Thu, 17 Mar 2016 13:12:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agbSm-0001J9-Q9 for grub-devel@gnu.org; Thu, 17 Mar 2016 13:12:00 -0400 Received: from mail-lb0-x233.google.com ([2a00:1450:4010:c04::233]:36627) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agbSm-0001J5-HI for grub-devel@gnu.org; Thu, 17 Mar 2016 13:11:56 -0400 Received: by mail-lb0-x233.google.com with SMTP id qe11so18368744lbc.3 for ; Thu, 17 Mar 2016 10:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=V8/2VxjCuqBPJXZtnQd0lDMbHR2OcU1RUdBwjkKesJ0=; b=zJr8nAdXJ5ECKV1q36Y1xcpWNU6FL+b6OJZQt8Z13O7Fl7EprYGFEH9xLmDFCn1A0C wW/kOmV8PUC65RWJ4fF6Wd/Uk0SGlkRCGNW5tfvjAGvUC402gQD3/7TOEhtOTnjDv21a S5m0d9X2BQLqUg3mdRuUAEhesixIuk8ZKoJuVcneDh8oUykRlf9SSptzYHOsnT5CwAkM UBvwmpImnLsO91DIXefG7YfJoSQFLQlHvWYyKx2bK30KKNJ+vpBHYeWY8vP0cJg2J/YJ mlwm8rXOK9yL3bfbP9ActN6PYlJdw2SYakiGChklD5CNlIeoRdb1AYpFUczb24jYbKM6 7kFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=V8/2VxjCuqBPJXZtnQd0lDMbHR2OcU1RUdBwjkKesJ0=; b=CZXrLiDTIiJR6sOFKZXV/vw+2CfEIfQzKWkoeP/WzPbwTewraX7mVhHjR/kgPoqCx2 TU6n1sO6/nwwLHaxLxY4LB9AHshxIWXbpn3ZEOIjahIqY0tCxm5jID4JCHBK2NQe5hFS 2a19Js6Xu/mQCotqnrYA86MAkBsQOUg7IGSPHGIrZUi3kNylM5F11ERsyuv9RfGqY9/1 9HxYnxLa4wpgB8fEkdv5wIz9ts18UnnzgvC1hJuSskGFKp8/7wmd0Uf10l1PvXEhgIkM Cv2j7uvC7LLxs1i4y+BEweFZPk+0JLkOeaJYsW4PBL9aAa5Lc5PA5bmZanwq5bNDUMfh cKyQ== X-Gm-Message-State: AD7BkJJhkR/DHeNk2ykhSTOCI+SjvW51OQ5wDl4iicWw2i8eNTwoQFH9bt33w7N3NNYOIQ== X-Received: by 10.112.55.200 with SMTP id u8mr3106766lbp.51.1458234715825; Thu, 17 Mar 2016 10:11:55 -0700 (PDT) Received: from [192.168.1.42] (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id zw5sm1514601lbb.47.2016.03.17.10.11.53 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 Mar 2016 10:11:54 -0700 (PDT) Subject: Re: [PATCH] getroot: Correctly handle missing btrfs device identifiers. To: The development of GNU GRUB References: <026301d18063$842a3010$8c7e9030$@codenest.com> From: Andrei Borzenkov X-Enigmail-Draft-Status: N1110 Message-ID: <56EAE559.1080409@gmail.com> Date: Thu, 17 Mar 2016 20:11:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <026301d18063$842a3010$8c7e9030$@codenest.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::233 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2016 17:12:05 -0000 17.03.2016 18:41, James Johnston пишет: > From 97bcb9eb8c34329a8ca1ec88fd89296e273ceb24 Mon Sep 17 00:00:00 2001 > From: James Johnston > Date: Thu, 17 Mar 2016 15:10:49 +0000 > Subject: [PATCH] getroot: Correctly handle missing btrfs device identifiers. > > The btrfs driver's BTRFS_IOC_FS_INFO ioctl only tells you the maximum > device ID and the number of devices. It does not tell you which > device IDs may no longer be allocated - for example, if a device is > later deleted from the file system, its device ID won't be allocated > any more. > > You must then probe each device ID with BTRFS_IOC_DEV_INFO to see if > it is a valid device or not. It is not an error condition for this > ioctl to return ENODEV: it seems to mean that the device was deleted > by the user. > Kernel returns ENODEV if device was not found; we do not know why it was not found. We need some other way to verify that all devices are actually present to preserve current behavior. Actually we probably need to handle redundant layout where non-essential devices are missing but that is another topic. > Signed-off-by: James Johnston > --- > grub-core/osdep/linux/getroot.c | 26 ++++++++++++++++++++------ > 1 file changed, 20 insertions(+), 6 deletions(-) > > diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c > index 10480b6..852f3a2 100644 > --- a/grub-core/osdep/linux/getroot.c > +++ b/grub-core/osdep/linux/getroot.c > @@ -242,15 +242,29 @@ grub_find_root_devices_from_btrfs (const char *dir) > struct btrfs_ioctl_dev_info_args devi; > memset (&devi, 0, sizeof (devi)); > devi.devid = i; > + /* We have to probe all possible device IDs, since btrfs doesn't > + give us a list of all the valid ones. */ > if (ioctl (fd, BTRFS_IOC_DEV_INFO, &devi) < 0) > { > - close (fd); > - free (ret); > - return NULL; > + /* ENODEV is normal, e.g. if the first device is deleted from > + an array. */ > + int last_error = errno; > + if (last_error != ENODEV) Why this temporary variable? Why you cannot check errno directly? > + { > + grub_util_warn(_("btrfs device info could not be read " > + "for %s, device %d: errno %d"), dir, i, > + last_error); > + close (fd); > + free (ret); > + return NULL; > + } > + } > + else > + { > + ret[j++] = xstrdup ((char *) devi.path); > + if (j >= fsi.num_devices) > + break; > } > - ret[j++] = xstrdup ((char *) devi.path); > - if (j >= fsi.num_devices) > - break; > } > close (fd); > ret[j] = 0; >