[lxc-devel] [PATCH] export lxc_cmd_get_config_item via API and use in for lxc-info

S.Çağlar Onur caglar at 10ur.org
Mon Jan 27 14:37:16 UTC 2014


On Jan 27, 2014 4:31 AM, "Stéphane Graber" <stgraber at ubuntu.com> wrote:
>
> On Mon, Jan 27, 2014 at 12:59:53AM -0500, S.Çağlar Onur wrote:
> > This allows external users to query network related config items
> > from the running containers.
> >
> > Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>
>
> Looks reasonable, though I'd probably go with get_running_config_item
> instead of get_cmd_config_item.
>
> If you're fine with that rename, I'll do the change and apply it.

Yes, that's fine with me. Thanks!

> > ---
> >  src/lxc/lxc_info.c     |  8 ++++----
> >  src/lxc/lxccontainer.c | 14 ++++++++++++++
> >  src/lxc/lxccontainer.h | 13 +++++++++++++
> >  3 files changed, 31 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c
> > index ee45c58..501d9c8 100644
> > --- a/src/lxc/lxc_info.c
> > +++ b/src/lxc/lxc_info.c
> > @@ -139,7 +139,7 @@ static unsigned long long str_size_humanize(char
*iobuf, size_t iobufsz)
> >       return val;
> >  }
> >
> > -static void print_net_stats(const char *name, const char *lxcpath)
> > +static void print_net_stats(struct lxc_container *c)
> >  {
> >       int rc,netnr;
> >       unsigned long long rx_bytes = 0, tx_bytes = 0;
> > @@ -149,7 +149,7 @@ static void print_net_stats(const char *name, const
char *lxcpath)
> >
> >       for(netnr = 0; ;netnr++) {
> >               sprintf(buf, "lxc.network.%d.type", netnr);
> > -             type = lxc_cmd_get_config_item(name, buf, lxcpath);
> > +             type = c->get_cmd_config_item(c, buf);
> >               if (!type)
> >                       break;
> >
> > @@ -159,7 +159,7 @@ static void print_net_stats(const char *name, const
char *lxcpath)
> >                       sprintf(buf, "lxc.network.%d.link", netnr);
> >               }
> >               free(type);
> > -             ifname = lxc_cmd_get_config_item(name, buf, lxcpath);
> > +             ifname = c->get_cmd_config_item(c, buf);
> >               if (!ifname)
> >                       return;
> >               printf("%-15s %s\n", "Link:", ifname);
> > @@ -326,7 +326,7 @@ static int print_info(const char *name, const char
*lxcpath)
> >
> >       if (stats) {
> >               print_stats(c);
> > -             print_net_stats(name, lxcpath);
> > +             print_net_stats(c);
> >       }
> >
> >       for(i = 0; i < keys; i++) {
> > diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> > index d0c5e07..1ddac35 100644
> > --- a/src/lxc/lxccontainer.c
> > +++ b/src/lxc/lxccontainer.c
> > @@ -1738,6 +1738,19 @@ static int lxcapi_get_config_item(struct
lxc_container *c, const char *key, char
> >       return ret;
> >  }
> >
> > +static char* lxcapi_get_cmd_config_item(struct lxc_container *c, const
char *key)
> > +{
> > +     char *ret;
> > +
> > +     if (!c || !c->lxc_conf)
> > +             return NULL;
> > +     if (container_mem_lock(c))
> > +             return NULL;
> > +     ret = lxc_cmd_get_config_item(c->name, key,
c->get_config_path(c));
> > +     container_mem_unlock(c);
> > +     return ret;
> > +}
> > +
> >  static int lxcapi_get_keys(struct lxc_container *c, const char *key,
char *retv, int inlen)
> >  {
> >       if (!key)
> > @@ -3259,6 +3272,7 @@ struct lxc_container *lxc_container_new(const
char *name, const char *configpath
> >       c->clear_config = lxcapi_clear_config;
> >       c->clear_config_item = lxcapi_clear_config_item;
> >       c->get_config_item = lxcapi_get_config_item;
> > +     c->get_cmd_config_item = lxcapi_get_cmd_config_item;
> >       c->get_cgroup_item = lxcapi_get_cgroup_item;
> >       c->set_cgroup_item = lxcapi_set_cgroup_item;
> >       c->get_config_path = lxcapi_get_config_path;
> > diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
> > index 84caa31..ed9b767 100644
> > --- a/src/lxc/lxccontainer.h
> > +++ b/src/lxc/lxccontainer.h
> > @@ -410,6 +410,19 @@ struct lxc_container {
> >        */
> >       int (*get_config_item)(struct lxc_container *c, const char *key,
char *retv, int inlen);
> >
> > +
> > +     /*!
> > +      * \brief Retrieve the value of a config item from running
container.
> > +      *
> > +      * \param c Container.
> > +      * \param key Name of option to get.
> > +      *
> > +      * \return the item or NULL on error.
> > +      *
> > +      * \note Returned string must be freed by the caller.
> > +      */
> > +     char* (*get_cmd_config_item)(struct lxc_container *c, const char
*key);
> > +
> >       /*!
> >        * \brief Retrieve a list of config item keys given a key
> >        * prefix.
> > --
> > 1.8.3.2
> >
> > _______________________________________________
> > lxc-devel mailing list
> > lxc-devel at lists.linuxcontainers.org
> > http://lists.linuxcontainers.org/listinfo/lxc-devel
>
> --
> Stéphane Graber
> Ubuntu developer
> http://www.ubuntu.com
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140127/8142f291/attachment.html>


More information about the lxc-devel mailing list