From bb8ca6184e11e2a9be7c8ea2f97dc44becdd69c1 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 10 Mar 2024 02:31:11 +0300 Subject: [PATCH] Support setattr guard --- src/nfs_kv_setattr.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/nfs_kv_setattr.cpp b/src/nfs_kv_setattr.cpp index cd27cddb..90666958 100644 --- a/src/nfs_kv_setattr.cpp +++ b/src/nfs_kv_setattr.cpp @@ -15,6 +15,7 @@ struct nfs_kv_setattr_state rpc_op_t *rop = NULL; uint64_t ino = 0; uint64_t old_size = 0, new_size = 0; + std::string expected_ctime; json11::Json::object set_attrs; int res = 0, cas_res = 0; std::string ientry_text; @@ -60,6 +61,16 @@ resume_1: cb(-EINVAL); return; } + if (st->expected_ctime != "") + { + auto actual_ctime = (st->ientry["ctime"].is_null() ? st->ientry["mtime"] : st->ientry["ctime"]); + if (actual_ctime != st->expected_ctime) + { + auto cb = std::move(st->cb); + cb(NFS3ERR_NOT_SYNC); + return; + } + } // Now we can update it st->new_attrs = st->ientry.object_items(); st->old_size = st->ientry["size"].uint64_value(); @@ -143,6 +154,8 @@ int kv_nfs3_setattr_proc(void *opaque, rpc_op_t *rop) return 0; } st->ino = kv_fh_inode(fh); + if (args->guard.check) + st->expected_ctime = nfstime_to_str(args->guard.obj_ctime); if (args->new_attributes.size.set_it) st->set_attrs["size"] = args->new_attributes.size.size; if (args->new_attributes.mode.set_it)