Whamcloud - gitweb
LU-14989 sec: keep encryption context in xattr cache
authorSebastien Buisson <sbuisson@ddn.com>
Thu, 7 Oct 2021 14:04:34 +0000 (16:04 +0200)
committerAndreas Dilger <adilger@whamcloud.com>
Sun, 10 Oct 2021 22:02:42 +0000 (22:02 +0000)
When an inode is being cleared, its xattr cache must be completely
wiped. But in case of lock cancel, we want to keep the encryption
context, as further processing might need to check it.

Lustre-change: https://review.whamcloud.com/45148
Lustre-commit: TBD (bc79d1bc90f9d094598985127f8386894d0b7355)

Fixes: bf291f2212 ("LU-14989 sec: access to enc file's xattrs")
Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Change-Id: I8a2f4497129353a7fbf86cdaaa13fae6e0988790
Reviewed-on: https://review.whamcloud.com/45149
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/llite/llite_internal.h
lustre/llite/namei.c
lustre/llite/xattr_cache.c

index bb1dc03..c647726 100644 (file)
@@ -456,6 +456,7 @@ static inline bool ll_file_test_and_clear_flag(struct ll_inode_info *lli,
 }
 
 int ll_xattr_cache_destroy(struct inode *inode);
+int ll_xattr_cache_empty(struct inode *inode);
 
 int ll_xattr_cache_get(struct inode *inode,
                       const char *name,
index 460e02d..d30638e 100644 (file)
@@ -255,7 +255,7 @@ static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
        }
 
        if (bits & MDS_INODELOCK_XATTR) {
-               ll_xattr_cache_destroy(inode);
+               ll_xattr_cache_empty(inode);
                bits &= ~MDS_INODELOCK_XATTR;
        }
 
index fe95002..03c5f9a 100644 (file)
@@ -315,6 +315,42 @@ int ll_xattr_cache_destroy(struct inode *inode)
 }
 
 /**
+ * ll_xattr_cache_empty - empty xattr cache for @ino
+ *
+ * Similar to ll_xattr_cache_destroy(), but preserves encryption context.
+ * So only LLIF_XATTR_CACHE_FILLED flag is cleared, but not LLIF_XATTR_CACHE.
+ */
+int ll_xattr_cache_empty(struct inode *inode)
+{
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct ll_xattr_entry *entry, *n;
+
+       ENTRY;
+
+       down_write(&lli->lli_xattrs_list_rwsem);
+       if (!ll_xattr_cache_valid(lli) ||
+           !ll_xattr_cache_filled(lli))
+               GOTO(out_empty, 0);
+
+       list_for_each_entry_safe(entry, n, &lli->lli_xattrs, xe_list) {
+               if (strcmp(entry->xe_name,
+                          LL_XATTR_NAME_ENCRYPTION_CONTEXT) == 0)
+                       continue;
+
+               CDEBUG(D_CACHE, "delete: %s\n", entry->xe_name);
+               list_del(&entry->xe_list);
+               OBD_FREE(entry->xe_name, entry->xe_namelen);
+               OBD_FREE(entry->xe_value, entry->xe_vallen);
+               OBD_SLAB_FREE_PTR(entry, xattr_kmem);
+       }
+       clear_bit(LLIF_XATTR_CACHE_FILLED, &lli->lli_flags);
+
+out_empty:
+       up_write(&lli->lli_xattrs_list_rwsem);
+       RETURN(0);
+}
+
+/**
  * Match or enqueue a PR lock.
  *
  * Find or request an LDLM lock with xattr data.