Message ID | 1401315594-12662-3-git-send-email-mreitz@redhat.com |
---|---|
State | New |
Headers | show |
On 05/28/2014 04:19 PM, Max Reitz wrote: > If bdrv_pread() returns an error, it is very unlikely that it was > ENOMEM. In this case, the return value should be passed along; as > bdrv_pread() will always either return the number of bytes read or a > negative value (the error code), the condition for checking whether > bdrv_pread() failed can be simplified (and clarified) as well. > > Signed-off-by: Max Reitz <mreitz@redhat.com> > --- > block/qcow2-refcount.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > ret = bdrv_pread(bs->file, s->refcount_table_offset, > s->refcount_table, refcount_table_size2); > - if (ret != refcount_table_size2) Can bdrv_pread() ever do a short read? If it can, then in the old code, that was an error, > + if (ret < 0) { > goto fail; but in the new code it falls through to the remaining code; and I'm not sure whether that changes semantics. (My quick read of bdrv_pread() didn't find an obvious answer, but it DID raise another question: why do we have '.iov_base = (void *)buf' when buf is already void*?)
On 29.05.2014 00:33, Eric Blake wrote: > On 05/28/2014 04:19 PM, Max Reitz wrote: >> If bdrv_pread() returns an error, it is very unlikely that it was >> ENOMEM. In this case, the return value should be passed along; as >> bdrv_pread() will always either return the number of bytes read or a >> negative value (the error code), the condition for checking whether >> bdrv_pread() failed can be simplified (and clarified) as well. >> >> Signed-off-by: Max Reitz <mreitz@redhat.com> >> --- >> block/qcow2-refcount.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> ret = bdrv_pread(bs->file, s->refcount_table_offset, >> s->refcount_table, refcount_table_size2); >> - if (ret != refcount_table_size2) > Can bdrv_pread() ever do a short read? If it can, then in the old code, > that was an error, As far as I'm informed, it cannot (see for instance the commit message of b404bf854217dbe8a5649449eb3ad33777f7d900). >> + if (ret < 0) { >> goto fail; > but in the new code it falls through to the remaining code; and I'm not > sure whether that changes semantics. > > (My quick read of bdrv_pread() didn't find an obvious answer, but it DID > raise another question: why do we have '.iov_base = (void *)buf' when > buf is already void*?) Perhaps because that way it resembles bdrv_pwrite() more closely. :-P Max
Am 29.05.2014 um 00:19 hat Max Reitz geschrieben: > If bdrv_pread() returns an error, it is very unlikely that it was > ENOMEM. In this case, the return value should be passed along; as > bdrv_pread() will always either return the number of bytes read or a > negative value (the error code), the condition for checking whether > bdrv_pread() failed can be simplified (and clarified) as well. > > Signed-off-by: Max Reitz <mreitz@redhat.com> Thanks, I applied this to my local branch with the malloc changes that you depend on. I'll either merge it together with my patches or include it in a v3 of my series. Kevin
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 494a182..a8d02e0 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -49,19 +49,21 @@ int qcow2_refcount_init(BlockDriverState *bs) if (s->refcount_table_size > 0) { if (s->refcount_table == NULL) { + ret = -ENOMEM; goto fail; } BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_LOAD); ret = bdrv_pread(bs->file, s->refcount_table_offset, s->refcount_table, refcount_table_size2); - if (ret != refcount_table_size2) + if (ret < 0) { goto fail; + } for(i = 0; i < s->refcount_table_size; i++) be64_to_cpus(&s->refcount_table[i]); } return 0; fail: - return -ENOMEM; + return ret; } void qcow2_refcount_close(BlockDriverState *bs)
If bdrv_pread() returns an error, it is very unlikely that it was ENOMEM. In this case, the return value should be passed along; as bdrv_pread() will always either return the number of bytes read or a negative value (the error code), the condition for checking whether bdrv_pread() failed can be simplified (and clarified) as well. Signed-off-by: Max Reitz <mreitz@redhat.com> --- block/qcow2-refcount.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)