Commit 8ac18377 by S.Çağlar Onur Committed by Stéphane Graber

export lxc_cmd_get_config_item via API and use in lxc-info

This allows external users to query network related config items from the running containers. changes since v1: - function name change Signed-off-by: 's avatarS.Çağlar Onur <caglar@10ur.org> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 4deda3b5
...@@ -139,7 +139,7 @@ static unsigned long long str_size_humanize(char *iobuf, size_t iobufsz) ...@@ -139,7 +139,7 @@ static unsigned long long str_size_humanize(char *iobuf, size_t iobufsz)
return val; 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; int rc,netnr;
unsigned long long rx_bytes = 0, tx_bytes = 0; unsigned long long rx_bytes = 0, tx_bytes = 0;
...@@ -149,7 +149,7 @@ static void print_net_stats(const char *name, const char *lxcpath) ...@@ -149,7 +149,7 @@ static void print_net_stats(const char *name, const char *lxcpath)
for(netnr = 0; ;netnr++) { for(netnr = 0; ;netnr++) {
sprintf(buf, "lxc.network.%d.type", 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) if (!type)
break; break;
...@@ -159,7 +159,7 @@ static void print_net_stats(const char *name, const char *lxcpath) ...@@ -159,7 +159,7 @@ static void print_net_stats(const char *name, const char *lxcpath)
sprintf(buf, "lxc.network.%d.link", netnr); sprintf(buf, "lxc.network.%d.link", netnr);
} }
free(type); free(type);
ifname = lxc_cmd_get_config_item(name, buf, lxcpath); ifname = c->get_running_config_item(c, buf);
if (!ifname) if (!ifname)
return; return;
printf("%-15s %s\n", "Link:", ifname); printf("%-15s %s\n", "Link:", ifname);
...@@ -326,7 +326,7 @@ static int print_info(const char *name, const char *lxcpath) ...@@ -326,7 +326,7 @@ static int print_info(const char *name, const char *lxcpath)
if (stats) { if (stats) {
print_stats(c); print_stats(c);
print_net_stats(name, lxcpath); print_net_stats(c);
} }
for(i = 0; i < keys; i++) { for(i = 0; i < keys; i++) {
......
...@@ -1738,6 +1738,19 @@ static int lxcapi_get_config_item(struct lxc_container *c, const char *key, char ...@@ -1738,6 +1738,19 @@ static int lxcapi_get_config_item(struct lxc_container *c, const char *key, char
return ret; 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) static int lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen)
{ {
if (!key) if (!key)
...@@ -3259,6 +3272,7 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath ...@@ -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 = lxcapi_clear_config;
c->clear_config_item = lxcapi_clear_config_item; c->clear_config_item = lxcapi_clear_config_item;
c->get_config_item = lxcapi_get_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->get_cgroup_item = lxcapi_get_cgroup_item;
c->set_cgroup_item = lxcapi_set_cgroup_item; c->set_cgroup_item = lxcapi_set_cgroup_item;
c->get_config_path = lxcapi_get_config_path; c->get_config_path = lxcapi_get_config_path;
......
...@@ -410,6 +410,19 @@ struct lxc_container { ...@@ -410,6 +410,19 @@ struct lxc_container {
*/ */
int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen); 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 * \brief Retrieve a list of config item keys given a key
* prefix. * prefix.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment