Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
4461568a
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4461568a
编写于
10月 03, 2008
作者:
D
Dan Smith
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add cgroup manipulation and LXC driver
上级
773441bb
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
101 addition
and
9 deletion
+101
-9
src/Makefile.am
src/Makefile.am
+4
-2
src/lxc_container.c
src/lxc_container.c
+6
-6
src/lxc_container.h
src/lxc_container.h
+10
-0
src/lxc_controller.c
src/lxc_controller.c
+74
-1
src/lxc_driver.c
src/lxc_driver.c
+7
-0
未找到文件。
src/Makefile.am
浏览文件 @
4461568a
...
@@ -90,13 +90,15 @@ LXC_DRIVER_SOURCES = \
...
@@ -90,13 +90,15 @@ LXC_DRIVER_SOURCES = \
lxc_conf.c lxc_conf.h
\
lxc_conf.c lxc_conf.h
\
lxc_container.c lxc_container.h
\
lxc_container.c lxc_container.h
\
lxc_driver.c lxc_driver.h
\
lxc_driver.c lxc_driver.h
\
veth.c veth.h
veth.c veth.h
\
cgroup.c cgroup.h
LXC_CONTROLLER_SOURCES
=
\
LXC_CONTROLLER_SOURCES
=
\
lxc_conf.c lxc_conf.h
\
lxc_conf.c lxc_conf.h
\
lxc_container.c lxc_container.h
\
lxc_container.c lxc_container.h
\
lxc_controller.c
\
lxc_controller.c
\
veth.c veth.h
veth.c veth.h
\
cgroup.c cgroup.h
OPENVZ_DRIVER_SOURCES
=
\
OPENVZ_DRIVER_SOURCES
=
\
openvz_conf.c openvz_conf.h
\
openvz_conf.c openvz_conf.h
\
...
...
src/lxc_container.c
浏览文件 @
4461568a
...
@@ -320,12 +320,12 @@ static int lxcContainerPopulateDevices(void)
...
@@ -320,12 +320,12 @@ static int lxcContainerPopulateDevices(void)
mode_t
mode
;
mode_t
mode
;
const
char
*
path
;
const
char
*
path
;
}
devs
[]
=
{
}
devs
[]
=
{
{
1
,
3
,
0666
,
"/dev/null"
},
{
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_NULL
,
0666
,
"/dev/null"
},
{
1
,
5
,
0666
,
"/dev/zero"
},
{
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_ZERO
,
0666
,
"/dev/zero"
},
{
1
,
7
,
0666
,
"/dev/full"
},
{
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_FULL
,
0666
,
"/dev/full"
},
{
5
,
1
,
0600
,
"/dev/console"
},
{
LXC_DEV_MAJ_TTY
,
LXC_DEV_MIN_CONSOLE
,
0600
,
"/dev/console"
},
{
1
,
8
,
0666
,
"/dev/random"
},
{
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_RANDOM
,
0666
,
"/dev/random"
},
{
1
,
9
,
0666
,
"/dev/urandom"
},
{
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_URANDOM
,
0666
,
"/dev/urandom"
},
};
};
if
(
virFileMakePath
(
"/dev"
)
<
0
||
if
(
virFileMakePath
(
"/dev"
)
<
0
||
...
...
src/lxc_container.h
浏览文件 @
4461568a
...
@@ -30,6 +30,16 @@ enum {
...
@@ -30,6 +30,16 @@ enum {
LXC_CONTAINER_FEATURE_NET
=
(
1
<<
0
),
LXC_CONTAINER_FEATURE_NET
=
(
1
<<
0
),
};
};
#define LXC_DEV_MAJ_MEMORY 1
#define LXC_DEV_MIN_NULL 3
#define LXC_DEV_MIN_ZERO 5
#define LXC_DEV_MIN_FULL 7
#define LXC_DEV_MIN_RANDOM 8
#define LXC_DEV_MIN_URANDOM 9
#define LXC_DEV_MAJ_TTY 5
#define LXC_DEV_MIN_CONSOLE 1
int
lxcContainerSendContinue
(
int
control
);
int
lxcContainerSendContinue
(
int
control
);
int
lxcContainerStart
(
virDomainDefPtr
def
,
int
lxcContainerStart
(
virDomainDefPtr
def
,
...
...
src/lxc_controller.c
浏览文件 @
4461568a
...
@@ -42,13 +42,83 @@
...
@@ -42,13 +42,83 @@
#include "veth.h"
#include "veth.h"
#include "memory.h"
#include "memory.h"
#include "util.h"
#include "util.h"
#include "cgroup.h"
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
int
debugFlag
=
0
;
int
debugFlag
=
0
;
struct
cgroup_device_policy
{
char
type
;
int
major
;
int
minor
;
};
/**
* lxcSetContainerResources
* @def: pointer to virtual machine structure
*
* Creates a cgroup for the container, moves the task inside,
* and sets resource limits
*
* Returns 0 on success or -1 in case of error
*/
static
int
lxcSetContainerResources
(
virDomainDefPtr
def
)
{
virCgroupPtr
cgroup
;
int
rc
=
-
1
;
int
i
;
struct
cgroup_device_policy
devices
[]
=
{
{
'c'
,
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_NULL
},
{
'c'
,
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_ZERO
},
{
'c'
,
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_FULL
},
{
'c'
,
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_RANDOM
},
{
'c'
,
LXC_DEV_MAJ_MEMORY
,
LXC_DEV_MIN_URANDOM
},
{
'c'
,
LXC_DEV_MAJ_TTY
,
LXC_DEV_MIN_CONSOLE
},
{
0
,
0
,
0
}};
if
(
virCgroupHaveSupport
()
!=
0
)
return
0
;
/* Not supported, so claim success */
rc
=
virCgroupForDomain
(
def
,
"lxc"
,
&
cgroup
);
if
(
rc
!=
0
)
{
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Unable to create cgroup for %s
\n
"
),
def
->
name
);
return
rc
;
}
rc
=
virCgroupSetMemory
(
cgroup
,
def
->
maxmem
);
if
(
rc
!=
0
)
goto
out
;
rc
=
virCgroupDenyAllDevices
(
cgroup
);
if
(
rc
!=
0
)
goto
out
;
for
(
i
=
0
;
devices
[
i
].
type
!=
0
;
i
++
)
{
struct
cgroup_device_policy
*
dev
=
&
devices
[
i
];
rc
=
virCgroupAllowDevice
(
cgroup
,
dev
->
type
,
dev
->
major
,
dev
->
minor
);
if
(
rc
!=
0
)
goto
out
;
}
rc
=
virCgroupAddTask
(
cgroup
,
getpid
());
out:
if
(
rc
!=
0
)
{
lxcError
(
NULL
,
NULL
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"Failed to set lxc resources: %s
\n
"
),
strerror
(
-
rc
));
virCgroupRemove
(
cgroup
);
}
virCgroupFree
(
&
cgroup
);
return
rc
;
}
static
char
*
lxcMonitorPath
(
virDomainDefPtr
def
)
static
char
*
lxcMonitorPath
(
virDomainDefPtr
def
)
{
{
char
*
sockpath
;
char
*
sockpath
;
...
@@ -394,6 +464,9 @@ lxcControllerRun(virDomainDefPtr def,
...
@@ -394,6 +464,9 @@ lxcControllerRun(virDomainDefPtr def,
if
(
lxcControllerMoveInterfaces
(
nveths
,
veths
,
container
)
<
0
)
if
(
lxcControllerMoveInterfaces
(
nveths
,
veths
,
container
)
<
0
)
goto
cleanup
;
goto
cleanup
;
if
(
lxcSetContainerResources
(
def
)
<
0
)
goto
cleanup
;
if
(
lxcContainerSendContinue
(
control
[
0
])
<
0
)
if
(
lxcContainerSendContinue
(
control
[
0
])
<
0
)
goto
cleanup
;
goto
cleanup
;
...
...
src/lxc_driver.c
浏览文件 @
4461568a
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
#include "bridge.h"
#include "bridge.h"
#include "veth.h"
#include "veth.h"
#include "event.h"
#include "event.h"
#include "cgroup.h"
/* debug macros */
/* debug macros */
...
@@ -376,6 +377,7 @@ static int lxcVMCleanup(virConnectPtr conn,
...
@@ -376,6 +377,7 @@ static int lxcVMCleanup(virConnectPtr conn,
int
waitRc
;
int
waitRc
;
int
childStatus
=
-
1
;
int
childStatus
=
-
1
;
virDomainNetDefPtr
net
;
virDomainNetDefPtr
net
;
virCgroupPtr
cgroup
;
while
(((
waitRc
=
waitpid
(
vm
->
pid
,
&
childStatus
,
0
))
==
-
1
)
&&
while
(((
waitRc
=
waitpid
(
vm
->
pid
,
&
childStatus
,
0
))
==
-
1
)
&&
errno
==
EINTR
)
errno
==
EINTR
)
...
@@ -410,6 +412,11 @@ static int lxcVMCleanup(virConnectPtr conn,
...
@@ -410,6 +412,11 @@ static int lxcVMCleanup(virConnectPtr conn,
vethDelete
(
net
->
ifname
);
vethDelete
(
net
->
ifname
);
}
}
if
(
virCgroupForDomain
(
vm
->
def
,
"lxc"
,
&
cgroup
)
==
0
)
{
virCgroupRemove
(
cgroup
);
virCgroupFree
(
&
cgroup
);
}
return
rc
;
return
rc
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录