From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhMJd-0003VN-IL for qemu-devel@nongnu.org; Fri, 15 Nov 2013 11:32:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VhMJV-0003TB-2b for qemu-devel@nongnu.org; Fri, 15 Nov 2013 11:32:17 -0500 Received: from mail-pb0-x235.google.com ([2607:f8b0:400e:c01::235]:62249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhMJU-0003T6-RO for qemu-devel@nongnu.org; Fri, 15 Nov 2013 11:32:09 -0500 Received: by mail-pb0-f53.google.com with SMTP id ma3so3757537pbc.26 for ; Fri, 15 Nov 2013 08:32:07 -0800 (PST) Message-ID: <52864C79.20800@gmail.com> Date: Sat, 16 Nov 2013 00:31:53 +0800 From: lijun MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] HMP: snapshot_blkdev can not consider //root/sn1 and /root/sn1 as the same file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lcapitulino@redhat.com From: Jun Li Hi all, snapshot_blkdev can not consider //root/sn1 and /root/sn1 as the same file. when file /root/sn1 is the base file, do snapshot using file //root/sn1, qemu consider it as a new file. So this will rewrite the base file. Signed-off-by: Jun Li --- a/hmp.c 2013-11-15 23:15:46.733361130 +0800 +++ b/hmp.c 2013-11-16 00:20:23.972248509 +0800 @@ -957,10 +957,12 @@ void hmp_snapshot_blkdev(Monitor *mon, c { const char *device = qdict_get_str(qdict, "device"); const char *filename = qdict_get_try_str(qdict, "snapshot-file"); + const char *p = filename; const char *format = qdict_get_try_str(qdict, "format"); int reuse = qdict_get_try_bool(qdict, "reuse", 0); enum NewImageMode mode; Error *errp = NULL; + int count = 1; if (!filename) { /* In the future, if 'snapshot-file' is not specified, the snapshot @@ -970,6 +972,18 @@ void hmp_snapshot_blkdev(Monitor *mon, c return; } + /* Delete duplicate '/' in filename. */ + while (*p != '\0') { + if (*p == '/') { + while (*(p + count++) == '/') { + /* do null. */ + } + strcpy((char *)(p + 1), (char *)(p + count - 1)); + count = 1; + } + p++; + } + mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS; qmp_blockdev_snapshot_sync(device, filename, !!format, format, true, mode, &errp);