From: Xiubo Li Date: Tue, 24 Nov 2020 08:49:06 +0000 (+0800) Subject: client: add ceph.{cluster_fsid/client_id} vxattrs suppport X-Git-Tag: v14.2.17~29^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e61de1e08f751fce0ff6075e45b49c4aafc83434;p=ceph.git client: add ceph.{cluster_fsid/client_id} vxattrs suppport These two vxattrs will only exist in local client side, with which we can easily know which mountpoint the file belongs to and also they can help locate the debugfs path quickly. Fixes: https://tracker.ceph.com/issues/48337 Signed-off-by: Xiubo Li (cherry picked from commit 5635f25dd4a134f2fb32d2cb9dd73c0e947295e6) Conflicts: src/client/Client.cc - add .hidden member because we still need it in nautilus src/client/Client.h - drop the mirror.info xattr related code because nautilus does not introduce it --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 2c56b9d389354..187413229aef0 100755 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -11938,6 +11938,17 @@ size_t Client::_vxattrcb_snap_btime(Inode *in, char *val, size_t size) (long unsigned)in->snap_btime.nsec()); } +size_t Client::_vxattrcb_cluster_fsid(Inode *in, char *val, size_t size) +{ + return snprintf(val, size, "%s", monclient->get_fsid().to_string().c_str()); +} + +size_t Client::_vxattrcb_client_id(Inode *in, char *val, size_t size) +{ + auto name = messenger->get_myname(); + return snprintf(val, size, "%s%ld", name.type_str(), name.num()); +} + #define CEPH_XATTR_NAME(_type, _name) "ceph." #_type "." #_name #define CEPH_XATTR_NAME2(_type, _name, _name2) "ceph." #_type "." #_name "." #_name2 @@ -12054,6 +12065,26 @@ const Client::VXattr Client::_file_vxattrs[] = { { name: "" } /* Required table terminator */ }; +const Client::VXattr Client::_common_vxattrs[] = { + { + name: "ceph.cluster_fsid", + getxattr_cb: &Client::_vxattrcb_cluster_fsid, + readonly: true, + hidden: false, + exists_cb: nullptr, + flags: 0, + }, + { + name: "ceph.client_id", + getxattr_cb: &Client::_vxattrcb_client_id, + readonly: true, + hidden: false, + exists_cb: nullptr, + flags: 0, + }, + { name: "" } /* Required table terminator */ +}; + const Client::VXattr *Client::_get_vxattrs(Inode *in) { if (in->is_dir()) @@ -12074,7 +12105,16 @@ const Client::VXattr *Client::_match_vxattr(Inode *in, const char *name) vxattr++; } } + + // for common vxattrs + vxattr = _common_vxattrs; + while (!vxattr->name.empty()) { + if (vxattr->name == name) + return vxattr; + vxattr++; + } } + return NULL; } diff --git a/src/client/Client.h b/src/client/Client.h index 9c4f02c04473c..2749cc42b5615 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1008,6 +1008,7 @@ private: static const VXattr _dir_vxattrs[]; static const VXattr _file_vxattrs[]; + static const VXattr _common_vxattrs[]; @@ -1157,6 +1158,9 @@ private: bool _vxattrcb_snap_btime_exists(Inode *in); size_t _vxattrcb_snap_btime(Inode *in, char *val, size_t size); + size_t _vxattrcb_cluster_fsid(Inode *in, char *val, size_t size); + size_t _vxattrcb_client_id(Inode *in, char *val, size_t size); + static const VXattr *_get_vxattrs(Inode *in); static const VXattr *_match_vxattr(Inode *in, const char *name);