Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
c6e87d1a
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看板
提交
c6e87d1a
编写于
2月 18, 2013
作者:
J
Ján Tomko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
storage: separate qemu-img command generation and execution
This allows us to create a test for the generated command line.
上级
41c73f66
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
39 deletion
+67
-39
src/storage/storage_backend.c
src/storage/storage_backend.c
+59
-39
src/storage/storage_backend.h
src/storage/storage_backend.h
+8
-0
未找到文件。
src/storage/storage_backend.c
浏览文件 @
c6e87d1a
...
...
@@ -636,17 +636,15 @@ cleanup:
return
ret
;
}
static
int
virStorageBackendCreateQemuImg
(
virConnectPtr
conn
,
virStoragePoolObjPtr
pool
,
virStorageVolDefPtr
vol
,
virStorageVolDefPtr
inputvol
,
unsigned
int
flags
)
virCommandPtr
virStorageBackendCreateQemuImgCmd
(
virConnectPtr
conn
,
virStoragePoolObjPtr
pool
,
virStorageVolDefPtr
vol
,
virStorageVolDefPtr
inputvol
,
unsigned
int
flags
,
const
char
*
create_tool
,
int
imgformat
)
{
int
ret
=
-
1
;
char
*
create_tool
;
int
imgformat
=
-
1
;
virCommandPtr
cmd
=
NULL
;
bool
do_encryption
=
(
vol
->
target
.
encryption
!=
NULL
);
unsigned
long
long
int
size_arg
;
...
...
@@ -674,18 +672,18 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"unknown storage vol type %d"
),
vol
->
target
.
format
);
return
-
1
;
return
NULL
;
}
if
(
inputvol
&&
inputType
==
NULL
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"unknown storage vol type %d"
),
inputvol
->
target
.
format
);
return
-
1
;
return
NULL
;
}
if
(
preallocate
&&
vol
->
target
.
format
!=
VIR_STORAGE_FILE_QCOW2
)
{
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
"%s"
,
_
(
"metadata preallocation only available with qcow2"
));
return
-
1
;
return
NULL
;
}
if
(
vol
->
backingStore
.
path
)
{
...
...
@@ -696,7 +694,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
"%s"
,
_
(
"metadata preallocation conflicts with backing"
" store"
));
return
-
1
;
return
NULL
;
}
/* XXX: Not strictly required: qemu-img has an option a different
...
...
@@ -709,14 +707,14 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"a different backing store cannot "
"be specified."
));
return
-
1
;
return
NULL
;
}
if
(
backingType
==
NULL
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"unknown storage vol backing store type %d"
),
vol
->
backingStore
.
format
);
return
-
1
;
return
NULL
;
}
/* Convert relative backing store paths to absolute paths for access
...
...
@@ -726,7 +724,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virAsprintf
(
&
absolutePath
,
"%s/%s"
,
pool
->
def
->
target
.
path
,
vol
->
backingStore
.
path
)
<
0
)
{
virReportOOMError
();
return
-
1
;
return
NULL
;
}
accessRetCode
=
access
(
absolutePath
?
absolutePath
:
vol
->
backingStore
.
path
,
R_OK
);
...
...
@@ -735,7 +733,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virReportSystemError
(
errno
,
_
(
"inaccessible backing store volume %s"
),
vol
->
backingStore
.
path
);
return
-
1
;
return
NULL
;
}
}
...
...
@@ -747,7 +745,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
_
(
"qcow volume encryption unsupported with "
"volume format %s"
),
type
);
return
-
1
;
return
NULL
;
}
enc
=
vol
->
target
.
encryption
;
if
(
enc
->
format
!=
VIR_STORAGE_ENCRYPTION_FORMAT_QCOW
&&
...
...
@@ -755,38 +753,23 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virReportError
(
VIR_ERR_CONFIG_UNSUPPORTED
,
_
(
"unsupported volume encryption format %d"
),
vol
->
target
.
encryption
->
format
);
return
-
1
;
return
NULL
;
}
if
(
enc
->
nsecrets
>
1
)
{
virReportError
(
VIR_ERR_XML_ERROR
,
"%s"
,
_
(
"too many secrets for qcow encryption"
));
return
-
1
;
return
NULL
;
}
if
(
enc
->
format
==
VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT
||
enc
->
nsecrets
==
0
)
{
if
(
virStorageGenerateQcowEncryption
(
conn
,
vol
)
<
0
)
return
-
1
;
return
NULL
;
}
}
/* Size in KB */
size_arg
=
VIR_DIV_UP
(
vol
->
capacity
,
1024
);
/* KVM is usually ahead of qemu on features, so try that first */
create_tool
=
virFindFileInPath
(
"kvm-img"
);
if
(
!
create_tool
)
create_tool
=
virFindFileInPath
(
"qemu-img"
);
if
(
!
create_tool
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"unable to find kvm-img or qemu-img"
));
return
-
1
;
}
imgformat
=
virStorageBackendQEMUImgBackingFormat
(
create_tool
);
if
(
imgformat
<
0
)
goto
cleanup
;
cmd
=
virCommandNew
(
create_tool
);
if
(
inputvol
)
{
...
...
@@ -849,11 +832,48 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
}
}
return
cmd
;
}
static
int
virStorageBackendCreateQemuImg
(
virConnectPtr
conn
,
virStoragePoolObjPtr
pool
,
virStorageVolDefPtr
vol
,
virStorageVolDefPtr
inputvol
,
unsigned
int
flags
)
{
int
ret
=
-
1
;
const
char
*
create_tool
;
int
imgformat
;
virCommandPtr
cmd
;
virCheckFlags
(
VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA
,
-
1
);
/* KVM is usually ahead of qemu on features, so try that first */
create_tool
=
virFindFileInPath
(
"kvm-img"
);
if
(
!
create_tool
)
create_tool
=
virFindFileInPath
(
"qemu-img"
);
if
(
!
create_tool
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"unable to find kvm-img or qemu-img"
));
return
-
1
;
}
imgformat
=
virStorageBackendQEMUImgBackingFormat
(
create_tool
);
if
(
imgformat
<
0
)
goto
cleanup
;
cmd
=
virStorageBackendCreateQemuImgCmd
(
conn
,
pool
,
vol
,
inputvol
,
flags
,
create_tool
,
imgformat
);
if
(
!
cmd
)
goto
cleanup
;
ret
=
virStorageBackendCreateExecCommand
(
pool
,
vol
,
cmd
);
virCommandFree
(
cmd
);
cleanup:
VIR_FREE
(
create_tool
);
virCommandFree
(
cmd
);
return
ret
;
}
...
...
src/storage/storage_backend.h
浏览文件 @
c6e87d1a
...
...
@@ -156,5 +156,13 @@ int virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
virStorageBackendListVolNulFunc
func
,
void
*
data
);
virCommandPtr
virStorageBackendCreateQemuImgCmd
(
virConnectPtr
conn
,
virStoragePoolObjPtr
pool
,
virStorageVolDefPtr
vol
,
virStorageVolDefPtr
inputvol
,
unsigned
int
flags
,
const
char
*
create_tool
,
int
imgformat
);
#endif
/* __VIR_STORAGE_BACKEND_H__ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录