Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp57423imm; Tue, 21 Aug 2018 23:31:01 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwgfNeCX8X9To64SZplNErtv07r84YaeS9xd+zFAGGMKrBDlAsYeDiPuTylgCZUuJNF9S2U X-Received: by 2002:a63:4386:: with SMTP id q128-v6mr49954439pga.353.1534919461844; Tue, 21 Aug 2018 23:31:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534919461; cv=none; d=google.com; s=arc-20160816; b=IYTnJcfSgTzWfjgby686FEBXTwUwau8HjgoBNLUXzww3zEMNlQmaHnCQGX+t6zXsvW i5LsaJA9rIZEu2djXVfSGUzY4MGE80YgBPwEuDkdGW6GewEegCoCI66lgqfyysjMl9Y1 jK6HkOqEOMOW7pOO4vPsei7yfV3vonJ0lPlH9pclNvzZ43+f87DI7M+sUfSg/H6bjg1K 8xN13YxVbVMphkq9909by8OJNzmRXJljrmC4fh8YgzNE/+jg4kKPGvu9QpNO63dBKMxe gH9I8zYB6p5zkIxsMOYhbc0PC4LMRH3zI0Wv50mrvOsyZRSh+tq1+jbJYSUgWCEPZ3OT gkHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:cc:to:subject :date:from:arc-authentication-results; bh=+ai7PILoh9wKY7mpy2c4e5tQlyRa2rd4H1w9C7wIm8g=; b=XezvOpoQzWNq0pdSjRsLOFJld7UR76yAXYEZlKidHbK4JJhYejgh3kGSzthFr8AIpL 0Z/E/91PtTg8xovCgYrKdHZg9bF2ptJdcOK59+ElUyqjzfk2xQI2j3Z2vP9HE9taySBK nH1kw14XiilKsP7Klr72LzhiR+/yxr41OABjUztc+zqKGsFtPdksvii1EvLKwysGtV1O g0uv2rEmQ0dnJbuu+OwIa+MKFhqXnDuMVKAxWLm9CPxfidD//oAaEY9ikaL0yz9uWuga tfEHtyYI9t7HMXfPEqUJJHZyI8UXP6B/fMGwZ5EWyze6SdGaVWX86yTjsb4vluKGJxDh 7SeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14-v6si917466pga.21.2018.08.21.23.30.45; Tue, 21 Aug 2018 23:31:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728184AbeHVJkX (ORCPT + 99 others); Wed, 22 Aug 2018 05:40:23 -0400 Received: from portal.weinmann.de ([62.8.140.122]:65478 "EHLO portal.loewensteinmedical.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728088AbeHVJkX (ORCPT ); Wed, 22 Aug 2018 05:40:23 -0400 X-Greylist: delayed 472 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Aug 2018 05:40:22 EDT From: Nikolaus Voss Date: Thu, 2 Aug 2018 08:29:13 +0200 Subject: [PATCH] init/do_mounts.c: add root=PARTLABEL= support To: Dominik Brodowski , Andrew Morton , "Levin, Alexander (Sasha Levin)" CC: Message-ID: <20180822060904.828E510665E@pc-niv.weinmann.com> MIME-Version: 1.0 Content-Type: text/plain X-C2ProcessedOrg: a378c7e9-0079-4426-8197-7b88a526ab38 x-msw-jemd-newsletter: false X-OriginalId: qfw7M8953p007051 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Support referencing the root partition label from GPT as argument to the root= option on the kernel command line in analogy to referencing the partition uuid as root=PARTUUID=. Specifying the partition label instead of the uuid is often much easier, e.g. in embedded environments when there is an A/B rootfs partition scheme for interruptible firmware updates (i.e. rootfsA/ rootfsB). The partition label can be queried with the blkid command. Signed-off-by: Nikolaus Voss --- init/do_mounts.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/init/do_mounts.c b/init/do_mounts.c index 2c71dabe5626..239b5104cff0 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -177,6 +177,24 @@ static dev_t devt_from_partuuid(const char *uuid_str) } return res; } + +/** + * match_dev_by_label - callback for finding a partition using its label + * @dev: device passed in by the caller + * @data: opaque pointer to the label to match + * + * Returns 1 if the device matches, and 0 otherwise. + */ +static int match_dev_by_label(struct device *dev, const void *data) +{ + const char *label = data; + struct hd_struct *part = dev_to_part(dev); + + if (part->info && !strcmp(label, part->info->volname)) + return 1; + + return 0; +} #endif /* @@ -200,6 +218,8 @@ static dev_t devt_from_partuuid(const char *uuid_str) * a partition with a known unique id. * 8) : major and minor number of the device separated by * a colon. + * 9) PARTLABEL= with name being the GPT partition label. + * MSDOS partitions do not support labels! * * If name doesn't have fall into the categories above, we return (0,0). * block_class is used to check if something is a disk name. If the disk @@ -221,6 +241,17 @@ dev_t name_to_dev_t(const char *name) if (!res) goto fail; goto done; + } else if (strncmp(name, "PARTLABEL=", 10) == 0) { + struct device *dev; + + dev = class_find_device(&block_class, NULL, name + 10, + &match_dev_by_label); + if (!dev) + goto fail; + + res = dev->devt; + put_device(dev); + goto done; } #endif -- 2.17.1