diff mbox series

[v11,07/10] file-posix: support BDRV_REQ_ALLOCATE

Message ID 20181218075707.12006-8-anton.nefedov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series qcow2: cluster space preallocation | expand

Commit Message

Anton Nefedov Dec. 18, 2018, 7:57 a.m. UTC
Current write_zeroes implementation is good enough to satisfy this flag too

Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
---
 block/file-posix.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Vladimir Sementsov-Ogievskiy Dec. 21, 2018, 2:18 p.m. UTC | #1
18.12.2018 10:57, Anton Nefedov wrote:
> Current write_zeroes implementation is good enough to satisfy this flag too
> 
> Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>


Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>


> ---
>   block/file-posix.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/block/file-posix.c b/block/file-posix.c
> index a65e464cbc..c3fbf53853 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -607,6 +607,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
>           } else {
>               s->discard_zeroes = true;
>               s->has_fallocate = true;
> +            bs->supported_zero_flags = BDRV_REQ_ALLOCATE;
>           }
>       } else {
>           if (!(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
> @@ -650,10 +651,11 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
>   #ifdef CONFIG_XFS
>       if (platform_test_xfs_fd(s->fd)) {
>           s->is_xfs = true;
> +        bs->supported_zero_flags = BDRV_REQ_ALLOCATE;
>       }
>   #endif
>   
> -    bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP;
> +    bs->supported_zero_flags |= BDRV_REQ_MAY_UNMAP;
>       ret = 0;
>   fail:
>       if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) {
> @@ -1552,6 +1554,10 @@ static int handle_aiocb_write_zeroes(void *opaque)
>       s->has_fallocate = false;
>   #endif
>   
> +    if (!s->has_fallocate) {
> +        aiocb->bs->supported_zero_flags &= ~BDRV_REQ_ALLOCATE;
> +    }
> +
>       return -ENOTSUP;
>   }
>   
>
Alberto Garcia Jan. 7, 2019, 3:24 p.m. UTC | #2
On Tue 18 Dec 2018 08:57:41 AM CET, Anton Nefedov wrote:
> Current write_zeroes implementation is good enough to satisfy this flag too
>
> Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>

Reviewed-by: Alberto Garcia <berto@igalia.com>

Berto
diff mbox series

Patch

diff --git a/block/file-posix.c b/block/file-posix.c
index a65e464cbc..c3fbf53853 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -607,6 +607,7 @@  static int raw_open_common(BlockDriverState *bs, QDict *options,
         } else {
             s->discard_zeroes = true;
             s->has_fallocate = true;
+            bs->supported_zero_flags = BDRV_REQ_ALLOCATE;
         }
     } else {
         if (!(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
@@ -650,10 +651,11 @@  static int raw_open_common(BlockDriverState *bs, QDict *options,
 #ifdef CONFIG_XFS
     if (platform_test_xfs_fd(s->fd)) {
         s->is_xfs = true;
+        bs->supported_zero_flags = BDRV_REQ_ALLOCATE;
     }
 #endif
 
-    bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP;
+    bs->supported_zero_flags |= BDRV_REQ_MAY_UNMAP;
     ret = 0;
 fail:
     if (filename && (bdrv_flags & BDRV_O_TEMPORARY)) {
@@ -1552,6 +1554,10 @@  static int handle_aiocb_write_zeroes(void *opaque)
     s->has_fallocate = false;
 #endif
 
+    if (!s->has_fallocate) {
+        aiocb->bs->supported_zero_flags &= ~BDRV_REQ_ALLOCATE;
+    }
+
     return -ENOTSUP;
 }