Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
6c504d6a
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看板
提交
6c504d6a
编写于
10月 08, 2008
作者:
D
Dan Smith
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add LXC scheduling parameters and support in virsh schedinfo
上级
6d670a1f
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
177 addition
and
37 deletion
+177
-37
ChangeLog
ChangeLog
+5
-0
docs/virsh.pod
docs/virsh.pod
+6
-4
src/cgroup.c
src/cgroup.c
+37
-27
src/cgroup.h
src/cgroup.h
+3
-0
src/lxc_driver.c
src/lxc_driver.c
+92
-4
src/virsh.c
src/virsh.c
+34
-2
未找到文件。
ChangeLog
浏览文件 @
6c504d6a
Wed Oct 8 08:29:25 PDT 2008 Dan Smith <danms@us.ibm.com>
* src/cgroup.c src/cgroup.h: Add cpu shares manipulation
* src/lxc_driver.c: Add scheduler parameters interface for cpu shares
* src/virsh.c: Add generic scheduler parameter interface
Wed Oct 8 15:42:44 CEST 2008 Daniel Veillard <veillard@redhat.com>
* src/cgroup.c: use safewrite()
...
...
docs/virsh.pod
浏览文件 @
6c504d6a
...
...
@@ -318,12 +318,14 @@ This is roughly equivalent to doing a hibernate on a running computer,
with all the same limitations. Open network connections may be
severed upon restore, as TCP timeouts may have expired.
=item B<schedinfo> optional I<--set> B<parameter=value> I<domain-id>
=item B<schedinfo> optional I<--weight> B<number> optional I<--cap> B<number> I<domain-id>
Allows to show (and set) the domain scheduler parameters.
This is currently
only defined for XEN_CREDIT scheduler, and the optional weight and cap
arguments allows to set the associated parameters in that scheduler if
provided
.
Allows to show (and set) the domain scheduler parameters.
B<Note>: The weight and cap parameters are defined only for the
XEN_CREDIT scheduler and are now I<DEPRECATED>
.
=item B<setmem> I<domain-id> B<kilobytes>
...
...
src/cgroup.c
浏览文件 @
6c504d6a
...
...
@@ -224,26 +224,6 @@ static int virCgroupSetValueU64(virCgroupPtr group,
return
rc
;
}
#if 0
/* This is included for completeness, but not yet used */
static int virCgroupSetValueI64(virCgroupPtr group,
const char *key,
int64_t value)
{
char *strval = NULL;
int rc;
if (asprintf(&strval, "%" PRIi64, value) == -1)
return -ENOMEM;
rc = virCgroupSetValueStr(group, key, strval);
VIR_FREE(strval);
return rc;
}
static
int
virCgroupGetValueStr
(
virCgroupPtr
group
,
const
char
*
key
,
char
**
value
)
...
...
@@ -293,9 +273,29 @@ out:
return
rc
;
}
static int virCgroupGetValueU64(virCgroupPtr group,
#if 0
/* This is included for completeness, but not yet used */
static int virCgroupSetValueI64(virCgroupPtr group,
const char *key,
uint64_t *value)
int64_t value)
{
char *strval = NULL;
int rc;
if (asprintf(&strval, "%" PRIi64, value) == -1)
return -ENOMEM;
rc = virCgroupSetValueStr(group, key, strval);
VIR_FREE(strval);
return rc;
}
static int virCgroupGetValueI64(virCgroupPtr group,
const char *key,
int64_t *value)
{
char *strval = NULL;
int rc = 0;
...
...
@@ -304,17 +304,18 @@ static int virCgroupGetValueU64(virCgroupPtr group,
if (rc != 0)
goto out;
if (sscanf(strval, "%" SCN
u
64, value) != 1)
if (sscanf(strval, "%" SCN
i
64, value) != 1)
rc = -EINVAL;
out:
VIR_FREE(strval);
return rc;
}
#endif
static int virCgroupGetValue
I
64(virCgroupPtr group,
static
int
virCgroupGetValue
U
64
(
virCgroupPtr
group
,
const
char
*
key
,
int64_t *value)
u
int64_t
*
value
)
{
char
*
strval
=
NULL
;
int
rc
=
0
;
...
...
@@ -323,14 +324,13 @@ static int virCgroupGetValueI64(virCgroupPtr group,
if
(
rc
!=
0
)
goto
out
;
if (sscanf(strval, "%" SCN
i
64, value) != 1)
if
(
sscanf
(
strval
,
"%"
SCN
u
64
,
value
)
!=
1
)
rc
=
-
EINVAL
;
out:
VIR_FREE
(
strval
);
return
rc
;
}
#endif
static
int
_virCgroupInherit
(
const
char
*
path
,
const
char
*
key
)
...
...
@@ -760,3 +760,13 @@ out:
return
rc
;
}
int
virCgroupSetCpuShares
(
virCgroupPtr
group
,
unsigned
long
shares
)
{
return
virCgroupSetValueU64
(
group
,
"cpu.shares"
,
(
uint64_t
)
shares
);
}
int
virCgroupGetCpuShares
(
virCgroupPtr
group
,
unsigned
long
*
shares
)
{
return
virCgroupGetValueU64
(
group
,
"cpu.shares"
,
(
uint64_t
*
)
shares
);
}
src/cgroup.h
浏览文件 @
6c504d6a
...
...
@@ -36,6 +36,9 @@ int virCgroupAllowDevice(virCgroupPtr group,
int
major
,
int
minor
);
int
virCgroupSetCpuShares
(
virCgroupPtr
group
,
unsigned
long
shares
);
int
virCgroupGetCpuShares
(
virCgroupPtr
group
,
unsigned
long
*
shares
);
int
virCgroupRemove
(
virCgroupPtr
group
);
void
virCgroupFree
(
virCgroupPtr
*
group
);
...
...
src/lxc_driver.c
浏览文件 @
6c504d6a
...
...
@@ -35,6 +35,7 @@
#include <unistd.h>
#include <wait.h>
#include "internal.h"
#include "lxc_conf.h"
#include "lxc_container.h"
#include "lxc_driver.h"
...
...
@@ -1144,6 +1145,94 @@ static int lxcVersion(virConnectPtr conn, unsigned long *version)
return
0
;
}
static
char
*
lxcGetSchedulerType
(
virDomainPtr
domain
,
int
*
nparams
)
{
if
(
nparams
)
*
nparams
=
1
;
return
strdup
(
"posix"
);
}
static
int
lxcSetSchedulerParameters
(
virDomainPtr
_domain
,
virSchedParameterPtr
params
,
int
nparams
)
{
int
i
;
int
rc
;
virCgroupPtr
group
;
virDomainObjPtr
domain
;
if
(
virCgroupHaveSupport
()
!=
0
)
return
0
;
domain
=
virDomainFindByUUID
(
lxc_driver
->
domains
,
_domain
->
uuid
);
if
(
domain
==
NULL
)
{
lxcError
(
NULL
,
_domain
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"No such domain %s"
),
_domain
->
uuid
);
return
-
EINVAL
;
}
rc
=
virCgroupForDomain
(
domain
->
def
,
"lxc"
,
&
group
);
if
(
rc
!=
0
)
return
rc
;
for
(
i
=
0
;
i
<
nparams
;
i
++
)
{
virSchedParameterPtr
param
=
&
params
[
i
];
if
(
STREQ
(
param
->
field
,
"cpu_shares"
))
{
rc
=
virCgroupSetCpuShares
(
group
,
params
[
i
].
value
.
ui
);
}
else
{
lxcError
(
NULL
,
_domain
,
VIR_ERR_INVALID_ARG
,
_
(
"Invalid parameter `%s'"
),
param
->
field
);
rc
=
-
ENOENT
;
goto
out
;
}
}
rc
=
0
;
out:
virCgroupFree
(
&
group
);
return
rc
;
}
static
int
lxcGetSchedulerParameters
(
virDomainPtr
_domain
,
virSchedParameterPtr
params
,
int
*
nparams
)
{
int
rc
=
0
;
virCgroupPtr
group
;
virDomainObjPtr
domain
;
if
(
virCgroupHaveSupport
()
!=
0
)
return
0
;
if
((
*
nparams
)
!=
1
)
{
lxcError
(
NULL
,
_domain
,
VIR_ERR_INVALID_ARG
,
_
(
"Invalid parameter count"
));
return
-
1
;
}
domain
=
virDomainFindByUUID
(
lxc_driver
->
domains
,
_domain
->
uuid
);
if
(
domain
==
NULL
)
{
lxcError
(
NULL
,
_domain
,
VIR_ERR_INTERNAL_ERROR
,
_
(
"No such domain %s"
),
_domain
->
uuid
);
return
-
ENOENT
;
}
rc
=
virCgroupForDomain
(
domain
->
def
,
"lxc"
,
&
group
);
if
(
rc
!=
0
)
return
rc
;
rc
=
virCgroupGetCpuShares
(
group
,
(
unsigned
long
*
)
&
params
[
0
].
value
.
ul
);
strncpy
(
params
[
0
].
field
,
"cpu_shares"
,
sizeof
(
params
[
0
].
field
));
params
[
0
].
type
=
VIR_DOMAIN_SCHED_FIELD_ULLONG
;
virCgroupFree
(
&
group
);
return
rc
;
}
/* Function Tables */
static
virDriver
lxcDriver
=
{
VIR_DRV_LXC
,
/* the number virDrvNo */
...
...
@@ -1193,9 +1282,9 @@ static virDriver lxcDriver = {
NULL
,
/* domainDetachDevice */
NULL
,
/* domainGetAutostart */
NULL
,
/* domainSetAutostart */
NULL
,
/* domainGetSchedulerType */
NULL
,
/* domainGetSchedulerParameters */
NULL
,
/* domainSetSchedulerParameters */
lxcGetSchedulerType
,
/* domainGetSchedulerType */
lxcGetSchedulerParameters
,
/* domainGetSchedulerParameters */
lxcSetSchedulerParameters
,
/* domainSetSchedulerParameters */
NULL
,
/* domainMigratePrepare */
NULL
,
/* domainMigratePerform */
NULL
,
/* domainMigrateFinish */
...
...
@@ -1207,7 +1296,6 @@ static virDriver lxcDriver = {
NULL
,
/* getFreeMemory */
};
static
virStateDriver
lxcStateDriver
=
{
.
initialize
=
lxcStartup
,
.
cleanup
=
lxcShutdown
,
...
...
src/virsh.c
浏览文件 @
6c504d6a
...
...
@@ -1112,6 +1112,7 @@ static const vshCmdInfo info_schedinfo[] = {
static
const
vshCmdOptDef
opts_schedinfo
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
gettext_noop
(
"domain name, id or uuid"
)},
{
"set"
,
VSH_OT_STRING
,
VSH_OFLAG_NONE
,
gettext_noop
(
"parameter=value"
)},
{
"weight"
,
VSH_OT_INT
,
VSH_OFLAG_NONE
,
gettext_noop
(
"weight for XEN_CREDIT"
)},
{
"cap"
,
VSH_OT_INT
,
VSH_OFLAG_NONE
,
gettext_noop
(
"cap for XEN_CREDIT"
)},
{
NULL
,
0
,
0
,
NULL
}
...
...
@@ -1121,6 +1122,9 @@ static int
cmdSchedinfo
(
vshControl
*
ctl
,
const
vshCmd
*
cmd
)
{
char
*
schedulertype
;
char
*
set
;
char
*
param_name
=
NULL
;
long
long
int
param_value
=
0
;
virDomainPtr
dom
;
virSchedParameterPtr
params
=
NULL
;
int
i
,
ret
;
...
...
@@ -1128,6 +1132,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
int
nr_inputparams
=
0
;
int
inputparams
=
0
;
int
weightfound
=
0
;
int
setfound
=
0
;
int
weight
=
0
;
int
capfound
=
0
;
int
cap
=
0
;
...
...
@@ -1141,7 +1146,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
if
(
!
(
dom
=
vshCommandOptDomain
(
ctl
,
cmd
,
"domain"
,
NULL
)))
return
FALSE
;
/*
Currently supports Xen Credit only
*/
/*
Deprecated Xen-only options
*/
if
(
vshCommandOptBool
(
cmd
,
"weight"
))
{
weight
=
vshCommandOptInt
(
cmd
,
"weight"
,
&
weightfound
);
if
(
!
weightfound
)
{
...
...
@@ -1162,6 +1167,25 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
}
}
if
(
vshCommandOptBool
(
cmd
,
"set"
))
{
set
=
vshCommandOptString
(
cmd
,
"set"
,
&
setfound
);
if
(
!
setfound
)
{
vshError
(
ctl
,
FALSE
,
"%s"
,
_
(
"Error getting param"
));
goto
cleanup
;
}
param_name
=
vshMalloc
(
ctl
,
strlen
(
set
)
+
1
);
if
(
param_name
==
NULL
)
goto
cleanup
;
if
(
sscanf
(
set
,
"%[^=]=%i"
,
param_name
,
&
param_value
)
!=
2
)
{
vshError
(
ctl
,
FALSE
,
"%s"
,
_
(
"Invalid value of param"
));
goto
cleanup
;
}
nr_inputparams
++
;
}
params
=
vshMalloc
(
ctl
,
sizeof
(
virSchedParameter
)
*
nr_inputparams
);
if
(
params
==
NULL
)
{
goto
cleanup
;
...
...
@@ -1180,7 +1204,14 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
params
[
inputparams
].
value
.
ui
=
cap
;
inputparams
++
;
}
/* End Currently supports Xen Credit only */
/* End Deprecated Xen-only options */
if
(
setfound
)
{
strncpy
(
params
[
inputparams
].
field
,
param_name
,
sizeof
(
params
[
0
].
field
));
params
[
inputparams
].
type
=
VIR_DOMAIN_SCHED_FIELD_LLONG
;
params
[
inputparams
].
value
.
l
=
param_value
;
inputparams
++
;
}
assert
(
inputparams
==
nr_inputparams
);
...
...
@@ -1247,6 +1278,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
}
cleanup:
free
(
params
);
free
(
param_name
);
virDomainFree
(
dom
);
return
ret_val
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录