Skip to contentSkip to conversation

kvm tools: Add QCOW version 1 read-only support

PATCH New Pekka Enberg 1 participant 1 message Apr 14, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm tools: Add QCOW version 1 read-only support

From: Prasad Joshi <[email protected]>

The patch only implements the basic read-only support for QCOW version 1 images. Many of the QCOW features are not implemented:

- write
- image creation
- snapshot
- copy-on-write
- encryption

The code is based on the following QCOW 1 image format specification:

http://people.gnome.org/~markmc/qcow-image-format-version-1.html

Cc Asias He <[email protected]>
Cc Cyrill Gorcunov <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Sasha Levin <[email protected]>
Cc Stefan Hajnoczi <[email protected]>

---
FYI, I dropped commit 910c791 ("kvm tools: Add QCOW version 1 read/write support") from the GIT repository and re-implemented read-only QCOW1 support from scratch.

 tools/kvm/Makefile                  |    1 +
 tools/kvm/disk-image.c              |    5 +
 tools/kvm/include/kvm/qcow.h        |   41 +++++++
 tools/kvm/include/linux/byteorder.h |    7 +
 tools/kvm/include/linux/types.h     |   19 +++
 tools/kvm/qcow.c                    |  227 +++++++++++++++++++++++++++++++++++
 6 files changed, 300 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/include/kvm/qcow.h
 create mode 100644 tools/kvm/include/linux/byteorder.h
 create mode 100644 tools/kvm/qcow.c
tools/kvm/Makefile +1 -0
index 6895113..28dd369 100644
@@ -34,6 +34,7 @@ OBJS    += util/strbuf.o
 OBJS    += kvm-help.o
 OBJS    += kvm-cmd.o
 OBJS    += kvm-run.o
+OBJS    += qcow.o
 
 DEPS	:= $(patsubst %.o,%.d,$(OBJS))
 
tools/kvm/disk-image.c +5 -0
index 5d0f342..fff71b4 100644
@@ -1,6 +1,7 @@
 #include "kvm/disk-image.h"
 
 #include "kvm/read-write.h"
+#include "kvm/qcow.h"
 #include "kvm/util.h"
 
 #include <sys/types.h>
@@ -131,6 +132,10 @@ struct disk_image *disk_image__open(const char *filename, bool readonly)
 	if (fd < 0)
 		return NULL;
 
+	self = qcow_probe(fd);
+	if (self)
+		return self;
+
 	self = raw_image__probe(fd, readonly);
 	if (self)
 		return self;
tools/kvm/include/kvm/qcow.h new file +41 -0

41 lines not on this page · raw message

tools/kvm/include/linux/byteorder.h new file +7 -0
new file mode 100644
index 0000000..c490de8
@@ -0,0 +1,7 @@
+#ifndef __BYTE_ORDER_H__
+#define __BYTE_ORDER_H__
+
+#include <asm/byteorder.h>
+#include <linux/byteorder/generic.h>
+
+#endif
tools/kvm/include/linux/types.h +19 -0
index 8b608e7..efd8519 100644
@@ -27,4 +27,23 @@ typedef __s16 s16;
 typedef __u8  u8;
 typedef __s8  s8;
 
+#ifdef __CHECKER__
+#define __bitwise__ __attribute__((bitwise))
+#else
+#define __bitwise__
+#endif
+#ifdef __CHECK_ENDIAN__
+#define __bitwise __bitwise__
+#else
+#define __bitwise
+#endif
+
+
+typedef __u16 __bitwise __le16;
+typedef __u16 __bitwise __be16;
+typedef __u32 __bitwise __le32;
+typedef __u32 __bitwise __be32;
+typedef __u64 __bitwise __le64;
+typedef __u64 __bitwise __be64;
+
 #endif /* LINUX_TYPES_H */
tools/kvm/qcow.c new file +227 -0

227 lines not on this page · raw message

Signature · 1 line
1.7.0.4