]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client: Breakout fscrypt get policy into method
authorChristopher Hoffman <choffman@redhat.com>
Tue, 24 Jun 2025 19:09:07 +0000 (19:09 +0000)
committerChristopher Hoffman <choffman@redhat.com>
Fri, 15 Aug 2025 16:03:31 +0000 (16:03 +0000)
Breakout fscrypt get policy into a method. Add
ceph_get_fscrypt_policy_v2 support.

Signed-off-by: Christopher Hoffman <choffman@redhat.com>
src/client/Client.cc
src/client/Client.h
src/client/fuse_ll.cc
src/include/cephfs/libcephfs.h
src/libcephfs.cc

index 316242b5279c5eb5903194d658d46d2a5fdf25cf..de5f07f608bd066f4a6b1be1d99d7cb5a8fef274 100644 (file)
@@ -18231,6 +18231,28 @@ int Client::ll_set_fscrypt_policy_v2(Inode *in, const struct fscrypt_policy_v2&
   return 0;
 }
 
+int Client::get_fscrypt_policy_v2(int fd, struct fscrypt_policy_v2* policy)
+{
+  Fh *f = get_filehandle(fd);
+  if (!f) {
+    return -EBADF;
+  }
+
+  return ll_get_fscrypt_policy_v2(f->inode.get(), policy);
+}
+
+int Client::ll_get_fscrypt_policy_v2(Inode *in, struct fscrypt_policy_v2* policy)
+{
+  if (in->is_fscrypt_enabled()) {
+    in->fscrypt_ctx->convert_to(policy);
+    if (policy->version != 2) {
+      return EINVAL;
+    }
+    return 0;
+  }
+  return ENODATA;
+}
+
 int Client::is_encrypted(int fd, UserPerm& perms, char* enctag)
 {
   Fh *f = get_filehandle(fd);
index 3b86078f179877a9d21ed603492248af0cfa6dc0..feafe4d1f9198fb7089f0a1d11edd79fc680ba1b 100644 (file)
@@ -349,6 +349,7 @@ public:
   int fcopyfile(const char *sname, const char *dname, UserPerm& perms, mode_t mode);
 
   int set_fscrypt_policy_v2(int fd, const struct fscrypt_policy_v2& policy);
+  int get_fscrypt_policy_v2(int fd, struct fscrypt_policy_v2* policy);
   int is_encrypted(int fd, UserPerm& perms, char* enctag);
 
   int mds_command(
@@ -711,6 +712,7 @@ public:
   }
 
   int ll_set_fscrypt_policy_v2(Inode *in, const struct fscrypt_policy_v2& policy);
+  int ll_get_fscrypt_policy_v2(Inode *in, struct fscrypt_policy_v2* policy);
 
   int ll_get_stripe_osd(struct Inode *in, uint64_t blockno,
                        file_layout_t* layout);
index 7bd92663b60ec24c4972dff956bed0254faa55a7..fa13de4e54039657d012b0936c0c38c48c3f0938 100644 (file)
@@ -971,7 +971,14 @@ static void fuse_ll_ioctl(fuse_req_t req, fuse_ino_t ino,
       Inode *in = fh->inode.get();
 
       if (in->is_fscrypt_enabled()) {
-        in->fscrypt_ctx->convert_to(&out_arg.policy.v2);
+
+        int r = cfuse->client->ll_get_fscrypt_policy_v2(in, &out_arg.policy.v2);
+
+        if (r < 0) {
+          fuse_reply_err(req, r);
+         break;
+        }
+
         out_arg.policy_size = sizeof(out_arg.policy);
 
         fuse_reply_ioctl(req, 0, &out_arg, sizeof(out_arg));
index ea0374d75358d46a803c099cf639b2ca70730e64..7cf7f77da4e1190b85fd14775974b45e02e491b3 100644 (file)
@@ -2049,6 +2049,17 @@ int ceph_set_fscrypt_policy_v2(struct ceph_mount_info *cmount,
 int ceph_is_encrypted(struct ceph_mount_info *cmount,
                       int fd, char* enctag);
 
+/**
+ * Get encryption policy of a directory.
+ *
+ * @param cmount the ceph mount handle to use.
+ * @param fd open directory file descriptor
+ * @param policy pointer to to the fscrypt v2 policy
+ * @returns zero on success, other returns a negative error code.
+ */
+int ceph_get_fscrypt_policy_v2(struct ceph_mount_info *cmount,
+                               int fd, struct fscrypt_policy_v2 *policy);
+
 /* Low Level */
 struct Inode *ceph_ll_get_inode(struct ceph_mount_info *cmount,
                                vinodeno_t vino);
index 0fe4a88efbb1c7976b5305481f6bf46391d18412..fcf69ca802fcf01bf469c14dd0131804276d9b95 100644 (file)
@@ -2542,6 +2542,15 @@ extern "C" int ceph_is_encrypted(struct ceph_mount_info *cmount,
   return cmount->get_client()->is_encrypted(fd, cmount->default_perms, enctag);
 }
 
+extern "C" int ceph_get_fscrypt_policy_v2(struct ceph_mount_info *cmount,
+                                          int fd, struct fscrypt_policy_v2 *policy)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+
+  return cmount->get_client()->get_fscrypt_policy_v2(fd, policy);
+}
+
 
 // This is deprecated, use ceph_ll_register_callbacks2 instead.
 extern "C" void ceph_ll_register_callbacks(class ceph_mount_info *cmount,