diff --git a/src/nfs_kv.cpp b/src/nfs_kv.cpp index 82abcfed6..4b58eb540 100644 --- a/src/nfs_kv.cpp +++ b/src/nfs_kv.cpp @@ -72,6 +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()); + nfstime3 ctime = attrs["ctime"].is_null() ? mtime : nfstime_from_str(attrs["ctime"].string_value()); // In theory we could store the binary structure itself, but JSON is simpler :-) return (fattr3){ .type = (type == 0 ? NF3REG : (ftype3)type), @@ -89,7 +90,7 @@ fattr3 get_kv_attributes(nfs_client_t *self, uint64_t ino, json11::Json attrs) .fileid = ino, .atime = atime, .mtime = mtime, - .ctime = mtime, + .ctime = ctime, }; } @@ -282,7 +283,7 @@ static void touch_inode(nfs_proxy_t *proxy, inode_t ino, bool allow_cache) if (!res) { auto ientry = attrs.object_items(); - ientry["mtime"] = nfstime_now_str(); + ientry["mtime"] = ientry["ctime"] = nfstime_now_str(); ientry.erase("verf"); // FIXME: Use "update" query bool *found = new bool; diff --git a/src/nfs_kv_create.cpp b/src/nfs_kv_create.cpp index cde45e707..2fdd01a98 100644 --- a/src/nfs_kv_create.cpp +++ b/src/nfs_kv_create.cpp @@ -101,10 +101,9 @@ static void kv_continue_create(kv_create_state *st, int state) cb(-EINVAL); return; } + st->attrobj["ctime"] = nfstime_now_str(); if (st->attrobj.find("mtime") == st->attrobj.end()) - st->attrobj["mtime"] = nfstime_now_str(); - if (st->attrobj.find("atime") == st->attrobj.end()) - st->attrobj["atime"] = st->attrobj["mtime"]; + st->attrobj["mtime"] = st->attrobj["ctime"]; st->attrs = std::move(st->attrobj); resume_1: // Generate inode ID diff --git a/src/nfs_kv_link.cpp b/src/nfs_kv_link.cpp index 1b7efec53..3dffc0abb 100644 --- a/src/nfs_kv_link.cpp +++ b/src/nfs_kv_link.cpp @@ -99,6 +99,7 @@ resume_2: auto new_ientry = st->ientry.object_items(); auto nlink = new_ientry["nlink"].uint64_value(); new_ientry["nlink"] = nlink ? nlink+1 : 2; + new_ientry["ctime"] = nfstime_now_str(); st->ientry = new_ientry; } st->self->parent->db->set(kv_inode_key(st->ino), st->ientry.dump(), [st](int res) diff --git a/src/nfs_kv_remove.cpp b/src/nfs_kv_remove.cpp index 6ba5c5e9c..27dacf962 100644 --- a/src/nfs_kv_remove.cpp +++ b/src/nfs_kv_remove.cpp @@ -196,6 +196,7 @@ resume_5: { auto copy = st->ientry.object_items(); copy["nlink"] = st->ientry["nlink"].uint64_value()-1; + copy["ctime"] = nfstime_now_str(); st->self->parent->db->set(kv_inode_key(st->ino), json11::Json(copy).dump(), [st](int res) { st->res = res; diff --git a/src/nfs_kv_rename.cpp b/src/nfs_kv_rename.cpp index 8e3ccb6e1..24f308466 100644 --- a/src/nfs_kv_rename.cpp +++ b/src/nfs_kv_rename.cpp @@ -238,6 +238,7 @@ resume_7: { auto copy = st->new_ientry.object_items(); copy["nlink"] = st->new_ientry["nlink"].uint64_value()-1; + copy["ctime"] = nfstime_now_str(); copy.erase("verf"); st->self->parent->db->set(kv_inode_key(st->new_direntry["ino"].uint64_value()), json11::Json(copy).dump(), [st](int res) { @@ -325,6 +326,7 @@ resume_11: { auto ientry_new = st->old_ientry.object_items(); ientry_new["parent_ino"] = st->new_dir_ino; + ientry_new["ctime"] = nfstime_now_str(); ientry_new.erase("verf"); st->self->parent->db->set(kv_inode_key(st->old_direntry["ino"].uint64_value()), json11::Json(ientry_new).dump(), [st](int res) { diff --git a/src/nfs_kv_setattr.cpp b/src/nfs_kv_setattr.cpp index e6e0f83b0..cd27cddb3 100644 --- a/src/nfs_kv_setattr.cpp +++ b/src/nfs_kv_setattr.cpp @@ -72,6 +72,7 @@ resume_1: st->new_attrs[kv.first] = kv.second; } st->new_attrs.erase("verf"); + st->new_attrs["ctime"] = nfstime_now_str(); st->self->parent->db->set(kv_inode_key(st->ino), json11::Json(st->new_attrs).dump(), [st](int res) { st->res = res; diff --git a/src/nfs_kv_write.cpp b/src/nfs_kv_write.cpp index 2ee4d6115..913020ee1 100644 --- a/src/nfs_kv_write.cpp +++ b/src/nfs_kv_write.cpp @@ -545,7 +545,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(); + ni["ctime"] = ni["mtime"] = nfstime_now_str(); ni.erase("verf"); return json11::Json(ni).dump(); } @@ -559,7 +559,7 @@ static std::string new_moved_ientry(nfs_kv_write_state *st) ni["shared_alloc"] = st->shared_alloc; ni.erase("shared_ver"); ni["size"] = st->new_size; - ni["mtime"] = nfstime_now_str(); + ni["ctime"] = ni["mtime"] = nfstime_now_str(); ni.erase("verf"); return json11::Json(ni).dump(); } @@ -569,7 +569,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["ctime"] = ni["mtime"] = nfstime_now_str(); ni["shared_ver"] = ni["shared_ver"].uint64_value()+1; ni.erase("verf"); return json11::Json(ni).dump(); @@ -583,7 +583,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(); + ni["ctime"] = ni["mtime"] = nfstime_now_str(); ni.erase("verf"); return json11::Json(ni).dump(); }