Skip to contentSkip to conversation

e2image: Add support for qcow2 format

PATCH Superseded Lukas Czerner 4 participants 12 messages Feb 25, 2011 – Mar 17, 2011

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 e2image: Add support for qcow2 format

This commit adds support for exporting filesystem into QCOW2 image format. Like sparse format this saves space, by writing only necessary (metadata blocks) into image. Unlike sparse image, QCOW2 image is NOT sparse, hence does not change its size by copying with not-sparse-aware tools.

New options '-Q' has been added to tell the e2image to use QCOW2 as an output image format. QCOW2 supports encryption and compression, however e2image so far does no support such features, however you can still scramble filenames with '-s' option.

---
 lib/ext2fs/Makefile.in |    4 +-
 lib/ext2fs/bitops.h    |    4 +
 lib/ext2fs/e2image.h   |   21 +-
 lib/ext2fs/qcow2.c     |  227 +++++++++++++++
 lib/ext2fs/qcow2.h     |   94 +++++++
 misc/e2image.8.in      |   47 +++-
 misc/e2image.c         |  723 ++++++++++++++++++++++++++++++++++++++++++++----
 7 files changed, 1048 insertions(+), 72 deletions(-)
 create mode 100644 lib/ext2fs/qcow2.c
 create mode 100644 lib/ext2fs/qcow2.h
lib/ext2fs/Makefile.in +3 -1
index 763694d..72a5331 100644
@@ -70,6 +70,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \
 	openfs.o \
 	progress.o \
 	punch.o \
+	qcow2.o \
 	read_bb.o \
 	read_bb_file.o \
 	res_gdt.o \
@@ -138,6 +139,7 @@ SRCS= ext2_err.c \
 	$(srcdir)/openfs.c \
 	$(srcdir)/progress.c \
 	$(srcdir)/punch.c \
+	$(srcdir)/qcow2.c \
 	$(srcdir)/read_bb.c \
 	$(srcdir)/read_bb_file.c \
 	$(srcdir)/res_gdt.c \
@@ -158,7 +160,7 @@ SRCS= ext2_err.c \
 	$(srcdir)/write_bb_file.c
 
 HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \
-	tdb.h
+	tdb.h qcow2.h
 HFILES_IN=  ext2_err.h ext2_types.h
 
 LIBRARY= libext2fs
lib/ext2fs/bitops.h +4 -0
index 3ded002..83a01e4 100644
@@ -31,6 +31,8 @@ extern __u64 ext2fs_swab64(__u64 val);
 #define ext2fs_le32_to_cpu(x) ext2fs_swab32((x))
 #define ext2fs_cpu_to_le16(x) ext2fs_swab16((x))
 #define ext2fs_le16_to_cpu(x) ext2fs_swab16((x))
+#define ext2fs_cpu_to_be64(x) ((__u64)(x))
+#define ext2fs_be64_to_cpu(x) ((__u64)(x))
 #define ext2fs_cpu_to_be32(x) ((__u32)(x))
 #define ext2fs_be32_to_cpu(x) ((__u32)(x))
 #define ext2fs_cpu_to_be16(x) ((__u16)(x))
@@ -42,6 +44,8 @@ extern __u64 ext2fs_swab64(__u64 val);
 #define ext2fs_le32_to_cpu(x) ((__u32)(x))
 #define ext2fs_cpu_to_le16(x) ((__u16)(x))
 #define ext2fs_le16_to_cpu(x) ((__u16)(x))
+#define ext2fs_cpu_to_be64(x) ext2fs_swab64((x))
+#define ext2fs_be64_to_cpu(x) ext2fs_swab64((x))
 #define ext2fs_cpu_to_be32(x) ext2fs_swab32((x))
 #define ext2fs_be32_to_cpu(x) ext2fs_swab32((x))
 #define ext2fs_cpu_to_be16(x) ext2fs_swab16((x))
lib/ext2fs/e2image.h +8 -13
index 4de2c8d..a47f9e6 100644
@@ -12,6 +12,14 @@
  * %End-Header%
  */
 
+/* Image types */
+#define IMAGE_RAW	1
+#define IMAGE_QCOW2	2
+
+/* Image flags */
+#define INSTALL_FLAG	1
+#define SCRAMBLE_FLAG	2
+#define IS_QCOW2_FLAG	3
 
 struct ext2_image_hdr {
 	__u32	magic_number;	/* This must be EXT2_ET_MAGIC_E2IMAGE */
@@ -36,16 +44,3 @@ struct ext2_image_hdr {
 	__u32	offset_blockmap; /* Byte offset of the inode bitmaps */
 	__u32	offset_reserved[8];
 };
-
-
-
-
-
-
-
-
-
-
-
-
-
lib/ext2fs/qcow2.c new file +227 -0

227 lines not on this page · raw message

lib/ext2fs/qcow2.h new file +94 -0

94 lines not on this page · raw message

misc/e2image.8.in +43 -4

69 lines not on this page · raw message

misc/e2image.c +669 -54

916 lines not on this page · raw message

Signature · 1 line
1.7.4
#1 lore raw

PATCH 2/4 e2image: Support for conversion QCOW2 image into raw

This commit adds support for converting QCOW2 image created previously with e2image into raw image. The QCOW2 image is detected automatically, so there is not new option. Just use following command:

e2image -r image.qcow image.raw

No that this tool is aimed to quickly convert qcow2 image created with e2image into raw image. In order to improve speed we are doing some assumption I believe might not be true for regular qcow2 images. So it was not tested with regular QCOW2 images and it might not work with them. The intention of this tool is only convert images previously created by e2image.

Note that there is nothing special with QCOW2 images created by e2images and it can be used with tools like qemu-img, or qemu-nbd without any problems.

---
 lib/ext2fs/qcow2.c |    3 ++-
 misc/e2image.8.in  |    4 ++++
 misc/e2image.c     |   43 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 48 insertions(+), 2 deletions(-)
lib/ext2fs/qcow2.c +2 -1
index 17eab38..9ac050b 100644
@@ -209,9 +209,10 @@ int qcow2_write_raw_image(int qcow2_fd, int raw_fd,
 	}
 
 	/* Resize the output image to the filesystem size */
-	if (lseek(raw_fd, img.image_size, SEEK_SET) < 0)
+	if (lseek(raw_fd, img.image_size - 1, SEEK_SET) < 0)
 		return errno;
 
+	memset(copy_buf, 0, 1);
 	size = write(raw_fd, copy_buf, 1);
 	if (size != 1)
 		return errno;
misc/e2image.8.in +4 -0
index 4a28580..6f31dd1 100644
@@ -131,6 +131,10 @@ the
 option will prevent analysis of problems related to hash-tree indexed
 directories.
 .PP
+Note that this will work even if you substitute "/dev/hda1" for another raw
+disk image, or QCOW2 image previously created by
+.BR e2image .
+.PP
 .SH QCOW2 IMAGE FILES
 The 
 .B \-Q
misc/e2image.c +42 -1

82 lines not on this page · raw message

Signature · 1 line
1.7.4
#2 lore raw

PATCH 4/4 e2fsck: Add QCOW2 support

In reply to Lukas Czerner

This commit adds QCOW2 support for e2fsck. In order to avoid creating real QCOW2 image support, which would require creating a lot of code, we simply bypass the problem by converting the QCOW2 image into raw image and than let e2fsck work with raw image. Conversion itself can be quite fast, so it should not be a serious slowdown.

Add '-Q' option to specify path for the raw image. It not specified the raw image will be saved in /tmp direcotry in format <qcow2_filename>.raw.XXXXXX, where X chosen randomly.

---
 e2fsck/e2fsck.8.in |    8 +++++-
 e2fsck/unix.c      |   74 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 76 insertions(+), 6 deletions(-)
e2fsck/e2fsck.8.in +7 -1
index 3fb15e6..36d1492 100644
@@ -8,7 +8,7 @@ e2fsck \- check a Linux ext2/ext3/ext4 file system
 .SH SYNOPSIS
 .B e2fsck
 [
-.B \-pacnyrdfkvtDFV
+.B \-pacnyrdfkvtDFVQ
 ]
 [
 .B \-b
@@ -263,6 +263,12 @@ will print a description of the problem and then exit with the value 4
 logically or'ed into the exit code.  (See the \fBEXIT CODE\fR section.)
 This option is normally used by the system's boot scripts.  It may not 
 be specified at the same time as the
+.TP
+.BI \-Q " filename"
+When e2fsck is attempting to check QCOW2 image, it has to convert QCOW2
+into raw image. This option specify the filename for the raw image. If
+this option is ommited, raw image will be created in /tmp direcotry.
+.TP
 .B \-n
 or
 .B \-y
e2fsck/unix.c +69 -5

112 lines not on this page · raw message

Signature · 1 line
1.7.4
#11 lore raw
In reply to Lukas Czerner
Quoted 6 lines · Lukas Czerner

This commit adds support for exporting filesystem into QCOW2 image format. Like sparse format this saves space, by writing only necessary (metadata blocks) into image. Unlike sparse image, QCOW2 image is NOT sparse, hence does not change its size by copying with not-sparse-aware tools.

Quoted 6 lines

New options '-Q' has been added to tell the e2image to use QCOW2 as an output image format. QCOW2 supports encryption and compression, however e2image so far does no support such features, however you can still scramble filenames with '-s' option.

I noticed that the qcow2 functions have a qcow2_ prefix and aren't prefixed with ext2_. That's a namespace leakage, although I understand why adding ext2_ to functions that really have nothing to do with ext2_ might not make sense.

What this *does* make me wonder though, is whether or not we should split off qcow2 into its own separate library...

- Ted

#3 lore raw

Re: [PATCH 4/4] e2fsck: Add QCOW2 support

In reply to Lukas Czerner
Quoted 11 lines · Lukas Czerner

This commit adds QCOW2 support for e2fsck. In order to avoid creating real QCOW2 image support, which would require creating a lot of code, we simply bypass the problem by converting the QCOW2 image into raw image and than let e2fsck work with raw image. Conversion itself can be quite fast, so it should not be a serious slowdown.

Add '-Q' option to specify path for the raw image. It not specified the raw image will be saved in /tmp direcotry in format <qcow2_filename>.raw.XXXXXX, where X chosen randomly.

If we're just going to convert the qcow2 image into a raw image, that means that if someone sends us a N gigabyte QCOW2 image, it will lots of time (I'm not sure I agree with the "quite fast part"), and consume an extra N gigabytes of free space to create the raw image.

In that case, I'm not so sure we really want to have a -Q option to e2fsck. We might be better off simply forcing the use of e2image to convert the image back.

Note that the other reason why it's a lot better to be able to allow e2fsck to be able to work on the raw image directly is that if a customer sends a qcow2's metadata-only image from their 3TB raid array, we won't be able to expand that to a raw image because of ext2/3/4's 2TB maximum file size limit. The qcow2 image might be only a few hundreds of megabytes, so being able to have e2fsck operate on that image directly would be a huge win.

Adding iomanager support would also allow debugfs to access the qcow2 image directly --- also a win.

Whether or not we add the io_manager support right away (eventually I think it's a must have feature), I don't think having a "decompress a qcow2 image to a sparse raw image" makes sense as an explicit e2fsck option. It just clutters up the e2fsck option space, and people might be confused because now e2fsck could break because there wasn't enough free space to decompress the raw image. Also, e2fsck doesn't delete the /tmp file afterwards, which is bad --- but if it takes a large amount of time to create the raw image, deleting afterwards is a bit of waste as well. Probably better to force the user to manage the converted raw file system image.

- Ted

#4 lore raw

Re: [PATCH 4/4] e2fsck: Add QCOW2 support

Quoted 3 lines · Ted Ts'o

ext2/3/4's 2TB maximum file size limit. The qcow2 image might be only a few hundreds of megabytes, so being able to have e2fsck operate on that image directly would be a huge win.

driepoot:~> ls -ls /mnt/md3.img
61558920 -rw------- 1 root root 2937535070208 Feb 26 00:36 /mnt/md3.img

61 Gigabytes in my case... (and my system finished counting: I have 8.9M directories on there...)

Roger.

Signature · 6 lines
** [email protected] ** http://www.BitWizard.nl/ ** +31-15-2600998 **
**    Delftechpark 26 2628 XH  Delft, The Netherlands. KVK: 27239233    **
*-- BitWizard writes Linux device drivers for any device you may have! --*
Q: It doesn't work. A: Look buddy, doesn't work is an ambiguous statement. 
Does it sit on the couch all day? Is it unemployed? Please be specific! 
Define 'it' and what it isn't doing. --------- Adapted from lxrbot FAQ
#5 lore raw

Re: [PATCH 4/4] e2fsck: Add QCOW2 support

In reply to Ted Ts'o
Quoted 44 lines · Ted Ts'o
Quoted 11 lines · Lukas Czerner

This commit adds QCOW2 support for e2fsck. In order to avoid creating real QCOW2 image support, which would require creating a lot of code, we simply bypass the problem by converting the QCOW2 image into raw image and than let e2fsck work with raw image. Conversion itself can be quite fast, so it should not be a serious slowdown.

Add '-Q' option to specify path for the raw image. It not specified the raw image will be saved in /tmp direcotry in format <qcow2_filename>.raw.XXXXXX, where X chosen randomly.

If we're just going to convert the qcow2 image into a raw image, that means that if someone sends us a N gigabyte QCOW2 image, it will lots of time (I'm not sure I agree with the "quite fast part"), and consume an extra N gigabytes of free space to create the raw image.

In that case, I'm not so sure we really want to have a -Q option to e2fsck. We might be better off simply forcing the use of e2image to convert the image back.

Note that the other reason why it's a lot better to be able to allow e2fsck to be able to work on the raw image directly is that if a customer sends a qcow2's metadata-only image from their 3TB raid array, we won't be able to expand that to a raw image because of ext2/3/4's 2TB maximum file size limit. The qcow2 image might be only a few hundreds of megabytes, so being able to have e2fsck operate on that image directly would be a huge win.

Adding iomanager support would also allow debugfs to access the qcow2 image directly --- also a win.

Whether or not we add the io_manager support right away (eventually I think it's a must have feature), I don't think having a "decompress a qcow2 image to a sparse raw image" makes sense as an explicit e2fsck option. It just clutters up the e2fsck option space, and people might be confused because now e2fsck could break because there wasn't enough free space to decompress the raw image. Also, e2fsck doesn't delete the /tmp file afterwards, which is bad --- but if it takes a large amount of time to create the raw image, deleting afterwards is a bit of waste as well. Probably better to force the user to manage the converted raw file system image.

Quoted 2 lines

- Ted

Hi Ted,

sorry for late answer, but I was running some benchmarks to have some numbers to throw at you :). Now let's see how "qite fast" it actually is in comparison:

I have 6TB raid composed of four drives and I flooded it with lots and lots of files (copying /usr/share over and over again) and even created some big files (1M, 20M, 1G, 10G) so the number of used inodes on the filesystem is 10928139. I am using e2fsck form top of the master branch.

Before each step I run:
sync; echo 3 > /proc/sys/vm/drop_caches

exporting raw image:
time .//misc/e2image -r /dev/mapper/vg_raid-lv_stripe image.raw

	real    12m3.798s
	user    2m53.116s
	sys     3m38.430s

6,0G image.raw

exporting qcow2 image
time .//misc/e2image -Q /dev/mapper/vg_raid-lv_stripe image.qcow2 e2image 1.41.14 (22-Dec-2010)

	real    11m55.574s
	user    2m50.521s
	sys     3m41.515s
	6,1G    image.qcow2

So we can see that the running time is essentially the same, so there is no crazy overhead in creating qcow2 image. Note that qcow2 image is slightly bigger because of all the qcow2 related metadata and it's size really depends on the size of the device. Also I tried to see how long does it take to export bzipped2 raw image, but it is running almost one day now, so it is not even comparable.

e2fsck on the device:
time .//e2fsck/e2fsck -fn /dev/mapper/vg_raid-lv_stripe

	real    3m9.400s
	user    0m47.558s
	sys     0m15.098s

e2fsck on the raw image:
time .//e2fsck/e2fsck -fn image.raw

	real    2m36.767s
	user    0m47.613s
	sys     0m8.403s

We can see that e2fsck on the raw image is a bit faster, but that is obvious since the drive does not have to seek so much (right?).

Now converting qcow2 image into raw image:
time .//misc/e2image -r image.qcow2 image.qcow2.raw

	real    1m23.486s
	user    0m0.704s
	sys     0m22.574s

It is hard to say if it is "quite fast" or not. But I would say it is not terribly slow either. Just out of curiosity, I have tried to convert raw->qcow2 with qemu-img convert tool:

time qemu-img convert -O raw image.qcow2 image.qemu.raw ..it is running almost an hour now, so it is not comparable as well :)

e2fsck on the qcow2 image.
time .//e2fsck/e2fsck -fn -Q ./image.qcow2.img.tmp image.qcow2

	real    2m47.256s
	user    0m41.646s
	sys     0m28.618s

Now that is surprising. Well, not so much actually.. We can see that e2fsck check on the qcow2 image, including qcow2->raw conversion is a bit slower than checking raw image (by 7% which is not much) but it is still faster than checking device itself. Now, the reason is probably that the raw image we are creating is partially loaded into memory, hence accelerate e2fsck. So I do not think that converting image before check is such a bad idea (especially when you have enough memory:)).

I completely agree that having io_manager for the qcow2 format would be cool, if someone is willing to do that, but I am not convinced that it is worth it. Your concerns are all valid and I agree, however I do not think e2image is used by regular unexperienced users, so it should not confuse them, but that is just stupid assumption :).

Also, remember that if you really do not want to convert the image because of file size limit, or whatever, you can always use qemu-nbd to attach qcow2 image into nbd block device and use that as regular device.

Regarding the e2fsck and the qcow2 support (or -Q option), I think it is useful, but I do not really insist on keeping it and as you said we can always force user to use e2image for conversion. It is just, this way it seems easier to do it automatically. Maybe we can ask user whether he wants to keep the raw image after the check or not ?

Regaring separate qcow2.h file and "qcow2_" prefix. I have done this because I am using this code from e2image and e2fsck so it seemed convenient to have it in separate header, however I guess I can move it into e2image.c and e2image.h if you want.

So what do you think.

Thanks!
-Lukas

#6 lore raw

Re: [PATCH 4/4] e2fsck: Add QCOW2 support

Quoted 141 lines · Lukas Czerner
Quoted 44 lines · Ted Ts'o
Quoted 11 lines · Lukas Czerner

This commit adds QCOW2 support for e2fsck. In order to avoid creating real QCOW2 image support, which would require creating a lot of code, we simply bypass the problem by converting the QCOW2 image into raw image and than let e2fsck work with raw image. Conversion itself can be quite fast, so it should not be a serious slowdown.

Add '-Q' option to specify path for the raw image. It not specified the raw image will be saved in /tmp direcotry in format <qcow2_filename>.raw.XXXXXX, where X chosen randomly.

If we're just going to convert the qcow2 image into a raw image, that means that if someone sends us a N gigabyte QCOW2 image, it will lots of time (I'm not sure I agree with the "quite fast part"), and consume an extra N gigabytes of free space to create the raw image.

In that case, I'm not so sure we really want to have a -Q option to e2fsck.  We might be better off simply forcing the use of e2image to convert the image back.

Note that the other reason why it's a lot better to be able to allow e2fsck to be able to work on the raw image directly is that if a customer sends a qcow2's metadata-only image from their 3TB raid array, we won't be able to expand that to a raw image because of ext2/3/4's 2TB maximum file size limit.  The qcow2 image might be only a few hundreds of megabytes, so being able to have e2fsck operate on that image directly would be a huge win.

Adding iomanager support would also allow debugfs to access the qcow2 image directly --- also a win.

Whether or not we add the io_manager support right away (eventually I think it's a must have feature), I don't think having a "decompress a qcow2 image to a sparse raw image" makes sense as an explicit e2fsck option.  It just clutters up the e2fsck option space, and people might be confused because now e2fsck could break because there wasn't enough free space to decompress the raw image.  Also, e2fsck doesn't delete the /tmp file afterwards, which is bad --- but if it takes a large amount of time to create the raw image, deleting afterwards is a bit of waste as well.  Probably better to force the user to manage the converted raw file system image.

Quoted 2 lines

                                      - Ted

Hi Ted,

sorry for late answer, but I was running some benchmarks to have some numbers to throw at you :). Now let's see how "qite fast" it actually is in comparison:

I have 6TB raid composed of four drives and I flooded it with lots and lots of files (copying /usr/share over and over again) and even created some big files (1M, 20M, 1G, 10G) so the number of used inodes on the filesystem is 10928139. I am using e2fsck form top of the master branch.

Before each step I run:
sync; echo 3 > /proc/sys/vm/drop_caches

exporting raw image:
time .//misc/e2image -r /dev/mapper/vg_raid-lv_stripe image.raw

       real    12m3.798s
       user    2m53.116s
       sys     3m38.430s

       6,0G    image.raw

exporting qcow2 image
time .//misc/e2image -Q /dev/mapper/vg_raid-lv_stripe image.qcow2 e2image 1.41.14 (22-Dec-2010)

       real    11m55.574s
       user    2m50.521s
       sys     3m41.515s

       6,1G    image.qcow2

So we can see that the running time is essentially the same, so there is no crazy overhead in creating qcow2 image. Note that qcow2 image is slightly bigger because of all the qcow2 related metadata and it's size really depends on the size of the device. Also I tried to see how long does it take to export bzipped2 raw image, but it is running almost one day now, so it is not even comparable.

e2fsck on the device:
time .//e2fsck/e2fsck -fn /dev/mapper/vg_raid-lv_stripe

       real    3m9.400s
       user    0m47.558s
       sys     0m15.098s

e2fsck on the raw image:
time .//e2fsck/e2fsck -fn image.raw

       real    2m36.767s
       user    0m47.613s
       sys     0m8.403s

We can see that e2fsck on the raw image is a bit faster, but that is obvious since the drive does not have to seek so much (right?).

Now converting qcow2 image into raw image:
time .//misc/e2image -r image.qcow2 image.qcow2.raw

       real    1m23.486s
       user    0m0.704s
       sys     0m22.574s

It is hard to say if it is "quite fast" or not. But I would say it is not terribly slow either. Just out of curiosity, I have tried to convert raw->qcow2 with qemu-img convert tool:

time qemu-img convert -O raw image.qcow2 image.qemu.raw ..it is running almost an hour now, so it is not comparable as well :)

e2fsck on the qcow2 image.
time .//e2fsck/e2fsck -fn -Q ./image.qcow2.img.tmp image.qcow2

       real    2m47.256s
       user    0m41.646s
       sys     0m28.618s

Now that is surprising. Well, not so much actually.. We can see that e2fsck check on the qcow2 image, including qcow2->raw conversion is a bit slower than checking raw image (by 7% which is not much) but it is still faster than checking device itself. Now, the reason is probably that the raw image we are creating is partially loaded into memory, hence accelerate e2fsck. So I do not think that converting image before check is such a bad idea (especially when you have enough memory:)).

I completely agree that having io_manager for the qcow2 format would be cool, if someone is willing to do that, but I am not convinced that it is worth it. Your concerns are all valid and I agree, however I do not think e2image is used by regular unexperienced users, so it should not confuse them, but that is just stupid assumption :).

Quoted 3 lines

Also, remember that if you really do not want to convert the image because of file size limit, or whatever, you can always use qemu-nbd to attach qcow2 image into nbd block device and use that as regular device.

Did you consider the possibility to use QCOW2 format for doing a "tryout" fsck on the filesystem with the option to rollback?

If QCOW2 image is created with the 'backing_file' option set to the origin block device (and 'backing_fmt' is set to 'host_device'), then qemu-nbd will be able to see the exported image metadata as well as the filesystem data.

You can then do an "intrusive" fsck run on the NBD, mount your filesystem (from the NBD) and view the results.

If you are satisfied with the results, you can apply the fsck changes to the origin block device (there is probably a qemu-img command to do that). If you are unsatisfied with the results, you can simply discard the image or better yet, revert to a QCOW2 snapshot, which you created just before running fsck.

Can you provide the performance figures for running fsck over NBD?

Quoted 12 lines

Regarding the e2fsck and the qcow2 support (or -Q option), I think it is useful, but I do not really insist on keeping it and as you said we can always force user to use e2image for conversion. It is just, this way it seems easier to do it automatically. Maybe we can ask user whether he wants to keep the raw image after the check or not ?

Regaring separate qcow2.h file and "qcow2_" prefix. I have done this because I am using this code from e2image and e2fsck so it seemed convenient to have it in separate header, however I guess I can move it into e2image.c and e2image.h if you want.

Quoted 9 lines

So what do you think.

Thanks!
-Lukas
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

Re: [PATCH 4/4] e2fsck: Add QCOW2 support

Quoted 154 lines · Amir Goldstein
Quoted 141 lines · Lukas Czerner
Quoted 44 lines · Ted Ts'o
Quoted 11 lines · Lukas Czerner

This commit adds QCOW2 support for e2fsck. In order to avoid creating real QCOW2 image support, which would require creating a lot of code, we simply bypass the problem by converting the QCOW2 image into raw image and than let e2fsck work with raw image. Conversion itself can be quite fast, so it should not be a serious slowdown.

Add '-Q' option to specify path for the raw image. It not specified the raw image will be saved in /tmp direcotry in format <qcow2_filename>.raw.XXXXXX, where X chosen randomly.

If we're just going to convert the qcow2 image into a raw image, that means that if someone sends us a N gigabyte QCOW2 image, it will lots of time (I'm not sure I agree with the "quite fast part"), and consume an extra N gigabytes of free space to create the raw image.

In that case, I'm not so sure we really want to have a -Q option to e2fsck.  We might be better off simply forcing the use of e2image to convert the image back.

Note that the other reason why it's a lot better to be able to allow e2fsck to be able to work on the raw image directly is that if a customer sends a qcow2's metadata-only image from their 3TB raid array, we won't be able to expand that to a raw image because of ext2/3/4's 2TB maximum file size limit.  The qcow2 image might be only a few hundreds of megabytes, so being able to have e2fsck operate on that image directly would be a huge win.

Adding iomanager support would also allow debugfs to access the qcow2 image directly --- also a win.

Whether or not we add the io_manager support right away (eventually I think it's a must have feature), I don't think having a "decompress a qcow2 image to a sparse raw image" makes sense as an explicit e2fsck option.  It just clutters up the e2fsck option space, and people might be confused because now e2fsck could break because there wasn't enough free space to decompress the raw image.  Also, e2fsck doesn't delete the /tmp file afterwards, which is bad --- but if it takes a large amount of time to create the raw image, deleting afterwards is a bit of waste as well.  Probably better to force the user to manage the converted raw file system image.

Quoted 2 lines

                                      - Ted

Hi Ted,

sorry for late answer, but I was running some benchmarks to have some numbers to throw at you :). Now let's see how "qite fast" it actually is in comparison:

I have 6TB raid composed of four drives and I flooded it with lots and lots of files (copying /usr/share over and over again) and even created some big files (1M, 20M, 1G, 10G) so the number of used inodes on the filesystem is 10928139. I am using e2fsck form top of the master branch.

Before each step I run:
sync; echo 3 > /proc/sys/vm/drop_caches

exporting raw image:
time .//misc/e2image -r /dev/mapper/vg_raid-lv_stripe image.raw

       real    12m3.798s
       user    2m53.116s
       sys     3m38.430s

       6,0G    image.raw

exporting qcow2 image
time .//misc/e2image -Q /dev/mapper/vg_raid-lv_stripe image.qcow2 e2image 1.41.14 (22-Dec-2010)

       real    11m55.574s
       user    2m50.521s
       sys     3m41.515s

       6,1G    image.qcow2

So we can see that the running time is essentially the same, so there is no crazy overhead in creating qcow2 image. Note that qcow2 image is slightly bigger because of all the qcow2 related metadata and it's size really depends on the size of the device. Also I tried to see how long does it take to export bzipped2 raw image, but it is running almost one day now, so it is not even comparable.

e2fsck on the device:
time .//e2fsck/e2fsck -fn /dev/mapper/vg_raid-lv_stripe

       real    3m9.400s
       user    0m47.558s
       sys     0m15.098s

e2fsck on the raw image:
time .//e2fsck/e2fsck -fn image.raw

       real    2m36.767s
       user    0m47.613s
       sys     0m8.403s

We can see that e2fsck on the raw image is a bit faster, but that is obvious since the drive does not have to seek so much (right?).

Now converting qcow2 image into raw image:
time .//misc/e2image -r image.qcow2 image.qcow2.raw

       real    1m23.486s
       user    0m0.704s
       sys     0m22.574s

It is hard to say if it is "quite fast" or not. But I would say it is not terribly slow either. Just out of curiosity, I have tried to convert raw->qcow2 with qemu-img convert tool:

time qemu-img convert -O raw image.qcow2 image.qemu.raw ..it is running almost an hour now, so it is not comparable as well :)

e2fsck on the qcow2 image.
time .//e2fsck/e2fsck -fn -Q ./image.qcow2.img.tmp image.qcow2

       real    2m47.256s
       user    0m41.646s
       sys     0m28.618s

Now that is surprising. Well, not so much actually.. We can see that e2fsck check on the qcow2 image, including qcow2->raw conversion is a bit slower than checking raw image (by 7% which is not much) but it is still faster than checking device itself. Now, the reason is probably that the raw image we are creating is partially loaded into memory, hence accelerate e2fsck. So I do not think that converting image before check is such a bad idea (especially when you have enough memory:)).

I completely agree that having io_manager for the qcow2 format would be cool, if someone is willing to do that, but I am not convinced that it is worth it. Your concerns are all valid and I agree, however I do not think e2image is used by regular unexperienced users, so it should not confuse them, but that is just stupid assumption :).

Quoted 3 lines

Also, remember that if you really do not want to convert the image because of file size limit, or whatever, you can always use qemu-nbd to attach qcow2 image into nbd block device and use that as regular device.

Did you consider the possibility to use QCOW2 format for doing a "tryout" fsck on the filesystem with the option to rollback?

If QCOW2 image is created with the 'backing_file' option set to the origin block device (and 'backing_fmt' is set to 'host_device'), then qemu-nbd will be able to see the exported image metadata as well as the filesystem data.

Quoted 8 lines

You can then do an "intrusive" fsck run on the NBD, mount your filesystem (from the NBD) and view the results.

If you are satisfied with the results, you can apply the fsck changes to the origin block device (there is probably a qemu-img command to do that). If you are unsatisfied with the results, you can simply discard the image or better yet, revert to a QCOW2 snapshot, which you created just before running fsck.

But this is something you can do even now. You can mount the qcow2 metadata image without any problems, you just will not see any data. But I can take a look at this functionality, it seems simple enough.

Quoted 2 lines

Can you provide the performance figures for running fsck over NBD?

Well, unfortunately I do not have access to the same machine anymore, but I have simple results which has been done elsewhere, but due to lack of proper storage this has been done on loop device (should not affect raw and qcow2 results).

[+] fsck raw image

real    0m30.176s
user    0m22.397s
sys     0m2.289s

[+] fsck NBD exported qcow2 image

real    0m31.667s
user    0m21.561s
sys     0m3.293s

So you can see that performance here is a bit worse (5%).

Thanks!
-Lukas

Quoted 23 lines
Quoted 22 lines

Regarding the e2fsck and the qcow2 support (or -Q option), I think it is useful, but I do not really insist on keeping it and as you said we can always force user to use e2image for conversion. It is just, this way it seems easier to do it automatically. Maybe we can ask user whether he wants to keep the raw image after the check or not ?

Regaring separate qcow2.h file and "qcow2_" prefix. I have done this because I am using this code from e2image and e2fsck so it seemed convenient to have it in separate header, however I guess I can move it into e2image.c and e2image.h if you want.

So what do you think.

Thanks!
-Lukas
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#8 lore raw

Re: [PATCH 4/4] e2fsck: Add QCOW2 support

--snip--

Quoted 18 lines
Quoted 9 lines

Did you consider the possibility to use QCOW2 format for doing a "tryout" fsck on the filesystem with the option to rollback?

If QCOW2 image is created with the 'backing_file' option set to the origin block device (and 'backing_fmt' is set to 'host_device'), then qemu-nbd will be able to see the exported image metadata as well as the filesystem data.

Quoted 8 lines

You can then do an "intrusive" fsck run on the NBD, mount your filesystem (from the NBD) and view the results.

If you are satisfied with the results, you can apply the fsck changes to the origin block device (there is probably a qemu-img command to do that). If you are unsatisfied with the results, you can simply discard the image or better yet, revert to a QCOW2 snapshot, which you created just before running fsck.

Quoted 3 lines

But this is something you can do even now. You can mount the qcow2 metadata image without any problems, you just will not see any data. But I can take a look at this functionality, it seems simple enough.

So I have done this and it works as expected as long as the device you've created the image from is present in the system, which might not be true, especially in the case you are transferring the image to the another machine (bug report).

If the device with the same name as the original does not exist in the system qemu-nbd is not smart enough to just ignore that fact and mount the image anyway. And looking at the man page there is no way to do it.

So, the result is I am not going to include this into my patches (if someone does not change my mind:)) as I do not want to create just-another switch for e2image. Also I fail to see the benefit if it anyway:).

Thanks!
-Lukas

Quoted 15 lines
Quoted 3 lines

Can you provide the performance figures for running fsck over NBD?

Well, unfortunately I do not have access to the same machine anymore, but I have simple results which has been done elsewhere, but due to lack of proper storage this has been done on loop device (should not affect raw and qcow2 results).

[+] fsck raw image

real    0m30.176s
user    0m22.397s
sys     0m2.289s

[+] fsck NBD exported qcow2 image

Quoted 9 lines
real    0m31.667s
user    0m21.561s
sys     0m3.293s

So you can see that performance here is a bit worse (5%).

Thanks!
-Lukas

--snip--

#9 lore raw

Re: [PATCH 4/4] e2fsck: Add QCOW2 support

Quoted 29 lines · Lukas Czerner

--snip--

Quoted 18 lines
Quoted 9 lines

Did you consider the possibility to use QCOW2 format for doing a "tryout" fsck on the filesystem with the option to rollback?

If QCOW2 image is created with the 'backing_file' option set to the origin block device (and 'backing_fmt' is set to 'host_device'), then qemu-nbd will be able to see the exported image metadata as well as the filesystem data.

Quoted 8 lines

You can then do an "intrusive" fsck run on the NBD, mount your filesystem (from the NBD) and view the results.

If you are satisfied with the results, you can apply the fsck changes to the origin block device (there is probably a qemu-img command to do that). If you are unsatisfied with the results, you can simply discard the image or better yet, revert to a QCOW2 snapshot, which you created just before running fsck.

Quoted 3 lines

But this is something you can do even now. You can mount the qcow2 metadata image without any problems, you just will not see any data. But I can take a look at this functionality, it seems simple enough.

So I have done this and it works as expected as long as the device you've created the image from is present in the system, which might not be true, especially in the case you are transferring the image to the another machine (bug report).

Quoted 8 lines

If the device with the same name as the original does not exist in the system qemu-nbd is not smart enough to just ignore that fact and mount the image anyway. And looking at the man page there is no way to do it.

So, the result is I am not going to include this into my patches (if someone does not change my mind:)) as I do not want to create just-another switch for e2image. Also I fail to see the benefit if it anyway:).

The benefit is, as I see it, is with the following capability:
A user with a corrupted fs, sends an e2image to an expert,
having him examine the file system (so far we already have).
Then the expert can fix the fs image (say using hard core debugfs'ing) and send it back to the user.
The user can then "test mount" the fixed fs and if his valuable data is back, send the other half of the payment to the expert, apply the fix to the origin device and go on with his life.

It's a shame that qemu-nbd doesn't play along with that plan, but you can't blame it, can you...

Anyway, thanks for testing my idea and thanks for QCOW2 e2image :-) This is just one example of the nice things that the new e2image format can be leveraged to.

Amir.

#10 lore raw

Re: [PATCH 4/4] e2fsck: Add QCOW2 support

In reply to Lukas Czerner

Hi Ted,

any comment on this ?

Thanks!
-Lukas

Quoted 161 lines · Lukas Czerner
Quoted 44 lines · Ted Ts'o
Quoted 11 lines · Lukas Czerner

This commit adds QCOW2 support for e2fsck. In order to avoid creating real QCOW2 image support, which would require creating a lot of code, we simply bypass the problem by converting the QCOW2 image into raw image and than let e2fsck work with raw image. Conversion itself can be quite fast, so it should not be a serious slowdown.

Add '-Q' option to specify path for the raw image. It not specified the raw image will be saved in /tmp direcotry in format <qcow2_filename>.raw.XXXXXX, where X chosen randomly.

If we're just going to convert the qcow2 image into a raw image, that means that if someone sends us a N gigabyte QCOW2 image, it will lots of time (I'm not sure I agree with the "quite fast part"), and consume an extra N gigabytes of free space to create the raw image.

In that case, I'm not so sure we really want to have a -Q option to e2fsck. We might be better off simply forcing the use of e2image to convert the image back.

Note that the other reason why it's a lot better to be able to allow e2fsck to be able to work on the raw image directly is that if a customer sends a qcow2's metadata-only image from their 3TB raid array, we won't be able to expand that to a raw image because of ext2/3/4's 2TB maximum file size limit. The qcow2 image might be only a few hundreds of megabytes, so being able to have e2fsck operate on that image directly would be a huge win.

Adding iomanager support would also allow debugfs to access the qcow2 image directly --- also a win.

Whether or not we add the io_manager support right away (eventually I think it's a must have feature), I don't think having a "decompress a qcow2 image to a sparse raw image" makes sense as an explicit e2fsck option. It just clutters up the e2fsck option space, and people might be confused because now e2fsck could break because there wasn't enough free space to decompress the raw image. Also, e2fsck doesn't delete the /tmp file afterwards, which is bad --- but if it takes a large amount of time to create the raw image, deleting afterwards is a bit of waste as well. Probably better to force the user to manage the converted raw file system image.

Quoted 2 lines

- Ted

Hi Ted,

sorry for late answer, but I was running some benchmarks to have some numbers to throw at you :). Now let's see how "qite fast" it actually is in comparison:

I have 6TB raid composed of four drives and I flooded it with lots and lots of files (copying /usr/share over and over again) and even created some big files (1M, 20M, 1G, 10G) so the number of used inodes on the filesystem is 10928139. I am using e2fsck form top of the master branch.

Before each step I run:
sync; echo 3 > /proc/sys/vm/drop_caches

exporting raw image:
time .//misc/e2image -r /dev/mapper/vg_raid-lv_stripe image.raw

	real    12m3.798s
	user    2m53.116s
	sys     3m38.430s

6,0G image.raw

exporting qcow2 image
time .//misc/e2image -Q /dev/mapper/vg_raid-lv_stripe image.qcow2 e2image 1.41.14 (22-Dec-2010)

	real    11m55.574s
	user    2m50.521s
	sys     3m41.515s
	6,1G    image.qcow2

So we can see that the running time is essentially the same, so there is no crazy overhead in creating qcow2 image. Note that qcow2 image is slightly bigger because of all the qcow2 related metadata and it's size really depends on the size of the device. Also I tried to see how long does it take to export bzipped2 raw image, but it is running almost one day now, so it is not even comparable.

e2fsck on the device:
time .//e2fsck/e2fsck -fn /dev/mapper/vg_raid-lv_stripe

	real    3m9.400s
	user    0m47.558s
	sys     0m15.098s

e2fsck on the raw image:
time .//e2fsck/e2fsck -fn image.raw

	real    2m36.767s
	user    0m47.613s
	sys     0m8.403s

We can see that e2fsck on the raw image is a bit faster, but that is obvious since the drive does not have to seek so much (right?).

Now converting qcow2 image into raw image:
time .//misc/e2image -r image.qcow2 image.qcow2.raw

	real    1m23.486s
	user    0m0.704s
	sys     0m22.574s

It is hard to say if it is "quite fast" or not. But I would say it is not terribly slow either. Just out of curiosity, I have tried to convert raw->qcow2 with qemu-img convert tool:

time qemu-img convert -O raw image.qcow2 image.qemu.raw ..it is running almost an hour now, so it is not comparable as well :)

e2fsck on the qcow2 image.
time .//e2fsck/e2fsck -fn -Q ./image.qcow2.img.tmp image.qcow2

	real    2m47.256s
	user    0m41.646s
	sys     0m28.618s

Now that is surprising. Well, not so much actually.. We can see that e2fsck check on the qcow2 image, including qcow2->raw conversion is a bit slower than checking raw image (by 7% which is not much) but it is still faster than checking device itself. Now, the reason is probably that the raw image we are creating is partially loaded into memory, hence accelerate e2fsck. So I do not think that converting image before check is such a bad idea (especially when you have enough memory:)).

I completely agree that having io_manager for the qcow2 format would be cool, if someone is willing to do that, but I am not convinced that it is worth it. Your concerns are all valid and I agree, however I do not think e2image is used by regular unexperienced users, so it should not confuse them, but that is just stupid assumption :).

Also, remember that if you really do not want to convert the image because of file size limit, or whatever, you can always use qemu-nbd to attach qcow2 image into nbd block device and use that as regular device.

Regarding the e2fsck and the qcow2 support (or -Q option), I think it is useful, but I do not really insist on keeping it and as you said we can always force user to use e2image for conversion. It is just, this way it seems easier to do it automatically. Maybe we can ask user whether he wants to keep the raw image after the check or not ?

Regaring separate qcow2.h file and "qcow2_" prefix. I have done this because I am using this code from e2image and e2fsck so it seemed convenient to have it in separate header, however I guess I can move it into e2image.c and e2image.h if you want.

So what do you think.

Thanks!
-Lukas