Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iNV04-00029y-V4 for mharc-grub-devel@gnu.org; Thu, 24 Oct 2019 00:45:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41443) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNV01-00026B-BC for grub-devel@gnu.org; Thu, 24 Oct 2019 00:45:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNUzy-0006vS-8D for grub-devel@gnu.org; Thu, 24 Oct 2019 00:45:24 -0400 Received: from m4a0041g.houston.softwaregrp.com ([15.124.2.87]:58252) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iNUzw-0006oc-Lg for grub-devel@gnu.org; Thu, 24 Oct 2019 00:45:22 -0400 Received: FROM m4a0041g.houston.softwaregrp.com (15.120.17.146) BY m4a0041g.houston.softwaregrp.com WITH ESMTP FOR grub-devel@gnu.org; Thu, 24 Oct 2019 04:44:26 +0000 Received: from M9W0067.microfocus.com (2002:f79:be::f79:be) by M4W0334.microfocus.com (2002:f78:1192::f78:1192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Thu, 24 Oct 2019 04:44:01 +0000 Received: from NAM03-CO1-obe.outbound.protection.outlook.com (15.124.72.14) by M9W0067.microfocus.com (15.121.0.190) 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; Thu, 24 Oct 2019 04:44:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U2/TqRCL1W84KxOrirJscPk/hYo9zWoOXuUN/OY3DVIHJJyRQ6tOdGzNZt+lujsWAeth6by1x9L+4zw0tHa0XNx0gk0MUg+RP9O6aQ2PIU9IM+3yiDi1q1x2dglOc9FJYtPoOGuSgHFbsP6RnrYD7l7hi5swOb16E5fn1q2cWJHhzstLK9w92sbyg8KCmJto3E+l9BFmL5ABGbt1GwY7xkA2HLl8Z0iv1lEX0DLJohyXV/hDBgY89UXB4ANO94tdRuDGxsMWDE97p3nWp6Oub47I0DOsDnFkkYsn8lNMrIRmHAIv4WfGwKCSshiIt3L/Rt0c3HlVr//n5t1aSd0rEw== 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=Z7cjWycOEILTIY14ZpNYZf32iQtnOCD4Uh6iBDo4dv0=; b=OQtE3WHgBu2m7PaVhmipjtqKwlYmU7nnykmDq7tlTls+V4hTvgWPVxpfFwRU+69tqR6IlRPwiDyTTgI7ZMQyjr9S6oOnvrq6lg3nIJFrbKH/b2H6HgypzJHFEoIWVUh4RrRuwEGGJQo+zV76htt/aZhFpQWt8fMUkycfvUekTUTxy06ijH4KVgK/FSP6w6xvnObH2xsZv6kfgTUdi1cz2UQMiNKkblu+kMR1ejHXOeX3hpKs0XmrTXALCLm43tG4DL24XCdK7BgxQfu8dG4arGDTmZVnNxdFBv2XRzr39dDy5Gc0jUVMdTq0efWKnvAk4OcxnIWk5WwBcMSfL3xLEw== 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 BY5PR18MB3300.namprd18.prod.outlook.com (10.255.137.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.24; Thu, 24 Oct 2019 04:43:58 +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.030; Thu, 24 Oct 2019 04:43:58 +0000 From: Michael Chang To: The development of GNU GRUB Subject: Re: [PATCH] lvm: add lvm cache logical volume handling Thread-Topic: [PATCH] lvm: add lvm cache logical volume handling Thread-Index: AQHVg+kcyQnYrvfSdkigs0DupfD//KdoFvWAgAEsfIA= Date: Thu, 24 Oct 2019 04:43:58 +0000 Message-ID: <20191024044351.GA8270@mazu> References: <20191016061516.32129-1-mchang@suse.com> <20191023104823.uxaqf5uxkr6jr3lx@tomti.i.net-space.pl> In-Reply-To: <20191023104823.uxaqf5uxkr6jr3lx@tomti.i.net-space.pl> Accept-Language: zh-TW, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HK2PR02CA0216.apcprd02.prod.outlook.com (2603:1096:201:20::28) 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-originating-ip: [60.251.47.116] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5119fbaa-0999-4f85-860e-08d7583cc899 x-ms-traffictypediagnostic: BY5PR18MB3300: x-ms-exchange-purlcount: 1 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 0200DDA8BE x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(7916004)(366004)(396003)(376002)(39860400002)(136003)(346002)(189003)(199004)(99286004)(26005)(386003)(966005)(6506007)(2906002)(102836004)(316002)(76176011)(33656002)(55236004)(33716001)(14454004)(5660300002)(14444005)(256004)(52116002)(186003)(1076003)(66066001)(71190400001)(71200400001)(25786009)(6916009)(81156014)(8676002)(81166006)(305945005)(476003)(486006)(6436002)(6512007)(7736002)(6116002)(478600001)(229853002)(3846002)(9686003)(6486002)(446003)(66446008)(64756008)(66556008)(66476007)(66946007)(86362001)(80792005)(6246003)(11346002)(6306002)(8936002)(403724002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY5PR18MB3300; H:BY5PR18MB3122.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:3; 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: 5qaacakURnyOOohNb6cdWg70pkhNQtKqdASnHEkOPwKxgKF+P7UwY5gtpYu+bs99Sba77LapkV9Jc8ONg0LorqkSVWylBKkFwY9KmbJKktXIXkZ9aiLet67thPcZnRNSm/M1dx5xe9LFviYOKU+knENcJwF3iWZpYjXSJLhDoljstjnwNYfRHcuqiI6VDJ/VFBXotunQTvqPpjwA0DPjQI//UfzP2pyT6bGsvlfZNvEksJfEyKhhkhP8gqNBawXwoS2hVicHgVCC8ANHjYa9YXnIMyxGbBp2nPd5CzMqZS9nSVUhCZ/p13UXM1CaUEMe0J5pUjxdGnmV/hqrYvlZk3x9D0O3kB7TfVbCxyHPZ7aOy1NhU7vih8Eu3Ogtpb+JiwpyKspOTzPzqx9pcCV4WgfRKNTp3XvwNURJiyW5vFEW81+t4PiIYxyXSpE8/rQ9n88zrCl44jE/tpxCV2mqO2B4KBa+rRCzkm0FNhAdVsY= Content-Type: text/plain; charset="us-ascii" Content-ID: <2E8357A8C3216E4FA222762FFB35FBF7@namprd18.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 5119fbaa-0999-4f85-860e-08d7583cc899 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Oct 2019 04:43:58.6668 (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: BQ0ey/NXJILIA2eRuTtThfAuB0EKxMd8UZFdl5/vsAhewHfqYgq9DhyB7uIdwONH X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR18MB3300 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.87 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, 24 Oct 2019 04:45:27 -0000 On Wed, Oct 23, 2019 at 12:48:23PM +0200, Daniel Kiper wrote: > On Wed, Oct 16, 2019 at 06:15:30AM +0000, Michael Chang wrote: > > 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 wil= l > > 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 no= t > > 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. >=20 > Is it possible to enforce all GRUB writes to the original device instead > of cache during installation process? I couldn't give concrete answer whether it is possible, but it sounds to me not good idea because in general bypassing the cache could potentially break the consistency of data and the data being cached. Perhaps some system calls could help to sync the data out of the lvm cache to the original LV during installation process. It seems fsync does it for us, but I didn't have good idea either if it is enough. >=20 > > 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, > > > > if (! vg) > > { > > + struct cache_lv { > > + struct grub_diskfilter_lv *lv; > > + char *cache_pool; > > + char *origin; > > + struct cache_lv *next; > > + } *cache_lvs =3D NULL; >=20 > I would move struct cache_lv definition to the beginning of the file. > Though you can leave variable declaration here. OK. I will do in next patch. >=20 > > + > > /* 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)); >=20 > You blindly assume that grub_zalloc() does not fail. This is dangerous. > Please fix it. OK. I will do in next patch. >=20 > > + 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); >=20 > Same for grub_strdup()... OK. I will do in next patch. > > + > > + 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); >=20 > Same for grub_malloc() and below. Please fix all of them. OK. I will do in next patch. Thanks a lot for your review and comments. :) Regards, Michael >=20 > Daniel >=20 > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel