Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
af35cece
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,发现更多精彩内容 >>
提交
af35cece
编写于
6月 07, 2011
作者:
M
Minoru Usui
提交者:
Eric Blake
6月 14, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
virNodeGetMemoryStats: Implement linux support
Signed-off-by:
N
Minoru Usui
<
usui@mxm.nes.nec.co.jp
>
上级
64609328
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
181 addition
and
0 deletion
+181
-0
src/libvirt_private.syms
src/libvirt_private.syms
+1
-0
src/lxc/lxc_driver.c
src/lxc/lxc_driver.c
+1
-0
src/nodeinfo.c
src/nodeinfo.c
+172
-0
src/nodeinfo.h
src/nodeinfo.h
+5
-0
src/qemu/qemu_driver.c
src/qemu/qemu_driver.c
+1
-0
src/uml/uml_driver.c
src/uml/uml_driver.c
+1
-0
未找到文件。
src/libvirt_private.syms
浏览文件 @
af35cece
...
...
@@ -737,6 +737,7 @@ nodeGetCPUStats;
nodeGetCellsFreeMemory;
nodeGetFreeMemory;
nodeGetInfo;
nodeGetMemoryStats;
# nwfilter_conf.h
...
...
src/lxc/lxc_driver.c
浏览文件 @
af35cece
...
...
@@ -2886,6 +2886,7 @@ static virDriver lxcDriver = {
.
domainSetSchedulerParametersFlags
=
lxcSetSchedulerParametersFlags
,
/* 0.9.2 */
.
domainInterfaceStats
=
lxcDomainInterfaceStats
,
/* 0.7.3 */
.
nodeGetCPUStats
=
nodeGetCPUStats
,
/* 0.9.3 */
.
nodeGetMemoryStats
=
nodeGetMemoryStats
,
/* 0.9.3 */
.
nodeGetCellsFreeMemory
=
nodeGetCellsFreeMemory
,
/* 0.6.5 */
.
nodeGetFreeMemory
=
nodeGetFreeMemory
,
/* 0.6.5 */
.
domainEventRegister
=
lxcDomainEventRegister
,
/* 0.7.0 */
...
...
src/nodeinfo.c
浏览文件 @
af35cece
...
...
@@ -58,8 +58,12 @@
# define CPUINFO_PATH "/proc/cpuinfo"
# define CPU_SYS_PATH "/sys/devices/system/cpu"
# define PROCSTAT_PATH "/proc/stat"
# define MEMINFO_PATH "/proc/meminfo"
# define NODE_SYS_PATH "/sys/devices/system/node"
# define LINUX_NB_CPU_STATS 4
# define LINUX_NB_MEMORY_STATS_ALL 4
# define LINUX_NB_MEMORY_STATS_CELL 2
/* NB, this is not static as we need to call it from the testsuite */
int
linuxNodeInfoCPUPopulate
(
FILE
*
cpuinfo
,
...
...
@@ -70,6 +74,10 @@ static int linuxNodeGetCPUStats(FILE *procstat,
int
cpuNum
,
virCPUStatsPtr
params
,
int
*
nparams
);
static
int
linuxNodeGetMemoryStats
(
FILE
*
meminfo
,
int
cellNum
,
virMemoryStatsPtr
params
,
int
*
nparams
);
/* Return the positive decimal contents of the given
* CPU_SYS_PATH/cpu%u/FILE, or -1 on error. If MISSING_OK and the
...
...
@@ -482,6 +490,110 @@ int linuxNodeGetCPUStats(FILE *procstat,
nodeReportError
(
VIR_ERR_INVALID_ARG
,
"%s"
,
_
(
"Invalid cpu number"
));
cleanup:
return
ret
;
}
int
linuxNodeGetMemoryStats
(
FILE
*
meminfo
,
int
cellNum
,
virMemoryStatsPtr
params
,
int
*
nparams
)
{
int
ret
=
-
1
;
int
i
=
0
,
j
=
0
,
k
=
0
;
int
found
=
0
;
int
nr_param
;
char
line
[
1024
];
char
meminfo_hdr
[
VIR_MEMORY_STATS_FIELD_LENGTH
];
unsigned
long
val
;
struct
field_conv
{
const
char
*
meminfo_hdr
;
// meminfo header
const
char
*
field
;
// MemoryStats field name
}
field_conv
[]
=
{
{
"MemTotal:"
,
VIR_MEMORY_STATS_TOTAL
},
{
"MemFree:"
,
VIR_MEMORY_STATS_FREE
},
{
"Buffers:"
,
VIR_MEMORY_STATS_BUFFERS
},
{
"Cached:"
,
VIR_MEMORY_STATS_CACHED
},
{
NULL
,
NULL
}
};
if
(
cellNum
==
VIR_MEMORY_STATS_ALL_CELLS
)
{
nr_param
=
LINUX_NB_MEMORY_STATS_ALL
;
}
else
{
nr_param
=
LINUX_NB_MEMORY_STATS_CELL
;
}
if
((
*
nparams
)
==
0
)
{
/* Current number of memory stats supported by linux */
*
nparams
=
nr_param
;
ret
=
0
;
goto
cleanup
;
}
if
((
*
nparams
)
!=
nr_param
)
{
nodeReportError
(
VIR_ERR_INVALID_ARG
,
"%s"
,
_
(
"Invalid stats count"
));
goto
cleanup
;
}
while
(
fgets
(
line
,
sizeof
(
line
),
meminfo
)
!=
NULL
)
{
char
*
buf
=
line
;
if
(
STRPREFIX
(
buf
,
"Node "
))
{
/*
* /sys/devices/system/node/nodeX/meminfo format is below.
* So, skip prefix "Node XX ".
*
* Node 0 MemTotal: 8386980 kB
* Node 0 MemFree: 5300920 kB
* :
*/
char
*
p
;
p
=
buf
;
for
(
i
=
0
;
i
<
2
;
i
++
)
{
p
=
strchr
(
p
,
' '
);
if
(
p
==
NULL
)
{
nodeReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"no prefix found"
));
goto
cleanup
;
}
p
++
;
}
buf
=
p
;
}
if
(
sscanf
(
buf
,
"%s %lu kB"
,
meminfo_hdr
,
&
val
)
<
2
)
continue
;
for
(
j
=
0
;
field_conv
[
j
].
meminfo_hdr
!=
NULL
;
j
++
)
{
struct
field_conv
*
convp
=
&
field_conv
[
j
];
if
(
STREQ
(
meminfo_hdr
,
convp
->
meminfo_hdr
))
{
virMemoryStatsPtr
param
=
&
params
[
k
++
];
if
(
virStrcpyStatic
(
param
->
field
,
convp
->
field
)
==
NULL
)
{
nodeReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"Field kernel memory too long for destination"
));
goto
cleanup
;
}
param
->
value
=
val
;
found
++
;
break
;
}
}
if
(
found
>=
nr_param
)
break
;
}
if
(
found
==
0
)
{
nodeReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"no available memory line found"
));
goto
cleanup
;
}
ret
=
0
;
cleanup:
return
ret
;
}
...
...
@@ -552,6 +664,66 @@ int nodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED,
#endif
}
int
nodeGetMemoryStats
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
int
cellNum
,
virMemoryStatsPtr
params
,
int
*
nparams
,
unsigned
int
flags
)
{
virCheckFlags
(
0
,
-
1
);
#ifdef __linux__
{
int
ret
;
char
*
meminfo_path
=
NULL
;
FILE
*
meminfo
;
if
(
cellNum
==
VIR_MEMORY_STATS_ALL_CELLS
)
{
meminfo_path
=
strdup
(
MEMINFO_PATH
);
if
(
!
meminfo_path
)
{
virReportOOMError
();
return
-
1
;
}
}
else
{
if
(
numa_available
()
<
0
)
{
nodeReportError
(
VIR_ERR_NO_SUPPORT
,
"%s"
,
_
(
"NUMA not supported on this host"
));
return
-
1
;
}
if
(
cellNum
>
numa_max_node
())
{
nodeReportError
(
VIR_ERR_INVALID_ARG
,
"%s"
,
_
(
"Invalid cell number"
));
return
-
1
;
}
if
(
virAsprintf
(
&
meminfo_path
,
"%s/node%d/meminfo"
,
NODE_SYS_PATH
,
cellNum
)
<
0
)
{
virReportOOMError
();
return
-
1
;
}
}
meminfo
=
fopen
(
meminfo_path
,
"r"
);
if
(
!
meminfo
)
{
virReportSystemError
(
errno
,
_
(
"cannot open %s"
),
meminfo_path
);
VIR_FREE
(
meminfo_path
);
return
-
1
;
}
ret
=
linuxNodeGetMemoryStats
(
meminfo
,
cellNum
,
params
,
nparams
);
VIR_FORCE_FCLOSE
(
meminfo
);
VIR_FREE
(
meminfo_path
);
return
ret
;
}
#else
nodeReportError
(
VIR_ERR_NO_SUPPORT
,
"%s"
,
_
(
"node memory stats not implemented on this platform"
));
return
-
1
;
#endif
}
#if HAVE_NUMACTL
# if LIBNUMA_API_VERSION <= 1
# define NUMA_MAX_N_CPUS 4096
...
...
src/nodeinfo.h
浏览文件 @
af35cece
...
...
@@ -35,6 +35,11 @@ int nodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED,
virCPUStatsPtr
params
,
int
*
nparams
,
unsigned
int
flags
ATTRIBUTE_UNUSED
);
int
nodeGetMemoryStats
(
virConnectPtr
conn
ATTRIBUTE_UNUSED
,
int
cellNum
,
virMemoryStatsPtr
params
,
int
*
nparams
,
unsigned
int
flags
ATTRIBUTE_UNUSED
);
int
nodeGetCellsFreeMemory
(
virConnectPtr
conn
,
unsigned
long
long
*
freeMems
,
int
startCell
,
...
...
src/qemu/qemu_driver.c
浏览文件 @
af35cece
...
...
@@ -8093,6 +8093,7 @@ static virDriver qemuDriver = {
.
domainMemoryPeek
=
qemudDomainMemoryPeek
,
/* 0.4.4 */
.
domainGetBlockInfo
=
qemuDomainGetBlockInfo
,
/* 0.8.1 */
.
nodeGetCPUStats
=
nodeGetCPUStats
,
/* 0.9.3 */
.
nodeGetMemoryStats
=
nodeGetMemoryStats
,
/* 0.9.3 */
.
nodeGetCellsFreeMemory
=
nodeGetCellsFreeMemory
,
/* 0.4.4 */
.
nodeGetFreeMemory
=
nodeGetFreeMemory
,
/* 0.4.4 */
.
domainEventRegister
=
qemuDomainEventRegister
,
/* 0.5.0 */
...
...
src/uml/uml_driver.c
浏览文件 @
af35cece
...
...
@@ -2219,6 +2219,7 @@ static virDriver umlDriver = {
.
domainSetAutostart
=
umlDomainSetAutostart
,
/* 0.5.0 */
.
domainBlockPeek
=
umlDomainBlockPeek
,
/* 0.5.0 */
.
nodeGetCPUStats
=
nodeGetCPUStats
,
/* 0.9.3 */
.
nodeGetMemoryStats
=
nodeGetMemoryStats
,
/* 0.9.3 */
.
nodeGetCellsFreeMemory
=
nodeGetCellsFreeMemory
,
/* 0.5.0 */
.
nodeGetFreeMemory
=
nodeGetFreeMemory
,
/* 0.5.0 */
.
isEncrypted
=
umlIsEncrypted
,
/* 0.7.3 */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录