From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Yhizk-0002SG-27 for mharc-grub-devel@gnu.org; Mon, 13 Apr 2015 14:22:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yhizh-0002RV-8D for grub-devel@gnu.org; Mon, 13 Apr 2015 14:22:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yhizd-0004S1-PY for grub-devel@gnu.org; Mon, 13 Apr 2015 14:22:01 -0400 Received: from mail-lb0-x22a.google.com ([2a00:1450:4010:c04::22a]:35460) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yhizd-0004Rv-Dj for grub-devel@gnu.org; Mon, 13 Apr 2015 14:21:57 -0400 Received: by lbbuc2 with SMTP id uc2so66095809lbb.2 for ; Mon, 13 Apr 2015 11:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=TSK+XxIQ8rFByX3eMIBHF/SEfgLjjAlO0LWFN0Z0H6k=; b=cM3sZCmEYDKylInPATPK890sSK2h74upQbNp9WaQhEczMBM3SUrJYhST5x1m8sON95 rzkdftx6WXSdAEqWT1ljRqIzwZDy0Wrpmbjs9Jxk3fUFjYDu3EM/PeyUNldfSxQx3V71 wpIA5hHsVxodzNZQ5neHRw1AUXPmHM9VNO6THhupAzS9irGHTW7pfzieP53QUHplUmr6 0rasjZYxO/usVXsRZPfcjN6hHL2gvphi9ZyreoPE/j46usCDJPpC2SRz7kBm+A3z+A17 oaYG96P6kCY8VM1kST4G1+05+4qyZBhggAIHCKts7naubxUno+L7IEt9KW5/pn1mgkS5 Z9pQ== X-Received: by 10.112.162.232 with SMTP id yd8mr14187498lbb.41.1428949316613; Mon, 13 Apr 2015 11:21:56 -0700 (PDT) Received: from opensuse.site (ppp91-76-14-38.pppoe.mtu-net.ru. [91.76.14.38]) by mx.google.com with ESMTPSA id m1sm1821350lah.46.2015.04.13.11.21.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 11:21:55 -0700 (PDT) Date: Mon, 13 Apr 2015 21:21:54 +0300 From: Andrei Borzenkov To: Toomas Soome Subject: Re: zfs pool devices detection in core/osdep/unix/getroot.c Message-ID: <20150413212154.0be15cf1@opensuse.site> In-Reply-To: References: X-Mailer: Claws Mail 3.11.0 (GTK+ 2.24.27; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22a Cc: The development of GRUB 2 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Apr 2015 18:22:02 -0000 =D0=92 Mon, 13 Apr 2015 21:00:20 +0300 Toomas Soome =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > hi! >=20 > this update is written by Richard Yao and is addressing= the issue that device names are not correctly discovered in more complex p= ool setups. This code walks over pool vdev list and will collect device nam= es from vdev children, ensuring the all device names will be presented to c= aller. >=20 > Since Richard has been busy, Im posting this update on his behalf and bas= ed on fact that the code is been quite extensively tested by me and few oth= er people anyhow:)=20 >=20 > rgds, > toomas >=20 >=20 Could you please send git format-patch (or git send-email) ready to apply? As far as I know policy, patches on behalf of others are rather frowned upon. Anyway minor nitpicks > diff --git a/grub-core/osdep/unix/getroot.c b/grub-core/osdep/unix/getroo= t.c > index b98b2df..329938a 100644 > --- a/grub-core/osdep/unix/getroot.c > +++ b/grub-core/osdep/unix/getroot.c > @@ -159,43 +159,17 @@ xgetcwd (void) > return path; > } > =20 > -char ** > -grub_util_find_root_devices_from_poolname (char *poolname) > -{ > - char **devices =3D 0; > - size_t ndevices =3D 0; > - size_t devices_allocated =3D 0; > - > #if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) > - zpool_handle_t *zpool; > - libzfs_handle_t *libzfs; > - nvlist_t *config, *vdev_tree; > +static void > +grub_util_find_child_vdevs(nvlist_t *vdev_tree, char ***devices, size_t = *ndevices, size_t *devices_allocated) > +{ > nvlist_t **children; > unsigned int nvlist_count; > unsigned int i; > char *device =3D 0; > =20 > - libzfs =3D grub_get_libzfs_handle (); > - if (! libzfs) > - return NULL; > - > - zpool =3D zpool_open (libzfs, poolname); > - config =3D zpool_get_config (zpool, NULL); > - > - if (nvlist_lookup_nvlist (config, "vdev_tree", &vdev_tree) !=3D 0) > - error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")"); > - > - if (nvlist_lookup_nvlist_array (vdev_tree, "children", &children, &nvl= ist_count) !=3D 0) > - error (1, errno, "nvlist_lookup_nvlist_array (\"children\")"); > - assert (nvlist_count > 0); > - > - while (nvlist_lookup_nvlist_array (children[0], "children", > - &children, &nvlist_count) =3D=3D 0) > - assert (nvlist_count > 0); > - > - for (i =3D 0; i < nvlist_count; i++) > - { > - if (nvlist_lookup_string (children[i], "path", &device) !=3D 0) > + if (nvlist_lookup_nvlist_array (vdev_tree, "children", &children, &nvl= ist_count) !=3D 0){ curly braces style > + if (nvlist_lookup_string (vdev_tree, "path", &device) !=3D 0) > error (1, errno, "nvlist_lookup_string (\"path\")"); > =20 > struct stat st; > @@ -214,17 +188,50 @@ grub_util_find_root_devices_from_poolname (char *po= olname) > else > #endif > device =3D xstrdup (device); > - if (ndevices >=3D devices_allocated) > + if (*ndevices >=3D *devices_allocated) > { > - devices_allocated =3D 2 * (devices_allocated + 8); > - devices =3D xrealloc (devices, sizeof (devices[0]) > - * devices_allocated); > + *devices_allocated =3D 2 * (*devices_allocated + 8); > + *devices =3D xrealloc (*devices, sizeof ((*devices)[0]) > + * *devices_allocated); > } > - devices[ndevices++] =3D device; > + (*devices)[(*ndevices)++] =3D device; > } > =20 > device =3D NULL; > - } > + > + } else { curly braces style > + for (i =3D 0; i < nvlist_count; i++) > + { > + grub_util_find_child_vdevs(children[i], devices, ndevices, devic= es_allocated); > + } > + } all braces in this branch are reundant.