Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
3447b53f
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看板
提交
3447b53f
编写于
12月 14, 2005
作者:
D
Daniel Veillard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* src/xml.c: started to add block devices and interfaces descriptions
in the XML dump. Daniel
上级
a4de636a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
233 addition
and
0 deletion
+233
-0
ChangeLog
ChangeLog
+5
-0
src/xml.c
src/xml.c
+228
-0
未找到文件。
ChangeLog
浏览文件 @
3447b53f
Wed Dec 14 12:20:06 CET 2005 Daniel Veillard <veillard@redhat.com>
* src/xml.c: started to add block devices and interfaces descriptions
in the XML dump.
Tue Dec 13 17:20:11 CET 2005 Daniel Veillard <veillard@redhat.com>
* include/libvir.h src/Makefile.am src/internal.h src/libvir.c
...
...
src/xml.c
浏览文件 @
3447b53f
...
...
@@ -132,6 +132,228 @@ virBufferVSprintf(virBufferPtr buf, const char *format, ...) {
return
(
0
);
}
/**
* virDomainGetXMLDevice:
* @domain: a domain object
* @sub: the xenstore subsection 'vbd', 'vif', ...
* @dev: the xenstrore internal device number
* @name: the value's name
*
* Extract one information the device used by the domain from xensttore
*
* Returns the new string or NULL in case of error
*/
static
char
*
virDomainGetXMLDeviceInfo
(
virDomainPtr
domain
,
const
char
*
sub
,
long
dev
,
const
char
*
name
)
{
struct
xs_transaction_handle
*
t
;
char
s
[
256
];
char
*
ret
=
NULL
;
unsigned
int
len
=
0
;
snprintf
(
s
,
255
,
"/local/domain/0/backend/%s/%d/%ld/%s"
,
sub
,
domain
->
handle
,
dev
,
name
);
s
[
255
]
=
0
;
t
=
xs_transaction_start
(
domain
->
conn
->
xshandle
);
if
(
t
==
NULL
)
goto
done
;
ret
=
xs_read
(
domain
->
conn
->
xshandle
,
t
,
&
s
[
0
],
&
len
);
done:
if
(
t
!=
NULL
)
xs_transaction_end
(
domain
->
conn
->
xshandle
,
t
,
0
);
return
(
ret
);
}
/**
* virDomainGetXMLDevice:
* @domain: a domain object
* @buf: the output buffer object
* @dev: the xenstrore internal device number
*
* Extract and dump in the buffer informations on the device used by the domain
*
* Returns 0 in case of success, -1 in case of failure
*/
static
int
virDomainGetXMLDevice
(
virDomainPtr
domain
,
virBufferPtr
buf
,
long
dev
)
{
char
*
type
,
*
val
;
type
=
virDomainGetXMLDeviceInfo
(
domain
,
"vbd"
,
dev
,
"type"
);
if
(
type
==
NULL
)
return
(
-
1
);
if
(
!
strcmp
(
type
,
"file"
))
{
virBufferVSprintf
(
buf
,
" <disk type='file'>
\n
"
);
val
=
virDomainGetXMLDeviceInfo
(
domain
,
"vbd"
,
dev
,
"params"
);
if
(
val
!=
NULL
)
{
virBufferVSprintf
(
buf
,
" <source file='%s'/>
\n
"
,
val
);
free
(
val
);
}
val
=
virDomainGetXMLDeviceInfo
(
domain
,
"vbd"
,
dev
,
"dev"
);
if
(
val
!=
NULL
)
{
virBufferVSprintf
(
buf
,
" <target dev='%s'/>
\n
"
,
val
);
free
(
val
);
}
virBufferAdd
(
buf
,
" </disk>
\n
"
,
12
);
}
else
{
TODO
fprintf
(
stderr
,
"Don't know how to handle device type %s
\n
"
,
type
);
}
free
(
type
);
return
(
0
);
}
/**
* virDomainGetXMLDevices:
* @domain: a domain object
* @buf: the output buffer object
*
* Extract the devices used by the domain and dumps then in the buffer
*
* Returns 0 in case of success, -1 in case of failure
*/
static
int
virDomainGetXMLDevices
(
virDomainPtr
domain
,
virBufferPtr
buf
)
{
struct
xs_transaction_handle
*
t
;
int
ret
=
-
1
;
unsigned
int
num
,
i
;
long
id
;
char
**
list
=
NULL
,
*
endptr
;
char
backend
[
200
];
virConnectPtr
conn
;
conn
=
domain
->
conn
;
if
((
conn
==
NULL
)
||
(
conn
->
magic
!=
VIR_CONNECT_MAGIC
))
return
(
-
1
);
t
=
xs_transaction_start
(
conn
->
xshandle
);
if
(
t
==
NULL
)
goto
done
;
snprintf
(
backend
,
199
,
"/local/domain/0/backend/vbd/%d"
,
virDomainGetID
(
domain
));
backend
[
199
]
=
0
;
list
=
xs_directory
(
conn
->
xshandle
,
t
,
backend
,
&
num
);
ret
=
0
;
if
(
list
==
NULL
)
goto
done
;
for
(
i
=
0
;
i
<
num
;
i
++
)
{
id
=
strtol
(
list
[
i
],
&
endptr
,
10
);
if
((
endptr
==
list
[
i
])
||
(
*
endptr
!=
0
))
{
ret
=
-
1
;
goto
done
;
}
virDomainGetXMLDevice
(
domain
,
buf
,
id
);
}
done:
if
(
t
!=
NULL
)
xs_transaction_end
(
conn
->
xshandle
,
t
,
0
);
if
(
list
!=
NULL
)
free
(
list
);
return
(
ret
);
}
/**
* virDomainGetXMLInterface:
* @domain: a domain object
* @buf: the output buffer object
* @dev: the xenstrore internal device number
*
* Extract and dump in the buffer informations on the interface used by
* the domain
*
* Returns 0 in case of success, -1 in case of failure
*/
static
int
virDomainGetXMLInterface
(
virDomainPtr
domain
,
virBufferPtr
buf
,
long
dev
)
{
char
*
type
,
*
val
;
type
=
virDomainGetXMLDeviceInfo
(
domain
,
"vif"
,
dev
,
"bridge"
);
if
(
type
==
NULL
)
{
TODO
fprintf
(
stderr
,
"Don't know how to handle non bridge interfaces
\n
"
);
return
(
-
1
);
}
else
{
virBufferVSprintf
(
buf
,
" <interface type='bridge'>
\n
"
);
virBufferVSprintf
(
buf
,
" <source bridge='%s'/>
\n
"
,
type
);
val
=
virDomainGetXMLDeviceInfo
(
domain
,
"vif"
,
dev
,
"mac"
);
if
(
val
!=
NULL
)
{
virBufferVSprintf
(
buf
,
" <mac address='%s'/>
\n
"
,
val
);
free
(
val
);
}
val
=
virDomainGetXMLDeviceInfo
(
domain
,
"vif"
,
dev
,
"script"
);
if
(
val
!=
NULL
)
{
virBufferVSprintf
(
buf
,
" <script path='%s'/>
\n
"
,
val
);
free
(
val
);
}
virBufferAdd
(
buf
,
" </interface>
\n
"
,
17
);
}
free
(
type
);
return
(
0
);
}
/**
* virDomainGetXMLInterfaces:
* @domain: a domain object
* @buf: the output buffer object
*
* Extract the interfaces used by the domain and dumps then in the buffer
*
* Returns 0 in case of success, -1 in case of failure
*/
static
int
virDomainGetXMLInterfaces
(
virDomainPtr
domain
,
virBufferPtr
buf
)
{
struct
xs_transaction_handle
*
t
;
int
ret
=
-
1
;
unsigned
int
num
,
i
;
long
id
;
char
**
list
=
NULL
,
*
endptr
;
char
backend
[
200
];
virConnectPtr
conn
;
conn
=
domain
->
conn
;
if
((
conn
==
NULL
)
||
(
conn
->
magic
!=
VIR_CONNECT_MAGIC
))
return
(
-
1
);
t
=
xs_transaction_start
(
conn
->
xshandle
);
if
(
t
==
NULL
)
goto
done
;
snprintf
(
backend
,
199
,
"/local/domain/0/backend/vif/%d"
,
virDomainGetID
(
domain
));
backend
[
199
]
=
0
;
list
=
xs_directory
(
conn
->
xshandle
,
t
,
backend
,
&
num
);
ret
=
0
;
if
(
list
==
NULL
)
goto
done
;
for
(
i
=
0
;
i
<
num
;
i
++
)
{
id
=
strtol
(
list
[
i
],
&
endptr
,
10
);
if
((
endptr
==
list
[
i
])
||
(
*
endptr
!=
0
))
{
ret
=
-
1
;
goto
done
;
}
virDomainGetXMLInterface
(
domain
,
buf
,
id
);
}
done:
if
(
t
!=
NULL
)
xs_transaction_end
(
conn
->
xshandle
,
t
,
0
);
if
(
list
!=
NULL
)
free
(
list
);
return
(
ret
);
}
/**
* virDomainGetXMLDesc:
* @domain: a domain object
...
...
@@ -166,6 +388,12 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) {
virBufferVSprintf
(
&
buf
,
"<domain type='xen' id='%d'>
\n
"
,
virDomainGetID
(
domain
));
virBufferVSprintf
(
&
buf
,
" <name>%s</name>
\n
"
,
virDomainGetName
(
domain
));
virBufferVSprintf
(
&
buf
,
" <memory>%lu</memory>
\n
"
,
info
.
maxMem
);
virBufferVSprintf
(
&
buf
,
" <vcpu>%d</vcpu>
\n
"
,
(
int
)
info
.
nrVirtCpu
);
virBufferAdd
(
&
buf
,
" <devices>
\n
"
,
12
);
virDomainGetXMLDevices
(
domain
,
&
buf
);
virDomainGetXMLInterfaces
(
domain
,
&
buf
);
virBufferAdd
(
&
buf
,
" </devices>
\n
"
,
13
);
virBufferAdd
(
&
buf
,
"</domain>
\n
"
,
10
);
buf
.
content
[
buf
.
use
]
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录