1 Star 0 Fork 131

src-openeuler-fork/qemu

forked from src-openEuler/qemu 
Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
qemu-img-create-cache-paramter-only-use-for-reg-file.patch 1.99 KB
Copy Edit Raw Blame History
From 9ca9391acb780f15a6d8769339e7cd0edf457529 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 80adee2620..49d914c9c4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -508,6 +508,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;
@@ -598,12 +614,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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler-fork/qemu.git
git@gitee.com:src-openeuler-fork/qemu.git
src-openeuler-fork
qemu
qemu
master

Search