qemu-img create: cache paramter only use for reg file image
The paramter 'cache' is invalid for host device(/dev/xxx). If 'qemu-img create' operator performed on host device, the host device not support 'cache' would result 'qemu-img create excute' failed. Signed-off-by: Jinhua Cao <caojinhua1@huawei.com>
This commit is contained in:
parent
d3ad6ab6ba
commit
f0684b551e
66
qemu-img-create-cache-paramter-only-use-for-reg-file.patch
Normal file
66
qemu-img-create-cache-paramter-only-use-for-reg-file.patch
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
From 85a876e0d28eac4c71350baede38ca755fdf6df0 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jinhua Cao <caojinhua1@huawei.com>
|
||||||
|
Date: Thu, 24 Mar 2022 17:12:49 +0800
|
||||||
|
Subject: [PATCH] qemu-img create: 'cache' paramter only use for reg file image
|
||||||
|
|
||||||
|
The paramter 'cache' is invalid for host device(/dev/xxx). If
|
||||||
|
'qemu-img create' operator performed on host device, the host
|
||||||
|
device not support 'cache' would result 'qemu-img create' execute
|
||||||
|
failed.
|
||||||
|
|
||||||
|
Signed-off-by: Jinhua Cao <caojinhua1@huawei.com>
|
||||||
|
---
|
||||||
|
qemu-img.c | 30 ++++++++++++++++++++++++------
|
||||||
|
1 file changed, 24 insertions(+), 6 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/qemu-img.c b/qemu-img.c
|
||||||
|
index 9409558772..059bf42fc1 100644
|
||||||
|
--- a/qemu-img.c
|
||||||
|
+++ b/qemu-img.c
|
||||||
|
@@ -496,6 +496,22 @@ static int64_t cvtnum(const char *name, const char *value)
|
||||||
|
return cvtnum_full(name, value, 0, INT64_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
+static bool is_reg_file(const char *filename)
|
||||||
|
+{
|
||||||
|
+ struct stat st;
|
||||||
|
+
|
||||||
|
+ /* file not exist, file will be create later, so it's a reg file */
|
||||||
|
+ if (access(filename, F_OK) == -1) {
|
||||||
|
+ return true;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /* file exist, check file type */
|
||||||
|
+ if (stat(filename, &st) >= 0 && S_ISREG(st.st_mode)) {
|
||||||
|
+ return true;
|
||||||
|
+ }
|
||||||
|
+ return false;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
static int img_create(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
@@ -586,12 +602,14 @@ static int img_create(int argc, char **argv)
|
||||||
|
error_exit("Unexpected argument: %s", argv[optind]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- if (!options) {
|
||||||
|
- options = g_strdup_printf(BLOCK_OPT_CACHE"=%s", cache);
|
||||||
|
- } else {
|
||||||
|
- char *old_options = options;
|
||||||
|
- options = g_strdup_printf("%s,"BLOCK_OPT_CACHE"=%s", options, cache);
|
||||||
|
- g_free(old_options);
|
||||||
|
+ if (is_reg_file(filename)) {
|
||||||
|
+ if (!options) {
|
||||||
|
+ options = g_strdup_printf(BLOCK_OPT_CACHE"=%s", cache);
|
||||||
|
+ } else {
|
||||||
|
+ char *old_options = options;
|
||||||
|
+ options = g_strdup_printf("%s,"BLOCK_OPT_CACHE"=%s", options, cache);
|
||||||
|
+ g_free(old_options);
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
bdrv_img_create(filename, fmt, base_filename, base_fmt,
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
Name: qemu
|
Name: qemu
|
||||||
Version: 6.2.0
|
Version: 6.2.0
|
||||||
Release: 28
|
Release: 29
|
||||||
Epoch: 2
|
Epoch: 2
|
||||||
Summary: QEMU is a generic and open source machine emulator and virtualizer
|
Summary: QEMU is a generic and open source machine emulator and virtualizer
|
||||||
License: GPLv2 and BSD and MIT and CC-BY-SA-4.0
|
License: GPLv2 and BSD and MIT and CC-BY-SA-4.0
|
||||||
@ -236,6 +236,7 @@ Patch0222: scsi-bus-fix-unmatched-object_unref.patch
|
|||||||
Patch0223: tools-virtiofsd-Add-rseq-syscall-to-the-seccomp-allo.patch
|
Patch0223: tools-virtiofsd-Add-rseq-syscall-to-the-seccomp-allo.patch
|
||||||
Patch0224: sw_64-Add-sw64-architecture-support.patch
|
Patch0224: sw_64-Add-sw64-architecture-support.patch
|
||||||
Patch0225: coro-support-live-patch-for-libcare.patch
|
Patch0225: coro-support-live-patch-for-libcare.patch
|
||||||
|
Patch0226: qemu-img-create-cache-paramter-only-use-for-reg-file.patch
|
||||||
|
|
||||||
BuildRequires: flex
|
BuildRequires: flex
|
||||||
BuildRequires: gcc
|
BuildRequires: gcc
|
||||||
@ -696,6 +697,9 @@ getent passwd qemu >/dev/null || \
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Mar 25 2022 Jinhua Cao <caojinhua1@huawei.com>
|
||||||
|
- qemu-img create: 'cache' paramter only use for reg file image
|
||||||
|
|
||||||
* Thu Mar 24 2022 Yan Wang <wangyan122@huawei.com>
|
* Thu Mar 24 2022 Yan Wang <wangyan122@huawei.com>
|
||||||
- spec: add hw-usb-host rpm package
|
- spec: add hw-usb-host rpm package
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user