From patchwork Wed Aug 4 17:55:49 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: 60879 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 85EA41007D1 for ; Thu, 5 Aug 2010 04:05:17 +1000 (EST) Received: from localhost ([127.0.0.1]:37561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgiKs-0005DU-RT for incoming@patchwork.ozlabs.org; Wed, 04 Aug 2010 14:05:02 -0400 Received: from [140.186.70.92] (port=60527 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OgiBE-00057R-Qb for qemu-devel@nongnu.org; Wed, 04 Aug 2010 13:55:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OgiBC-0007ZS-AI for qemu-devel@nongnu.org; Wed, 04 Aug 2010 13:55:04 -0400 Received: from mail-gw0-f45.google.com ([74.125.83.45]:57805) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OgiBC-0007Z9-69 for qemu-devel@nongnu.org; Wed, 04 Aug 2010 13:55:02 -0400 Received: by gwb11 with SMTP id 11so2313776gwb.4 for ; Wed, 04 Aug 2010 10:55:01 -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=Ysg7SU97kAJsg3OD2C/Lw/faW81X59unidGoyDFuxcE=; b=jnHeD7UquSmHvvvNBAjyFw74/QKghAJg9DbIKqu5PO/jb1vddw4wH1W0JAV3ZxR8qh glUb0AxANPzHvuqBMU64QjTIj5S0ZBVbufQS7zSGBmo3h/MSYwJRVjqQ16gT/Mlqql5+ cFoNXAEs5xsSAOtHpXBWfSDNFE75+5gsausow= 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=OWslwKMPrcrQEUtnaeNwJmIovF3Fu6FAOhycQGHRwKLyqUbtFFXfpOk9DbDMU5v8Xr xzIYw4bOVxmeAfo2OOd6MI6uB1RBGgV0GJjwDJaDTIHBIhwwUkzzuIVSO4jTdI+2WRKM 5Y4sZGepi3hQo0rR2GS23Lgs3Sp+8I9Jijxf0= Received: by 10.101.144.4 with SMTP id w4mr10328481ann.196.1280944501646; Wed, 04 Aug 2010 10:55:01 -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.54.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 04 Aug 2010 10:55:00 -0700 (PDT) From: Miguel Di Ciurcio Filho To: qemu-devel@nongnu.org Date: Wed, 4 Aug 2010 14:55:49 -0300 Message-Id: <1280944550-6502-3-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 2/3] savevm: Generate a name when run without one 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 without a name, the name stays blank and the snapshot is saved anyway. The new behavior is when savevm is run without parameters a name will be created automaticaly, so the snapshot is accessible to the user without needing the id when loadvm is run. (qemu) savevm (qemu) info snapshots ID TAG VM SIZE DATE VM CLOCK 1 vm-20100728134640 978K 2010-07-28 13:46:40 00:00:08.603 We use a name with the format 'vm-YYYYMMDDHHMMSS'. This is a first step to hide the internal id, because I don't see a reason to expose this kind of internals to the user. Signed-off-by: Miguel Di Ciurcio Filho --- savevm.c | 29 ++++++++++++++++++++--------- 1 files changed, 20 insertions(+), 9 deletions(-) diff --git a/savevm.c b/savevm.c index 9291cfb..025bee6 100644 --- a/savevm.c +++ b/savevm.c @@ -1799,8 +1799,10 @@ void do_savevm(Monitor *mon, const QDict *qdict) uint32_t vm_state_size; #ifdef _WIN32 struct _timeb tb; + struct tm *ptm; #else struct timeval tv; + struct tm tm; #endif const char *name = qdict_get_try_str(qdict, "name"); @@ -1831,15 +1833,6 @@ void do_savevm(Monitor *mon, const QDict *qdict) vm_stop(0); memset(sn, 0, sizeof(*sn)); - 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); - } - } /* fill auxiliary fields */ #ifdef _WIN32 @@ -1853,6 +1846,24 @@ void do_savevm(Monitor *mon, const QDict *qdict) #endif sn->vm_clock_nsec = qemu_get_clock(vm_clock); + 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); + } + } else { +#ifdef _WIN32 + ptm = localtime(&tb.time); + strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", ptm); +#else + localtime_r(&tv.tv_sec, &tm); + strftime(sn->name, sizeof(sn->name), "vm-%Y%m%d%H%M%S", &tm); +#endif + } + /* Delete old snapshots of the same name */ if (name && del_existing_snapshots(mon, name) < 0) { goto the_end;