From patchwork Wed Nov 7 13:09:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 10672351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4DED14D6 for ; Wed, 7 Nov 2018 13:15:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A306328DBF for ; Wed, 7 Nov 2018 13:15:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96D2E2BB18; Wed, 7 Nov 2018 13:15:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1F1A828DBF for ; Wed, 7 Nov 2018 13:15:30 +0000 (UTC) Received: from localhost ([::1]:48175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNgA-00054L-6O for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Nov 2018 08:15:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKNbb-0006pc-CK for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:10:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKNba-0002th-3E for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:10:47 -0500 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:35496) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKNbZ-0002BT-B3 for qemu-devel@nongnu.org; Wed, 07 Nov 2018 08:10:45 -0500 Received: by mail-qk1-x741.google.com with SMTP id v68-v6so20648751qka.2 for ; Wed, 07 Nov 2018 05:10:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TBubUBsR2Xuuqks167Ohlds4cljvN8VUgNwJt2kmpOI=; b=DjpjPf4LK4EMYxqZp+hPdObJ+t7W1bc42VyxhofYfOSIcgCN+9AFKVuEobFxB0KuYf pF0J/rWwVR2ymYaf9HKpB27rur8k3K9CQ9AgHY6AUJXpCK8i14T9IzrOoeSWDa8El3+g 3EUph2e1cKrbBwb8J61TWny7ZbH5SDE7kbgUF6qyAqkIJfWGVl/CDmwaqF3zgzskrCEK anC/6clWennIZj854+/fQHr/w43P1gNDcWQ0yDIMI6LBzBeIGZnq1UaD5y7hcCslaS/e iSdZhATrYrwkM+LrsDPINBEvxhAnoIC3K3xgd5GzdDqtU7HFrfjCx2uQzJ6SBoePoYKs XSEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TBubUBsR2Xuuqks167Ohlds4cljvN8VUgNwJt2kmpOI=; b=lZvJV5FA7X2CMN+8/l1tCMbPcKe8HXTkzGQOsB0CCLzsCb/BZSMQlUn0X2tLpQilz+ tOktsfcfaUeyKO+v3gyuDZv4DHKxarnXR2fa6Ww9soAxIzh/G41Pbt9Aa32xA2zDwjLr /MSHhQX8E3cdolkdncHQHlejDP77olqvKfIe5WhSwsqSAdfe5oYnuH5Xd3D2z9GQzR8B OVKpujyl1RSUlqVEMSUs1Grc02352AqAXUBIKC36FZz4SODpUoSmfaA4vtUBmyVeGbVT HaJ4wi7GI9GyxBLOIKomRrdfJpzgePiI2CgdhgZp26vZZyaGei+ZpITrr+I6b8frkwdZ yspg== X-Gm-Message-State: AGRZ1gLGZiwONIUj1qYuijmaJ9UF/Tbq0nQ6R5GZBFkNSxdm8f2ub4ku 3Xbtn8MfAfDzSiOv6DpovzuunYu+Vvc= X-Google-Smtp-Source: AJdET5ch0DRs8qeKkSwt7L0BL/otsprPQ641PMV8ey2RNtj+QtUcVf9Bdnb5MtM1Fo5Fpqb6HGfkyA== X-Received: by 2002:a0c:a1c6:: with SMTP id e64mr150389qva.196.1541596227129; Wed, 07 Nov 2018 05:10:27 -0800 (PST) Received: from localhost.localdomain ([2804:431:f700:ba45:6a73:9179:662c:d5bc]) by smtp.gmail.com with ESMTPSA id i35-v6sm317282qtb.16.2018.11.07.05.10.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 07 Nov 2018 05:10:26 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Wed, 7 Nov 2018 11:09:59 -0200 Message-Id: <20181107131000.27744-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181107131000.27744-1-danielhb413@gmail.com> References: <20181107131000.27744-1-danielhb413@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::741 Subject: [Qemu-devel] [PATCH for-3.2 v3 2/3] block/snapshot: remove bdrv_snapshot_delete_by_id_or_name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, Daniel Henrique Barboza , dgilbert@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP After the previous patch, the only instance of this function left is inside qemu-img.c. qemu-img is using it inside the 'img_snapshot' function to delete snapshots in the SNAPSHOT_DELETE case, based on a "snapshot_name" string that refers to the tag, not ID, of the QEMUSnapshotInfo struct. This can be verified by checking the SNAPSHOT_CREATE case that comes shortly before SNAPSHOT_DELETE. In that case, the same "snapshot_name" variable is being strcpy to the 'name' field of the QEMUSnapshotInfo struct sn: pstrcpy(sn.name, sizeof(sn.name), snapshot_name); Based on that, it is unlikely that "snapshot_name" might contain an "id" in SNAPSHOT_DELETE. This patch changes SNAPSHOT_DELETE to use snapshot_find() and snapshot_delete() instead of bdrv_snapshot_delete_by_id_or_name. After that, there is no instances left of bdrv_snapshot_delete_by_id_or_name in the code, so it is safe to remove it entirely. Suggested-by: Murilo Opsfelder Araujo Signed-off-by: Daniel Henrique Barboza --- block/snapshot.c | 20 -------------------- include/block/snapshot.h | 3 --- qemu-img.c | 15 +++++++++++---- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/block/snapshot.c b/block/snapshot.c index e371d2243d..f2f48f926a 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -301,26 +301,6 @@ int bdrv_snapshot_delete(BlockDriverState *bs, return ret; } -int bdrv_snapshot_delete_by_id_or_name(BlockDriverState *bs, - const char *id_or_name, - Error **errp) -{ - int ret; - Error *local_err = NULL; - - ret = bdrv_snapshot_delete(bs, id_or_name, NULL, &local_err); - if (ret == -ENOENT || ret == -EINVAL) { - error_free(local_err); - local_err = NULL; - ret = bdrv_snapshot_delete(bs, NULL, id_or_name, &local_err); - } - - if (ret < 0) { - error_propagate(errp, local_err); - } - return ret; -} - int bdrv_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_info) { diff --git a/include/block/snapshot.h b/include/block/snapshot.h index f73d1094af..b5d5084a12 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -61,9 +61,6 @@ int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id, const char *name, Error **errp); -int bdrv_snapshot_delete_by_id_or_name(BlockDriverState *bs, - const char *id_or_name, - Error **errp); int bdrv_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_info); int bdrv_snapshot_load_tmp(BlockDriverState *bs, diff --git a/qemu-img.c b/qemu-img.c index 4c96db7ba4..7b4910adcf 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3121,11 +3121,18 @@ static int img_snapshot(int argc, char **argv) break; case SNAPSHOT_DELETE: - bdrv_snapshot_delete_by_id_or_name(bs, snapshot_name, &err); - if (err) { - error_reportf_err(err, "Could not delete snapshot '%s': ", - snapshot_name); + ret = bdrv_snapshot_find(bs, &sn, snapshot_name); + if (ret < 0) { + error_report("Could not delete snapshot '%s': snapshot not " + "found", snapshot_name); ret = 1; + } else { + ret = bdrv_snapshot_delete(bs, sn.id_str, sn.name, &err); + if (ret < 0) { + error_reportf_err(err, "Could not delete snapshot '%s': ", + snapshot_name); + ret = 1; + } } break; }