Hello Stefan,

Is it your means:

There is an assumption that a block device cannot be addressed below 512
byte sectors.
A reasonable protection in block.c:bdrv_create() to check whether size is a
multiple of BDRV_SECTOR_SIZE.

Signed-off-by: Mitnick Lyu <mitnick....@gmail.com>
---
 block.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index f731c7a..a80ec49 100644
--- a/block.c
+++ b/block.c
@@ -239,6 +239,16 @@ int bdrv_create(BlockDriver *drv, const char* filename,
    if (!drv->bdrv_create)
        return -ENOTSUP;

+       while (options && options->name) {
+               if (!strcmp(options->name, "size")) {
+                       if (options->value.n % 512 == 0)
+                               break;
+                       else
+                               return -EINVAL;
+               }
+               options++;
+       }
+
    return drv->bdrv_create(filename, options);
 }

--
1.7.0.4

2011/4/10 Stefan Hajnoczi <stefa...@gmail.com>

> On Sat, Apr 9, 2011 at 5:51 PM, Lyu Mitnick <mitnick....@gmail.com> wrote:
> > Hell all,
> > I have take a look of block/vpc.c and meet a question in vpc_create(). At
> > the line
> > 550, the code is:
> > total_sectors = options->value.n / 512;
> > I am wondering whether the size between total_sectors * 512
> > and options->value.n
> > would be discard.
>
> Yes, it rounds down.  This reflects the assumption that a block device
> cannot be addressed below 512 byte sectors.  Because of this block
> devices size must be a multiple of 512 bytes.
>
> I think a reasonable protection would be to have block.c:bdrv_create()
> fail if size is not a multiple of BDRV_SECTOR_SIZE.  This way other
> image formats are protected too.
>
> Stefan
>


By the way, how could I know a submitted patch is accepted or not??

Thanks a lot

Mitnick

Reply via email to