diff mbox series

[05/18] fuse: Allow growable exports

Message ID 20191219143818.1646168-6-mreitz@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: Allow exporting BDSs via FUSE | expand

Commit Message

Max Reitz Dec. 19, 2019, 2:38 p.m. UTC
These will behave more like normal files in that writes beyond the EOF
will automatically grow the export size.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/fuse.c    | 16 +++++++++++++++-
 qapi/block.json |  6 +++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/block/fuse.c b/block/fuse.c
index 4e662e6dfb..d7c7824815 100644
--- a/block/fuse.c
+++ b/block/fuse.c
@@ -42,6 +42,7 @@  typedef struct BdrvFuseSession {
     uint64_t perm, shared_perm;
     bool mounted, fd_handler_set_up;
     bool writable;
+    bool growable;
 } BdrvFuseSession;
 
 static GHashTable *sessions;
@@ -59,6 +60,7 @@  static bool is_regular_file(const char *path, Error **errp);
 
 void qmp_fuse_export_add(const char *node_name, const char *mountpoint,
                          bool has_writable, bool writable,
+                         bool has_growable, bool growable,
                          Error **errp)
 {
     BlockDriverState *bs;
@@ -67,6 +69,9 @@  void qmp_fuse_export_add(const char *node_name, const char *mountpoint,
     if (!has_writable) {
         writable = false;
     }
+    if (!has_growable) {
+        growable = false;
+    }
 
     init_fuse();
 
@@ -98,6 +103,7 @@  void qmp_fuse_export_add(const char *node_name, const char *mountpoint,
         },
 
         .writable = writable,
+        .growable = growable,
     };
 
     session->perm = BLK_PERM_CONSISTENT_READ;
@@ -463,7 +469,15 @@  static void fuse_write(fuse_req_t req, fuse_ino_t inode, const char *buf,
 
     size = MIN(size, BDRV_REQUEST_MAX_BYTES);
     if (offset + size > length) {
-        size = length - offset;
+        if (session->growable) {
+            ret = fuse_do_truncate(session, offset + size, PREALLOC_MODE_OFF);
+            if (ret < 0) {
+                fuse_reply_err(req, -ret);
+                return;
+            }
+        } else {
+            size = length - offset;
+        }
     }
 
     ret = blk_pwrite(session->blk, offset, buf, size, 0);
diff --git a/qapi/block.json b/qapi/block.json
index 26768dc8ef..039cbc6773 100644
--- a/qapi/block.json
+++ b/qapi/block.json
@@ -330,13 +330,17 @@ 
 # @writable: Whether clients should be able to write to the block
 #            device via the FUSE export. (default: false)
 #
+# @growable: Whether writes beyond the EOF should grow the block node
+#            fit. (default: false)
+#
 # Since: 5.0
 ##
 { 'command': 'fuse-export-add',
   'data': {
       'node-name': 'str',
       'mountpoint': 'str',
-      '*writable': 'bool'
+      '*writable': 'bool',
+      '*growable': 'bool'
   },
   'if': 'defined(CONFIG_FUSE)' }