From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1m43Op-0006fw-Q3 for mharc-grub-devel@gnu.org; Thu, 15 Jul 2021 11:35:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m43On-0006er-OA for grub-devel@gnu.org; Thu, 15 Jul 2021 11:35:41 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:44814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m43Om-000850-28 for grub-devel@gnu.org; Thu, 15 Jul 2021 11:35:41 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id ADB061FE43; Thu, 15 Jul 2021 15:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1626363336; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sJI+6HuMMxYMZmB702zmpoa8NAgy88VW7Z/t+SpLkUU=; b=gIlPz5O2gCAXImQqmEwS0yPt7GM83PEvQdife/UvuTA2Dws4wBfLmwMPywgI9ydM0RN8tt 8ymTchIGNZyRD17qYLQUYMN3QnmQjh5kp7pRtCpr1fgHSupRcfeYjRgfWLnBA//D/N+owH TiEUlL8hZWklIY65RfQreFYr376lFaA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1626363336; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sJI+6HuMMxYMZmB702zmpoa8NAgy88VW7Z/t+SpLkUU=; b=5BYAFucoBTMlGGsI2gd75MDHDiJ58laWTpPeDXoX8OBcFqQ1jWeiCBbzycii2M3ZUWWC35 KMeMNs1RIq8hUaBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6B95913C3B; Thu, 15 Jul 2021 15:35:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yKGWGMhV8GA+dQAAMHmgww (envelope-from ); Thu, 15 Jul 2021 15:35:36 +0000 From: Petr Vorel To: grub-devel@gnu.org Cc: Jeff Mahoney , Daniel Kiper , Michael Chang , Mike Gilbert , Petr Vorel Subject: [PATCH v2 2/2] linux/hostdisk: use stat() instead of udevadm for partition lookup Date: Thu, 15 Jul 2021 17:35:28 +0200 Message-Id: <20210715153528.16233-3-pvorel@suse.cz> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715153528.16233-1-pvorel@suse.cz> References: <20210715153528.16233-1-pvorel@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=195.135.220.29; envelope-from=pvorel@suse.cz; helo=smtp-out2.suse.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jul 2021 15:35:42 -0000 From: Jeff Mahoney sysfs_partition_path() calls udevadm to resolve the sysfs path for a block device. That can be accomplished by stating the device node and using the major/minor to follow the symlinks in /sys/dev/block/. This cuts the execution time of grub-mkconfig to somewhere near 55% on system without LVM (which uses libdevmapper instead sysfs_partition_path()). Signed-off-by: Jeff Mahoney [ pvorel: remove udevadm fallback as it does not help us more than calling stat() directly; include , update commit message. ] Signed-off-by: Petr Vorel --- changes v1->v2: * remove udevadm fallback from sysfs_partition_path() as we agreed it does not bring any advantage over plain stat() call. * improve commit message * fix code style (spaces) grub-core/osdep/linux/hostdisk.c | 52 ++++---------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c index da62f924e..d3326d095 100644 --- a/grub-core/osdep/linux/hostdisk.c +++ b/grub-core/osdep/linux/hostdisk.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -98,54 +99,13 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const char *name, unsigned *log_sec static char * sysfs_partition_path (const char *dev, const char *entry) { - const char *argv[7]; - int fd; - pid_t pid; - FILE *udevadm; - char *buf = NULL; - size_t len = 0; - char *path = NULL; - - argv[0] = "udevadm"; - argv[1] = "info"; - argv[2] = "--query"; - argv[3] = "path"; - argv[4] = "--name"; - argv[5] = dev; - argv[6] = NULL; - - pid = grub_util_exec_pipe (argv, &fd); - - if (!pid) - return NULL; - - /* Parent. Read udevadm's output. */ - udevadm = fdopen (fd, "r"); - if (!udevadm) - { - grub_util_warn (_("Unable to open stream from %s: %s"), - "udevadm", strerror (errno)); - close (fd); - goto out; - } - - if (getline (&buf, &len, udevadm) > 0) - { - char *newline; - - newline = strchr (buf, '\n'); - if (newline) - *newline = '\0'; - path = xasprintf ("/sys%s/%s", buf, entry); - } + struct stat st; -out: - if (udevadm) - fclose (udevadm); - waitpid (pid, NULL, 0); - free (buf); + if (stat (dev, &st) == 0 && S_ISBLK (st.st_mode)) + return xasprintf ("/sys/dev/block/%u:%u/%s", + major (st.st_rdev), minor (st.st_rdev), entry); - return path; + return NULL; } static int -- 2.32.0