From 6c78a52f989c00a3d5281f4119dd5de096168f59 Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Mon, 27 Jan 2025 18:12:34 +0530 Subject: [PATCH] cephfs_mirror: avoid latest changes on the source fs to enable mirroring This avoids considering latest changes from the source filesystem for the mirroring of already existing snapshots. Thus the destination filesystem and snapshots would be created based only on the source snapshots. The destination fs would be a replica of the last snapshot taken. Fixes: https://tracker.ceph.com/issues/68567 Signed-off-by: Jos Collin (cherry picked from commit 23e4cd5756718ce0183688c9a6514ff53226d9d1) --- src/tools/cephfs_mirror/PeerReplayer.cc | 34 ++++++++++--------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/tools/cephfs_mirror/PeerReplayer.cc b/src/tools/cephfs_mirror/PeerReplayer.cc index 50610c7503a3b..357821484ccc1 100644 --- a/src/tools/cephfs_mirror/PeerReplayer.cc +++ b/src/tools/cephfs_mirror/PeerReplayer.cc @@ -68,12 +68,6 @@ std::string entry_path(const std::string &dir, const std::string &name) { return dir + "/" + name; } -std::string entry_diff_path(const std::string &dir, const std::string &name) { - if (dir == ".") - return name; - return dir + "/" + name; -} - std::map decode_snap_metadata(snap_metadata *snap_metadata, size_t nr_snap_metadata) { std::map metadata; @@ -1446,7 +1440,7 @@ int PeerReplayer::do_synchronize(const std::string &dir_root, const Snapshot &cu std::queue sync_queue; //start with initial/default entry - std::string epath = ".", npath = "", nabs_path = "", nname = ""; + std::string epath = ".", npath = "", nname = ""; sync_queue.emplace(SyncEntry(epath, cstx)); while (!sync_queue.empty()) { @@ -1481,19 +1475,17 @@ int PeerReplayer::do_synchronize(const std::string &dir_root, const Snapshot &cu if ("." == nname || ".." == nname) continue; // create path for the newly found entry - npath = entry_diff_path(epath, nname); - nabs_path = entry_diff_path(dir_root, npath); - - r = ceph_statx(sd_info.cmount, nabs_path.c_str(), &cstx, - CEPH_STATX_MODE | CEPH_STATX_UID | CEPH_STATX_GID | - CEPH_STATX_SIZE | CEPH_STATX_ATIME | CEPH_STATX_MTIME, - AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); + npath = entry_path(epath, nname); + r = ceph_statxat(m_local_mount, fh.c_fd, npath.c_str(), &cstx, + CEPH_STATX_MODE | CEPH_STATX_UID | CEPH_STATX_GID | + CEPH_STATX_SIZE | CEPH_STATX_ATIME | CEPH_STATX_MTIME, + AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); if (r < 0) { // can't stat, so it's a deleted entry. if (DT_DIR == sd_entry.dir_entry.d_type) { // is a directory r = cleanup_remote_dir(dir_root, npath, fh); if (r < 0) { - derr << ": failed to remove directory=" << nabs_path << dendl; + derr << ": failed to remove directory=" << npath << dendl; break; } } @@ -1506,17 +1498,17 @@ int PeerReplayer::do_synchronize(const std::string &dir_root, const Snapshot &cu } else { // stat success, update the existing entry struct ceph_statx tstx; - int rstat_r = ceph_statx(m_remote_mount, nabs_path.c_str(), &tstx, - CEPH_STATX_MODE | CEPH_STATX_UID | CEPH_STATX_GID | - CEPH_STATX_SIZE | CEPH_STATX_ATIME | CEPH_STATX_MTIME, - AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); + int rstat_r = ceph_statxat(m_remote_mount, fh.r_fd_dir_root, npath.c_str(), &tstx, + CEPH_STATX_MODE | CEPH_STATX_UID | CEPH_STATX_GID | + CEPH_STATX_SIZE | CEPH_STATX_ATIME | CEPH_STATX_MTIME, + AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); if (S_ISDIR(cstx.stx_mode)) { // is a directory //cleanup if it's a file in the remotefs if ((0 == rstat_r) && !S_ISDIR(tstx.stx_mode)) { r = ceph_unlinkat(m_remote_mount, fh.r_fd_dir_root, npath.c_str(), 0); if (r < 0) { derr << ": Error in directory sync. Failed to remove file=" - << nabs_path << dendl; + << npath << dendl; break; } } @@ -1541,7 +1533,7 @@ int PeerReplayer::do_synchronize(const std::string &dir_root, const Snapshot &cu r = cleanup_remote_dir(dir_root, npath, fh); if (r < 0) { derr << ": Error in file sync. Failed to remove remote directory=" - << nabs_path << dendl; + << npath << dendl; break; } } -- 2.39.5