]> git.proxmox.com Git - mirror_lxc.git/commitdiff
export lxc_cmd_get_config_item via API and use in lxc-info
authorS.Çağlar Onur <caglar@10ur.org>
Mon, 27 Jan 2014 22:57:37 +0000 (17:57 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 27 Jan 2014 23:03:14 +0000 (23:03 +0000)
This allows external users to query network related config items
from the running containers.

changes since v1:
- function name change

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxc_info.c
src/lxc/lxccontainer.c
src/lxc/lxccontainer.h

index ee45c589226bdbed7f086e32934a7a6d05714ee5..7915c0e3ed30a8d039b0fb85013645ea2337efb7 100644 (file)
@@ -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_running_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_running_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++) {
index dcdeaad6a32cb2737b4715cd9b6f9481c2e34a1a..aad692f3fdd9f544a183daa00c57cab8cfe78b21 100644 (file)
@@ -1738,6 +1738,19 @@ static int lxcapi_get_config_item(struct lxc_container *c, const char *key, char
        return ret;
 }
 
+static char* lxcapi_get_running_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_running_config_item = lxcapi_get_running_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;
index 84caa312a01afbe83440311d54060031a8d3c821..5f5d9b22a2d3518b020df90bad3a0eeae786add8 100644 (file)
@@ -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_running_config_item)(struct lxc_container *c, const char *key);
+
        /*!
         * \brief Retrieve a list of config item keys given a key
         * prefix.