qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block:Fix FIXED base vpc be probed to raw format
@ 2015-02-08 12:39 Xiaodong Gong
  2015-02-09 14:54 ` Stefan Hajnoczi
  0 siblings, 1 reply; 6+ messages in thread
From: Xiaodong Gong @ 2015-02-08 12:39 UTC (permalink / raw)
  To: kwolf, stefanha; +Cc: Xiaodong Gong, qemu-devel

When open the vpc snapshot based FIXED format, its backing file,
this FIXED vpc image, could be probed as a raw image, because that
the find_image_format just checkout the first sector.

Add a re-probe for the last sector to FIXED base vpc image,when get
a NULL or raw driver in first sector probe.

Signed-off-by: Xiaodong Gong <gongxiaodong1@huawei.com>
---
 block.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 7 deletions(-)

diff --git a/block.c b/block.c
index d45e4dd..e183515 100644
--- a/block.c
+++ b/block.c
@@ -702,20 +702,24 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,
     return drv;
 }
 
-static int find_image_format(BlockDriverState *bs, const char *filename,
-                             BlockDriver **pdrv, Error **errp)
+static int probe_image_format(BlockDriverState *bs, const char *filename,
+                              int64_t offset, BlockDriver **pdrv, Error **errp,
+                              bool isfoot)
 {
     BlockDriver *drv;
     uint8_t buf[BLOCK_PROBE_BUF_SIZE];
     int ret = 0;
 
-    /* Return the raw BlockDriver * to scsi-generic devices or empty drives */
-    if (bs->sg || !bdrv_is_inserted(bs) || bdrv_getlength(bs) == 0) {
-        *pdrv = &bdrv_raw;
+    if (!bs || !filename) {
+        *pdrv = NULL;
         return ret;
     }
 
-    ret = bdrv_pread(bs, 0, buf, sizeof(buf));
+    if (offset + sizeof(buf) > bs->total_sectors << BDRV_SECTOR_BITS) {
+        return ret;
+    }
+
+    ret = bdrv_pread(bs, offset, buf, sizeof(buf));
     if (ret < 0) {
         error_setg_errno(errp, -ret, "Could not read image for determining its "
                          "format");
@@ -724,12 +728,49 @@ static int find_image_format(BlockDriverState *bs, const char *filename,
     }
 
     drv = bdrv_probe_all(buf, ret, filename);
-    if (!drv) {
+    if (!drv && isfoot) {
         error_setg(errp, "Could not determine image format: No compatible "
                    "driver found");
         ret = -ENOENT;
     }
     *pdrv = drv;
+
+    return ret;
+}
+
+static int find_image_format(BlockDriverState *bs, const char *filename,
+                             BlockDriver **pdrv, Error **errp)
+{
+    int last_sector_offset;
+    int ret = 0;
+
+    *pdrv = NULL;
+
+    /* Return the raw BlockDriver * to scsi-generic devices or empty drives */
+    if (bs->sg || !bdrv_is_inserted(bs) || bdrv_getlength(bs) == 0) {
+        *pdrv = &bdrv_raw;
+        return ret;
+    }
+
+    /* probe the header to guess image format */
+    ret = probe_image_format(bs, filename, 0, pdrv, errp, false);
+    if (ret < 0) {
+        return ret;
+    }
+
+    /* The FIXED base img of VHD only has the footer in tail. The drv could
+     * be NULL or raw */
+    if (*pdrv && *pdrv != &bdrv_raw) {
+        return ret;
+    }
+
+    last_sector_offset = (bs->total_sectors - 1) << BDRV_SECTOR_BITS;
+    ret = probe_image_format(bs, filename, last_sector_offset, pdrv,
+        errp, true);
+    if (ret < 0) {
+        return ret;
+    }
+
     return ret;
 }
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] block:Fix FIXED base vpc be probed to raw format
  2015-02-08 12:39 [Qemu-devel] [PATCH] block:Fix FIXED base vpc be probed to raw format Xiaodong Gong
@ 2015-02-09 14:54 ` Stefan Hajnoczi
  2015-02-10 15:04   ` Xiaodong Gong
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-02-09 14:54 UTC (permalink / raw)
  To: Xiaodong Gong; +Cc: kwolf, Xiaodong Gong, qemu-devel, stefanha

[-- Attachment #1: Type: text/plain, Size: 986 bytes --]

On Sun, Feb 08, 2015 at 08:39:52PM +0800, Xiaodong Gong wrote:
> When open the vpc snapshot based FIXED format, its backing file,
> this FIXED vpc image, could be probed as a raw image, because that
> the find_image_format just checkout the first sector.
> 
> Add a re-probe for the last sector to FIXED base vpc image,when get
> a NULL or raw driver in first sector probe.
> 
> Signed-off-by: Xiaodong Gong <gongxiaodong1@huawei.com>
> ---
>  block.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 48 insertions(+), 7 deletions(-)

This approach is likely to cause issues because it makes no distiction
between headers and footers.  Most image formats only have a header and
would now be misdetected if a raw image had a header in its last sector.

When a vpc image has a backing file, does it make sense to set the
bs->backing_format to "vpc"?  That way we'll try to open the backing
file as a vpc image without probing.

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] block:Fix FIXED base vpc be probed to raw format
  2015-02-09 14:54 ` Stefan Hajnoczi
@ 2015-02-10 15:04   ` Xiaodong Gong
  2015-02-11 13:39     ` Stefan Hajnoczi
  0 siblings, 1 reply; 6+ messages in thread
From: Xiaodong Gong @ 2015-02-10 15:04 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Xiaodong Gong, qemu-devel@nongnu.org, Stefan Hajnoczi

[-- Attachment #1: Type: text/plain, Size: 1282 bytes --]

On Mon, Feb 9, 2015 at 10:54 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:

> On Sun, Feb 08, 2015 at 08:39:52PM +0800, Xiaodong Gong wrote:
> > When open the vpc snapshot based FIXED format, its backing file,
> > this FIXED vpc image, could be probed as a raw image, because that
> > the find_image_format just checkout the first sector.
> >
> > Add a re-probe for the last sector to FIXED base vpc image,when get
> > a NULL or raw driver in first sector probe.
> >
> > Signed-off-by: Xiaodong Gong <gongxiaodong1@huawei.com>
> > ---
> >  block.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
> >  1 file changed, 48 insertions(+), 7 deletions(-)
>
> This approach is likely to cause issues because it makes no distiction
> between headers and footers.  Most image formats only have a header and
> would now be misdetected if a raw image had a header in its last sector.
>
> When a vpc image has a backing file, does it make sense to set the
> bs->backing_format to "vpc"?  That way we'll try to open the backing
> file as a vpc image without probing.
>
> Stefan
>


It works, but this probing of format sounds good . Giving a argument of bs
to bdrv_probe and each of funtion of probe get it's own checking method is
better, but the foot-print of patch is longer.

[-- Attachment #2: Type: text/html, Size: 1992 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] block:Fix FIXED base vpc be probed to raw format
  2015-02-10 15:04   ` Xiaodong Gong
@ 2015-02-11 13:39     ` Stefan Hajnoczi
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2015-02-11 13:39 UTC (permalink / raw)
  To: Xiaodong Gong
  Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel@nongnu.org, Xiaodong Gong

[-- Attachment #1: Type: text/plain, Size: 1638 bytes --]

On Tue, Feb 10, 2015 at 11:04:31PM +0800, Xiaodong Gong wrote:
> On Mon, Feb 9, 2015 at 10:54 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> 
> > On Sun, Feb 08, 2015 at 08:39:52PM +0800, Xiaodong Gong wrote:
> > > When open the vpc snapshot based FIXED format, its backing file,
> > > this FIXED vpc image, could be probed as a raw image, because that
> > > the find_image_format just checkout the first sector.
> > >
> > > Add a re-probe for the last sector to FIXED base vpc image,when get
> > > a NULL or raw driver in first sector probe.
> > >
> > > Signed-off-by: Xiaodong Gong <gongxiaodong1@huawei.com>
> > > ---
> > >  block.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
> > >  1 file changed, 48 insertions(+), 7 deletions(-)
> >
> > This approach is likely to cause issues because it makes no distiction
> > between headers and footers.  Most image formats only have a header and
> > would now be misdetected if a raw image had a header in its last sector.
> >
> > When a vpc image has a backing file, does it make sense to set the
> > bs->backing_format to "vpc"?  That way we'll try to open the backing
> > file as a vpc image without probing.
> >
> > Stefan
> >
> 
> 
> It works, but this probing of format sounds good . Giving a argument of bs
> to bdrv_probe and each of funtion of probe get it's own checking method is
> better, but the foot-print of patch is longer.

I'm not suggesting a longer patch.

Can the vpc .bdrv_open() code that loads the backing filename also set
bs->backing_format to "vpc" so QEMU will always use vpc for the backing
file?

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] block:Fix FIXED base vpc be probed to raw format
@ 2015-02-14  2:13 Xiaodong Gong
  2015-02-15 13:41 ` Xiaodong Gong
  0 siblings, 1 reply; 6+ messages in thread
From: Xiaodong Gong @ 2015-02-14  2:13 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel@nongnu.org, Xiaodong Gong

[-- Attachment #1: Type: text/plain, Size: 1833 bytes --]

On Wed, Feb 11, 2015 at 9:39 PM, Stefan Hajnoczi <stefanha@redhat.com>
wrote:

> On Tue, Feb 10, 2015 at 11:04:31PM +0800, Xiaodong Gong wrote:
> > On Mon, Feb 9, 2015 at 10:54 PM, Stefan Hajnoczi <stefanha@gmail.com>
> wrote:
> >
> > > On Sun, Feb 08, 2015 at 08:39:52PM +0800, Xiaodong Gong wrote:
> > > > When open the vpc snapshot based FIXED format, its backing file,
> > > > this FIXED vpc image, could be probed as a raw image, because that
> > > > the find_image_format just checkout the first sector.
> > > >
> > > > Add a re-probe for the last sector to FIXED base vpc image,when get
> > > > a NULL or raw driver in first sector probe.
> > > >
> > > > Signed-off-by: Xiaodong Gong <gongxiaodong1@huawei.com>
> > > > ---
> > > >  block.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
> > > >  1 file changed, 48 insertions(+), 7 deletions(-)
> > >
> > > This approach is likely to cause issues because it makes no distiction
> > > between headers and footers.  Most image formats only have a header and
> > > would now be misdetected if a raw image had a header in its last
> sector.
> > >
> > > When a vpc image has a backing file, does it make sense to set the
> > > bs->backing_format to "vpc"?  That way we'll try to open the backing
> > > file as a vpc image without probing.
> > >
> > > Stefan
> > >
> >
> >
> > It works, but this probing of format sounds good . Giving a argument of
> bs
> > to bdrv_probe and each of funtion of probe get it's own checking method
> is
> > better, but the foot-print of patch is longer.
>
> I'm not suggesting a longer patch.
>
> Can the vpc .bdrv_open() code that loads the backing filename also set
> bs->backing_format to "vpc" so QEMU will always use vpc for the backing
> file?
>
> Stefan
>

It is not a perfect choice, but a right one. I will give a v2 of patch.

[-- Attachment #2: Type: text/html, Size: 2709 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] block:Fix FIXED base vpc be probed to raw format
  2015-02-14  2:13 Xiaodong Gong
@ 2015-02-15 13:41 ` Xiaodong Gong
  0 siblings, 0 replies; 6+ messages in thread
From: Xiaodong Gong @ 2015-02-15 13:41 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Kevin Wolf, Stefan Hajnoczi, qemu-devel@nongnu.org, Xiaodong Gong

[-- Attachment #1: Type: text/plain, Size: 2104 bytes --]

Sent the v2 version of this patch integrated in v9 verison of VHD_DEFFERING
patch.
Fixed this problem with backing_format.

On Sat, Feb 14, 2015 at 10:13 AM, Xiaodong Gong <gordongong0350@gmail.com>
wrote:

>
>
> On Wed, Feb 11, 2015 at 9:39 PM, Stefan Hajnoczi <stefanha@redhat.com>
> wrote:
>
>> On Tue, Feb 10, 2015 at 11:04:31PM +0800, Xiaodong Gong wrote:
>> > On Mon, Feb 9, 2015 at 10:54 PM, Stefan Hajnoczi <stefanha@gmail.com>
>> wrote:
>> >
>> > > On Sun, Feb 08, 2015 at 08:39:52PM +0800, Xiaodong Gong wrote:
>> > > > When open the vpc snapshot based FIXED format, its backing file,
>> > > > this FIXED vpc image, could be probed as a raw image, because that
>> > > > the find_image_format just checkout the first sector.
>> > > >
>> > > > Add a re-probe for the last sector to FIXED base vpc image,when get
>> > > > a NULL or raw driver in first sector probe.
>> > > >
>> > > > Signed-off-by: Xiaodong Gong <gongxiaodong1@huawei.com>
>> > > > ---
>> > > >  block.c | 55
>> ++++++++++++++++++++++++++++++++++++++++++++++++-------
>> > > >  1 file changed, 48 insertions(+), 7 deletions(-)
>> > >
>> > > This approach is likely to cause issues because it makes no distiction
>> > > between headers and footers.  Most image formats only have a header
>> and
>> > > would now be misdetected if a raw image had a header in its last
>> sector.
>> > >
>> > > When a vpc image has a backing file, does it make sense to set the
>> > > bs->backing_format to "vpc"?  That way we'll try to open the backing
>> > > file as a vpc image without probing.
>> > >
>> > > Stefan
>> > >
>> >
>> >
>> > It works, but this probing of format sounds good . Giving a argument of
>> bs
>> > to bdrv_probe and each of funtion of probe get it's own checking method
>> is
>> > better, but the foot-print of patch is longer.
>>
>> I'm not suggesting a longer patch.
>>
>> Can the vpc .bdrv_open() code that loads the backing filename also set
>> bs->backing_format to "vpc" so QEMU will always use vpc for the backing
>> file?
>>
>> Stefan
>>
>
> It is not a perfect choice, but a right one. I will give a v2 of patch.
>

[-- Attachment #2: Type: text/html, Size: 3252 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-02-15 13:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-08 12:39 [Qemu-devel] [PATCH] block:Fix FIXED base vpc be probed to raw format Xiaodong Gong
2015-02-09 14:54 ` Stefan Hajnoczi
2015-02-10 15:04   ` Xiaodong Gong
2015-02-11 13:39     ` Stefan Hajnoczi
  -- strict thread matches above, loose matches on Subject: below --
2015-02-14  2:13 Xiaodong Gong
2015-02-15 13:41 ` Xiaodong Gong

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).