From e2a67f2a65553ad45721bb391081bc61aa97e0e9 Mon Sep 17 00:00:00 2001 From: Xiubo Li Date: Mon, 11 Apr 2022 10:22:00 +0800 Subject: [PATCH] client: switch AT_NO_ATTR_SYNC to AT_STATX_DONT_SYNC The glibc has defined its own STATX SYNC related flags: define AT_STATX_SYNC_TYPE 0x6000 define AT_STATX_SYNC_AS_STAT 0x0000 define AT_STATX_FORCE_SYNC 0x2000 define AT_STATX_DONT_SYNC 0x4000 Just switch to use the standard ones. Fixes: https://tracker.ceph.com/issues/55253 Signed-off-by: Xiubo Li (cherry picked from commit 4654f9350cb1285859f58e1bc0abdcc9e141f879) --- src/client/Client.cc | 8 ++++---- src/client/Client.h | 2 +- src/client/hypertable/CephBroker.cc | 2 +- src/include/cephfs/ceph_ll_client.h | 9 ++++++--- src/include/cephfs/libcephfs.h | 6 +++--- src/pybind/cephfs/cephfs.pyx | 9 ++++++--- src/test/libcephfs/test.cc | 6 +++--- src/tools/cephfs_mirror/PeerReplayer.cc | 14 +++++++------- 8 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index ccc9f66bb9c08..3513de3518b3a 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7903,11 +7903,11 @@ unsigned Client::statx_to_mask(unsigned int flags, unsigned int want) { unsigned mask = 0; - /* if NO_ATTR_SYNC is set, then we don't need any -- just use what's in cache */ - if (flags & AT_NO_ATTR_SYNC) + /* if AT_STATX_DONT_SYNC is set, then we don't need any -- just use what's in cache */ + if (flags & AT_STATX_DONT_SYNC) goto out; - /* Always set PIN to distinguish from AT_NO_ATTR_SYNC case */ + /* Always set PIN to distinguish from AT_STATX_DONT_SYNC case */ mask |= CEPH_CAP_PIN; if (want & (CEPH_STATX_MODE|CEPH_STATX_UID|CEPH_STATX_GID|CEPH_STATX_BTIME|CEPH_STATX_CTIME|CEPH_STATX_VERSION)) mask |= CEPH_CAP_AUTH_SHARED; @@ -8035,7 +8035,7 @@ void Client::fill_statx(Inode *in, unsigned int mask, struct ceph_statx *stx) memset(stx, 0, sizeof(struct ceph_statx)); /* - * If mask is 0, then the caller set AT_NO_ATTR_SYNC. Reset the mask + * If mask is 0, then the caller set AT_STATX_DONT_SYNC. Reset the mask * so that all bits are set. */ if (!mask) diff --git a/src/client/Client.h b/src/client/Client.h index 43263a1cdfadc..57c18289f0acc 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -343,7 +343,7 @@ public: * If @a cb returns a negative error code, stop and return that. */ int readdir_r_cb(dir_result_t *dirp, add_dirent_cb_t cb, void *p, - unsigned want=0, unsigned flags=AT_NO_ATTR_SYNC, + unsigned want=0, unsigned flags=AT_STATX_DONT_SYNC, bool getref=false); struct dirent * readdir(dir_result_t *d); diff --git a/src/client/hypertable/CephBroker.cc b/src/client/hypertable/CephBroker.cc index d3f283a0b070b..596e722871f1b 100644 --- a/src/client/hypertable/CephBroker.cc +++ b/src/client/hypertable/CephBroker.cc @@ -388,7 +388,7 @@ int CephBroker::rmdir_recursive(const char *directory) { int r; if ((r = ceph_opendir(cmount, directory, &dirp)) < 0) return r; //failed to open - while ((r = ceph_readdirplus_r(cmount, dirp, &de, &stx, CEPH_STATX_INO, AT_NO_ATTR_SYNC, NULL)) > 0) { + while ((r = ceph_readdirplus_r(cmount, dirp, &de, &stx, CEPH_STATX_INO, AT_STATX_DONT_SYNC, NULL)) > 0) { String new_dir = de.d_name; if(!(new_dir.compare(".")==0 || new_dir.compare("..")==0)) { new_dir = directory; diff --git a/src/include/cephfs/ceph_ll_client.h b/src/include/cephfs/ceph_ll_client.h index 78731db218d68..53cccc8504014 100644 --- a/src/include/cephfs/ceph_ll_client.h +++ b/src/include/cephfs/ceph_ll_client.h @@ -92,15 +92,18 @@ struct ceph_statx { /* * Compatibility macros until these defines make their way into glibc */ -#ifndef AT_NO_ATTR_SYNC -#define AT_NO_ATTR_SYNC 0x4000 /* Don't sync attributes with the server */ +#ifndef AT_STATX_DONT_SYNC +#define AT_STATX_SYNC_TYPE 0x6000 +#define AT_STATX_SYNC_AS_STAT 0x0000 +#define AT_STATX_FORCE_SYNC 0x2000 +#define AT_STATX_DONT_SYNC 0x4000 /* Don't sync attributes with the server */ #endif /* * The statx interfaces only allow these flags. In order to allow us to add * others in the future, we disallow setting any that aren't recognized. */ -#define CEPH_REQ_FLAG_MASK (AT_SYMLINK_NOFOLLOW|AT_NO_ATTR_SYNC) +#define CEPH_REQ_FLAG_MASK (AT_SYMLINK_NOFOLLOW|AT_STATX_DONT_SYNC) /* delegation recalls */ typedef void (*ceph_deleg_cb_t)(Fh *fh, void *priv); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 4e20549dc385f..185d5e40e04b1 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -851,7 +851,7 @@ int ceph_rename(struct ceph_mount_info *cmount, const char *from, const char *to * @param fd the file descriptor of the file to get statistics of. * @param stx the ceph_statx struct that will be filled in with the file's statistics. * @param want bitfield of CEPH_STATX_* flags showing designed attributes - * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW) + * @param flags bitfield that can be used to set AT_* modifier flags (AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC and AT_SYMLINK_NOFOLLOW) * @returns 0 on success or negative error code on failure. */ int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, @@ -865,7 +865,7 @@ int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, * @param relpath to the file/directory to get statistics of * @param stx the ceph_statx struct that will be filled in with the file's statistics. * @param want bitfield of CEPH_STATX_* flags showing designed attributes - * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW) + * @param flags bitfield that can be used to set AT_* modifier flags (AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC and AT_SYMLINK_NOFOLLOW) * @returns 0 on success or negative error code on failure. */ int ceph_statxat(struct ceph_mount_info *cmount, int dirfd, const char *relpath, @@ -878,7 +878,7 @@ int ceph_statxat(struct ceph_mount_info *cmount, int dirfd, const char *relpath, * @param path the file or directory to get the statistics of. * @param stx the ceph_statx struct that will be filled in with the file's statistics. * @param want bitfield of CEPH_STATX_* flags showing designed attributes - * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW) + * @param flags bitfield that can be used to set AT_* modifier flags (AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC and AT_SYMLINK_NOFOLLOW) * @returns 0 on success or negative error code on failure. */ int ceph_statx(struct ceph_mount_info *cmount, const char *path, struct ceph_statx *stx, diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 493b3a2c77636..3535a39644aef 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -21,8 +21,11 @@ from datetime import datetime import os import time -AT_NO_ATTR_SYNC = 0x4000 -AT_SYMLINK_NOFOLLOW = 0x100 +AT_SYMLINK_NOFOLLOW = 0x0100 +AT_STATX_SYNC_TYPE = 0x6000 +AT_STATX_SYNC_AS_STAT = 0x0000 +AT_STATX_FORCE_SYNC = 0x2000 +AT_STATX_DONT_SYNC = 0x4000 cdef int AT_SYMLINK_NOFOLLOW_CDEF = AT_SYMLINK_NOFOLLOW CEPH_STATX_BASIC_STATS = 0x7ff cdef int CEPH_STATX_BASIC_STATS_CDEF = CEPH_STATX_BASIC_STATS @@ -1939,7 +1942,7 @@ cdef class LibCephFS(object): :param path: the file or directory to get the statistics of. :param mask: want bitfield of CEPH_STATX_* flags showing designed attributes. - :param flag: bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW) + :param flag: bitfield that can be used to set AT_* modifier flags (AT_STATX_SYNC_AS_STAT, AT_STATX_FORCE_SYNC, AT_STATX_DONT_SYNC and AT_SYMLINK_NOFOLLOW) """ self.require_state("mounted") diff --git a/src/test/libcephfs/test.cc b/src/test/libcephfs/test.cc index 8208029bbae2d..c41569152baff 100644 --- a/src/test/libcephfs/test.cc +++ b/src/test/libcephfs/test.cc @@ -467,7 +467,7 @@ TEST(LibCephFS, DirLs) { struct dirent rdent; struct ceph_statx stx; int len = ceph_readdirplus_r(cmount, ls_dir, &rdent, &stx, - CEPH_STATX_SIZE, AT_NO_ATTR_SYNC, NULL); + CEPH_STATX_SIZE, AT_STATX_DONT_SYNC, NULL); if (len == 0) break; ASSERT_EQ(len, 1); @@ -1808,13 +1808,13 @@ TEST(LibCephFS, LazyStatx) { /* * Now sleep, do a chmod on the first client and the see whether we get a - * different ctime with a statx that uses AT_NO_ATTR_SYNC + * different ctime with a statx that uses AT_STATX_DONT_SYNC */ sleep(1); stx.stx_mode = 0644; ASSERT_EQ(ceph_ll_setattr(cmount1, file1, &stx, CEPH_SETATTR_MODE, perms1), 0); - ASSERT_EQ(ceph_ll_getattr(cmount2, file2, &stx, CEPH_STATX_CTIME, AT_NO_ATTR_SYNC, perms2), 0); + ASSERT_EQ(ceph_ll_getattr(cmount2, file2, &stx, CEPH_STATX_CTIME, AT_STATX_DONT_SYNC, perms2), 0); ASSERT_TRUE(stx.stx_mask & CEPH_STATX_CTIME); ASSERT_TRUE(stx.stx_ctime.tv_sec == old_ctime.tv_sec && stx.stx_ctime.tv_nsec == old_ctime.tv_nsec); diff --git a/src/tools/cephfs_mirror/PeerReplayer.cc b/src/tools/cephfs_mirror/PeerReplayer.cc index 44796cb4973af..aaf97b8684c47 100644 --- a/src/tools/cephfs_mirror/PeerReplayer.cc +++ b/src/tools/cephfs_mirror/PeerReplayer.cc @@ -759,7 +759,7 @@ int PeerReplayer::cleanup_remote_dir(const std::string &dir_root, int r = ceph_statxat(m_remote_mount, fh.r_fd_dir_root, epath.c_str(), &tstx, CEPH_STATX_MODE | CEPH_STATX_UID | CEPH_STATX_GID | CEPH_STATX_SIZE | CEPH_STATX_ATIME | CEPH_STATX_MTIME, - AT_NO_ATTR_SYNC | AT_SYMLINK_NOFOLLOW); + AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); if (r < 0) { derr << ": failed to stat remote directory=" << epath << ": " << cpp_strerror(r) << dendl; @@ -792,7 +792,7 @@ int PeerReplayer::cleanup_remote_dir(const std::string &dir_root, struct dirent de; while (true) { r = ceph_readdirplus_r(m_remote_mount, entry.dirp, &de, &stx, - CEPH_STATX_MODE, AT_NO_ATTR_SYNC | AT_SYMLINK_NOFOLLOW, NULL); + CEPH_STATX_MODE, AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW, NULL); if (r < 0) { derr << ": failed to read remote directory=" << entry.epath << dendl; break; @@ -878,7 +878,7 @@ int PeerReplayer::should_sync_entry(const std::string &epath, const struct ceph_ int r = ceph_statxat(fh.p_mnt, fh.p_fd, epath.c_str(), &pstx, CEPH_STATX_MODE | CEPH_STATX_UID | CEPH_STATX_GID | CEPH_STATX_SIZE | CEPH_STATX_CTIME | CEPH_STATX_MTIME, - AT_NO_ATTR_SYNC | AT_SYMLINK_NOFOLLOW); + AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); if (r < 0 && r != -ENOENT && r != -ENOTDIR) { derr << ": failed to stat prev entry= " << epath << ": " << cpp_strerror(r) << dendl; @@ -972,7 +972,7 @@ int PeerReplayer::propagate_deleted_entries(const std::string &dir_root, struct ceph_statx pstx; auto dpath = entry_path(epath, d_name); r = ceph_statxat(fh.p_mnt, fh.p_fd, dpath.c_str(), &pstx, - CEPH_STATX_MODE, AT_NO_ATTR_SYNC | AT_SYMLINK_NOFOLLOW); + CEPH_STATX_MODE, AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); if (r < 0) { derr << ": failed to stat (prev) directory=" << dpath << ": " << cpp_strerror(r) << dendl; @@ -986,7 +986,7 @@ int PeerReplayer::propagate_deleted_entries(const std::string &dir_root, struct ceph_statx cstx; r = ceph_statxat(m_local_mount, fh.c_fd, dpath.c_str(), &cstx, - CEPH_STATX_MODE, AT_NO_ATTR_SYNC | AT_SYMLINK_NOFOLLOW); + CEPH_STATX_MODE, AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); if (r < 0 && r != -ENOENT) { derr << ": failed to stat local (cur) directory=" << dpath << ": " << cpp_strerror(r) << dendl; @@ -1167,7 +1167,7 @@ int PeerReplayer::do_synchronize(const std::string &dir_root, const Snapshot &cu r = ceph_fstatx(m_local_mount, fh.c_fd, &tstx, CEPH_STATX_MODE | CEPH_STATX_UID | CEPH_STATX_GID | CEPH_STATX_SIZE | CEPH_STATX_ATIME | CEPH_STATX_MTIME, - AT_NO_ATTR_SYNC | AT_SYMLINK_NOFOLLOW); + AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW); if (r < 0) { derr << ": failed to stat snap=" << current.first << ": " << cpp_strerror(r) << dendl; @@ -1212,7 +1212,7 @@ int PeerReplayer::do_synchronize(const std::string &dir_root, const Snapshot &cu r = ceph_readdirplus_r(m_local_mount, entry.dirp, &de, &stx, CEPH_STATX_MODE | CEPH_STATX_UID | CEPH_STATX_GID | CEPH_STATX_SIZE | CEPH_STATX_ATIME | CEPH_STATX_MTIME, - AT_NO_ATTR_SYNC | AT_SYMLINK_NOFOLLOW, NULL); + AT_STATX_DONT_SYNC | AT_SYMLINK_NOFOLLOW, NULL); if (r < 0) { derr << ": failed to local read directory=" << entry.epath << dendl; break; -- 2.39.5