Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cUFiL-00076I-Va for mharc-grub-devel@gnu.org; Thu, 19 Jan 2017 11:37:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUFiH-0006wy-50 for grub-devel@gnu.org; Thu, 19 Jan 2017 11:37:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cUFiC-0005sm-4n for grub-devel@gnu.org; Thu, 19 Jan 2017 11:37:25 -0500 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:35034) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cUFiB-0005ra-Tp for grub-devel@gnu.org; Thu, 19 Jan 2017 11:37:20 -0500 Received: by mail-lf0-x242.google.com with SMTP id v186so6033526lfa.2 for ; Thu, 19 Jan 2017 08:37:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1tR0Ev0VQOUWij3JDG5Yy4j+4OfMCVnnYGYkqaaCThY=; b=MB9r4jImoBT4oqfvn9/+f3k+6p2Le6y+wBz5eVtLPdg7vmFgbLXP9QtJXBk041nbE8 4sM5G+Ge3j5XlmL/GhExG1+0x/C6TZimu1ZkG8PO4lnieInjimk65IcCXc2ToS4+fF38 l7g50LmwOqk0eh3RmH5GtSoxa9z5irEbHSnTTe039l67t23KOZ6brIiXks1YjgHzwmuP B4htoXHO/SC7WbYZi1IEwV5X11TmDfFrokXhzdixae7Yf1fcwIQ0UBxRmNAKR91HUs9z mYhBu8P2epMgQLKBN63CqzKUPyNzy0ZEBeot2FmO1JkuL42cpVesjTzuZegAs/9S7VXG d3kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1tR0Ev0VQOUWij3JDG5Yy4j+4OfMCVnnYGYkqaaCThY=; b=Y2hQvpsYx8yO/nf0cQgI6vIcCUvNP47grUXkZkfTp9x/7s4sB1ZuSqFQrNpcgitI0i xBv5SxIzPMGHHacqtojACKxNpkdBjfCJcKdwO0lf1G996+fL3iAVxcrXK9UqM9qRk2A6 ATne4WG0hWtMrf2f1CGVtBgNwP3R214Iyu1gdHJ5WMiwCuny9L8rlTZwo/u7WCZa697x yv/kjmLQ+oIISswcPwR40aezq49po0jnxKR7mrOxIXvLuY862SdlAIhiRspCPsuwec7C r29kNXhNExvNk020cbOsgh18cbXo/TWiKN9wHXXpebJeVZrpZRRbjTBvpYCD4vUoSsoj xNcQ== X-Gm-Message-State: AIkVDXLZCWndTGQyPO9XX5lZX2pqmO2VvnTIrlzg/URstKII95+83uU4iB7/YSVDFi07Yg== X-Received: by 10.25.99.29 with SMTP id x29mr3439138lfb.104.1484843838373; Thu, 19 Jan 2017 08:37:18 -0800 (PST) Received: from localhost.localdomain (ppp109-252-90-129.pppoe.spdop.ru. [109.252.90.129]) by smtp.gmail.com with ESMTPSA id f17sm2145156ljb.13.2017.01.19.08.37.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Jan 2017 08:37:17 -0800 (PST) From: Andrei Borzenkov To: grub-devel@gnu.org Cc: felix.von.s@posteo.de Subject: [PATCH v2] osdep/linux: handle autofs entries in /proc/self/mountinfo Date: Thu, 19 Jan 2017 19:37:04 +0300 Message-Id: <1484843824-16723-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484758044-6258-1-git-send-email-arvidjaar@gmail.com> References: <1484758044-6258-1-git-send-email-arvidjaar@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::242 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Jan 2017 16:37:29 -0000 These entries have placeholder for device name and so are useless for our purpose. grub failed with something like grub-install: error: failed to get canonical path of `systemd-1'. When we see autofs entry, record it (to keep parent-child relationship) but continue to look for real mount. If it is found, we process it as usual. If only autofs entry exists, attempt to trigger mount by opening mount point and retry. Mount point itself is then kept open to avoid timeout. Recent systemd is by default using automount for /boot/efi so this should become more popular problem on EFI systems. Closes: 49942 --- v2: - remove bogus autofs check in main mountinfo read loop, it was result of misunderstanding - consolidate cleanup code to avoid memory leak on retry. If there are no objections in next days, I'll commit it. It was confirmed to fix the problem. grub-core/osdep/linux/getroot.c | 45 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c index 09e7e6e..90d92d3 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -380,24 +380,30 @@ get_btrfs_fs_prefix (const char *mount_path) char ** grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) { - FILE *fp; + FILE *fp = NULL; char *buf = NULL; size_t len = 0; - grub_size_t entry_len = 0, entry_max = 4; + grub_size_t entry_len, entry_max = 4; struct mountinfo_entry *entries; struct mountinfo_entry parent_entry = { 0, 0, 0, "", "", "", "" }; int i; + int retry = 0; + int dir_fd = -1; + char **ret = NULL; if (! *dir) dir = "/"; if (relroot) *relroot = NULL; + entries = xmalloc (entry_max * sizeof (*entries)); + +again: fp = grub_util_fopen ("/proc/self/mountinfo", "r"); if (! fp) - return NULL; /* fall through to other methods */ + goto out; /* fall through to other methods */ - entries = xmalloc (entry_max * sizeof (*entries)); + entry_len = 0; /* First, build a list of relevant visible mounts. */ while (getline (&buf, &len, fp) > 0) @@ -484,7 +490,6 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) /* Now scan visible mounts for the ones we're interested in. */ for (i = entry_len - 1; i >= 0; i--) { - char **ret = NULL; char *fs_prefix = NULL; if (!*entries[i].device) continue; @@ -515,6 +520,23 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) ret = grub_find_root_devices_from_btrfs (dir); fs_prefix = get_btrfs_fs_prefix (entries[i].enc_path); } + else if (!retry && grub_strcmp (entries[i].fstype, "autofs") == 0) + { + /* If the best match is automounted, try to trigger mount. We cannot + simply return here because stat() on automounted directory does not + trigger mount and returns bogus (pseudo)device number instead. + We keep mountpoint open until end of scan to prevent timeout. */ + + int flags = O_RDONLY|O_DIRECTORY; + + fclose (fp); +#ifdef O_LARGEFILE + flags |= O_LARGEFILE; +#endif + dir_fd = open (entries[i].enc_path, flags); + retry = 1; + goto again; + } if (!ret) { ret = xmalloc (2 * sizeof (ret[0])); @@ -544,16 +566,17 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) } if (fs_prefix != entries[i].enc_root) free (fs_prefix); - free (buf); - free (entries); - fclose (fp); - return ret; + break; } +out: free (buf); free (entries); - fclose (fp); - return NULL; + if (fp) + fclose (fp); + if (dir_fd != -1) + close (dir_fd); + return ret; } static char * -- tg: (972765f..) bug/49942 (depends on: master)