From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [RFC PATCH 4/5] qcow2.py: add method to load backing image
Date: Thu, 18 Apr 2013 17:17:28 +0200 [thread overview]
Message-ID: <1366298249-11739-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1366298249-11739-1-git-send-email-pbonzini@redhat.com>
This also adds support for raw ImageFiles.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
tests/qemu-iotests/qcow2.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/tests/qemu-iotests/qcow2.py b/tests/qemu-iotests/qcow2.py
index 77e03cb..77a9d52 100755
--- a/tests/qemu-iotests/qcow2.py
+++ b/tests/qemu-iotests/qcow2.py
@@ -19,12 +19,22 @@ class QcowHeaderExtension:
class ImageFile:
def __init__(self, fd, fields):
self.__dict__ = fields
+ if 'backing_file' not in fields:
+ self.backing_file = None
+ self.backing_image = None
self.fd = fd
def close(self):
self.fd.close()
self.fd = None
+ def open_backing_image(self, mode='rb'):
+ if not self.backing_image:
+ if self.backing_file:
+ self.backing_image = load_image(self.backing_file, mode,
+ self.backing_format)
+ return None
+
def raw_pread(self, offset, size):
self.fd.seek(offset)
return self.fd.read(size)
@@ -33,6 +43,10 @@ class ImageFile:
self.fd.seek(offset)
return self.fd.write(data)
+class Raw(ImageFile):
+ def __init__(self, fd):
+ size = os.fstat(fd.fileno()).st_size
+ ImageFile.__init__(self, fd, dict(size=size))
class Qcow(ImageFile):
@@ -65,6 +79,8 @@ class Qcow(ImageFile):
HEADER_FMT = '>' + ''.join(field[0] for field in fields)
QCOW_MAGIC = 0x514649fb
+ EXT_BACKING_FORMAT = 0xE2792ACA
+ EXT_FEATURE_NAMES = 0x6803f857
def __init__(self, fd):
@@ -93,6 +109,8 @@ class Qcow(ImageFile):
else:
self.backing_file = None
+ self.backing_format = self.get_extension(Qcow.EXT_BACKING_FORMAT)
+
def set_defaults(self):
if self.version == 2:
self.incompatible_features = 0
@@ -135,6 +153,12 @@ class Qcow(ImageFile):
if self.fd.tell() > self.cluster_size:
raise Exception("I think I just broke the image...")
+ def get_extension(self, magic):
+ for ex in self.extensions:
+ if ex.magic == magic:
+ return ex.data
+ return None
+
def update(self):
header_bytes = self.header_length
@@ -178,6 +202,8 @@ def load_image(filename, mode='rb', format=None):
if format == 'qcow2':
return Qcow(fd)
+ elif format == 'raw':
+ return Raw(fd)
raise Error('unknown format %s' % format)
--
1.8.2
next prev parent reply other threads:[~2013-04-18 15:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-18 15:17 [Qemu-devel] [RFC PATCH 0/5] qcow2.py: dump metadata Paolo Bonzini
2013-04-18 15:17 ` [Qemu-devel] [RFC PATCH 1/5] qcow2.py: rename class to Qcow Paolo Bonzini
2013-04-18 15:17 ` [Qemu-devel] [RFC PATCH 2/5] qcow2.py: add ImageFile superclass Paolo Bonzini
2013-04-18 15:17 ` [Qemu-devel] [RFC PATCH 3/5] qcow2.py: add load_image() method Paolo Bonzini
2013-04-18 15:17 ` Paolo Bonzini [this message]
2013-04-18 15:17 ` [Qemu-devel] [RFC PATCH 5/5] qcow2.py: add dump-map command Paolo Bonzini
2013-04-22 12:38 ` [Qemu-devel] [RFC PATCH 0/5] qcow2.py: dump metadata Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1366298249-11739-5-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).