Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
f7e0594f
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看板
提交
f7e0594f
编写于
8月 07, 2006
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added vcpuinfo vcpupin commands to virsh. Fixed off by one bug in virDomainVcpuPin method
上级
d7815361
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
221 addition
and
1 deletion
+221
-1
ChangeLog
ChangeLog
+8
-0
include/libvirt/libvirt.h
include/libvirt/libvirt.h
+24
-0
src/libvirt.c
src/libvirt.c
+1
-1
src/virsh.c
src/virsh.c
+188
-0
未找到文件。
ChangeLog
浏览文件 @
f7e0594f
Fri Aug 4 20:19:23 EDT 2006 Daniel Berrange <berrange@redhat.com>
* src/libvirt.c: Fix off-by-one in validated VCPU number (it is
zero based, not one based).
* include/libvirt/libvirt.h: Add some convenience macros for
calculating neccessary CPU map lengths & total host CPUs
* src/virsh.c: Add 'vcpuinfo' and 'vcpumap' commands
Fri Aug 4 14:45:25 CEST 2006 Daniel Veillard <veillard@redhat.com>
* python/generator.py: fix the generator when handling long integers
...
...
include/libvirt/libvirt.h
浏览文件 @
f7e0594f
...
...
@@ -167,6 +167,18 @@ struct _virNodeInfo {
unsigned
int
threads
;
/* number of threads per core */
};
/**
* VIR_NODEINFO_MAXCPUS:
* @nodeinfo: virNodeInfo instance
*
* This macro is to calculate the total number of CPUs supported
* but not neccessarily active in the host.
*/
#define VIR_NODEINFO_MAXCPUS(nodeinfo) ((nodeinfo).nodes*(nodeinfo).sockets*(nodeinfo).cores*(nodeinfo).threads)
/**
* virNodeInfoPtr:
*
...
...
@@ -339,6 +351,18 @@ int virDomainPinVcpu (virDomainPtr domain,
#define VIR_UNUSE_CPU(cpumap,cpu) (cpumap[(cpu)/8] &= ~(1<<((cpu)%8)))
/**
* VIR_CPU_MAPLEN
* @cpu: number of physical CPUs
*
* This macro is to be used in conjonction with virDomainPinVcpu() API.
* It returns the length (in bytes) required to store the complete
* CPU map between a single virtual & all physical CPUs of a domain.
*/
#define VIR_CPU_MAPLEN(cpu) (((cpu)+7)/8)
int
virDomainGetVcpus
(
virDomainPtr
domain
,
virVcpuInfoPtr
info
,
int
maxinfo
,
...
...
src/libvirt.c
浏览文件 @
f7e0594f
...
...
@@ -1720,7 +1720,7 @@ virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
}
if
(
domain
->
conn
->
flags
&
VIR_CONNECT_RO
)
return
(
-
1
);
if
((
vcpu
<
1
)
||
(
cpumap
==
NULL
)
||
(
maplen
<
1
))
{
if
((
vcpu
<
0
)
||
(
cpumap
==
NULL
)
||
(
maplen
<
1
))
{
virLibDomainError
(
domain
,
VIR_ERR_INVALID_ARG
,
__FUNCTION__
);
return
(
-
1
);
}
...
...
src/virsh.c
浏览文件 @
f7e0594f
...
...
@@ -207,6 +207,7 @@ static void vshDebug(vshControl * ctl, int level, const char *format, ...);
#define vshPrint(_ctl, ...) fprintf(stdout, __VA_ARGS__)
static
const
char
*
vshDomainStateToString
(
int
state
);
static
const
char
*
vshDomainVcpuStateToString
(
int
state
);
static
int
vshConnectionUsability
(
vshControl
*
ctl
,
virConnectPtr
conn
,
int
showerror
);
...
...
@@ -793,6 +794,175 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
return
ret
;
}
/*
* "vcpuinfo" command
*/
static
vshCmdInfo
info_vcpuinfo
[]
=
{
{
"syntax"
,
"vcpuinfo <domain>"
},
{
"help"
,
"domain vcpu information"
},
{
"desc"
,
"Returns basic information about the domain virtual CPUs."
},
{
NULL
,
NULL
}
};
static
vshCmdOptDef
opts_vcpuinfo
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name, id or uuid"
},
{
NULL
,
0
,
0
,
NULL
}
};
static
int
cmdVcpuinfo
(
vshControl
*
ctl
,
vshCmd
*
cmd
)
{
virDomainInfo
info
;
virDomainPtr
dom
;
virNodeInfo
nodeinfo
;
virVcpuInfoPtr
cpuinfo
;
unsigned
char
*
cpumap
;
int
ncpus
;
size_t
cpumaplen
;
int
ret
=
TRUE
;
if
(
!
vshConnectionUsability
(
ctl
,
ctl
->
conn
,
TRUE
))
return
FALSE
;
if
(
!
(
dom
=
vshCommandOptDomain
(
ctl
,
cmd
,
"domain"
,
NULL
)))
return
FALSE
;
if
(
virNodeGetInfo
(
ctl
->
conn
,
&
nodeinfo
)
!=
0
)
{
virDomainFree
(
dom
);
return
FALSE
;
}
if
(
virDomainGetInfo
(
dom
,
&
info
)
!=
0
)
{
virDomainFree
(
dom
);
return
FALSE
;
}
cpuinfo
=
malloc
(
sizeof
(
virVcpuInfo
)
*
info
.
nrVirtCpu
);
cpumaplen
=
VIR_CPU_MAPLEN
(
VIR_NODEINFO_MAXCPUS
(
nodeinfo
));
cpumap
=
malloc
(
info
.
nrVirtCpu
*
cpumaplen
);
if
((
ncpus
=
virDomainGetVcpus
(
dom
,
cpuinfo
,
info
.
nrVirtCpu
,
cpumap
,
cpumaplen
))
>=
0
)
{
int
n
;
for
(
n
=
0
;
n
<
ncpus
;
n
++
)
{
unsigned
int
m
;
vshPrint
(
ctl
,
"%-15s %d
\n
"
,
"VCPU:"
,
n
);
vshPrint
(
ctl
,
"%-15s %d
\n
"
,
"CPU:"
,
cpuinfo
[
n
].
cpu
);
vshPrint
(
ctl
,
"%-15s %s
\n
"
,
"State:"
,
vshDomainVcpuStateToString
(
cpuinfo
[
n
].
state
));
if
(
cpuinfo
[
n
].
cpuTime
!=
0
)
{
double
cpuUsed
=
cpuinfo
[
n
].
cpuTime
;
cpuUsed
/=
1000000000
.
0
;
vshPrint
(
ctl
,
"%-15s %.1lfs
\n
"
,
"CPU time:"
,
cpuUsed
);
}
vshPrint
(
ctl
,
"%-15s "
,
"CPU Affinity:"
);
for
(
m
=
0
;
m
<
VIR_NODEINFO_MAXCPUS
(
nodeinfo
)
;
m
++
)
{
vshPrint
(
ctl
,
"%c"
,
VIR_CPU_USABLE
(
cpumap
,
cpumaplen
,
n
,
m
)
?
'y'
:
'-'
);
}
vshPrint
(
ctl
,
"
\n
"
);
if
(
n
<
(
ncpus
-
1
))
{
vshPrint
(
ctl
,
"
\n
"
);
}
}
}
else
{
ret
=
FALSE
;
}
free
(
cpumap
);
free
(
cpuinfo
);
virDomainFree
(
dom
);
return
ret
;
}
/*
* "vcpupin" command
*/
static
vshCmdInfo
info_vcpupin
[]
=
{
{
"syntax"
,
"vcpupin <domain>"
},
{
"help"
,
"control domain vcpu affinity"
},
{
"desc"
,
"Pin domain VCPUs to host physical CPUs"
},
{
NULL
,
NULL
}
};
static
vshCmdOptDef
opts_vcpupin
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name, id or uuid"
},
{
"vcpu"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"vcpu number"
},
{
"cpulist"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"host cpu number(s) (comma separated)"
},
{
NULL
,
0
,
0
,
NULL
}
};
static
int
cmdVcpupin
(
vshControl
*
ctl
,
vshCmd
*
cmd
)
{
virDomainInfo
info
;
virDomainPtr
dom
;
virNodeInfo
nodeinfo
;
int
vcpu
;
char
*
cpulist
;
int
ret
=
TRUE
;
int
vcpufound
=
0
;
unsigned
char
*
cpumap
;
int
cpumaplen
;
if
(
!
vshConnectionUsability
(
ctl
,
ctl
->
conn
,
TRUE
))
return
FALSE
;
if
(
!
(
dom
=
vshCommandOptDomain
(
ctl
,
cmd
,
"domain"
,
NULL
)))
return
FALSE
;
vcpu
=
vshCommandOptInt
(
cmd
,
"vcpu"
,
&
vcpufound
);
if
(
!
vcpufound
)
{
virDomainFree
(
dom
);
return
FALSE
;
}
if
(
!
(
cpulist
=
vshCommandOptString
(
cmd
,
"cpulist"
,
NULL
)))
{
virDomainFree
(
dom
);
return
FALSE
;
}
if
(
virNodeGetInfo
(
ctl
->
conn
,
&
nodeinfo
)
!=
0
)
{
virDomainFree
(
dom
);
return
FALSE
;
}
if
(
virDomainGetInfo
(
dom
,
&
info
)
!=
0
)
{
virDomainFree
(
dom
);
return
FALSE
;
}
if
(
vcpu
>=
info
.
nrVirtCpu
)
{
virDomainFree
(
dom
);
return
FALSE
;
}
cpumaplen
=
VIR_CPU_MAPLEN
(
VIR_NODEINFO_MAXCPUS
(
nodeinfo
));
cpumap
=
malloc
(
cpumaplen
);
memset
(
cpumap
,
0
,
cpumaplen
);
do
{
unsigned
int
cpu
=
atoi
(
cpulist
);
if
(
cpu
<
VIR_NODEINFO_MAXCPUS
(
nodeinfo
))
{
VIR_USE_CPU
(
cpumap
,
cpu
);
}
cpulist
=
index
(
cpulist
,
','
);
if
(
cpulist
)
cpulist
++
;
}
while
(
cpulist
);
if
(
virDomainPinVcpu
(
dom
,
vcpu
,
cpumap
,
cpumaplen
)
!=
0
)
{
ret
=
FALSE
;
}
free
(
cpumap
);
virDomainFree
(
dom
);
return
ret
;
}
/*
* "nodeinfo" command
*/
...
...
@@ -1081,6 +1251,8 @@ static vshCmdDef commands[] = {
{
"save"
,
cmdSave
,
opts_save
,
info_save
},
{
"shutdown"
,
cmdShutdown
,
opts_shutdown
,
info_shutdown
},
{
"suspend"
,
cmdSuspend
,
opts_suspend
,
info_suspend
},
{
"vcpuinfo"
,
cmdVcpuinfo
,
opts_vcpuinfo
,
info_vcpuinfo
},
{
"vcpupin"
,
cmdVcpupin
,
opts_vcpupin
,
info_vcpupin
},
{
"version"
,
cmdVersion
,
NULL
,
info_version
},
{
NULL
,
NULL
,
NULL
,
NULL
}
};
...
...
@@ -1643,6 +1815,22 @@ vshDomainStateToString(int state)
return
NULL
;
}
static
const
char
*
vshDomainVcpuStateToString
(
int
state
)
{
switch
(
state
)
{
case
VIR_VCPU_OFFLINE
:
return
"offline"
;
case
VIR_VCPU_BLOCKED
:
return
"blocked"
;
case
VIR_VCPU_RUNNING
:
return
"running"
;
default:
return
"no state"
;
}
return
NULL
;
}
static
int
vshConnectionUsability
(
vshControl
*
ctl
,
virConnectPtr
conn
,
int
showerror
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录