Skip to content

Commit a29aa59

Browse files
committed
client: Breakout fscrypt get policy into method
Breakout fscrypt get policy into a method. Add ceph_get_fscrypt_policy_v2 support. Signed-off-by: Christopher Hoffman <[email protected]> (cherry picked from commit e11f4a7)
1 parent cefa9bb commit a29aa59

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

src/client/Client.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18178,6 +18178,28 @@ int Client::ll_set_fscrypt_policy_v2(Inode *in, const struct fscrypt_policy_v2&
1817818178
return 0;
1817918179
}
1818018180

18181+
int Client::get_fscrypt_policy_v2(int fd, struct fscrypt_policy_v2* policy)
18182+
{
18183+
Fh *f = get_filehandle(fd);
18184+
if (!f) {
18185+
return -EBADF;
18186+
}
18187+
18188+
return ll_get_fscrypt_policy_v2(f->inode.get(), policy);
18189+
}
18190+
18191+
int Client::ll_get_fscrypt_policy_v2(Inode *in, struct fscrypt_policy_v2* policy)
18192+
{
18193+
if (in->is_fscrypt_enabled()) {
18194+
in->fscrypt_ctx->convert_to(policy);
18195+
if (policy->version != 2) {
18196+
return EINVAL;
18197+
}
18198+
return 0;
18199+
}
18200+
return ENODATA;
18201+
}
18202+
1818118203
int Client::is_encrypted(int fd, UserPerm& perms, char* enctag)
1818218204
{
1818318205
Fh *f = get_filehandle(fd);

src/client/Client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ class Client : public Dispatcher, public md_config_obs_t {
349349
int fcopyfile(const char *sname, const char *dname, UserPerm& perms, mode_t mode);
350350

351351
int set_fscrypt_policy_v2(int fd, const struct fscrypt_policy_v2& policy);
352+
int get_fscrypt_policy_v2(int fd, struct fscrypt_policy_v2* policy);
352353
int is_encrypted(int fd, UserPerm& perms, char* enctag);
353354

354355
int mds_command(
@@ -709,6 +710,7 @@ class Client : public Dispatcher, public md_config_obs_t {
709710
}
710711

711712
int ll_set_fscrypt_policy_v2(Inode *in, const struct fscrypt_policy_v2& policy);
713+
int ll_get_fscrypt_policy_v2(Inode *in, struct fscrypt_policy_v2* policy);
712714

713715
int ll_get_stripe_osd(struct Inode *in, uint64_t blockno,
714716
file_layout_t* layout);

src/client/fuse_ll.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,14 @@ static void fuse_ll_ioctl(fuse_req_t req, fuse_ino_t ino,
969969
Inode *in = fh->inode.get();
970970

971971
if (in->is_fscrypt_enabled()) {
972-
in->fscrypt_ctx->convert_to(&out_arg.policy.v2);
972+
973+
int r = cfuse->client->ll_get_fscrypt_policy_v2(in, &out_arg.policy.v2);
974+
975+
if (r < 0) {
976+
fuse_reply_err(req, r);
977+
break;
978+
}
979+
973980
out_arg.policy_size = sizeof(out_arg.policy);
974981

975982
fuse_reply_ioctl(req, 0, &out_arg, sizeof(out_arg));

src/include/cephfs/libcephfs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,17 @@ int ceph_is_encrypted(struct ceph_mount_info *cmount,
20392039
*/
20402040
int get_inode_flags(struct ceph_mount_info *cmount, int fd, int* file_attr_out);
20412041

2042+
/**
2043+
* Get encryption policy of a directory.
2044+
*
2045+
* @param cmount the ceph mount handle to use.
2046+
* @param fd open directory file descriptor
2047+
* @param policy pointer to to the fscrypt v2 policy
2048+
* @returns zero on success, other returns a negative error code.
2049+
*/
2050+
int ceph_get_fscrypt_policy_v2(struct ceph_mount_info *cmount,
2051+
int fd, struct fscrypt_policy_v2 *policy);
2052+
20422053
/* Low Level */
20432054
struct Inode *ceph_ll_get_inode(struct ceph_mount_info *cmount,
20442055
vinodeno_t vino);

src/libcephfs.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,15 @@ extern "C" int ceph_is_encrypted(struct ceph_mount_info *cmount,
27372737
return cmount->get_client()->is_encrypted(fd, cmount->default_perms, enctag);
27382738
}
27392739

2740+
extern "C" int ceph_get_fscrypt_policy_v2(struct ceph_mount_info *cmount,
2741+
int fd, struct fscrypt_policy_v2 *policy)
2742+
{
2743+
if (!cmount->is_mounted())
2744+
return -ENOTCONN;
2745+
2746+
return cmount->get_client()->get_fscrypt_policy_v2(fd, policy);
2747+
}
2748+
27402749

27412750
// This is deprecated, use ceph_ll_register_callbacks2 instead.
27422751
extern "C" void ceph_ll_register_callbacks(class ceph_mount_info *cmount,

0 commit comments

Comments
 (0)