1 Star 0 Fork 71

wangyangdahai/libvirt

forked from src-openEuler/libvirt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
qemuMonitorJSON-Add-Remove-Netdev-Refactor-cleanup.patch 3.09 KB
一键复制 编辑 原始数据 按行查看 历史
imxcc 提交于 2022-02-22 00:16 . update patch with openeuler !54
From 3e1026fb3619aae6b1be4879797474d10d22a54c Mon Sep 17 00:00:00 2001
From: Peter Krempa <pkrempa@redhat.com>
Date: Fri, 15 May 2020 11:16:32 +0200
Subject: [PATCH 08/18] qemuMonitorJSON(Add|Remove)Netdev: Refactor cleanup
Use automatic pointer cleanup for virJSONValuePtrs to get rid of the
cleanup label and ret variable.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
src/qemu/qemu_monitor_json.c | 52 +++++++++++++++---------------------
1 file changed, 22 insertions(+), 30 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index ef25764a98..e6b5c7140e 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3991,13 +3991,13 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
}
-int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
- const char *netdevstr)
+int
+qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
+ const char *netdevstr)
{
- int ret = -1;
- virJSONValuePtr cmd = NULL;
- virJSONValuePtr reply = NULL;
- virJSONValuePtr args = NULL;
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+ g_autoptr(virJSONValue) args = NULL;
cmd = qemuMonitorJSONMakeCommand("netdev_add", NULL);
if (!cmd)
@@ -4005,49 +4005,41 @@ int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
args = qemuMonitorJSONKeywordStringToJSON(netdevstr, "type");
if (!args)
- goto cleanup;
+ return -1;
if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
- goto cleanup;
+ return -1;
args = NULL; /* obj owns reference to args now */
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
- goto cleanup;
+ return -1;
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- virJSONValueFree(args);
- virJSONValueFree(cmd);
- virJSONValueFree(reply);
- return ret;
+ return 0;
}
-int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
- const char *alias)
+int
+qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
+ const char *alias)
{
- int ret = -1;
- virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("netdev_del",
- "s:id", alias,
- NULL);
- virJSONValuePtr reply = NULL;
+ g_autoptr(virJSONValue) cmd = qemuMonitorJSONMakeCommand("netdev_del",
+ "s:id", alias,
+ NULL);
+ g_autoptr(virJSONValue) reply = NULL;
+
if (!cmd)
return -1;
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
- goto cleanup;
+ return -1;
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- virJSONValueFree(cmd);
- virJSONValueFree(reply);
- return ret;
+ return 0;
}
--
2.23.0.windows.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangyangdahai/libvirt.git
git@gitee.com:wangyangdahai/libvirt.git
wangyangdahai
libvirt
libvirt
master

搜索帮助