From 9e287a777820fe2a25269850e23e1007b9385b6a Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 25 Jul 2023 01:42:06 +0000 Subject: [PATCH] Handle extending writes correctly in NFS proxy Previously, multiple parallel writes extending file size through NFS were racing with each other and triggering deletions of part of the written data I.e. if you mounted vitastor-nfs and just copied a file into it in MC then you could end up with only a part of the file actually written --- src/cli_modify.cpp | 7 ++++--- src/nfs_conn.cpp | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cli_modify.cpp b/src/cli_modify.cpp index 43bb69c9..bda949da 100644 --- a/src/cli_modify.cpp +++ b/src/cli_modify.cpp @@ -13,7 +13,7 @@ struct image_changer_t std::string image_name; std::string new_name; uint64_t new_size = 0; - bool force_size = false; + bool force_size = false, inc_size = false; bool set_readonly = false, set_readwrite = false, force = false; // interval between fsyncs int fsync_interval = 128; @@ -81,14 +81,14 @@ struct image_changer_t } if ((!set_readwrite || !cfg.readonly) && (!set_readonly || cfg.readonly) && - (!new_size && !force_size || cfg.size == new_size) && + (!new_size && !force_size || cfg.size == new_size || cfg.size >= new_size && inc_size) && (new_name == "" || new_name == image_name)) { result = (cli_result_t){ .text = "No change" }; state = 100; return; } - if (new_size != 0 || force_size) + if ((new_size != 0 || force_size) && (cfg.size < new_size || !inc_size)) { if (cfg.size >= new_size) { @@ -233,6 +233,7 @@ std::function cli_tool_t::start_modify(json11::Json cfg) changer->new_name = cfg["rename"].string_value(); changer->new_size = parse_size(cfg["resize"].as_string()); changer->force_size = cfg["force_size"].bool_value(); + changer->inc_size = cfg["inc_size"].bool_value(); changer->force = cfg["force"].bool_value(); changer->set_readonly = cfg["readonly"].bool_value(); changer->set_readwrite = cfg["readwrite"].bool_value(); diff --git a/src/nfs_conn.cpp b/src/nfs_conn.cpp index 36679040..002e5644 100644 --- a/src/nfs_conn.cpp +++ b/src/nfs_conn.cpp @@ -446,6 +446,7 @@ static void nfs_resize_write(nfs_client_t *self, rpc_op_t *rop, uint64_t inode, self->parent->cmd->loop_and_wait(self->parent->cmd->start_modify(json11::Json::object { { "image", inode_it->second.name }, { "resize", new_size }, + { "inc_size", true }, { "force_size", true }, }), [=](const cli_result_t & r) {