From 9abf18ace7fc0b99f5ec66a57bb4036c48791345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Fri, 10 Dec 2021 17:25:04 +0100 Subject: [PATCH] util: iscsi: use two vars in CreateIfaceIQN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not mix automatic and manual cleanup. Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- src/util/viriscsi.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index ab4363a5ab..e84d49b03c 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -208,7 +208,8 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn, int exitstatus = -1; g_autofree char *iface_name = NULL; g_autofree char *temp_ifacename = NULL; - g_autoptr(virCommand) cmd = NULL; + g_autoptr(virCommand) newcmd = NULL; + g_autoptr(virCommand) updatecmd = NULL; temp_ifacename = g_strdup_printf("libvirt-iface-%08llx", (unsigned long long)virRandomBits(32)); @@ -216,35 +217,34 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriqn, VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'", temp_ifacename, initiatoriqn); - cmd = virCommandNewArgList(ISCSIADM, - "--mode", "iface", - "--interface", temp_ifacename, - "--op", "new", - NULL); + newcmd = virCommandNewArgList(ISCSIADM, + "--mode", "iface", + "--interface", temp_ifacename, + "--op", "new", + NULL); /* Note that we ignore the exitstatus. Older versions of iscsiadm * tools returned an exit status of > 0, even if they succeeded. * We will just rely on whether the interface got created * properly. */ - if (virCommandRun(cmd, &exitstatus) < 0) { + if (virCommandRun(newcmd, &exitstatus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' to create new iscsi interface"), ISCSIADM); return -1; } - virCommandFree(cmd); - cmd = virCommandNewArgList(ISCSIADM, - "--mode", "iface", - "--interface", temp_ifacename, - "--op", "update", - "--name", "iface.initiatorname", - "--value", - initiatoriqn, - NULL); + updatecmd = virCommandNewArgList(ISCSIADM, + "--mode", "iface", + "--interface", temp_ifacename, + "--op", "update", + "--name", "iface.initiatorname", + "--value", + initiatoriqn, + NULL); /* Note that we ignore the exitstatus. Older versions of iscsiadm tools * returned an exit status of > 0, even if they succeeded. We will just * rely on whether iface file got updated properly. */ - if (virCommandRun(cmd, &exitstatus) < 0) { + if (virCommandRun(updatecmd, &exitstatus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to run command '%s' to update iscsi interface with IQN '%s'"), ISCSIADM, initiatoriqn);