From nobody Tue Apr 23 16:52:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585053920; cv=none; d=zohomail.com; s=zohoarc; b=K6H/hV8/0IA2P7FW8ecQNDKcwlxI7n2jNXmW0thP8xvvMuLDcnFimKIEE4o/sp08te6jjP9IBlUZExUwQgciyX73AbTLVGDvQwQ5F0BoZVTlftMVqSfsB2jEJF9FmQT53UL/EFBf9rFjLLKD8Lz90TaEMzRfWpKFjilLSXfDA7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585053920; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=4TLkJH99v6yqdC4xl+gyK8geRPw6qe1UWVIDJAdEIwE=; b=U4KqKZfH67wOM+42lPE5AWO4W/ekzio/7clq6nN2i4KFide11iMZ6518kpkB7DsT5XDPyppFaA0lWZ0FV6Pd16d6Z524o3v45FWGs4RjT034dvHseWyzqBQO0l5hw2/jcM2MBERdAyjKnSWK5Waq/iWtGCXfpMqtkZ2k+55X7No= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1585053920713961.5114457672179; Tue, 24 Mar 2020 05:45:20 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-365-VUNmpA5SOs6AwVOEe0_wAA-1; Tue, 24 Mar 2020 08:45:15 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E72508017CC; Tue, 24 Mar 2020 12:45:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F1A7395; Tue, 24 Mar 2020 12:45:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5D12A86FF7; Tue, 24 Mar 2020 12:45:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02OCj2Qc020601 for ; Tue, 24 Mar 2020 08:45:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5B1742166B2F; Tue, 24 Mar 2020 12:45:02 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56ACD2166B2A for ; Tue, 24 Mar 2020 12:44:58 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9574A800295 for ; Tue, 24 Mar 2020 12:44:58 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-38-rRn9aQijMICW4tR0IE0i0Q-1; Tue, 24 Mar 2020 08:44:56 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02OCXmdV043643 for ; Tue, 24 Mar 2020 08:44:55 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ywet3hhhw-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 24 Mar 2020 08:44:55 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 24 Mar 2020 12:44:53 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 24 Mar 2020 12:44:52 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 02OCipko51445930 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Mar 2020 12:44:51 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7FAD1AE053; Tue, 24 Mar 2020 12:44:51 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A7E4FAE04D; Tue, 24 Mar 2020 12:44:50 +0000 (GMT) Received: from oc2388111647.ibm.com (unknown [9.85.99.5]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 24 Mar 2020 12:44:50 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585053919; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4TLkJH99v6yqdC4xl+gyK8geRPw6qe1UWVIDJAdEIwE=; b=d9/gokPKHRlibZ+zSolPx4tN0XTIs/sDfo/MAPvpQwGCzUnwa9fKIUztZd2yMI0y4detpx jatGN0QVJ0dBmFI0jbQTKHGwUoT8ZSAWqB6mJCJ1u/Qwm16YtvJSt62z+kIoMZ7tOK3+1E PsTpEGBdl43ry8+fI6ML1KboJFC4Ftc= X-MC-Unique: VUNmpA5SOs6AwVOEe0_wAA-1 X-MC-Unique: rRn9aQijMICW4tR0IE0i0Q-1 From: Seeteena Thoufeek To: libvir-list@redhat.com Subject: [PATCH] qemu_monitor_text.c: Use g_autofree Date: Tue, 24 Mar 2020 18:14:46 +0530 X-TM-AS-GCONF: 00 x-cbid: 20032412-0028-0000-0000-000003EA8F3E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20032412-0029-0000-0000-000024AFF8C4 Message-Id: <1585053886-30333-1-git-send-email-s1seetee@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-24_05:2020-03-23, 2020-03-24 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 spamscore=0 clxscore=1015 phishscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 suspectscore=3 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003240067 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 02OCj2Qc020601 X-loop: libvir-list@redhat.com Cc: s1seetee@linux.vnet.ibm.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Seeteena Thoufeek Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_monitor_text.c | 85 ++++++++++++++++------------------------= ---- 1 file changed, 30 insertions(+), 55 deletions(-) diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 9135a11..5a890af 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -36,27 +36,26 @@ VIR_LOG_INIT("qemu.qemu_monitor_text"); int qemuMonitorTextAddDrive(qemuMonitorPtr mon, const char *drivestr) { - char *cmd =3D NULL; - char *reply =3D NULL; - int ret =3D -1; + g_autofree char *cmd =3D NULL; + g_autofree char *reply =3D NULL; =20 /* 'dummy' here is just a placeholder since there is no PCI * address required when attaching drives to a controller */ cmd =3D g_strdup_printf("drive_add dummy %s", drivestr); =20 if (qemuMonitorJSONHumanCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; =20 if (strstr(reply, "unknown command:")) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("drive hotplug is not supported")); - goto cleanup; + return -1; } =20 if (strstr(reply, "could not open disk image")) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("open disk image file failed")); - goto cleanup; + return -1; } =20 if (strstr(reply, "Could not open")) { @@ -66,48 +65,41 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon, =20 virReportError(VIR_ERR_OPERATION_FAILED, "%s", reply); - goto cleanup; + return -1; } =20 if (strstr(reply, "Image is not in")) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("Incorrect disk format")); - goto cleanup; + return -1; } =20 if (strstr(reply, "IOMMU") || strstr(reply, "VFIO")) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", reply); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(cmd); - VIR_FREE(reply); - return ret; + return 0; } =20 =20 int qemuMonitorTextDriveDel(qemuMonitorPtr mon, const char *drivestr) { - char *cmd =3D NULL; - char *reply =3D NULL; - int ret =3D -1; + g_autofree char *cmd =3D NULL; + g_autofree char *reply =3D NULL; =20 cmd =3D g_strdup_printf("drive_del %s", drivestr); =20 if (qemuMonitorJSONHumanCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; =20 if (strstr(reply, "unknown command:")) { VIR_ERROR(_("deleting drive is not supported. " "This may leak data if disk is reassigned")); - ret =3D 1; - goto cleanup; + return 1; =20 /* (qemu) drive_del wark * Device 'wark' not found */ @@ -117,15 +109,10 @@ int qemuMonitorTextDriveDel(qemuMonitorPtr mon, } else if (STRNEQ(reply, "")) { virReportError(VIR_ERR_OPERATION_FAILED, _("deleting %s drive failed: %s"), drivestr, reply); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(cmd); - VIR_FREE(reply); - return ret; + return 0; } =20 int @@ -159,28 +146,27 @@ qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon, =20 int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, const char *name) { - char *cmd =3D NULL; - char *reply =3D NULL; - int ret =3D -1; + g_autofree char *cmd =3D NULL; + g_autofree char *reply =3D NULL; =20 cmd =3D g_strdup_printf("loadvm \"%s\"", name); =20 if (qemuMonitorJSONHumanCommand(mon, cmd, &reply)) - goto cleanup; + return -1; =20 if (strstr(reply, "No block device supports snapshots")) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("this domain does not have a device to load snaps= hots")); - goto cleanup; + return -1; } else if (strstr(reply, "Could not find snapshot")) { virReportError(VIR_ERR_OPERATION_INVALID, _("the snapshot '%s' does not exist, and was not lo= aded"), name); - goto cleanup; + return -1; } else if (strstr(reply, "Snapshots not supported on device")) { virReportError(VIR_ERR_OPERATION_INVALID, _("Failed to load snapshot: %s"), reply); - goto cleanup; + return -1; } else if (strstr(reply, "Could not open VM state file") || strstr(reply, "Error: ") || (strstr(reply, "Error") && @@ -188,46 +174,35 @@ int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, c= onst char *name) strstr(reply, "while activating snapshot on")))) { virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to load snapshot: %s"), reply); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(cmd); - VIR_FREE(reply); - return ret; + return 0; } =20 int qemuMonitorTextDeleteSnapshot(qemuMonitorPtr mon, const char *name) { - char *cmd =3D NULL; - char *reply =3D NULL; - int ret =3D -1; + g_autofree char *cmd =3D NULL; + g_autofree char *reply =3D NULL; =20 cmd =3D g_strdup_printf("delvm \"%s\"", name); if (qemuMonitorJSONHumanCommand(mon, cmd, &reply)) - goto cleanup; + return -1; =20 if (strstr(reply, "No block device supports snapshots")) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("this domain does not have a device to delete sna= pshots")); - goto cleanup; + return -1; } else if (strstr(reply, "Snapshots not supported on device")) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", reply); - goto cleanup; + return -1; } else if (strstr(reply, "Error: ") || (strstr(reply, "Error") && strstr(reply, "while deleting snapshot"))) { virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to delete snapshot: %s"), reply); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(cmd); - VIR_FREE(reply); - return ret; + return 0; } --=20 1.8.3.1