All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: Toomas Soome <tsoome@me.com>
Cc: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: zfs pool devices detection in core/osdep/unix/getroot.c
Date: Mon, 13 Apr 2015 21:21:54 +0300	[thread overview]
Message-ID: <20150413212154.0be15cf1@opensuse.site> (raw)
In-Reply-To: <C4D4F974-67D9-41EE-8D66-CF373FCE5307@me.com>

В Mon, 13 Apr 2015 21:00:20 +0300
Toomas Soome <tsoome@me.com> пишет:

> hi!
> 
> this update is written by Richard Yao <ryao@gentoo.org> and is addressing the issue that device names are not correctly discovered in more complex pool setups. This code walks over pool vdev list and will collect device names from vdev children, ensuring the all device names will be presented to caller.
> 
> Since Richard has been busy, Im posting this update on his behalf and based on fact that the code is been quite extensively tested by me and few other people anyhow:) 
> 
> rgds,
> toomas
> 
> 

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/getroot.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;
>  }
>  
> -char **
> -grub_util_find_root_devices_from_poolname (char *poolname)
> -{
> -  char **devices = 0;
> -  size_t ndevices = 0;
> -  size_t devices_allocated = 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 = 0;
>  
> -  libzfs = grub_get_libzfs_handle ();
> -  if (! libzfs)
> -    return NULL;
> -
> -  zpool = zpool_open (libzfs, poolname);
> -  config = zpool_get_config (zpool, NULL);
> -
> -  if (nvlist_lookup_nvlist (config, "vdev_tree", &vdev_tree) != 0)
> -    error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")");
> -
> -  if (nvlist_lookup_nvlist_array (vdev_tree, "children", &children, &nvlist_count) != 0)
> -    error (1, errno, "nvlist_lookup_nvlist_array (\"children\")");
> -  assert (nvlist_count > 0);
> -
> -  while (nvlist_lookup_nvlist_array (children[0], "children",
> -				     &children, &nvlist_count) == 0)
> -    assert (nvlist_count > 0);
> -
> -  for (i = 0; i < nvlist_count; i++)
> -    {
> -      if (nvlist_lookup_string (children[i], "path", &device) != 0)
> +  if (nvlist_lookup_nvlist_array (vdev_tree, "children", &children, &nvlist_count) != 0){

curly braces style

> +      if (nvlist_lookup_string (vdev_tree, "path", &device) != 0)
>  	error (1, errno, "nvlist_lookup_string (\"path\")");
>  
>        struct stat st;
> @@ -214,17 +188,50 @@ grub_util_find_root_devices_from_poolname (char *poolname)
>  	  else
>  #endif
>  	    device = xstrdup (device);
> -	  if (ndevices >= devices_allocated)
> +	  if (*ndevices >= *devices_allocated)
>  	    {
> -	      devices_allocated = 2 * (devices_allocated + 8);
> -	      devices = xrealloc (devices, sizeof (devices[0])
> -				  * devices_allocated);
> +	      *devices_allocated = 2 * (*devices_allocated + 8);
> +	      *devices = xrealloc (*devices, sizeof ((*devices)[0])
> +				  * *devices_allocated);
>  	    }
> -	  devices[ndevices++] = device;
> +	  (*devices)[(*ndevices)++] = device;
>  	}
>  
>        device = NULL;
> -    }
> +
> +  } else {

curly braces style

> +    for (i = 0; i < nvlist_count; i++)
> +      {
> +        grub_util_find_child_vdevs(children[i], devices, ndevices, devices_allocated);
> +      }
> +  }

all braces in this branch are reundant.



  reply	other threads:[~2015-04-13 18:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 18:00 zfs pool devices detection in core/osdep/unix/getroot.c Toomas Soome
2015-04-13 18:21 ` Andrei Borzenkov [this message]
2015-04-13 22:08   ` Toomas Soome

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150413212154.0be15cf1@opensuse.site \
    --to=arvidjaar@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=tsoome@me.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.