]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client: Add additional case for fscrypt enabled setattr
authorChristopher Hoffman <choffman@redhat.com>
Fri, 28 Mar 2025 18:57:40 +0000 (18:57 +0000)
committerChristopher Hoffman <choffman@redhat.com>
Wed, 5 Nov 2025 13:59:35 +0000 (13:59 +0000)
During setattr in fscrypt case, there's two cases that happen
1. A logical size is provided and then a vector must be populated.
2. A request from setxattr is received and fscrypt_file vector
   is already set.

Also rework tests when setting fscrypt_file, to use logical sizes.

Signed-off-by: Christopher Hoffman <choffman@redhat.com>
qa/workunits/fs/fscrypt.sh
src/client/Client.cc
src/test/libcephfs/test.cc
src/test/libcephfs/vxattr.cc

index e1695f28740d4c962b378ff026efa598e6508df0..2c523d0a01f971d56c97343fb2b90da51dd8a8b7 100755 (executable)
@@ -80,4 +80,4 @@ case ${fscrypt_type} in
         echo "Unknown parameter $1"
         exit 1
         ;;
-esac
\ No newline at end of file
+esac
index b2c1c1658873ab1aaa91c8df8dc90b2d1a592fda..dce0a7090056a573089ed7e051cec08f21c9291d 100644 (file)
@@ -1161,7 +1161,7 @@ Inode * Client::add_update_inode(InodeStat *st, utime_t from,
       (new_issued & (CEPH_CAP_ANY_FILE_RD | CEPH_CAP_ANY_FILE_WR))) {
     in->layout = st->layout;
     uint64_t size = st->size;
-    if (in->fscrypt_ctx) {
+    if (in->fscrypt_auth.size()) {
       if (st->fscrypt_file.size() >= sizeof(uint64_t)) {
         size = *(ceph_le64 *)st->fscrypt_file.data();
       }
@@ -8503,8 +8503,12 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask,
   if (mask & CEPH_SETATTR_SIZE) {
     auto stx_size = stx->stx_size;
 
+    if (paux && !(mask & CEPH_SETATTR_FSCRYPT_FILE)) {
+      mask |= CEPH_SETATTR_FSCRYPT_FILE;
+    }
+
     if (in->fscrypt_ctx &&
-        (!(mask & CEPH_SETATTR_FSCRYPT_FILE))) {
+       (!(mask & CEPH_SETATTR_FSCRYPT_FILE))) {
       ldout(cct,10) << "fscrypt: set file size: orig stx_size=" << stx->stx_size <<" new stx_size=" << stx_size << dendl;
 
       alt_aux.resize(sizeof(stx->stx_size));
@@ -15271,10 +15275,10 @@ int Client::_vxattrcb_fscrypt_file_set(Inode *in, const void *val, size_t size,
   struct ceph_statx stx = { 0 };
   std::vector<uint8_t> aux;
 
-  aux.resize(size);
+  aux.resize(sizeof(uint64_t));
   memcpy(aux.data(), val, size);
 
-  return _do_setattr(in, &stx, CEPH_SETATTR_FSCRYPT_FILE, perms, nullptr, &aux);
+  return _do_setattr(in, &stx, CEPH_SETATTR_SIZE, perms, nullptr, &aux);
 }
 
 bool Client::_vxattrcb_quota_exists(Inode *in)
index 77f71ccb87d9b1f8feabe039c0beb2e4c9d02073..edd567635775f28f45a0a8be9cff64dd6193d649 100644 (file)
@@ -3832,12 +3832,13 @@ TEST(LibCephFS, FsCrypt) {
   int fd = ceph_open(cmount, test_xattr_file, O_RDWR|O_CREAT, 0666);
   ASSERT_GT(fd, 0);
 
+  uint64_t size = 64;
   ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.auth", "foo", 3, CEPH_XATTR_CREATE));
-  ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.file", "foo", 3, CEPH_XATTR_CREATE));
+  ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.file", &size, sizeof(size), CEPH_XATTR_CREATE));
 
   char buf[64];
   ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf)));
-  ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf)));
+  ASSERT_EQ(sizeof(size), ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf)));
   ASSERT_EQ(0, ceph_close(cmount, fd));
 
   ASSERT_EQ(0, ceph_unmount(cmount));
@@ -3846,7 +3847,7 @@ TEST(LibCephFS, FsCrypt) {
   fd = ceph_open(cmount, test_xattr_file, O_RDWR, 0666);
   ASSERT_GT(fd, 0);
   ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf)));
-  ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf)));
+  ASSERT_EQ(sizeof(size), ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf)));
 
   ASSERT_EQ(0, ceph_close(cmount, fd));
   ASSERT_EQ(0, ceph_unmount(cmount));
index b058f90fe8eb8fa0cf38baaf1094c5b980280cae..ac6806b6487a2ba27cd56afe4eaf52bb469f3c86 100644 (file)
@@ -397,12 +397,13 @@ TEST(LibCephFS, FsCrypt) {
   int fd = ceph_open(cmount, test_xattr_file, O_RDWR|O_CREAT, 0666);
   ASSERT_GT(fd, 0);
 
+  uint64_t size = 64;
   ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.auth", "foo", 3, XATTR_CREATE));
-  ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.file", "foo", 3, XATTR_CREATE));
+  ASSERT_EQ(0, ceph_fsetxattr(cmount, fd, "ceph.fscrypt.file", &size, sizeof(size), XATTR_CREATE));
 
   char buf[64];
   ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf)));
-  ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf)));
+  ASSERT_EQ(sizeof(size), ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf)));
   ASSERT_EQ(0, ceph_close(cmount, fd));
 
   ASSERT_EQ(0, ceph_unmount(cmount));
@@ -411,7 +412,7 @@ TEST(LibCephFS, FsCrypt) {
   fd = ceph_open(cmount, test_xattr_file, O_RDWR, 0666);
   ASSERT_GT(fd, 0);
   ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.auth", buf, sizeof(buf)));
-  ASSERT_EQ(3, ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf)));
+  ASSERT_EQ(sizeof(size), ceph_fgetxattr(cmount, fd, "ceph.fscrypt.file", buf, sizeof(buf)));
 
   ASSERT_EQ(0, ceph_close(cmount, fd));
   ASSERT_EQ(0, ceph_unmount(cmount));