[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH 08/12] mountable: Make list-filesystems return btrfsvols



On Fri, 2013-02-08 at 13:22 +0000, Richard W.M. Jones wrote:
> On Thu, Feb 07, 2013 at 03:57:54PM +0000, Matthew Booth wrote:
> > ---
> >  src/listfs.c | 37 ++++++++++++++++++++++++++++++-------
> >  1 file changed, 30 insertions(+), 7 deletions(-)
> > 
> > diff --git a/src/listfs.c b/src/listfs.c
> > index 4bcdf51..3e4f28e 100644
> > --- a/src/listfs.c
> > +++ b/src/listfs.c
> > @@ -136,6 +136,20 @@ remove_from_list (char **list, const char *item)
> >      }
> >  }
> >  
> > +static void
> > +add_vfs(guestfs_h *g, char *mountable, char *vfs_type,
> > +        char ***ret, size_t *ret_size)
> 
> You love these indirections!  There must surely be a simpler
> way to express this ...
> 
> > +{
> > +  /* Extend the return array. */
> > +  size_t i = *ret_size;
> > +  *ret_size += 2;
> > +  *ret = safe_realloc (g, *ret, (*ret_size + 1) * sizeof (char *));
> > +
> > +  (*ret)[i] = mountable;
> > +  (*ret)[i+1] = vfs_type;
> > +  (*ret)[i+2] = NULL;
> > +}
> > +
> >  /* Use vfs-type to look for a filesystem of some sort on 'dev'.
> >   * Apart from some types which we ignore, add the result to the
> >   * 'ret' string list.
> > @@ -157,6 +171,21 @@ check_with_vfs_type (guestfs_h *g, const char *device,
> >      v = safe_strdup (g, "unknown");
> >      free (vfs_type);
> >    }
> > +  else if (STREQ (vfs_type, "btrfs")) {
> > +    struct guestfs_btrfssubvolume_list *vols =
> > +      guestfs_btrfs_subvolume_list (g, device);
> > +
> > +    for (size_t i = 0; i < vols->len; i++) {
> > +      struct guestfs_btrfssubvolume *this = &vols->val[i];
> > +      char *mountable = safe_asprintf (g, "btrfsvol:%s/%s",
> > +                                       device, this->btrfssubvolume_path);
> > +      add_vfs (g, mountable, safe_strdup (g, "btrfs"), ret, ret_size);
> > +    }
> > +
> > +    guestfs_free_btrfssubvolume_list (vols);
> > +
> > +    v = safe_strdup (g, "btrfs");
> > +  }
> >    else {
> >      /* Ignore all "*_member" strings.  In libblkid these are returned
> >       * for things which are members of some RAID or LVM set, most
> > @@ -177,13 +206,7 @@ check_with_vfs_type (guestfs_h *g, const char *device,
> >      v = vfs_type;
> >    }
> >  
> > -  /* Extend the return array. */
> > -  size_t i = *ret_size;
> > -  *ret_size += 2;
> > -  *ret = safe_realloc (g, *ret, (*ret_size + 1) * sizeof (char *));
> > -  (*ret)[i] = safe_strdup (g, device);
> > -  (*ret)[i+1] = v;
> > -  (*ret)[i+2] = NULL;
> > +  add_vfs (g, safe_strdup (g, device), v, ret, ret_size);
> >  }
> 
> Patch looks fine so ACK, but dammit the indirections make my
> brain hurt ...

Heh. It's a simple pattern. You just have to recognise it for what it
is, then you don't have to think about it ;)

Matt


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]