return 1;
}
+static int container_get_cgroup_item(lua_State *L)
+{
+ struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+ const char *key = luaL_checkstring(L, 2);
+ int len;
+ char *value;
+
+ len = c->get_cgroup_item(c, key, NULL, 0);
+ if (len <= 0)
+ goto not_found;
+
+ value = alloca(sizeof(char)*len + 1);
+ if (c->get_cgroup_item(c, key, value, len + 1) != len)
+ goto not_found;
+
+ lua_pushstring(L, value);
+ return 1;
+
+not_found:
+ lua_pushnil(L);
+ return 1;
+}
+
static int container_get_config_item(lua_State *L)
{
struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
return 1;
}
+static int container_set_cgroup_item(lua_State *L)
+{
+ struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
+ const char *key = luaL_checkstring(L, 2);
+ const char *value = luaL_checkstring(L, 3);
+
+ lua_pushboolean(L, !!c->set_cgroup_item(c, key, value));
+ return 1;
+}
+
static int container_set_config_item(lua_State *L)
{
struct lxc_container *c = lua_unboxpointer(L, 1, CONTAINER_TYPENAME);
{"config_file_name", container_config_file_name},
{"load_config", container_load_config},
{"save_config", container_save_config},
+ {"get_cgroup_item", container_get_cgroup_item},
+ {"set_cgroup_item", container_set_cgroup_item},
{"get_config_path", container_get_config_path},
{"set_config_path", container_set_config_path},
{"get_config_item", container_get_config_item},
return self.core:clear_config_item(key)
end
+function container:get_cgroup_item(key)
+ return self.core:get_cgroup_item(key)
+end
+
function container:get_config_item(key)
local value
local vals = {}
return vals
end
+function container:set_cgroup_item(key, value)
+ return self.core:set_cgroup_item(key, value)
+end
+
function container:set_config_item(key, value)
return self.core:set_config_item(key, value)
end
return containers
end
+function M.version_get()
+ return core.version_get()
+end
+
+function M.default_config_path_get()
+ return core.default_config_path_get()
+end
+
lxc_path = core.default_config_path_get()
cgroup_path = cgroup_path_get()
end
end
+function test_container_cgroup()
+ log(0, "Test get/set cgroup items...")
+
+ max_mem = container:get_cgroup_item("memory.max_usage_in_bytes")
+ saved_limit = container:get_cgroup_item("memory.limit_in_bytes")
+ assert(saved_limit ~= max_mem)
+ assert(container:set_cgroup_item("memory.limit_in_bytes", max_mem))
+ assert(container:get_cgroup_item("memory.limit_in_bytes") ~= saved_limit)
+ assert(container:set_cgroup_item("memory.limit_in_bytes", "-1"))
+end
+
function test_config_items()
log(0, "Test set/clear configuration items...")
test_container_start()
test_container_started()
+test_container_cgroup()
+
test_container_freeze()
test_container_frozen()
test_container_unfreeze()