All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher?
@ 2017-08-04 12:16 Markus Armbruster
  2017-08-04 12:31 ` [Qemu-devel] Is the use of bdrv_getlength() in parallels.c kosher? (was: Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher?) Markus Armbruster
  2017-08-04 13:08 ` [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher? Denis V. Lunev
  0 siblings, 2 replies; 5+ messages in thread
From: Markus Armbruster @ 2017-08-04 12:16 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: qemu-devel, qemu-block, Kevin Wolf

Denis, you added this in commit d50d822:

#ifdef CONFIG_FALLOCATE
    if (s->has_fallocate && aiocb->aio_offset >= bdrv_getlength(aiocb->bs)) {
        int ret = do_fallocate(s->fd, 0, aiocb->aio_offset, aiocb->aio_nbytes);
        if (ret == 0 || ret != -ENOTSUP) {
            return ret;
        }
        s->has_fallocate = false;
    }
#endif

bdrv_getlength() can fail.  Does it do the right thing then?  For what
it's worth, the comparison of its value is signed.

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

* [Qemu-devel] Is the use of bdrv_getlength() in parallels.c kosher? (was: Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher?)
  2017-08-04 12:16 [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher? Markus Armbruster
@ 2017-08-04 12:31 ` Markus Armbruster
  2017-08-04 13:10   ` [Qemu-devel] Is the use of bdrv_getlength() in parallels.c kosher? Denis V. Lunev
  2017-08-04 13:08 ` [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher? Denis V. Lunev
  1 sibling, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2017-08-04 12:31 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: qemu-devel, qemu-block, Kevin Wolf

Same question for allocate_clusters() in parallels.c, commit 5a41e1f,
modified in commit ddd2ef2:

    if (s->data_end + space > bdrv_getlength(bs->file->bs) >> BDRV_SECTOR_BITS) {

bdrv_getlength() can fail.  Does it do the right thing then?  For what
it's worth, the comparison of its value is signed.

There's another one in parallels_open():

    if (!(flags & BDRV_O_RESIZE) || !bdrv_has_zero_init(bs->file->bs) ||
            bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs),
                          PREALLOC_MODE_OFF, NULL) != 0) {
        s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
    }

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

* Re: [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher?
  2017-08-04 12:16 [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher? Markus Armbruster
  2017-08-04 12:31 ` [Qemu-devel] Is the use of bdrv_getlength() in parallels.c kosher? (was: Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher?) Markus Armbruster
@ 2017-08-04 13:08 ` Denis V. Lunev
  2017-08-04 14:20   ` Markus Armbruster
  1 sibling, 1 reply; 5+ messages in thread
From: Denis V. Lunev @ 2017-08-04 13:08 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, qemu-block, Kevin Wolf

On 08/04/2017 03:16 PM, Markus Armbruster wrote:
> Denis, you added this in commit d50d822:
>
> #ifdef CONFIG_FALLOCATE
>     if (s->has_fallocate && aiocb->aio_offset >= bdrv_getlength(aiocb->bs)) {
>         int ret = do_fallocate(s->fd, 0, aiocb->aio_offset, aiocb->aio_nbytes);
>         if (ret == 0 || ret != -ENOTSUP) {
>             return ret;
>         }
>         s->has_fallocate = false;
>     }
> #endif
>
> bdrv_getlength() can fail.  Does it do the right thing then?  For what
> it's worth, the comparison of its value is signed.
fallocate() with 0 flags can work only beyond end of file
or on top of the hole. Thus the check is made to validate
that we are beyond EOF.

Technically fallocate should fail if that condition will be
violated. But you right, we can add sanity check here.
This would not harm.

Should I send it?

Den

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

* Re: [Qemu-devel] Is the use of bdrv_getlength() in parallels.c kosher?
  2017-08-04 12:31 ` [Qemu-devel] Is the use of bdrv_getlength() in parallels.c kosher? (was: Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher?) Markus Armbruster
@ 2017-08-04 13:10   ` Denis V. Lunev
  0 siblings, 0 replies; 5+ messages in thread
From: Denis V. Lunev @ 2017-08-04 13:10 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, qemu-block, Kevin Wolf

On 08/04/2017 03:31 PM, Markus Armbruster wrote:
> Same question for allocate_clusters() in parallels.c, commit 5a41e1f,
> modified in commit ddd2ef2:
>
>     if (s->data_end + space > bdrv_getlength(bs->file->bs) >> BDRV_SECTOR_BITS) {
>
> bdrv_getlength() can fail.  Does it do the right thing then?  For what
> it's worth, the comparison of its value is signed.
>
> There's another one in parallels_open():
>
>     if (!(flags & BDRV_O_RESIZE) || !bdrv_has_zero_init(bs->file->bs) ||
>             bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs),
>                           PREALLOC_MODE_OFF, NULL) != 0) {
>         s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
>     }
the same as in the previous letter. Saniti checks will not harm.
I'll make a patch.

Thank you for the suggestion.

Den

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

* Re: [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher?
  2017-08-04 13:08 ` [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher? Denis V. Lunev
@ 2017-08-04 14:20   ` Markus Armbruster
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Armbruster @ 2017-08-04 14:20 UTC (permalink / raw)
  To: Denis V. Lunev; +Cc: Kevin Wolf, qemu-devel, qemu-block

"Denis V. Lunev" <den@openvz.org> writes:

> On 08/04/2017 03:16 PM, Markus Armbruster wrote:
>> Denis, you added this in commit d50d822:
>>
>> #ifdef CONFIG_FALLOCATE
>>     if (s->has_fallocate && aiocb->aio_offset >= bdrv_getlength(aiocb->bs)) {
>>         int ret = do_fallocate(s->fd, 0, aiocb->aio_offset, aiocb->aio_nbytes);
>>         if (ret == 0 || ret != -ENOTSUP) {
>>             return ret;
>>         }
>>         s->has_fallocate = false;
>>     }
>> #endif
>>
>> bdrv_getlength() can fail.  Does it do the right thing then?  For what
>> it's worth, the comparison of its value is signed.
> fallocate() with 0 flags can work only beyond end of file
> or on top of the hole. Thus the check is made to validate
> that we are beyond EOF.
>
> Technically fallocate should fail if that condition will be
> violated. But you right, we can add sanity check here.
> This would not harm.
>
> Should I send it?

I figure an explicit check for bdrv_getlength() failure would make the
code easier to understand.  In short: yes, please!

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

end of thread, other threads:[~2017-08-04 14:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-04 12:16 [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher? Markus Armbruster
2017-08-04 12:31 ` [Qemu-devel] Is the use of bdrv_getlength() in parallels.c kosher? (was: Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher?) Markus Armbruster
2017-08-04 13:10   ` [Qemu-devel] Is the use of bdrv_getlength() in parallels.c kosher? Denis V. Lunev
2017-08-04 13:08 ` [Qemu-devel] Is the use of bdrv_getlength() in handle_aiocb_write_zeroes() kosher? Denis V. Lunev
2017-08-04 14:20   ` Markus Armbruster

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.