Re: [PATCH] kvm tool: add QCOW verions 1 read/write support

2011-04-15 Thread Pekka Enberg
Hi Christoph,

On Wed, Apr 13, 2011 at 08:01:58PM +0100, Prasad Joshi wrote:
 The patch only implements the basic read write support for QCOW version 1
 images. Many of the QCOW features are not implmented, for example

On Fri, Apr 15, 2011 at 6:24 AM, Christoph Hellwig h...@infradead.org wrote:
 What's the point?  Qcow1 has been deprecated for a long time.

We're going to add QCOW2 too. Do you think there's no value in
supporting QCOW1 and we should drop it completely? I have no
objections in being QCOW2-only.

 Pekka
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tool: add QCOW verions 1 read/write support

2011-04-15 Thread Kevin Wolf
Am 15.04.2011 08:24, schrieb Pekka Enberg:
 Hi Christoph,
 
 On Wed, Apr 13, 2011 at 08:01:58PM +0100, Prasad Joshi wrote:
 The patch only implements the basic read write support for QCOW version 1
 images. Many of the QCOW features are not implmented, for example
 
 On Fri, Apr 15, 2011 at 6:24 AM, Christoph Hellwig h...@infradead.org wrote:
 What's the point?  Qcow1 has been deprecated for a long time.
 
 We're going to add QCOW2 too. Do you think there's no value in
 supporting QCOW1 and we should drop it completely? I have no
 objections in being QCOW2-only.

We're not going to remove it from qemu soon, but the main point for
keeping it is conversion of old qcow1 images to current formats.

Kevin
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tool: add QCOW verions 1 read/write support

2011-04-14 Thread Christoph Hellwig
On Wed, Apr 13, 2011 at 08:01:58PM +0100, Prasad Joshi wrote:
 The patch only implements the basic read write support for QCOW version 1
 images. Many of the QCOW features are not implmented, for example

What's the point?  Qcow1 has been deprecated for a long time.

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm tool: add QCOW verions 1 read/write support

2011-04-13 Thread Prasad Joshi
The patch only implements the basic read write support for QCOW version 1
images. Many of the QCOW features are not implmented, for example
 - image creation
 - snapshot
 - copy-on-write
 - encryption

Renamed the file CREDITS-Git to CREDITS and added QEMU credits to CREDITS file.

Signed-off-by: Prasad Joshi prasadjoshi...@gmail.com
---
 tools/kvm/CREDITS   |   46 +
 tools/kvm/Makefile  |2 +
 tools/kvm/disk-image.c  |7 +
 tools/kvm/include/kvm/qcow.h|   55 ++
 tools/kvm/include/linux/byteorder.h |7 +
 tools/kvm/include/linux/types.h |   19 ++
 tools/kvm/qcow.c|  123 +
 tools/kvm/qcow1.c   |  325 +++
 8 files changed, 584 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/CREDITS
 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
 create mode 100644 tools/kvm/qcow1.c

diff --git a/tools/kvm/CREDITS b/tools/kvm/CREDITS
new file mode 100644
index 000..3e6cf55
--- /dev/null
+++ b/tools/kvm/CREDITS
@@ -0,0 +1,46 @@
+Perf/Git:
+Most of the infrastructure that 'perf' uses here has been reused
+from the Git project, as of version:
+
+66996ec: Sync with 1.6.2.4
+
+Here is an (incomplete!) list of main contributors to those files
+in util/* and elsewhere:
+
+ Alex Riesen
+ Christian Couder
+ Dmitry Potapov
+ Jeff King
+ Johannes Schindelin
+ Johannes Sixt
+ Junio C Hamano
+ Linus Torvalds
+ Matthias Kestenholz
+ Michal Ostrowski
+ Miklos Vajna
+ Petr Baudis
+ Pierre Habouzit
+ René Scharfe
+ Samuel Tardieu
+ Shawn O. Pearce
+ Steffen Prohaska
+ Steve Haslam
+
+Thanks guys!
+
+The full history of the files can be found in the upstream Git commits.
+
+
+QEMU
+The source code of the QEMU was referenced while developing the QCOW support
+for the kvm tool. The relevant QEMU commits were
+
+66f82ce block: Open the underlying image file in generic code
+ea2384d new disk image layer
+
+Here is a possibly incomplete list of main contributors
+ Kevin Wolf kw...@redhat.com
+ Fabrice Bellard
+ Stefan Hajnoczi stefa...@linux.vnet.ibm.com
+
+Thanks a lot all!
diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 6895113..098b328 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -34,6 +34,8 @@ OBJS+= util/strbuf.o
 OBJS+= kvm-help.o
 OBJS+= kvm-cmd.o
 OBJS+= kvm-run.o
+OBJS+= qcow.o
+OBJS+= qcow1.o
 
 DEPS   := $(patsubst %.o,%.d,$(OBJS))
 
diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c
index 908a744..ff3c076 100644
--- a/tools/kvm/disk-image.c
+++ b/tools/kvm/disk-image.c
@@ -13,6 +13,9 @@
 #include unistd.h
 #include fcntl.h
 
+#include linux/types.h
+#include kvm/qcow.h
+
 struct disk_image *disk_image__new(int fd, uint64_t size, struct 
disk_image_operations *ops)
 {
struct disk_image *self;
@@ -124,6 +127,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;
diff --git a/tools/kvm/include/kvm/qcow.h b/tools/kvm/include/kvm/qcow.h
new file mode 100644
index 000..96f7ad5
--- /dev/null
+++ b/tools/kvm/include/kvm/qcow.h
@@ -0,0 +1,55 @@
+#ifndef __QEMU_H__
+
+#define __QEMU_H__
+
+#define QCOW_MAGIC (('Q'  24) | ('F'  16) | ('I'  8) | 0xfb)
+#define QCOW1_VERSION 1
+#define QCOW2_VERSION 2
+
+#define QCOW_OFLAG_COMPRESSED (1LL  63)
+
+struct qcow_table {
+   uint32_t table_size;
+   u64 *l1_table;
+};
+
+struct qcow {
+   struct qcow_table *table;
+   void *header;
+   int fd;
+};
+
+/* common qcow header */
+struct qcow_common_header {
+   uint32_t magic;
+   uint32_t version;
+};
+
+/* qcow version 1 header format */
+struct qcow1_header {
+   uint32_t magic;
+   uint32_t version;
+
+   u64 backing_file_offset;
+   uint32_t backing_file_size;
+   uint32_t mtime;
+
+   u64 size; /* in bytes */
+
+   uint8_t cluster_bits;
+   uint8_t l2_bits;
+   uint32_t crypt_method;
+
+   u64 l1_table_offset;
+};
+
+/* qcow common operations  */
+struct disk_image *qcow_probe(int fd);
+int qcow_read_l1_table(struct qcow *q);
+int qcow_pwrite_with_sync(int fd, void *buf, size_t count, off_t offset);
+
+/* qcow1 global variables and operations */
+extern struct disk_image_operations qcow1_disk_ops;
+uint32_t qcow1_get_table_size(struct qcow *q);
+struct disk_image *qcow1_probe(int fd);
+#endif
diff --git a/tools/kvm/include/linux/byteorder.h 
b/tools/kvm/include/linux/byteorder.h
new file mode 100644
index 000..c490de8
--- /dev/null
+++ b/tools/kvm/include/linux/byteorder.h
@@ -0,0 +1,7 @@
+#ifndef __BYTE_ORDER_H__
+#define __BYTE_ORDER_H__
+
+#include asm/byteorder.h
+#include linux/byteorder/generic.h

Re: [PATCH] kvm tool: add QCOW verions 1 read/write support

2011-04-13 Thread Pekka Enberg
On Wed, Apr 13, 2011 at 10:01 PM, Prasad Joshi prasadjoshi...@gmail.com wrote:
 --- /dev/null
 +++ b/tools/kvm/qcow.c
 @@ -0,0 +1,123 @@
 +/*
 + * This file contains code copied from QEMU source code
 + *
 + * Copyright (c) 2004-2006 Fabrice Bellard
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a 
 copy
 + * of this software and associated documentation files (the Software), to 
 deal
 + * in the Software without restriction, including without limitation the 
 rights
 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 + * copies of the Software, and to permit persons to whom the Software is
 + * furnished to do so, subject to the following conditions:
 + *
 + * The above copyright notice and this permission notice shall be included in
 + * all copies or substantial portions of the Software.
 + *
 + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 FROM,
 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 + * THE SOFTWARE.
 + */

Heh, almost there. Lets just drop these from the individual files now
that we have attributions in CREDITS. Now you get the impression that
the files are directly taken from QEMU which is not the case at all.

 Pekka
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html