Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
a1674fd9
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看板
提交
a1674fd9
编写于
7月 14, 2016
作者:
P
Peter Krempa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
util: storage: Add JSON backing volume parser for 'nbd' protocol
上级
3236bb23
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
75 addition
and
0 deletion
+75
-0
src/util/virstoragefile.c
src/util/virstoragefile.c
+45
-0
tests/virstoragetest.c
tests/virstoragetest.c
+30
-0
未找到文件。
src/util/virstoragefile.c
浏览文件 @
a1674fd9
...
@@ -2702,6 +2702,50 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
...
@@ -2702,6 +2702,50 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
}
}
static
int
virStorageSourceParseBackingJSONNbd
(
virStorageSourcePtr
src
,
virJSONValuePtr
json
,
int
opaque
ATTRIBUTE_UNUSED
)
{
const
char
*
path
=
virJSONValueObjectGetString
(
json
,
"path"
);
const
char
*
host
=
virJSONValueObjectGetString
(
json
,
"host"
);
const
char
*
port
=
virJSONValueObjectGetString
(
json
,
"port"
);
const
char
*
export
=
virJSONValueObjectGetString
(
json
,
"export"
);
if
(
!
path
&&
!
host
)
{
virReportError
(
VIR_ERR_INVALID_ARG
,
"%s"
,
_
(
"missing path or host of NBD server in JSON backing "
"volume definition"
));
return
-
1
;
}
src
->
type
=
VIR_STORAGE_TYPE_NETWORK
;
src
->
protocol
=
VIR_STORAGE_NET_PROTOCOL_NBD
;
if
(
VIR_STRDUP
(
src
->
path
,
export
)
<
0
)
return
-
1
;
if
(
VIR_ALLOC_N
(
src
->
hosts
,
1
)
<
0
)
return
-
1
;
src
->
nhosts
=
1
;
if
(
path
)
{
src
->
hosts
[
0
].
transport
=
VIR_STORAGE_NET_HOST_TRANS_UNIX
;
if
(
VIR_STRDUP
(
src
->
hosts
[
0
].
socket
,
path
)
<
0
)
return
-
1
;
}
else
{
src
->
hosts
[
0
].
transport
=
VIR_STORAGE_NET_HOST_TRANS_TCP
;
if
(
VIR_STRDUP
(
src
->
hosts
[
0
].
name
,
host
)
<
0
)
return
-
1
;
if
(
VIR_STRDUP
(
src
->
hosts
[
0
].
port
,
port
)
<
0
)
return
-
1
;
}
return
0
;
}
struct
virStorageSourceJSONDriverParser
{
struct
virStorageSourceJSONDriverParser
{
const
char
*
drvname
;
const
char
*
drvname
;
int
(
*
func
)(
virStorageSourcePtr
src
,
virJSONValuePtr
json
,
int
opaque
);
int
(
*
func
)(
virStorageSourcePtr
src
,
virJSONValuePtr
json
,
int
opaque
);
...
@@ -2719,6 +2763,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
...
@@ -2719,6 +2763,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
{
"tftp"
,
virStorageSourceParseBackingJSONUri
,
VIR_STORAGE_NET_PROTOCOL_TFTP
},
{
"tftp"
,
virStorageSourceParseBackingJSONUri
,
VIR_STORAGE_NET_PROTOCOL_TFTP
},
{
"gluster"
,
virStorageSourceParseBackingJSONGluster
,
0
},
{
"gluster"
,
virStorageSourceParseBackingJSONGluster
,
0
},
{
"iscsi"
,
virStorageSourceParseBackingJSONiSCSI
,
0
},
{
"iscsi"
,
virStorageSourceParseBackingJSONiSCSI
,
0
},
{
"nbd"
,
virStorageSourceParseBackingJSONNbd
,
0
},
};
};
...
...
tests/virstoragetest.c
浏览文件 @
a1674fd9
...
@@ -1437,6 +1437,36 @@ mymain(void)
...
@@ -1437,6 +1437,36 @@ mymain(void)
" <host transport='unix' socket='/path/socket'/>
\n
"
" <host transport='unix' socket='/path/socket'/>
\n
"
" <host name='example.com'/>
\n
"
" <host name='example.com'/>
\n
"
"</source>
\n
"
);
"</source>
\n
"
);
TEST_BACKING_PARSE
(
"json:{
\"
file
\"
:{
\"
driver
\"
:
\"
nbd
\"
,"
"
\"
path
\"
:
\"
/path/to/socket
\"
"
"}"
"}"
,
"<source protocol='nbd'>
\n
"
" <host transport='unix' socket='/path/to/socket'/>
\n
"
"</source>
\n
"
);
TEST_BACKING_PARSE
(
"json:{
\"
file.driver
\"
:
\"
nbd
\"
,"
"
\"
file.path
\"
:
\"
/path/to/socket
\"
"
"}"
,
"<source protocol='nbd'>
\n
"
" <host transport='unix' socket='/path/to/socket'/>
\n
"
"</source>
\n
"
);
TEST_BACKING_PARSE
(
"json:{
\"
file
\"
:{
\"
driver
\"
:
\"
nbd
\"
,"
"
\"
export
\"
:
\"
blah
\"
,"
"
\"
host
\"
:
\"
example.org
\"
,"
"
\"
port
\"
:
\"
6000
\"
"
"}"
"}"
,
"<source protocol='nbd' name='blah'>
\n
"
" <host name='example.org' port='6000'/>
\n
"
"</source>
\n
"
);
TEST_BACKING_PARSE
(
"json:{
\"
file.driver
\"
:
\"
nbd
\"
,"
"
\"
file.export
\"
:
\"
blah
\"
,"
"
\"
file.host
\"
:
\"
example.org
\"
,"
"
\"
file.port
\"
:
\"
6000
\"
"
"}"
,
"<source protocol='nbd' name='blah'>
\n
"
" <host name='example.org' port='6000'/>
\n
"
"</source>
\n
"
);
cleanup:
cleanup:
/* Final cleanup */
/* Final cleanup */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录