WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] [blktap] Fix block device getsize bug in

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] [blktap] Fix block device getsize bug in qcow when backing_filename is a block device.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 05 Sep 2006 16:50:12 +0000
Delivery-date: Tue, 05 Sep 2006 09:50:39 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User jchesterfield@xxxxxxxxxxxxxxxxxxxxxxx
# Node ID 323a89a3c01c6c1c0b421b5ff9877ab3d3b31364
# Parent  45746c770018bc8ab54b39d5798bfd47eeb73cbc
[blktap] Fix block device getsize bug in qcow when backing_filename is a block 
device.
---
 tools/blktap/drivers/block-qcow.c |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff -r 45746c770018 -r 323a89a3c01c tools/blktap/drivers/block-qcow.c
--- a/tools/blktap/drivers/block-qcow.c Tue Sep 05 14:28:19 2006 +0100
+++ b/tools/blktap/drivers/block-qcow.c Tue Sep 05 15:35:42 2006 +0100
@@ -235,6 +235,25 @@ static uint32_t gen_cksum(char *ptr, int
        memcpy(&ret, md, sizeof(uint32_t));
        free(md);
        return ret;
+}
+
+static int get_filesize(char *filename, uint64_t *size, struct stat *st)
+{
+       int blockfd;
+
+       /*Set to the backing file size*/
+       if(S_ISBLK(st->st_mode)) {
+               blockfd = open(filename, O_RDONLY);
+               if (blockfd < 0)
+                       return -1;
+               if (ioctl(blockfd,BLKGETSIZE,size)!=0) {
+                       printf("Unable to get Block device size\n");
+                       close(blockfd);
+                       return -1;
+               }
+               close(blockfd);
+       } else *size = (st->st_size >> SECTOR_SHIFT);   
+       return 0;
 }
 
 static int qcow_set_key(struct td_state *bs, const char *key)
@@ -1204,12 +1223,14 @@ int qcow_create(const char *filename, ui
                        header_size += backing_filename_len;
                        
                        /*Set to the backing file size*/
-                       size = (st.st_size >> SECTOR_SHIFT);
+                       if(get_filesize(backing_filename, &size, &st)) {
+                               return -1;
+                       }
                        DPRINTF("Backing file size detected: %lld sectors" 
                                "(total %lld [%lld MB])\n", 
-                               (long long)total_size, 
-                               (long long)(total_size << SECTOR_SHIFT), 
-                               (long long)(total_size >> 11));
+                               (long long)size, 
+                               (long long)(size << SECTOR_SHIFT), 
+                               (long long)(size >> 11));
                } else {
                        backing_file = NULL;
                        DPRINTF("Setting file size: %lld (total %lld)\n", 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] [blktap] Fix block device getsize bug in qcow when backing_filename is a block device., Xen patchbot-unstable <=