提交 272c6224 编写于 作者: C Cole Robinson

storage: drop the plumbing needed for kvm-img/qcow-create

Remove all the plumbing needed for the different qcow-create/kvm-img
non-raw file creation.

We can drop the error messages because CreateQemuImg will thrown an
error for us but with slightly less fidelity (unable to find qemu-img),
which I think is acceptable given the unlikeliness of that error in
practice.
上级 487d211d
...@@ -151,10 +151,6 @@ static virStorageFileBackendPtr fileBackends[] = { ...@@ -151,10 +151,6 @@ static virStorageFileBackendPtr fileBackends[] = {
}; };
enum {
TOOL_QEMU_IMG,
};
#define READ_BLOCK_SIZE_DEFAULT (1024 * 1024) #define READ_BLOCK_SIZE_DEFAULT (1024 * 1024)
#define WRITE_BLOCK_SIZE_DEFAULT (4 * 1024) #define WRITE_BLOCK_SIZE_DEFAULT (4 * 1024)
...@@ -1219,7 +1215,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, ...@@ -1219,7 +1215,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
return cmd; return cmd;
} }
static int int
virStorageBackendCreateQemuImg(virConnectPtr conn, virStorageBackendCreateQemuImg(virConnectPtr conn,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,
virStorageVolDefPtr vol, virStorageVolDefPtr vol,
...@@ -1235,8 +1231,9 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, ...@@ -1235,8 +1231,9 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
create_tool = virFindFileInPath("qemu-img"); create_tool = virFindFileInPath("qemu-img");
if (!create_tool) { if (!create_tool) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
"%s", _("unable to find qemu-img")); _("creation of non-raw file images is "
"not supported without qemu-img."));
return -1; return -1;
} }
...@@ -1257,44 +1254,10 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, ...@@ -1257,44 +1254,10 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
return ret; return ret;
} }
virStorageBackendBuildVolFrom
virStorageBackendFSImageToolTypeToFunc(int tool_type)
{
switch (tool_type) {
case TOOL_QEMU_IMG:
return virStorageBackendCreateQemuImg;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown file create tool type '%d'."),
tool_type);
}
return NULL;
}
int
virStorageBackendFindFSImageTool(char **tool)
{
int tool_type = -1;
char *tmp = NULL;
if ((tmp = virFindFileInPath("qemu-img")) != NULL)
tool_type = TOOL_QEMU_IMG;
if (tool)
*tool = tmp;
else
VIR_FREE(tmp);
return tool_type;
}
virStorageBackendBuildVolFrom virStorageBackendBuildVolFrom
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol, virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol) virStorageVolDefPtr inputvol)
{ {
int tool_type;
if (!inputvol) if (!inputvol)
return NULL; return NULL;
...@@ -1305,15 +1268,7 @@ virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol, ...@@ -1305,15 +1268,7 @@ virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
vol->target.format != VIR_STORAGE_FILE_RAW) || vol->target.format != VIR_STORAGE_FILE_RAW) ||
(inputvol->type == VIR_STORAGE_VOL_FILE && (inputvol->type == VIR_STORAGE_VOL_FILE &&
inputvol->target.format != VIR_STORAGE_FILE_RAW)) { inputvol->target.format != VIR_STORAGE_FILE_RAW)) {
return virStorageBackendCreateQemuImg;
if ((tool_type = virStorageBackendFindFSImageTool(NULL)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("creation of non-raw file images is "
"not supported without qemu-img."));
return NULL;
}
return virStorageBackendFSImageToolTypeToFunc(tool_type);
} }
if (vol->type == VIR_STORAGE_VOL_PLOOP) if (vol->type == VIR_STORAGE_VOL_PLOOP)
......
...@@ -109,6 +109,12 @@ int virStorageBackendCreateRaw(virConnectPtr conn, ...@@ -109,6 +109,12 @@ int virStorageBackendCreateRaw(virConnectPtr conn,
virStorageVolDefPtr inputvol, virStorageVolDefPtr inputvol,
unsigned int flags); unsigned int flags);
int virStorageBackendCreateQemuImg(virConnectPtr conn,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
unsigned int flags);
int virStorageBackendCreatePloop(virConnectPtr conn, int virStorageBackendCreatePloop(virConnectPtr conn,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,
virStorageVolDefPtr vol, virStorageVolDefPtr vol,
...@@ -126,9 +132,6 @@ bool virStorageBackendIsPloopDir(char *path); ...@@ -126,9 +132,6 @@ bool virStorageBackendIsPloopDir(char *path);
virStorageBackendBuildVolFrom virStorageBackendBuildVolFrom
virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol, virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol); virStorageVolDefPtr inputvol);
int virStorageBackendFindFSImageTool(char **tool);
virStorageBackendBuildVolFrom
virStorageBackendFSImageToolTypeToFunc(int tool_type);
int virStorageBackendFindGlusterPoolSources(const char *host, int virStorageBackendFindGlusterPoolSources(const char *host,
int pooltype, int pooltype,
......
...@@ -1170,7 +1170,6 @@ _virStorageBackendFileSystemVolBuild(virConnectPtr conn, ...@@ -1170,7 +1170,6 @@ _virStorageBackendFileSystemVolBuild(virConnectPtr conn,
unsigned int flags) unsigned int flags)
{ {
virStorageBackendBuildVolFrom create_func; virStorageBackendBuildVolFrom create_func;
int tool_type;
if (inputvol) { if (inputvol) {
if (vol->target.encryption != NULL) { if (vol->target.encryption != NULL) {
...@@ -1190,16 +1189,8 @@ _virStorageBackendFileSystemVolBuild(virConnectPtr conn, ...@@ -1190,16 +1189,8 @@ _virStorageBackendFileSystemVolBuild(virConnectPtr conn,
create_func = createFileDir; create_func = createFileDir;
} else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) { } else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
create_func = virStorageBackendCreatePloop; create_func = virStorageBackendCreatePloop;
} else if ((tool_type = virStorageBackendFindFSImageTool(NULL)) != -1) {
create_func = virStorageBackendFSImageToolTypeToFunc(tool_type);
if (!create_func)
return -1;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, create_func = virStorageBackendCreateQemuImg;
"%s", _("creation of non-raw images "
"is not supported without qemu-img"));
return -1;
} }
if (create_func(conn, pool, vol, inputvol, flags) < 0) if (create_func(conn, pool, vol, inputvol, flags) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册