Allow discard to fail, and fall back to the write operation.  This
is needed because there's no simple way to probe for availability
of FALLOC_FL_PUNCH_HOLE.

Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
---
 block.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/block.c b/block.c
index af73497..7397df6 100644
--- a/block.c
+++ b/block.c
@@ -1798,7 +1798,10 @@ static int coroutine_fn 
bdrv_co_do_write_zeroes(BlockDriverState *bs,
         bdi.discard_granularity &&
         (sector_num & (bdi.discard_granularity - 1)) == 0 &&
         (nb_sectors & (bdi.discard_granularity - 1)) == 0) {
-        return bdrv_co_do_discard(bs, sector_num, nb_sectors);
+        ret = bdrv_co_do_discard(bs, sector_num, nb_sectors);
+        if (ret != -ENOTSUP) {
+            return ret;
+        }
     }
 
     if (qiov) {
-- 
1.7.7.6



Reply via email to