From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mUn7O-00087q-0L for mharc-grub-devel@gnu.org; Mon, 27 Sep 2021 05:40:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUn7M-00087g-Lb for grub-devel@gnu.org; Mon, 27 Sep 2021 05:40:12 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.111.102]:29705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUn7K-0001yq-3I for grub-devel@gnu.org; Mon, 27 Sep 2021 05:40:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1632735604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=XXWDpJChedul0VmBgmzRFBKbnjGfcb5reS+29i+Esjw=; b=ZgLF6bEGirBPlm0oHezxP+pKE2iMW9wam3g8LGA6SACKfe4KAbsw7uWCuj8owqGPQn/aEK Nx+bJe8ROASLqEri3zVAW0xkTltInsew4F1QxBhJc1Lf9rpofqbg46O0dDcLQEn9cq2gi5 /ep/0yy9WFSFQkpFiDiEpyACRhUYC6U= Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2053.outbound.protection.outlook.com [104.47.4.53]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-22-qOKpDIBYMJeGQ0bNBE4rlg-1; Mon, 27 Sep 2021 11:40:03 +0200 X-MC-Unique: qOKpDIBYMJeGQ0bNBE4rlg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c49ci/o9CODH4bfOcodPRKwy2ROpNskQC17ZuhoxrhTAkfFtiNs/UgS0vtubDOTSMc4WKrzf+3qha2EnrBFd3jFbi/yQgwPsYhX5ytNPjfwgUnBD2xqJQ0BDsb57kt3RRj8qMl0QKjW+qWHkFhJdYv1Wf17VJMqL2LQu0UlaEHSVF16bpIC+pDuZzuLm4mwd/jnAKBh42gFLGJl+sy0WC7/lEAGkWoBTa5f8jQgdNbozLqiUc2NohQ+n119zvK1cVWvFukSSjJ1R7s3n9oJA0tb5Sl9I4Hj7pLJEqnHjKSbIj0ZT7QeVwTls/lpRLhIn9tpLcr7/a12mJKKVsl55+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=G0N6dLC4u7RaGBoXHx5dC8BlNdyS0oEzySLIqC6hM/s=; b=ITlYaz2XI2e/j6nWE6RLoKCt4tbkZTbcnFOT8owiNanFYgbQ20xe6kEd8XCmQVMjU/KxaC1s1oXhg9Oc0f/01NrwycJzQYrbPkMcaQJVXzKSjTsV3ojUn9NIp6wb9bAjmSD4LTKd8MQ5rvYckK/XmwAKsLWc/GA4EhBu+6GFVWT8KceV1VwxcynsqWx7FAWC46z1kEZDH5yj1ZBRu/DR8bvntniJuAPetg0UTtIv0iAjmNcHdRzHF142Q4w5jrFYyx1b1bedOCSWDOkfaCnSWrHr5Tdad4Ov49WT1Ccn4BX9zhkAO5cHvSHOG89UUwb+xsSQxITHdmUXCI8V65yjOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: gnu.org; dkim=none (message not signed) header.d=none;gnu.org; dmarc=none action=none header.from=suse.com; Received: from DU2PR04MB8648.eurprd04.prod.outlook.com (2603:10a6:10:2df::21) by DU2PR04MB9020.eurprd04.prod.outlook.com (2603:10a6:10:2e3::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Mon, 27 Sep 2021 09:40:02 +0000 Received: from DU2PR04MB8648.eurprd04.prod.outlook.com ([fe80::7c78:3729:f82b:6802]) by DU2PR04MB8648.eurprd04.prod.outlook.com ([fe80::7c78:3729:f82b:6802%8]) with mapi id 15.20.4544.021; Mon, 27 Sep 2021 09:40:02 +0000 From: Michael Chang To: The development of GNU GRUB CC: Olav Reinert Subject: [PATCH v3] diskfilter: use nodes in logical volume's segment as member device Date: Mon, 27 Sep 2021 17:39:56 +0800 Message-ID: <20210927093956.12489-1-mchang@suse.com> X-Mailer: git-send-email 2.31.1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-ClientProxiedBy: HK2PR02CA0205.apcprd02.prod.outlook.com (2603:1096:201:20::17) To DU2PR04MB8648.eurprd04.prod.outlook.com (2603:10a6:10:2df::21) MIME-Version: 1.0 Received: from localhost (2001:b011:30d0:199c:6600:6aff:fe77:a7be) by HK2PR02CA0205.apcprd02.prod.outlook.com (2603:1096:201:20::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13 via Frontend Transport; Mon, 27 Sep 2021 09:40:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c283e219-f9ac-48fc-e1c5-08d9819ac774 X-MS-TrafficTypeDiagnostic: DU2PR04MB9020: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TvpB8yQpG7OjmO++uxK9QfCObRYcTHtstuxWa8H7wdbJDxcEKOR0B23s8e2yVwo7QLqLMIk59i2fQ/eFj1s/8JEQKh4QgtYg8UCnMND+cYUim7vn4bd7kpdUmMwwNc3zs5ejQ6Y1VsGUXEI5u5P5l9cAY+Ln3KUmxunTyImTrA4NJfa2sRL+tECsVj+2hO0x8ZQMMr2/Zmegh0UEluSZV3s/lGh6YBkSOlq819Xwj339NX1AYeukom102iop7PA24E13RqIaR/ndHYO2lJ41AYVoo64jFCTQ0w4A2vvM8C1vOnWeCVw8Mk5zThW1yxyak0Tsno/0l8iClxNa0vM5p+PN8SKVqiIdsht7XPY1t95fyttbaGfn4migWWv2Dy9VlII6S6Xpa/5bMDT5qP+R3QoHo+sAs6PL6XoIK2dvyQYX9K/ORNZrB3Cbw7/zLE2R/Toh4NIHeScPutaS3W04poZ36FJ/x0RSUxaY+WzIv+rQ5c5RAJrGvxh34V759TAu0qGPpnZvskbvj1eKrbXuqNy7ZrmIMJHCXNbWiAiDIqEYGFWXB4e7T2taqJtDP0ovoMTnRc+U/XpTZjR5tFksEKCbE6jFYpyyRhjIQA/6iaGH3a0J7fDW6K3IjOsHmKu9uJVNW+feJBTQfJj1U7IZ6Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8648.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(66556008)(508600001)(8676002)(8936002)(186003)(36756003)(2906002)(6916009)(38100700002)(6486002)(316002)(2616005)(83380400001)(1076003)(6666004)(66476007)(5660300002)(6496006)(4326008)(66946007)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?YZu3zG6EoJbaf/eqEKpm5HXq2id1UGo2FzdQNG2lQvYZrV9G6J1iTIvTCLDJ?= =?us-ascii?Q?DSr9VFPTfXONemRvj6kK6jKRPZNKGMYIi3m9tHCV+XyLNjZ6PhKmiuDvyEIv?= =?us-ascii?Q?1A5ez1iow1Q7YMcUTxfSQKskOfODp76kj/6bGBtCpXK+KC/rnwoHrokWLlLl?= =?us-ascii?Q?T3mg+mjXqloTT4TVs82SK7nqXStElN7jj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cQ4B9l8gePLrKbrm6/X3MQHg+ddKYf46ReFk19G6+G7i8L5Zaw/fUVIvWS?= =?us-ascii?Q?a0usUMdqo/en5Lj9WpozPApJ08xyUYe7LsvOn0Gscsuz7mkn8JICmMIWVcvz?= =?us-ascii?Q?2EyiHEKA/NdTTryA4bpGd0Plq9AVB/CqjjjYaPoaEiXKdNVTQ2pRmLNccr1s?= =?us-ascii?Q?GjPdO3A3hfepHLBrt8OT+gUwuAD1+nQSwACUUgT9mApzifl+8qYboyx0jZ+f?= =?us-ascii?Q?ssMyK8ZlVr9gfIN1HlMUE1Hlw/6cq88DA623EGq+Aw+hX2omuEcpQfPU4/k5?= =?us-ascii?Q?LxTcvtP3LIqiSJvtWODh0S5lcOae?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c283e219-f9ac-48fc-e1c5-08d9819ac774 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8648.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2021 09:40:02.2103 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: A99Pj4fvQ8WrS6VMk7DIYsWUM1PZT0nvU+JblWC/cLZxaMEbGkXd3jbdp75SonUU X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB9020 Received-SPF: pass client-ip=194.104.111.102; envelope-from=mchang@suse.com; helo=de-smtp-delivery-102.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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: Mon, 27 Sep 2021 09:40:12 -0000 Currently the grub_diskfilter_memberlist function returns all physical volumes added to a volume group to which a logical volume (LV) belongs. However this is suboptimal as it doesn't fit the intended behavior of returning underlying devices that make up the LV. To give a clear picture, the result should be identical to running commands below to display the logical volumes with underlying physical volumes in use. localhost:~ # lvs -o lv_name,vg_name,devices /dev/system/root LV VG Devices root system /dev/vda2(512) localhost:~ # lvdisplay --maps /dev/system/root --- Logical volume --- ... --- Segments --- Logical extents 0 to 4604: Type linear Physical volume /dev/vda2 Physical extents 512 to 5116 As shown above, we can know system-root lv uses only /dev/vda2 to allocate it's extents, or we can say that /dev/vda2 is the member device comprising the system-root lv. It is important to be precise on the member devices, because that helps to avoid pulling in excessive dependency. Let's use an example to demonstrate why it is needed. localhost:~ # findmnt / TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/system-root ext4 rw,relatime localhost:~ # pvs PV VG Fmt Attr PSize PFree /dev/mapper/data system lvm2 a-- 1020.00m 0 /dev/vda2 system lvm2 a-- 19.99g 0 localhost:~ # cryptsetup status /dev/mapper/data /dev/mapper/data is active and is in use. type: LUKS1 cipher: aes-xts-plain64 keysize: 512 bits key location: dm-crypt device: /dev/vdb sector size: 512 offset: 4096 sectors size: 2093056 sectors mode: read/write localhost:~ # vgs VG #PV #LV #SN Attr VSize VFree system 2 3 0 wz--n- 20.98g 0 localhost:~ # lvs -o lv_name,vg_name,devices LV VG Devices data system /dev/mapper/data(0) root system /dev/vda2(512) swap system /dev/vda2(0) We can learn from above that /dev/mapper/data is an encrypted volume and also gets assigned to volume group 'system' as one of it's physical volumes. And also it is not used by root device, /dev/mapper/system-root, for allocating extents, so it shouldn't be taking part in the process of setting up grub to access root device. However running grub-install reports error as volume group 'system' contains encrypted volume. error: attempt to install to encrypted disk without cryptodisk enabled. Set `GRUB_ENABLE_CRYPTODISK=3Dy' in file `/etc/default/grub'. Certainly we can enable GRUB_ENABLE_CRYPTODISK=3Dy and move on, but that is not always acceptable since the server may need to be booted unattended. Additionally, typing passphase for every system startup can be a big hassle of which most users would like to avoid. This patch solves the problem by returning exact physical volume, /dev/vda2, rightly used by system-root from the example above, thus grub-install will not error out because the excessive encrypted device to boot the root device is not configured. Signed-off-by: Michael Chang Tested-by: Olav Reinert --- grub-core/disk/diskfilter.c | 61 ++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c index 032011566..1eafc2dc3 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -300,6 +300,8 @@ grub_diskfilter_memberlist (grub_disk_t disk) grub_disk_dev_t p; struct grub_diskfilter_vg *vg; struct grub_diskfilter_lv *lv2 =3D NULL; + struct grub_diskfilter_segment *seg; + unsigned int i, j; =20 if (!lv->vg->pvs) return NULL; @@ -331,27 +333,52 @@ grub_diskfilter_memberlist (grub_disk_t disk) } } =20 - for (pv =3D lv->vg->pvs; pv; pv =3D pv->next) - { - if (!pv->disk) + for (i =3D 0, seg =3D lv->segments; i < lv->segment_count; i++, seg++) + for (j =3D 0; j < seg->node_count; ++j) + if (seg->nodes[j].pv !=3D NULL) { - /* TRANSLATORS: This message kicks in during the detection of - which modules needs to be included in core image. This happens - in the case of degraded RAID and means that autodetection may - fail to include some of modules. It's an installation time - message, not runtime message. */ - grub_util_warn (_("Couldn't find physical volume `%s'." - " Some modules may be missing from core image."), - pv->name); - continue; + pv =3D seg->nodes[j].pv; + + if (!pv->disk) + { + /* + * TRANSLATORS: This message kicks in during the detection of + * which modules needs to be included in core image. This happens + * in the case of degraded RAID and means that autodetection may + * fail to include some of modules. It's an installation time + * message, not runtime message. + */ + grub_util_warn (_("Couldn't find physical volume `%s'." + " Some modules may be missing from core image."), + pv->name); + continue; + } + + for (tmp =3D list; tmp !=3D NULL; tmp =3D tmp->next) + if (!grub_strcmp (tmp->disk->name, pv->disk->name)) + break; + if (tmp !=3D NULL) + continue; + + tmp =3D grub_malloc (sizeof (*tmp)); + if (!tmp) + goto fail; + tmp->disk =3D pv->disk; + tmp->next =3D list; + list =3D tmp; } - tmp =3D grub_malloc (sizeof (*tmp)); - tmp->disk =3D pv->disk; - tmp->next =3D list; - list =3D tmp; - } =20 return list; + + fail: + while (list !=3D NULL) + { + tmp =3D list; + list =3D list->next; + grub_free (tmp); + } + + return NULL; } =20 void --=20 2.31.1