]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: Add ceph.caps vxattr 41481/head
authorKotresh HR <khiremat@redhat.com>
Thu, 20 May 2021 12:45:57 +0000 (18:15 +0530)
committerKotresh HR <khiremat@redhat.com>
Mon, 24 May 2021 10:28:49 +0000 (15:58 +0530)
Fixes: https://tracker.ceph.com/issues/48404
Signed-off-by: Kotresh HR <khiremat@redhat.com>
src/client/Client.cc
src/client/Client.h
src/test/libcephfs/test.cc

index b1b86290ae4d12c72044c7bcd05fb3c93ecb074a..f91634815529c326ba89a9c9aae3ce80c8f8d04f 100644 (file)
@@ -12735,6 +12735,14 @@ size_t Client::_vxattrcb_snap_btime(Inode *in, char *val, size_t size)
       (long unsigned)in->snap_btime.nsec());
 }
 
+size_t Client::_vxattrcb_caps(Inode *in, char *val, size_t size)
+{
+  int issued;
+
+  in->caps_issued(&issued);
+  return snprintf(val, size, "%s/0x%x", ccap_string(issued).c_str(), issued);
+}
+
 bool Client::_vxattrcb_mirror_info_exists(Inode *in)
 {
   // checking one of the xattrs would suffice
@@ -12841,6 +12849,13 @@ const Client::VXattr Client::_dir_vxattrs[] = {
     exists_cb: &Client::_vxattrcb_mirror_info_exists,
     flags: 0,
   },
+  {
+    name: "ceph.caps",
+    getxattr_cb: &Client::_vxattrcb_caps,
+    readonly: true,
+    exists_cb: NULL,
+    flags: 0,
+  },
   { name: "" }     /* Required table terminator */
 };
 
@@ -12864,6 +12879,13 @@ const Client::VXattr Client::_file_vxattrs[] = {
     exists_cb: &Client::_vxattrcb_snap_btime_exists,
     flags: 0,
   },
+  {
+    name: "ceph.caps",
+    getxattr_cb: &Client::_vxattrcb_caps,
+    readonly: true,
+    exists_cb: NULL,
+    flags: 0,
+  },
   { name: "" }     /* Required table terminator */
 };
 
index d8e53e7856114656113e7551795fc181f5bc1365..5dc1565290973d7e9503729a77f465f7d9d64908 100644 (file)
@@ -1412,6 +1412,8 @@ private:
   bool _vxattrcb_snap_btime_exists(Inode *in);
   size_t _vxattrcb_snap_btime(Inode *in, char *val, size_t size);
 
+  size_t _vxattrcb_caps(Inode *in, char *val, size_t size);
+
   bool _vxattrcb_mirror_info_exists(Inode *in);
   size_t _vxattrcb_mirror_info(Inode *in, char *val, size_t size);
 
index 959ff14fee52c8aa090282116598aeb6eef91dde..ac899f85556d7859f0e05be4e1333e145790ec62 100644 (file)
@@ -38,6 +38,7 @@
 #include <map>
 #include <vector>
 #include <thread>
+#include <regex>
 
 #ifndef ALLPERMS
 #define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
@@ -2287,6 +2288,32 @@ TEST(LibCephFS, OperationsOnDotDot) {
   ceph_shutdown(cmount);
 }
 
+TEST(LibCephFS, Caps_vxattr) {
+  struct ceph_mount_info *cmount;
+  ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+  ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
+  ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+
+  char test_caps_vxattr_file[256];
+  char gxattrv[128];
+  int xbuflen = sizeof(gxattrv);
+  pid_t mypid = getpid();
+
+  sprintf(test_caps_vxattr_file, "test_caps_vxattr_%d", mypid);
+  int fd = ceph_open(cmount, test_caps_vxattr_file, O_CREAT, 0666);
+  ASSERT_GT(fd, 0);
+  ceph_close(cmount, fd);
+
+  int alen = ceph_getxattr(cmount, test_caps_vxattr_file, "ceph.caps", (void *)gxattrv, xbuflen);
+  ASSERT_GT(alen, 0);
+  gxattrv[alen] = '\0';
+
+  char caps_regex[] = "pA[sx]*L[sx]*X[sx]*F[sxcrwbal]*/0x[0-9a-fA-f]+";
+  ASSERT_TRUE(regex_match(gxattrv, regex(caps_regex)) == 1);
+  ceph_shutdown(cmount);
+}
+
 TEST(LibCephFS, SnapXattrs) {
   struct ceph_mount_info *cmount;
   ASSERT_EQ(ceph_create(&cmount, NULL), 0);