xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Miroslav Rezanina <mrezanin@redhat.com>
To: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH] Fix old QCow tapdisk image handling
Date: Fri, 30 Apr 2010 05:07:49 -0400 (EDT)	[thread overview]
Message-ID: <1802353510.89601272618469980.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> (raw)
In-Reply-To: <256268088.89581272618420775.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>

When I tried to use QCow image, I found that only each second boot is successful. As I discovered, this is caused by wrong handling old qcow tapdisk images. Extended header flag is not stored correctly so the blktap tries to change endian fo L1 table on each startup.

Here is a fix for this problem:

--
diff -r 9a1d7caa2024 tools/blktap/drivers/block-qcow.c
--- a/tools/blktap/drivers/block-qcow.c	Mon Apr 26 12:13:23 2010 +0100
+++ b/tools/blktap/drivers/block-qcow.c	Fri Apr 30 11:00:41 2010 +0200
@@ -862,11 +862,12 @@
 		be32_to_cpus(&exthdr->xmagic);
 		if(exthdr->xmagic != XEN_MAGIC) 
 			goto end_xenhdr;
-    
+	
+		be32_to_cpus(&exthdr->flags);
 		/* Try to detect old tapdisk images. They have to be fixed because 
 		 * they don't use big endian but native endianess for the L1 table */
 		if ((exthdr->flags & EXTHDR_L1_BIG_ENDIAN) == 0) {
-
+			QCowHeader_ext *tmphdr = (QCowHeader_ext *)(buf2 + sizeof(QCowHeader));
 			/* 
 			   The image is broken. Fix it. The L1 table has already been 
 			   byte-swapped, so we can write it to the image file as it is
@@ -874,6 +875,11 @@
 			   for operation.
 			 */
 
+			/* Change ENDIAN flag and copy it to store buffer */
+			exthdr->flags |= EXTHDR_L1_BIG_ENDIAN;
+			tmphdr->flags = cpu_to_be32(exthdr->flags);
+
+
 			DPRINTF("qcow: Converting image to big endian L1 table\n");
 
 			memcpy(buf2 + s->l1_table_offset, s->l1_table, l1_table_size);
@@ -888,13 +894,6 @@
 				cpu_to_be64s(&s->l1_table[i]);
 			}
 
-			/* Write the big endian flag to the extended header */
-			exthdr->flags |= EXTHDR_L1_BIG_ENDIAN;
-
-			if (write(fd, buf, 512) != 512) {
-				DPRINTF("qcow: Failed to write extended header\n");
-				goto fail;
-			}
 		}
 
 		/*Finally check the L1 table cksum*/
@@ -905,7 +904,6 @@
 			goto end_xenhdr;
 			
 		be32_to_cpus(&exthdr->min_cluster_alloc);
-		be32_to_cpus(&exthdr->flags);
 		s->sparse = (exthdr->flags & SPARSE_FILE);
 		s->min_cluster_alloc = exthdr->min_cluster_alloc; 
 	}
@@ -1263,6 +1261,7 @@
 	} else
 		flags = SPARSE_FILE;
 
+	flags |= EXTHDR_L1_BIG_ENDIAN;
 	exthdr.flags = cpu_to_be32(flags);
 	
 	/* write all the data */
-- 
Miroslav Rezanina
Software Engineer - XEN Virtualization Team

           reply	other threads:[~2010-04-30  9:07 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <256268088.89581272618420775.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>]

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=1802353510.89601272618469980.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com \
    --to=mrezanin@redhat.com \
    --cc=xen-devel@lists.xensource.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).