From ba574afb1f1622cff93cb5d7a537d49c4421d698 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 9 Mar 2024 14:58:42 +0300 Subject: [PATCH] Fix zero used space, update mtime when moving/changing inode --- src/nfs_kv.cpp | 5 +++-- src/nfs_kv_write.cpp | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/nfs_kv.cpp b/src/nfs_kv.cpp index ba0b9b23..ed81a851 100644 --- a/src/nfs_kv.cpp +++ b/src/nfs_kv.cpp @@ -72,7 +72,7 @@ fattr3 get_kv_attributes(nfs_client_t *self, uint64_t ino, json11::Json attrs) auto nlink = attrs["nlink"].uint64_value(); nfstime3 mtime = nfstime_from_str(attrs["mtime"].string_value()); nfstime3 atime = attrs["atime"].is_null() ? mtime : nfstime_from_str(attrs["atime"].string_value()); - // FIXME In theory we could store the binary structure itself instead of JSON + // In theory we could store the binary structure itself, but JSON is simpler :-) return (fattr3){ .type = (type == 0 ? NF3REG : (ftype3)type), .mode = (attrs["mode"].is_null() ? (type == NF3DIR ? 0755 : 0644) : (uint32_t)mode), @@ -80,7 +80,8 @@ fattr3 get_kv_attributes(nfs_client_t *self, uint64_t ino, json11::Json attrs) .uid = (uint32_t)attrs["uid"].uint64_value(), .gid = (uint32_t)attrs["gid"].uint64_value(), .size = (type == NF3DIR ? 4096 : attrs["size"].uint64_value()), - .used = (type == NF3DIR ? 4096 : attrs["alloc"].uint64_value()), + // FIXME Counting actual used file size would require reworking statistics + .used = (type == NF3DIR ? 4096 : attrs["size"].uint64_value()), .rdev = (type == NF3BLK || type == NF3CHR ? (specdata3){ (uint32_t)attrs["major"].uint64_value(), (uint32_t)attrs["minor"].uint64_value() } : (specdata3){}), diff --git a/src/nfs_kv_write.cpp b/src/nfs_kv_write.cpp index 5056ed18..e445934e 100644 --- a/src/nfs_kv_write.cpp +++ b/src/nfs_kv_write.cpp @@ -512,6 +512,7 @@ static std::string new_normal_ientry(nfs_kv_write_state *st) ni.erase("shared_alloc"); ni.erase("shared_ver"); ni["size"] = st->ext->cur_extend; + ni["mtime"] = nfstime_now_str(); return json11::Json(ni).dump(); } @@ -524,6 +525,7 @@ static std::string new_moved_ientry(nfs_kv_write_state *st) ni["shared_alloc"] = st->aligned_size; ni.erase("shared_ver"); ni["size"] = st->new_size; + ni["mtime"] = nfstime_now_str(); return json11::Json(ni).dump(); } @@ -532,6 +534,7 @@ static std::string new_shared_ientry(nfs_kv_write_state *st) auto ni = st->ientry.object_items(); ni.erase("empty"); ni["size"] = st->new_size; + ni["mtime"] = nfstime_now_str(); ni["shared_ver"] = ni["shared_ver"].uint64_value()+1; return json11::Json(ni).dump(); } @@ -544,6 +547,7 @@ static std::string new_unshared_ientry(nfs_kv_write_state *st) ni.erase("shared_offset"); ni.erase("shared_alloc"); ni.erase("shared_ver"); + ni["mtime"] = nfstime_now_str(); return json11::Json(ni).dump(); }