Commit 7456fb2c by Serge Hallyn Committed by GitHub

Merge pull request #1750 from brauner/2017-08-10/further_lxc_2.1_preparations

further lxc 2.1. preparations
parents 4393ebc3 7ec2e32a
...@@ -37,6 +37,7 @@ src/lxc/lxc-attach ...@@ -37,6 +37,7 @@ src/lxc/lxc-attach
src/lxc/lxc-autostart src/lxc/lxc-autostart
src/lxc/lxc-cgroup src/lxc/lxc-cgroup
src/lxc/tools/lxc-checkconfig src/lxc/tools/lxc-checkconfig
src/lxc/tools/lxc-update-config
src/lxc/lxc-checkpoint src/lxc/lxc-checkpoint
src/lxc/lxc-clone src/lxc/lxc-clone
src/lxc/lxc-console src/lxc/lxc-console
......
...@@ -914,6 +914,7 @@ AC_CONFIG_FILES([ ...@@ -914,6 +914,7 @@ AC_CONFIG_FILES([
src/lxc/lxc.functions src/lxc/lxc.functions
src/lxc/tools/lxc-checkconfig src/lxc/tools/lxc-checkconfig
src/lxc/tools/lxc-start-ephemeral src/lxc/tools/lxc-start-ephemeral
src/lxc/tools/lxc-update-config
src/lxc/version.h src/lxc/version.h
src/python-lxc/Makefile src/python-lxc/Makefile
......
...@@ -208,7 +208,8 @@ liblxc_la_LIBADD += $(CGMANAGER_LIBS) $(DBUS_LIBS) $(NIH_LIBS) $(NIH_DBUS_LIBS) ...@@ -208,7 +208,8 @@ liblxc_la_LIBADD += $(CGMANAGER_LIBS) $(DBUS_LIBS) $(NIH_LIBS) $(NIH_DBUS_LIBS)
liblxc_la_CFLAGS += $(CGMANAGER_CFLAGS) $(DBUS_CFLAGS) $(NIH_CFLAGS) $(NIH_DBUS_CFLAGS) liblxc_la_CFLAGS += $(CGMANAGER_CFLAGS) $(DBUS_CFLAGS) $(NIH_CFLAGS) $(NIH_DBUS_CFLAGS)
endif endif
bin_SCRIPTS = tools/lxc-checkconfig bin_SCRIPTS = tools/lxc-checkconfig \
tools/lxc-update-config
EXTRA_DIST = \ EXTRA_DIST = \
tools/lxc-top.lua tools/lxc-top.lua
......
...@@ -516,7 +516,7 @@ static int lxc_cmd_get_config_item_callback(int fd, struct lxc_cmd_req *req, ...@@ -516,7 +516,7 @@ static int lxc_cmd_get_config_item_callback(int fd, struct lxc_cmd_req *req,
struct lxc_config_t *item; struct lxc_config_t *item;
memset(&rsp, 0, sizeof(rsp)); memset(&rsp, 0, sizeof(rsp));
item = lxc_getconfig(req->data); item = lxc_get_config(req->data);
if (!item) if (!item)
goto err1; goto err1;
cilen = item->get(req->data, NULL, 0, handler->conf, NULL); cilen = item->get(req->data, NULL, 0, handler->conf, NULL);
......
...@@ -408,6 +408,12 @@ struct lxc_conf { ...@@ -408,6 +408,12 @@ struct lxc_conf {
/* RLIMIT_* limits */ /* RLIMIT_* limits */
struct lxc_list limits; struct lxc_list limits;
/* REMOVE IN LXC 3.0
* Indicator whether the current config file we're using contained any
* legacy configuration keys.
*/
bool contains_legacy_key;
}; };
#ifdef HAVE_TLS #ifdef HAVE_TLS
......
...@@ -33,21 +33,44 @@ ...@@ -33,21 +33,44 @@
struct lxc_conf; struct lxc_conf;
struct lxc_list; struct lxc_list;
/* Callback prototype to set a configuration item.
* Must be implemented when adding a new configuration key.
*/
typedef int (*config_set_cb)(const char *key, const char *value, typedef int (*config_set_cb)(const char *key, const char *value,
struct lxc_conf *conf, void *data); struct lxc_conf *conf, void *data);
/* Callback prototype to get a configuration item.
* Must be implemented when adding a new configuration key.
*/
typedef int (*config_get_cb)(const char *key, char *value, int inlen, typedef int (*config_get_cb)(const char *key, char *value, int inlen,
struct lxc_conf *conf, void *data); struct lxc_conf *conf, void *data);
/* Callback prototype to clear a configuration item.
* Must be implemented when adding a new configuration key.
*/
typedef int (*config_clr_cb)(const char *key, struct lxc_conf *conf, typedef int (*config_clr_cb)(const char *key, struct lxc_conf *conf,
void *data); void *data);
struct lxc_config_t { struct lxc_config_t {
char *name; char *name;
bool is_legacy_key; /* REMOVE in LXC 3.0 */
config_set_cb set; config_set_cb set;
config_get_cb get; config_get_cb get;
config_clr_cb clr; config_clr_cb clr;
}; };
extern struct lxc_config_t *lxc_getconfig(const char *key); /* Get the jump table entry for the given configuration key. */
extern struct lxc_config_t *lxc_get_config(const char *key);
/* List all available config items. */
extern int lxc_list_config_items(char *retv, int inlen);
/* Given a configuration key namespace (e.g. lxc.apparmor) list all associated
* subkeys for that namespace.
* Must be implemented when adding a new configuration key.
*/
extern int lxc_list_subkeys(struct lxc_conf *conf, const char *key, char *retv,
int inlen);
/* List all configuration items associated with a given network. For example /* List all configuration items associated with a given network. For example
* pass "lxc.net.[i]" to retrieve all configuration items associated with * pass "lxc.net.[i]" to retrieve all configuration items associated with
...@@ -55,29 +78,41 @@ extern struct lxc_config_t *lxc_getconfig(const char *key); ...@@ -55,29 +78,41 @@ extern struct lxc_config_t *lxc_getconfig(const char *key);
*/ */
extern int lxc_list_net(struct lxc_conf *c, const char *key, char *retv, extern int lxc_list_net(struct lxc_conf *c, const char *key, char *retv,
int inlen); int inlen);
extern int lxc_list_config_items(char *retv, int inlen);
extern int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include); extern int lxc_config_read(const char *file, struct lxc_conf *conf,
bool from_include);
extern int append_unexp_config_line(const char *line, struct lxc_conf *conf); extern int append_unexp_config_line(const char *line, struct lxc_conf *conf);
extern int lxc_config_define_add(struct lxc_list *defines, char* arg); extern int lxc_config_define_add(struct lxc_list *defines, char* arg);
extern int lxc_config_define_load(struct lxc_list *defines, extern int lxc_config_define_load(struct lxc_list *defines,
struct lxc_conf *conf); struct lxc_conf *conf);
/* needed for lxc-attach */ /* needed for lxc-attach */
extern signed long lxc_config_parse_arch(const char *arch); extern signed long lxc_config_parse_arch(const char *arch);
extern int lxc_fill_elevated_privileges(char *flaglist, int *flags); extern int lxc_fill_elevated_privileges(char *flaglist, int *flags);
extern int lxc_clear_config_item(struct lxc_conf *c, const char *key); extern int lxc_clear_config_item(struct lxc_conf *c, const char *key);
extern void write_config(FILE *fout, struct lxc_conf *c); extern void write_config(FILE *fout, struct lxc_conf *c);
extern bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key, const char *v); extern bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key,
const char *v);
/* These are used when cloning a container */ /* These are used when cloning a container */
extern void clear_unexp_config_line(struct lxc_conf *conf, const char *key, bool rm_subkeys); extern void clear_unexp_config_line(struct lxc_conf *conf, const char *key,
bool rm_subkeys);
extern bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, extern bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
const char *newpath, const char *oldname, const char *newmame); const char *newpath, const char *oldname,
const char *newmame);
bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath, bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
const char *newpath, const char *oldname, const char *newpath, const char *oldname,
const char *newname, const char *ovldir); const char *newname, const char *ovldir);
extern bool network_new_hwaddrs(struct lxc_conf *conf); extern bool network_new_hwaddrs(struct lxc_conf *conf);
#endif
#endif /* __LXC_CONFILE_H */
...@@ -91,7 +91,7 @@ int set_config_network_legacy_nic(const char *key, const char *value, ...@@ -91,7 +91,7 @@ int set_config_network_legacy_nic(const char *key, const char *value,
goto out; goto out;
strcpy(copy + 12, p + 1); strcpy(copy + 12, p + 1);
config = lxc_getconfig(copy); config = lxc_get_config(copy);
if (!config) { if (!config) {
ERROR("unknown key %s", key); ERROR("unknown key %s", key);
goto out; goto out;
......
...@@ -1902,7 +1902,7 @@ static bool do_lxcapi_clear_config_item(struct lxc_container *c, ...@@ -1902,7 +1902,7 @@ static bool do_lxcapi_clear_config_item(struct lxc_container *c,
if (container_mem_lock(c)) if (container_mem_lock(c))
return false; return false;
config = lxc_getconfig(key); config = lxc_get_config(key);
/* Verify that the config key exists and that it has a callback /* Verify that the config key exists and that it has a callback
* implemented. * implemented.
*/ */
...@@ -2218,7 +2218,7 @@ static int do_lxcapi_get_config_item(struct lxc_container *c, const char *key, c ...@@ -2218,7 +2218,7 @@ static int do_lxcapi_get_config_item(struct lxc_container *c, const char *key, c
if (container_mem_lock(c)) if (container_mem_lock(c))
return -1; return -1;
config = lxc_getconfig(key); config = lxc_get_config(key);
/* Verify that the config key exists and that it has a callback /* Verify that the config key exists and that it has a callback
* implemented. * implemented.
*/ */
...@@ -2248,22 +2248,29 @@ WRAP_API_1(char *, lxcapi_get_running_config_item, const char *) ...@@ -2248,22 +2248,29 @@ WRAP_API_1(char *, lxcapi_get_running_config_item, const char *)
static int do_lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen) static int do_lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen)
{ {
int ret = -1;
/* List all config items. */
if (!key) if (!key)
return lxc_list_config_items(retv, inlen); return lxc_list_config_items(retv, inlen);
/*
* Support 'lxc.net.<idx>', i.e. 'lxc.net.0'
* This is an intelligent result to show which keys are valid given
* the type of nic it is
*/
if (!c || !c->lxc_conf) if (!c || !c->lxc_conf)
return -1; return -1;
if (container_mem_lock(c)) if (container_mem_lock(c))
return -1; return -1;
int ret = -1;
/* Support 'lxc.net.<idx>', i.e. 'lxc.net.0'
* This is an intelligent result to show which keys are valid given the
* type of nic it is.
*/
if (!strncmp(key, "lxc.net.", 8)) if (!strncmp(key, "lxc.net.", 8))
ret = lxc_list_net(c->lxc_conf, key, retv, inlen); ret = lxc_list_net(c->lxc_conf, key, retv, inlen);
else if (strncmp(key, "lxc.network.", 12) == 0) else if (strncmp(key, "lxc.network.", 12) == 0)
ret = lxc_list_nicconfigs_legacy(c->lxc_conf, key, retv, inlen); ret = lxc_list_nicconfigs_legacy(c->lxc_conf, key, retv, inlen);
else
ret = lxc_list_subkeys(c->lxc_conf, key, retv, inlen);
container_mem_unlock(c); container_mem_unlock(c);
return ret; return ret;
} }
...@@ -2755,7 +2762,7 @@ static bool set_config_item_locked(struct lxc_container *c, const char *key, con ...@@ -2755,7 +2762,7 @@ static bool set_config_item_locked(struct lxc_container *c, const char *key, con
if (!c->lxc_conf) if (!c->lxc_conf)
return false; return false;
config = lxc_getconfig(key); config = lxc_get_config(key);
if (!config) if (!config)
return false; return false;
...@@ -4867,5 +4874,5 @@ free_ct_name: ...@@ -4867,5 +4874,5 @@ free_ct_name:
bool lxc_config_item_is_supported(const char *key) bool lxc_config_item_is_supported(const char *key)
{ {
return !!lxc_getconfig(key); return !!lxc_get_config(key);
} }
...@@ -105,16 +105,16 @@ echo ...@@ -105,16 +105,16 @@ echo
echo -n "User namespace: " && is_enabled CONFIG_USER_NS echo -n "User namespace: " && is_enabled CONFIG_USER_NS
echo echo
if is_set CONFIG_USER_NS; then if is_set CONFIG_USER_NS; then
if type newuidmap > /dev/null 2>&1; then if which newuidmap > /dev/null 2>&1; then
f=`type -P newuidmap` f=`which newuidmap`
if [ ! -u "${f}" ]; then if [ ! -u "${f}" ]; then
echo "Warning: newuidmap is not setuid-root" echo "Warning: newuidmap is not setuid-root"
fi fi
else else
echo "newuidmap is not installed" echo "newuidmap is not installed"
fi fi
if type newgidmap > /dev/null 2>&1; then if which newgidmap > /dev/null 2>&1; then
f=`type -P newgidmap` f=`which newgidmap`
if [ ! -u "${f}" ]; then if [ ! -u "${f}" ]; then
echo "Warning: newgidmap is not setuid-root" echo "Warning: newgidmap is not setuid-root"
fi fi
......
#!/bin/sh
# Make sure the usual locations are in PATH
export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
set -e
usage()
{
cat <<EOF
$1 -h|--help [-c|--config]
config: the container configuration to update
EOF
return 0
}
OPTIONS=`getopt -o c:h --long config:,help -- "${@}"`
eval set -- "${OPTIONS}"
while true; do
case "${1}" in
-h|--help)
usage "${0}"
exit 0
;;
-c|--config)
CONFIGPATH="${2}"
shift 2
;;
--)
shift 1
break
;;
*)
break
;;
esac
done
echo "${CONFIGPATH}"
sed -i".backup" \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.rootfs\)\([[:blank:]*]\|=\)/\1lxc\.rootfs\.path\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.id_map\)\([[:blank:]*]\|=\)/\1lxc\.idmap\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.pts\)\([[:blank:]*]\|=\)/\1lxc\.pty\.max\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.tty\)\([[:blank:]*]\|=\)/\1lxc\.tty\.max\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.devttydir\)\([[:blank:]*]\|=\)/\1lxc\.tty\.dir\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.aa_profile\)\([[:blank:]*]\|=\)/\1lxc\.apparmor\.profile\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.aa_allow_incomplete\)\([[:blank:]*]\|=\)/\1lxc\.apparmor\.allow_incomplete\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.se_context\)\([[:blank:]*]\|=\)/\1lxc\.selinux\.context\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.mount\)\([[:blank:]*]\|=\)/\1lxc\.mount\.fstab\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.utsname\)\([[:blank:]*]\|=\)/\1lxc\.uts\.name\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.rootfs\)\([[:blank:]*]\|=\)/\1lxc\.rootfs\.path\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.seccomp\)\([[:blank:]*]\|=\)/\1lxc\.seccomp\.profile\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.console\)\([[:blank:]*]\|=\)/\1lxc\.console\.path\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.haltsignal\)\([[:blank:]*]\|=\)/\1lxc\.signal\.halt\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.rebootsignal\)\([[:blank:]*]\|=\)/\1lxc\.signal\.reboot\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.stopsignal\)\([[:blank:]*]\|=\)/\1lxc\.signal\.stop\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.syslog\)\([[:blank:]*]\|=\)/\1lxc\.log\.syslog\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.loglevel\)\([[:blank:]*]\|=\)/\1lxc\.log\.level\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.logfile\)\([[:blank:]*]\|=\)/1lxc\.log\.file\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.init_cmd\)\([[:blank:]*]\|=\)/\1lxc\.init\.cmd\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.init_uid\)\([[:blank:]*]\|=\)/\1lxc\.init\.uid\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.init_gid\)\([[:blank:]*]\|=\)/\1lxc\.init\.gid\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.limit\)\([[:blank:]*]\|=\)/\1lxc\.prlimit\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.network\)\.\([^[:digit:]*]\)/\1lxc\.net\.0\.\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.network\)\(\.[[:digit:]*]\)/\1lxc\.net\3/g' \
-e 's/\([[:blank:]*]\|#*\)\(lxc\.network\)\([[:blank:]*]\|=\)/\1lxc\.net\3/g' \
"${CONFIGPATH}"
...@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) ...@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
for (key = strtok_r(keys, "\n", &saveptr); key != NULL; for (key = strtok_r(keys, "\n", &saveptr); key != NULL;
key = strtok_r(NULL, "\n", &saveptr)) { key = strtok_r(NULL, "\n", &saveptr)) {
struct lxc_config_t *config; struct lxc_config_t *config;
config = lxc_getconfig(key); config = lxc_get_config(key);
if (!config) { if (!config) {
lxc_error("configuration key \"%s\" not implemented in " lxc_error("configuration key \"%s\" not implemented in "
"jump table", "jump table",
......
...@@ -16,15 +16,17 @@ ...@@ -16,15 +16,17 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <lxc/lxccontainer.h>
#include <unistd.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <stdlib.h> #include <lxc/lxccontainer.h>
#include <errno.h>
#include "lxc/state.h" #include "lxc/state.h"
#define MYNAME "lxctest1" #define MYNAME "lxctest1"
...@@ -64,6 +66,103 @@ int main(int argc, char *argv[]) ...@@ -64,6 +66,103 @@ int main(int argc, char *argv[])
goto out; goto out;
} }
printf("get_keys for nic 1 returned %d\n%s", ret, v3); printf("get_keys for nic 1 returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.apparmor", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.selinux", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.mount", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.rootfs", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.uts", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.hook", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.cap", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.console", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.seccomp", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.signal", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.start", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = c->get_keys(c, "lxc.monitor", v3, 2000);
if (ret < 0) {
fprintf(stderr, "%d: failed to get keys(%d)\n", __LINE__, ret);
ret = 1;
goto out;
}
printf("get_keys returned %d\n%s", ret, v3);
ret = 0; ret = 0;
out: out:
......
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