Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iKdE0-0007Ig-5d for mharc-grub-devel@gnu.org; Wed, 16 Oct 2019 02:56:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60575) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKdDw-0007II-Jn for grub-devel@gnu.org; Wed, 16 Oct 2019 02:55:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKdDu-0005YT-CO for grub-devel@gnu.org; Wed, 16 Oct 2019 02:55:55 -0400 Received: from m4a0039g.houston.softwaregrp.com ([15.124.2.85]:44919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iKdDu-0005Y1-5t for grub-devel@gnu.org; Wed, 16 Oct 2019 02:55:54 -0400 Received: FROM m4a0039g.houston.softwaregrp.com (15.120.17.147) BY m4a0039g.houston.softwaregrp.com WITH ESMTP FOR grub-devel@gnu.org; Wed, 16 Oct 2019 06:54:58 +0000 Received: from M9W0068.microfocus.com (2002:f79:bf::f79:bf) by M4W0335.microfocus.com (2002:f78:1193::f78:1193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Wed, 16 Oct 2019 06:15:37 +0000 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (15.124.72.13) by M9W0068.microfocus.com (15.121.0.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10 via Frontend Transport; Wed, 16 Oct 2019 06:15:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UCper7nW3E33LGCpXOUefG8SIaYiI/UyQHKmkhsQEvg4nM2s+rsXhWO55A182Pz2SlKSt6b3INKzmRpGDncj3RqqmiH4NQB331bJiKXwFCOM17AylupZ1LhwlrQYt2gXcmyisIm8f0i9BZUqo/5Apt4IulAR2d1AfLdHnth9GvTaw8WN1Vfzg/APZoHLVrlbftZ69Ux5dAThHXSr8IysptTwMFC2POdZmlcR57BSzEoZC9nPBCL8Sa81mvMg/w/QFH2CU8QI4sB6ndCEA2c2vhznKnm31G2/rxhYh6Hd4oPkJtSLPQQOOLgZmNaKzxsyrkN5Ygnuq3nknWfxpjsr9w== 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:X-MS-Exchange-SenderADCheck; bh=sAv9hLXv05qjylic7pezTU2eHCLUHtFzV1r7yXmSt0s=; b=jgyotLPiGVKI7p9hz3O6hmouUu5/bNqw4MG6mCxWuleW+ylXEd1G0aDaKurSzJKfRng91Y9uUSZwnp/o//OEJQu3AbA3sYlELAYkdQwpFqbJp1y1ONBIvoUHdVbkExXNgEHCOgOpa+wAeNRroOVcmdGS7pHvJ3/HoHLnb95fzrsF2TJkaAIoZjEDDYvPSyyhLl5jtqk7KgEJ3Kct3riYtdmuvv+HKWeUo1YlYhzwjFwYVSZM6pxtfd62OkywU4gXVXlKvI8Ee92gYQ151EyO3rZcYl+o5UGpSpQDWa9W/BsmeMxgpVi4sr7jQiqAotVclgzG9nK3J3dWfwWvN1QNiA== 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 Received: from BY5PR18MB3122.namprd18.prod.outlook.com (10.255.139.11) by BY5PR18MB3138.namprd18.prod.outlook.com (10.255.137.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.16; Wed, 16 Oct 2019 06:15:31 +0000 Received: from BY5PR18MB3122.namprd18.prod.outlook.com ([fe80::2c63:52aa:e278:b47a]) by BY5PR18MB3122.namprd18.prod.outlook.com ([fe80::2c63:52aa:e278:b47a%6]) with mapi id 15.20.2347.023; Wed, 16 Oct 2019 06:15:31 +0000 From: Michael Chang To: "grub-devel@gnu.org" Subject: [PATCH] lvm: add lvm cache logical volume handling Thread-Topic: [PATCH] lvm: add lvm cache logical volume handling Thread-Index: AQHVg+kcyQnYrvfSdkigs0DupfD//A== Date: Wed, 16 Oct 2019 06:15:30 +0000 Message-ID: <20191016061516.32129-1-mchang@suse.com> Accept-Language: zh-TW, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0158.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::26) To BY5PR18MB3122.namprd18.prod.outlook.com (2603:10b6:a03:1af::11) authentication-results: spf=none (sender IP is ) smtp.mailfrom=MChang@suse.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.16.4 x-originating-ip: [60.251.47.116] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f9cfe69e-4e1a-4a2f-8eec-08d752003eea x-ms-traffictypediagnostic: BY5PR18MB3138: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 0192E812EC x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(366004)(396003)(376002)(136003)(346002)(39860400002)(199004)(189003)(6436002)(36756003)(3846002)(6486002)(6116002)(8936002)(2906002)(7736002)(86362001)(55236004)(14444005)(66446008)(50226002)(80792005)(71190400001)(71200400001)(305945005)(256004)(2351001)(6512007)(102836004)(386003)(6506007)(66476007)(1076003)(66556008)(26005)(6916009)(52116002)(14454004)(478600001)(186003)(2616005)(476003)(316002)(5640700003)(81156014)(81166006)(8676002)(99286004)(5660300002)(66066001)(64756008)(2501003)(66946007)(25786009)(486006)(403724002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY5PR18MB3138; H:BY5PR18MB3122.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: suse.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4Nh5aKvCbLisflWFJn1s5GYH6rVBjN/Ei/YTtMDhTFfzthEGsOJYgzU5xUvTKxSapk77Cg7IgkhOExzUlOLsF+2lDwUhaeN2u9IieSlaKSIiGdroCvqob12m+/5uoOi3hhXQ5jBBX2fh5Hsj4/3BPTusc1kSv8SH9v4wW34jLCrQjloJGDMVPtOPj7eYQkGUpvepC0vUxAX0L7GD7BBEzN8R5ow6zIpKyJ5AwkM36EMlr1m6+SFtMlp7lmLwiM1dJRyvwOORodmNMOOCXlmKQkCBLpAKqS5tBHeJZyEVCNOT6SNoxg21M1hNEO5ZONmooFx2A+IxfqncgntRaAEK+4GZW5j2pbUVN3oL/Gi1gtd2y9Nnb0MdvofmNmVW4eh/gTgQlfZngcUAQvdOYkEXbAssPnb6pNz7zY/3E9daHYU= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: f9cfe69e-4e1a-4a2f-8eec-08d752003eea X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Oct 2019 06:15:30.8839 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: uRqpMhvhIpg4qtNqhZafth6nLwT0zFW5VfTwsjKUmRPw9W2NTurg8fCnpoQVbnhM X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR18MB3138 X-OriginatorOrg: suse.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 15.124.2.85 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: Wed, 16 Oct 2019 06:55:58 -0000 The lvm cache logical volume is the logical volume consisting of the original and the cache pool logical volume. The original is usually on a larger and slower storage device while the cache pool is on a smaller and faster one. The performance of the original volume can be improved by storing the frequently used data on the cache pool to utilize the greater performance of faster device. The default cache mode "writethrough" ensures that any data written will be stored both in the cache and on the origin LV, therefore grub can go straight to read the original lv as no data loss is guarenteed. The second cache mode is "writeback", which delays writing from the cache pool back to the origin LV to have increased performance. The drawback is potential data loss if losing the associated cache device. During the boot time grub reads the LVM offline i.e. LVM volumes are not activated and mounted, IMHO it should be fine to read directly from original lv since all cached data should have been flushed back in the process of taking it offline. Signed-off-by: Michael Chang --- grub-core/disk/lvm.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 125 insertions(+) diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 32b9e289f..a1eeaa737 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -272,6 +272,13 @@ grub_lvm_detect (grub_disk_t disk, =20 if (! vg) { + struct cache_lv { + struct grub_diskfilter_lv *lv; + char *cache_pool; + char *origin; + struct cache_lv *next; + } *cache_lvs =3D NULL; + /* First time we see this volume group. We've to create the whole volume group structure. */ vg =3D grub_malloc (sizeof (*vg)); @@ -701,6 +708,72 @@ grub_lvm_detect (grub_disk_t disk, seg->nodes[seg->node_count - 1].name =3D tmp; } } + else if (grub_memcmp (p, "cache\"", + sizeof ("cache\"") - 1) =3D=3D 0) + { + struct cache_lv *cache; + + char *p2, *p3; + grub_ssize_t sz; + + cache =3D grub_zalloc (sizeof (*cache)); + cache->lv =3D grub_zalloc (sizeof (*cache->lv)); + grub_memcpy (cache->lv, lv, sizeof (*cache->lv)); + + if (lv->fullname) + cache->lv->fullname =3D grub_strdup (lv->fullname); + if (lv->idname) + cache->lv->idname =3D grub_strdup (lv->idname); + if (lv->name) + cache->lv->name =3D grub_strdup (lv->name); + + skip_lv =3D 1; + + if (!(p2 =3D grub_strstr (p, "cache_pool =3D \""))) + goto cache_lv_fail; + + if (!(p2 =3D grub_strchr (p2, '"'))) + goto cache_lv_fail; + + p3 =3D ++p2; + if (!(p3 =3D grub_strchr (p3, '"'))) + goto cache_lv_fail; + + sz =3D p3 - p2; + + cache->cache_pool =3D grub_malloc (sz + 1); + grub_memcpy (cache->cache_pool, p2, sz); + cache->cache_pool[sz] =3D '\0'; + + if (!(p2 =3D grub_strstr (p, "origin =3D \""))) + goto cache_lv_fail; + + if (!(p2 =3D grub_strchr (p2, '"'))) + goto cache_lv_fail; + + p3 =3D ++p2; + if (!(p3 =3D grub_strchr (p3, '"'))) + goto cache_lv_fail; + + sz =3D p3 - p2; + + cache->origin =3D grub_malloc (sz + 1); + grub_memcpy (cache->origin, p2, sz); + cache->origin[sz] =3D '\0'; + + cache->next =3D cache_lvs; + cache_lvs =3D cache; + break; + + cache_lv_fail: + grub_free (cache->origin); + grub_free (cache->cache_pool); + grub_free (cache->lv->fullname); + grub_free (cache->lv->idname); + grub_free (cache->lv->name); + grub_free (cache); + break; + } else { #ifdef GRUB_UTIL @@ -777,6 +850,58 @@ grub_lvm_detect (grub_disk_t disk, } =09 } + + { + struct cache_lv *cache; + + for (cache =3D cache_lvs; cache; cache =3D cache->next) + { + struct grub_diskfilter_lv *lv; + + for (lv =3D vg->lvs; lv; lv =3D lv->next) + { + if (grub_strcmp (lv->name, cache->origin) =3D=3D 0) + break; + } + if (lv) + { + cache->lv->segment_count =3D lv->segment_count; + cache->lv->segments =3D grub_malloc (lv->segment_count * sizeof (*lv->se= gments)); + grub_memcpy (cache->lv->segments, lv->segments, lv->segment_count * size= of (*lv->segments)); + + for (i =3D 0; i < lv->segment_count; ++i) + { + struct grub_diskfilter_node *nodes =3D lv->segments[i].nodes; + grub_size_t node_count =3D lv->segments[i].node_count; + cache->lv->segments[i].nodes =3D grub_malloc (node_count * sizeof (*= nodes)); + grub_memcpy (cache->lv->segments[i].nodes, nodes, node_count * sizeo= f (*nodes)); + } + cache->lv->vg =3D vg; + cache->lv->next =3D vg->lvs; + vg->lvs =3D cache->lv; + cache->lv =3D NULL; + } + } + + while ((cache =3D cache_lvs)) + { + cache_lvs =3D cache_lvs->next; + + if (cache->lv) + { + for (i =3D 0; i < cache->lv->segment_count; ++i) + grub_free (cache->lv->segments[i].nodes); + grub_free (cache->lv->fullname); + grub_free (cache->lv->idname); + grub_free (cache->lv->name); + } + grub_free (cache->lv); + grub_free (cache->origin); + grub_free (cache->cache_pool); + grub_free (cache); + } + } + if (grub_diskfilter_vg_register (vg)) goto fail4; } --=20 2.16.4