[lxc-devel] [PATCH 2/4] Add bdev_destroy() and bdev_destroy_wrapper()

Christian Brauner christianvanbrauner at gmail.com
Tue Sep 8 19:24:05 UTC 2015


Yes, missed this. Updated patch follows after you reviewed the rest.
On Sep 8, 2015 9:19 PM, "Serge Hallyn" <serge.hallyn at ubuntu.com> wrote:

> Quoting Christian Brauner (christianvanbrauner at gmail.com):
> > static do_bdev_destroy() and bdev_destroy_wrapper() from lxccontainer.c
> become
> > public bdev_destroy() and bdev_destroy_wrapper() in bdev.c and bdev.h
> >
> > Signed-off-by: Christian Brauner <christianvanbrauner at gmail.com>
> > ---
> >  src/lxc/bdev.c | 39 +++++++++++++++++++++++++++++++++++++++
> >  src/lxc/bdev.h |  3 +++
> >  2 files changed, 42 insertions(+)
> >
> > diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
> > index ada3958..eb76709 100644
> > --- a/src/lxc/bdev.c
> > +++ b/src/lxc/bdev.c
> > @@ -3614,3 +3614,42 @@ bool rootfs_is_blockdev(struct lxc_conf *conf)
> >               return true;
> >       return false;
> >  }
> > +
> > +bool bdev_destroy(struct lxc_conf *conf)
> > +{
> > +     struct bdev *r;
> > +     bool ret = false;
> > +
> > +     r = bdev_init(conf, conf->rootfs.path, conf->rootfs.mount, NULL);
> > +     if (!r)
> > +             return ret;
> > +
> > +     if (r->ops->destroy(r) < 0) {
> > +             bdev_put(r);
> > +             return ret;
> > +     }
>
> You need to bdev_put(r) here too right?  Probably simplest to just
>
>         if (r->ops->destroy(r) == 0)
>                 ret = true;
>         bdev_put(r);
>
>         return ret;
>
> > +
> > +     ret = true;
> > +     return ret;
> > +}
> > +
> > +int bdev_destroy_wrapper(void *data)
> > +{
> > +     struct lxc_conf *conf = data;
> > +
> > +     if (setgid(0) < 0) {
> > +             ERROR("Failed to setgid to 0");
> > +             return -1;
> > +     }
> > +     if (setgroups(0, NULL) < 0)
> > +             WARN("Failed to clear groups");
> > +     if (setuid(0) < 0) {
> > +             ERROR("Failed to setuid to 0");
> > +             return -1;
> > +     }
> > +     if (!bdev_destroy(conf))
> > +             return -1;
> > +     else
> > +             return 0;
> > +}
> > +
> > diff --git a/src/lxc/bdev.h b/src/lxc/bdev.h
> > index 428b3b7..f7b3fca 100644
> > --- a/src/lxc/bdev.h
> > +++ b/src/lxc/bdev.h
> > @@ -123,6 +123,9 @@ struct bdev *bdev_copy(struct lxc_container *c0,
> const char *cname,
> >  struct bdev *bdev_create(const char *dest, const char *type,
> >                       const char *cname, struct bdev_specs *specs);
> >  void bdev_put(struct bdev *bdev);
> > +bool bdev_destroy(struct lxc_conf *conf);
> > +/* callback function to be used with userns_exec_1() */
> > +int bdev_destroy_wrapper(void *data);
> >
> >  /*
> >   * these are really for qemu-nbd support, as container shutdown
> > --
> > 2.5.1
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20150908/074200f8/attachment.html>


More information about the lxc-devel mailing list