218e99
From f7c79aada82c99552499bc075021128f4a8653a6 Mon Sep 17 00:00:00 2001
218e99
From: Paolo Bonzini <pbonzini@redhat.com>
218e99
Date: Fri, 18 Oct 2013 08:14:43 +0200
218e99
Subject: [PATCH 18/81] docs, qapi: document qemu-img map
218e99
218e99
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
218e99
Message-id: <1382084091-16636-19-git-send-email-pbonzini@redhat.com>
218e99
Patchwork-id: 55001
218e99
O-Subject: [RHEL 7.0 qemu-kvm PATCH 18/26] docs, qapi: document qemu-img map
218e99
Bugzilla: 989646
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
218e99
Eric Blake also requested including the output in qapi-schema.json,
218e99
so that it is published through the introspection mechanism.
218e99
218e99
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
(cherry picked from commit facd6e2b5c0217f9d9eeb2ee497dda28009518bd)
218e99
---
218e99
 qapi-schema.json | 29 +++++++++++++++++++++++++++++
218e99
 qemu-img.texi    | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
218e99
 2 files changed, 84 insertions(+)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 qapi-schema.json |   29 ++++++++++++++++++++++++++++
218e99
 qemu-img.texi    |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
218e99
 2 files changed, 84 insertions(+), 0 deletions(-)
218e99
218e99
diff --git a/qapi-schema.json b/qapi-schema.json
218e99
index 780c6fe..b779458 100644
218e99
--- a/qapi-schema.json
218e99
+++ b/qapi-schema.json
218e99
@@ -795,6 +795,35 @@
218e99
 { 'enum': 'BlockDeviceIoStatus', 'data': [ 'ok', 'failed', 'nospace' ] }
218e99
 
218e99
 ##
218e99
+# @BlockDeviceMapEntry:
218e99
+#
218e99
+# Entry in the metadata map of the device (returned by "qemu-img map")
218e99
+#
218e99
+# @start: Offset in the image of the first byte described by this entry
218e99
+#         (in bytes)
218e99
+#
218e99
+# @length: Length of the range described by this entry (in bytes)
218e99
+#
218e99
+# @depth: Number of layers (0 = top image, 1 = top image's backing file, etc.)
218e99
+#         before reaching one for which the range is allocated.  The value is
218e99
+#         in the range 0 to the depth of the image chain - 1.
218e99
+#
218e99
+# @zero: the sectors in this range read as zeros
218e99
+#
218e99
+# @data: reading the image will actually read data from a file (in particular,
218e99
+#        if @offset is present this means that the sectors are not simply
218e99
+#        preallocated, but contain actual data in raw format)
218e99
+#
218e99
+# @offset: if present, the image file stores the data for this range in
218e99
+#          raw format at the given offset.
218e99
+#
218e99
+# Since 1.7
218e99
+##
218e99
+{ 'type': 'BlockDeviceMapEntry',
218e99
+  'data': { 'start': 'int', 'length': 'int', 'depth': 'int', 'zero': 'bool',
218e99
+            'data': 'bool', '*offset': 'int' } }
218e99
+
218e99
+##
218e99
 # @BlockDirtyInfo:
218e99
 #
218e99
 # Block dirty bitmap information.
218e99
diff --git a/qemu-img.texi b/qemu-img.texi
218e99
index 69f1bda..8364fa1 100644
218e99
--- a/qemu-img.texi
218e99
+++ b/qemu-img.texi
218e99
@@ -213,6 +213,61 @@ To enumerate information about each disk image in the above chain, starting from
218e99
 qemu-img info --backing-chain snap2.qcow2
218e99
 @end example
218e99
 
218e99
+@item map [-f @var{fmt}] [--output=@var{ofmt}] @var{filename}
218e99
+
218e99
+Dump the metadata of image @var{filename} and its backing file chain.
218e99
+In particular, this commands dumps the allocation state of every sector
218e99
+of @var{filename}, together with the topmost file that allocates it in
218e99
+the backing file chain.
218e99
+
218e99
+Two option formats are possible.  The default format (@code{human})
218e99
+only dumps known-nonzero areas of the file.  Known-zero parts of the
218e99
+file are omitted altogether, and likewise for parts that are not allocated
218e99
+throughout the chain.  @command{qemu-img} output will identify a file
218e99
+from where the data can be read, and the offset in the file.  Each line
218e99
+will include four fields, the first three of which are hexadecimal
218e99
+numbers.  For example the first line of:
218e99
+@example
218e99
+Offset          Length          Mapped to       File
218e99
+0               0x20000         0x50000         /tmp/overlay.qcow2
218e99
+0x100000        0x10000         0x95380000      /tmp/backing.qcow2
218e99
+@end example
218e99
+@noindent
218e99
+means that 0x20000 (131072) bytes starting at offset 0 in the image are
218e99
+available in /tmp/overlay.qcow2 (opened in @code{raw} format) starting
218e99
+at offset 0x50000 (327680).  Data that is compressed, encrypted, or
218e99
+otherwise not available in raw format will cause an error if @code{human}
218e99
+format is in use.  Note that file names can include newlines, thus it is
218e99
+not safe to parse this output format in scripts.
218e99
+
218e99
+The alternative format @code{json} will return an array of dictionaries
218e99
+in JSON format.  It will include similar information in
218e99
+the @code{start}, @code{length}, @code{offset} fields;
218e99
+it will also include other more specific information:
218e99
+@itemize @minus
218e99
+@item
218e99
+whether the sectors contain actual data or not (boolean field @code{data};
218e99
+if false, the sectors are either unallocated or stored as optimized
218e99
+all-zero clusters);
218e99
+
218e99
+@item
218e99
+whether the data is known to read as zero (boolean field @code{zero});
218e99
+
218e99
+@item
218e99
+in order to make the output shorter, the target file is expressed as
218e99
+a @code{depth}; for example, a depth of 2 refers to the backing file
218e99
+of the backing file of @var{filename}.
218e99
+@end itemize
218e99
+
218e99
+In JSON format, the @code{offset} field is optional; it is absent in
218e99
+cases where @code{human} format would omit the entry or exit with an error.
218e99
+If @code{data} is false and the @code{offset} field is present, the
218e99
+corresponding sectors in the file are not yet in use, but they are
218e99
+preallocated.
218e99
+
218e99
+For more information, consult @file{include/block/block.h} in QEMU's
218e99
+source code.
218e99
+
218e99
 @item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot} ] @var{filename}
218e99
 
218e99
 List, apply, create or delete snapshots in image @var{filename}.
218e99
-- 
218e99
1.7.1
218e99