Skip to content

Commit 9c958c6

Browse files
author
Igor Fedotov
committed
cephfs/snapdiff: introduce mask param for file attr changes
Fixes: https://tracker.ceph.com/issues/75705 Signed-off-by: Igor Fedotov <[email protected]>
1 parent 5c08d23 commit 9c958c6

13 files changed

Lines changed: 209 additions & 29 deletions

File tree

‎src/client/Client.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10462,6 +10462,7 @@ int Client::file_blockdiff(struct scan_state_t *state, const UserPerm &perms,
1046210462
}
1046310463

1046410464
int Client::readdir_snapdiff(dir_result_t* d1, snapid_t snap2,
10465+
unsigned diff_mask,
1046510466
struct dirent* out_de,
1046610467
snapid_t* out_snap)
1046710468
{
@@ -10499,6 +10500,7 @@ int Client::readdir_snapdiff(dir_result_t* d1, snapid_t snap2,
1049910500
} else if (dirp->hash_order()) {
1050010501
req->head.args.snapdiff.offset_hash = dirp->offset_high();
1050110502
}
10503+
req->head.args.snapdiff.mask = diff_mask;
1050210504
req->dirp = dirp;
1050310505
};
1050410506

‎src/client/Client.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ class Client : public Dispatcher, public md_config_obs_t {
443443
*
444444
*/
445445
int readdir_snapdiff(dir_result_t* dir1, snapid_t snap2,
446+
unsigned diff_mask,
446447
struct dirent* out_de, snapid_t* out_snap);
447448

448449
int getdir(const char *relpath, std::list<std::string>& names,

‎src/include/ceph_fs.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,19 @@ extern const char *ceph_mds_op_name(int op);
470470
#define CEPH_SETATTR_KILL_SGID (1 << 14)
471471
#endif
472472

473+
// attr mask bits in an int
474+
#ifndef CEPH_SNAPDIFF_MODE
475+
#define CEPH_SNAPDIFF_MODE (1 << 0)
476+
#define CEPH_SNAPDIFF_UID (1 << 1)
477+
#define CEPH_SNAPDIFF_GID (1 << 2)
478+
#define CEPH_SNAPDIFF_SIZE (1 << 3)
479+
#define CEPH_SNAPDIFF_NLINK (1 << 4)
480+
#define CEPH_SNAPDIFF_MTIME (1 << 5)
481+
#define CEPH_SNAPDIFF_ATIME (1 << 6)
482+
#define CEPH_SNAPDIFF_CTIME (1 << 7)
483+
#define CEPH_SNAPDIFF_BTIME (1 << 8)
484+
#endif
485+
473486
/*
474487
* open request flags
475488
*/
@@ -650,6 +663,7 @@ union ceph_mds_request_args {
650663
__le16 flags;
651664
__le32 offset_hash;
652665
__le64 snap_other;
666+
__le32 mask; /*CEPH_SNAPDIFF_*/
653667
} __attribute__ ((packed)) snapdiff;
654668
struct {
655669
// latest scan "pointer"

‎src/include/cephfs/libcephfs.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,27 @@ int ceph_readdir_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp,
645645
int ceph_readdirplus_r(struct ceph_mount_info *cmount, struct ceph_dir_result *dirp, struct dirent *de,
646646
struct ceph_statx *stx, unsigned want, unsigned flags, struct Inode **out);
647647

648+
/* attr mask bits (up to an int in size) */
649+
#ifndef CEPH_SNAPDIFF_MODE
650+
#define CEPH_SNAPDIFF_MODE (1 << 0)
651+
#define CEPH_SNAPDIFF_UID (1 << 1)
652+
#define CEPH_SNAPDIFF_GID (1 << 2)
653+
#define CEPH_SNAPDIFF_SIZE (1 << 3)
654+
#define CEPH_SNAPDIFF_NLINK (1 << 4)
655+
#define CEPH_SNAPDIFF_MTIME (1 << 5)
656+
#define CEPH_SNAPDIFF_ATIME (1 << 6)
657+
#define CEPH_SNAPDIFF_CTIME (1 << 7)
658+
#define CEPH_SNAPDIFF_BTIME (1 << 8)
659+
#endif
660+
648661
struct ceph_snapdiff_info
649662
{
650663
struct ceph_mount_info* cmount;
651664
struct ceph_dir_result* dir1; // primary dir entry to build snapdiff for.
652665
struct ceph_dir_result* dir_aux; // aux dir entry to identify the second snapshot.
653666
// Can point to the parent dir entry if entry-in-question
654667
// doesn't exist in the second snapshot
668+
unsigned mask; // snapdiff file metadata mask (CEPH_SNAPDIFF_*)
655669
};
656670

657671
struct ceph_file_blockdiff_result;
@@ -727,6 +741,7 @@ int ceph_file_blockdiff_finish(struct ceph_file_blockdiff_info* info);
727741
* @param rel_path subpath under the root to build delta for
728742
* @param snap1 the first snapshot name
729743
* @param snap2 the second snapshot name
744+
* @param diff_mask file metadata change mask to apply for delta building
730745
* @param out resulting snapdiff stream handle to be used for snapdiff results
731746
retrieval via ceph_readdir_snapdiff
732747
* @returns 0 on success and negative error code otherwise
@@ -736,6 +751,7 @@ int ceph_open_snapdiff(struct ceph_mount_info* cmount,
736751
const char* rel_path,
737752
const char* snap1,
738753
const char* snap2,
754+
unsigned diff_mask,
739755
struct ceph_snapdiff_info* out);
740756
/**
741757
* Get the next snapshot delta entry.

‎src/libcephfs.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ extern "C" int ceph_open_snapdiff(struct ceph_mount_info* cmount,
853853
const char* rel_path,
854854
const char* snap1,
855855
const char* snap2,
856+
unsigned diff_mask,
856857
struct ceph_snapdiff_info* out)
857858
{
858859
if (!cmount->is_mounted()) {
@@ -867,6 +868,7 @@ extern "C" int ceph_open_snapdiff(struct ceph_mount_info* cmount,
867868
}
868869
out->cmount = cmount;
869870
out->dir1 = out->dir_aux = nullptr;
871+
out->mask = diff_mask;
870872

871873
char full_path1[PATH_MAX];
872874
char snapdir[PATH_MAX];
@@ -939,6 +941,7 @@ extern "C" int ceph_readdir_snapdiff(struct ceph_snapdiff_info* snapdiff,
939941
int r = snapdiff->cmount->get_client()->readdir_snapdiff(
940942
d1,
941943
d2->inode->snapid,
944+
snapdiff->mask,
942945
&(out->dir_entry),
943946
&snapid);
944947
if (r >= 0) {

‎src/mds/Server.cc‎

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5495,7 +5495,6 @@ void Server::handle_client_setattr(const MDRequestRef& mdr)
54955495
respond_to_request(mdr, -EPERM);
54965496
return;
54975497
}
5498-
54995498
__u32 mask = req->head.args.setattr.mask;
55005499
__u32 access_mask = MAY_WRITE;
55015500

@@ -12677,6 +12676,7 @@ void Server::handle_client_readdir_snapdiff(const MDRequestRef& mdr)
1267712676
// which frag?
1267812677
frag_t fg = (__u32)req->head.args.snapdiff.frag;
1267912678
unsigned req_flags = (__u32)req->head.args.snapdiff.flags;
12679+
unsigned diff_mask = (__u32)req->head.args.snapdiff.mask;
1268012680
string offset_str = req->get_path2();
1268112681

1268212682
__u32 offset_hash = 0;
@@ -12739,6 +12739,7 @@ void Server::handle_client_readdir_snapdiff(const MDRequestRef& mdr)
1273912739
dout(10) << __func__
1274012740
<< " snap " << mdr->snapid
1274112741
<< " vs. snap " << mdr->snapid_diff_other
12742+
<< " input mask 0x" << diff_mask
1274212743
<< dendl;
1274312744

1274412745
if (mdr->snapid_diff_other == mdr->snapid ||
@@ -12785,6 +12786,7 @@ void Server::handle_client_readdir_snapdiff(const MDRequestRef& mdr)
1278512786
offset_str,
1278612787
offset_hash,
1278712788
req_flags,
12789+
diff_mask,
1278812790
dirbl);
1278912791
}
1279012792

@@ -12831,6 +12833,7 @@ void Server::_readdir_diff(
1283112833
const string& offset_str,
1283212834
uint32_t offset_hash,
1283312835
unsigned req_flags,
12836+
unsigned diff_mask,
1283412837
bufferlist& dirbl)
1283512838
{
1283612839
// build dir contents
@@ -12863,6 +12866,7 @@ void Server::_readdir_diff(
1286312866
from_the_beginning ? nullptr : & skip_key,
1286412867
snapid_prev,
1286512868
snapid,
12869+
diff_mask,
1286612870
dnbl,
1286712871
[&](CDentry* dn, CInode* in, bool exists) {
1286812872
string name;
@@ -12946,19 +12950,52 @@ bool Server::build_snap_diff(
1294612950
dentry_key_t* skip_key,
1294712951
snapid_t snapid_prev,
1294812952
snapid_t snapid,
12953+
unsigned diff_mask,
1294912954
const bufferlist& dnbl,
1295012955
std::function<bool (CDentry*, CInode*, bool)> add_result_cb)
1295112956
{
12952-
client_t client = mdr->client_request->get_source().num();
12953-
1295412957
struct EntryInfo {
1295512958
CDentry* dn = nullptr;
1295612959
CInode* in = nullptr;
12957-
utime_t mtime;
1295812960

1295912961
void reset() {
1296012962
*this = EntryInfo();
1296112963
}
12964+
EntryInfo() {}
12965+
EntryInfo(CDentry* _dn, CInode* _in) : dn(_dn), in(_in) {}
12966+
12967+
bool valid() const {
12968+
return in != nullptr && dn != nullptr;
12969+
}
12970+
bool meta_differs(const CInode* _in, unsigned mask, unsigned& res_mask) const {
12971+
ceph_assert(in);
12972+
ceph_assert(_in);
12973+
12974+
auto my = in->get_inode();
12975+
auto oth = _in->get_inode();
12976+
ceph_assert(my);
12977+
ceph_assert(oth);
12978+
res_mask = 0;
12979+
if ((mask & CEPH_SNAPDIFF_MODE) && (my->mode != oth->mode))
12980+
res_mask |= CEPH_SNAPDIFF_MODE;
12981+
if ((mask & CEPH_SNAPDIFF_UID) && (my->uid != oth->uid))
12982+
res_mask |= CEPH_SNAPDIFF_UID;
12983+
if ((mask & CEPH_SNAPDIFF_GID) && (my->gid != oth->gid))
12984+
res_mask |= CEPH_SNAPDIFF_GID;
12985+
if ((mask & CEPH_SNAPDIFF_SIZE) && (my->size != oth->size))
12986+
res_mask |= CEPH_SNAPDIFF_SIZE;
12987+
if ((mask & CEPH_SNAPDIFF_NLINK) && (my->nlink != oth->nlink))
12988+
res_mask |= CEPH_SNAPDIFF_NLINK;
12989+
if ((mask & CEPH_SNAPDIFF_MTIME) && (my->mtime != oth->mtime))
12990+
res_mask |= CEPH_SNAPDIFF_MTIME;
12991+
if ((mask & CEPH_SNAPDIFF_ATIME) && (my->atime != oth->atime))
12992+
res_mask |= CEPH_SNAPDIFF_ATIME;
12993+
if ((mask & CEPH_SNAPDIFF_CTIME) && (my->ctime != oth->ctime))
12994+
res_mask |= CEPH_SNAPDIFF_CTIME;
12995+
if ((mask & CEPH_SNAPDIFF_BTIME) && (my->btime != oth->btime))
12996+
res_mask |= CEPH_SNAPDIFF_BTIME;
12997+
return res_mask != 0;
12998+
}
1296212999
} before;
1296313000

1296413001
auto insert_deleted = [&](EntryInfo& ei) {
@@ -12968,9 +13005,11 @@ bool Server::build_snap_diff(
1296813005
ei.reset();
1296913006
return r;
1297013007
};
13008+
client_t client = mdr->client_request->get_source().num();
1297113009

1297213010
auto it = !skip_key ? dir->begin() : dir->upper_bound(*skip_key);
1297313011

13012+
diff_mask = diff_mask != 0 ? diff_mask : CEPH_SNAPDIFF_MTIME; // to preserve backward compatibility with the original impl.
1297413013
while(it != dir->end()) {
1297513014
CDentry* dn = it->second;
1297613015
dout(20) << __func__ << " " << it->first << "->" << *dn << dendl;
@@ -13027,7 +13066,6 @@ bool Server::build_snap_diff(
1302713066
}
1302813067
ceph_assert(in);
1302913068

13030-
utime_t mtime = in->get_inode()->mtime;
1303113069
if (in->is_dir()) {
1303213070

1303313071
// we need to maintain the order of entries (determined by their name hashes)
@@ -13063,9 +13101,7 @@ bool Server::build_snap_diff(
1306313101
<< dn->first << "/" << dn->last << dendl;
1306413102
continue;
1306513103
}
13066-
string_view name_before =
13067-
before.dn ? string_view(before.dn->get_name()) : string_view();
13068-
if (before.dn && dn->get_name() != name_before) {
13104+
if (before.valid() && before.dn->get_name() != dn->get_name()) {
1306913105
if (!insert_deleted(before)) {
1307013106
break;
1307113107
}
@@ -13074,33 +13110,32 @@ bool Server::build_snap_diff(
1307413110
if (snapid_prev >= dn->first && snapid_prev <= dn->last) {
1307513111
dout(30) << __func__ << " dn_before " << dn->get_name() << " "
1307613112
<< dn->first << "/" << dn->last << dendl;
13077-
before = EntryInfo {dn, in, mtime};
13113+
before = EntryInfo {dn, in};
1307813114
continue;
1307913115
} else {
13080-
if (before.dn && dn->get_name() == name_before) {
13116+
if (before.valid() && before.dn->get_name() == dn->get_name()) {
1308113117
if (before.in->ino() != in->ino()) {
1308213118
dout(30) << __func__ << " inode changed " << dn->get_name() << " "
1308313119
<< dn->first << "/" << dn->last
13084-
<< " " << before.mtime << " vs. " << mtime
1308513120
<< dendl;
1308613121
if (!insert_deleted(before)) {
1308713122
break;
1308813123
}
1308913124
before.reset();
1309013125
} else {
13091-
if (mtime == before.mtime) {
13092-
dout(30) << __func__ << " timestamp not changed " << dn->get_name() << " "
13093-
<< dn->first << "/" << dn->last
13094-
<< " " << mtime
13095-
<< dendl;
13126+
unsigned res_mask = 0;
13127+
if (before.meta_differs(in, diff_mask, res_mask) ) {
13128+
dout(0) << __func__ << " attrs changed " << dn->get_name() << " "
13129+
<< dn->first << "/" << dn->last
13130+
<< " result mask: 0x" << std::hex << res_mask << std::dec
13131+
<< dendl;
1309613132
before.reset();
13097-
continue;
1309813133
} else {
13099-
dout(30) << __func__ << " timestamp changed " << dn->get_name() << " "
13100-
<< dn->first << "/" << dn->last
13101-
<< " " << before.mtime << " vs. " << mtime
13102-
<< dendl;
13134+
dout(0) << __func__ << " attrs not changed " << dn->get_name() << " "
13135+
<< dn->first << "/" << dn->last
13136+
<< dendl;
1310313137
before.reset();
13138+
continue;
1310413139
}
1310513140
}
1310613141
}

‎src/mds/Server.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ class Server {
572572
const std::string& offset_str,
573573
uint32_t offset_hash,
574574
unsigned req_flags,
575+
unsigned diff_mask,
575576
bufferlist& dirbl);
576577
bool build_snap_diff(
577578
const MDRequestRef& mdr,
@@ -580,6 +581,7 @@ class Server {
580581
dentry_key_t* skip_key,
581582
snapid_t snapid_before,
582583
snapid_t snapid,
584+
unsigned diff_mask,
583585
const bufferlist& dnbl,
584586
std::function<bool(CDentry*, CInode*, bool)> add_result_cb);
585587

‎src/pybind/cephfs/c_cephfs.pxd‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ cdef extern from "cephfs/libcephfs.h" nogil:
161161
const char *rel_path,
162162
const char *snap1,
163163
const char *snap2,
164+
unsigned snapdiff_mask,
164165
ceph_snapdiff_info *out)
165166
int ceph_readdir_snapdiff(ceph_snapdiff_info *snapdiff, ceph_snapdiff_entry_t *out);
166167
int ceph_close_snapdiff(ceph_snapdiff_info *snapdiff)

‎src/pybind/cephfs/cephfs.pyx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ CEPH_SETATTR_SIZE = 0x20
6969
CEPH_SETATTR_CTIME = 0x40
7070
CEPH_SETATTR_BTIME = 0x200
7171

72+
CEPH_SNAPDIFF_MODE = 0x1
73+
CEPH_SNAPDIFF_UID = 0x2
74+
CEPH_SNAPDIFF_GID = 0x4
75+
CEPH_SNAPDIFF_SIZE = 0x8
76+
CEPH_SNAPDIFF_NLINK = 0x10
77+
CEPH_SNAPDIFF_MTIME = 0x20
78+
CEPH_SNAPDIFF_ATIME = 0x40
79+
CEPH_SNAPDIFF_CTIME = 0x80
80+
CEPH_SNAPDIFF_BTIME = 0x100
81+
7282
CEPH_NOSNAP = -2
7383

7484
# XXX: errno definitions, hard-coded numbers here are errnos defined by Linux
@@ -1063,7 +1073,7 @@ cdef class LibCephFS(object):
10631073

10641074
return handle.close()
10651075

1066-
def opensnapdiff(self, root_path, rel_path, snap1name, snap2name) -> SnapDiffHandle:
1076+
def opensnapdiff(self, root_path, rel_path, snap1name, snap2name, diff_mask) -> SnapDiffHandle:
10671077
"""
10681078
Open the given directory.
10691079

@@ -1083,8 +1093,9 @@ cdef class LibCephFS(object):
10831093
char* _relp = relp
10841094
char* _snap1 = snap1
10851095
char* _snap2 = snap2
1096+
unsigned _diff_mask = diff_mask
10861097
with nogil:
1087-
ret = ceph_open_snapdiff(self.cluster, _root, _relp, _snap1, _snap2, &h.handle);
1098+
ret = ceph_open_snapdiff(self.cluster, _root, _relp, _snap1, _snap2, _diff_mask, &h.handle);
10881099
if ret < 0:
10891100
raise make_ex(ret, "open_snapdiff failed for {} vs. {}"
10901101
.format(snap1.decode('utf-8'), snap2.decode('utf-8')))

‎src/pybind/cephfs/mock_cephfs.pxi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ cdef nogil:
222222
pass
223223
dirent * ceph_readdir(ceph_mount_info *cmount, ceph_dir_result *dirp):
224224
pass
225-
int ceph_open_snapdiff(ceph_mount_info *cmount, const char *root_path, const char *rel_path, const char *snap1path, const char *snap2root, ceph_snapdiff_info *out):
225+
int ceph_open_snapdiff(ceph_mount_info *cmount, const char *root_path, const char *rel_path, const char *snap1path, const char *snap2root, unsigned mask, ceph_snapdiff_info *out):
226226
pass
227227
int ceph_readdir_snapdiff(ceph_snapdiff_info *snapdiff, ceph_snapdiff_entry_t *out):
228228
pass

0 commit comments

Comments
 (0)