From patchwork Wed Aug 4 17:55:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Di Ciurcio Filho X-Patchwork-Id: 60877 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 062FCB6EF3 for ; Thu, 5 Aug 2010 03:58:51 +1000 (EST) Received: from localhost ([127.0.0.1]:38568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgiEi-0007IY-TG for incoming@patchwork.ozlabs.org; Wed, 04 Aug 2010 13:58:40 -0400 Received: from [140.186.70.92] (port=60550 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgiBG-00058r-JO for qemu-devel@nongnu.org; Wed, 04 Aug 2010 13:55:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OgiBF-0007aG-1x for qemu-devel@nongnu.org; Wed, 04 Aug 2010 13:55:06 -0400 Received: from mail-gy0-f173.google.com ([209.85.160.173]:46450) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgiBE-0007YG-SY for qemu-devel@nongnu.org; Wed, 04 Aug 2010 13:55:04 -0400 Received: by mail-gy0-f173.google.com with SMTP id 10so2302063gyd.4 for ; Wed, 04 Aug 2010 10:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=jt0mkkKyA5ztV5ms5+w9xZYzzkQvowmTBT1u5gs6eJo=; b=h/irw7LhUGxJ2kZFNgn4qeEZs6zNrswI2oVXCChelLyhcXFc/ObiP+7BfDRyt1AQkT 51UPMi2lXvH4VKeeV46fr0JzwKRsb9XkE44+H6qLwb82Vx4qUGkStvOMbzjdMNfTaHKD ExsvqwugDQo0FEx2ftBSUkd9s3mM7eodLN/7k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=EdjB1IlCPL9AV3m80nZwNXuKMPUkrHTkLEQz51Xaej4ykV4PW5aEIo6kpQp8XZk2jI uWfyu27oNFgGEZBlaWD/iSibd3lz/6JTpcqPLvRe8nORmFEDTUbT8iS+oeAWkgTR75+D B2ffw2IhwNPAk/LqM5KOftcsUtpiUZZSDWKOs= Received: by 10.100.109.1 with SMTP id h1mr10281668anc.184.1280944504489; Wed, 04 Aug 2010 10:55:04 -0700 (PDT) Received: from localhost.localdomain (quake.ic.unicamp.br [143.106.7.51]) by mx.google.com with ESMTPS id c6sm14115658anj.31.2010.08.04.10.55.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 04 Aug 2010 10:55:03 -0700 (PDT) From: Miguel Di Ciurcio Filho To: qemu-devel@nongnu.org Date: Wed, 4 Aug 2010 14:55:50 -0300 Message-Id: <1280944550-6502-4-git-send-email-miguel.filho@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1280944550-6502-1-git-send-email-miguel.filho@gmail.com> References: <1280944550-6502-1-git-send-email-miguel.filho@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: kwolf@redhat.com, Miguel Di Ciurcio Filho , armbru@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 3/3] savevm: prevent snapshot overwriting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When savevm is run using an previously saved snapshot id or name, it will delete the original and create a new one, using the same id and name and not prompting the user of what just happened. This behaviour is not good, IMHO. We add a '-f' parameter to savevm, to really force that to happen, in case the user really wants to. New behavior: (qemu) savevm snap1 An snapshot named 'snap1' already exists (qemu) savevm -f snap1 We do better error reporting in case '-f' is used too than before and don't reuse the previous id. Note: This patch depends on "savevm: Generate a name when run without one" Signed-off-by: Miguel Di Ciurcio Filho --- qemu-monitor.hx | 7 ++++--- savevm.c | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 2af3de6..683ac73 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -275,9 +275,10 @@ ETEXI { .name = "savevm", - .args_type = "name:s?", - .params = "[tag|id]", - .help = "save a VM snapshot. If no tag or id are provided, a new snapshot is created", + .args_type = "force:-f,name:s?", + .params = "[-f] [tag|id]", + .help = "save a VM snapshot. If no tag is provided, a new one is created" + "\n\t\t\t -f to overwrite an snapshot if it already exists", .mhandler.cmd = do_savevm, }, diff --git a/savevm.c b/savevm.c index 025bee6..f0a4b78 100644 --- a/savevm.c +++ b/savevm.c @@ -1805,6 +1805,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) struct tm tm; #endif const char *name = qdict_get_try_str(qdict, "name"); + int force = qdict_get_try_bool(qdict, "force", 0); /* Verify if there is a device that doesn't support snapshots and is writable */ bs = NULL; @@ -1848,12 +1849,20 @@ void do_savevm(Monitor *mon, const QDict *qdict) if (name) { ret = bdrv_snapshot_find(bs, old_sn, name); - if (ret >= 0) { - pstrcpy(sn->name, sizeof(sn->name), old_sn->name); - pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str); - } else { - pstrcpy(sn->name, sizeof(sn->name), name); + if (ret == 0) { + if (force) { + ret = del_existing_snapshots(mon, name); + if (ret < 0) { + monitor_printf(mon, "Error deleting snapshot '%s', error: %d\n", name, ret); + goto the_end; + } + } else { + monitor_printf(mon, "An snapshot named '%s' already exists\n", name); + goto the_end; + } } + + pstrcpy(sn->name, sizeof(sn->name), name); } else { #ifdef _WIN32 ptm = localtime(&tb.time);