[Devel] [PATCH RH7] pfcache: hide trusted.pfcache from listxattr

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Thu Sep 22 02:44:53 PDT 2016


In SyS_listxattr -> listxattr -> ext4_listxattr ->
ext4_xattr_list_entries we choose list handler for
each ext4_xattr_entry based on e_name_index, and as
for trusted.pfcache index is EXT4_XATTR_INDEX_TRUSTED,
we chouse ext4_xattr_trusted_list which prints xattr
to the list.

To hide our trusted.pfcache from list change e_name_index
to new EXT4_XATTR_INDEX_TRUSTED_CSUM and thus use
ext4_xattr_trusted_csum_list instead which won't put
xattr to the returned list.

Test:

TEST_FILE=/vz/root/101/testfile
TEST_SHA1=`sha1sum $TEST_FILE | awk '{print $1}'`
setfattr -n trusted.pfcache -v $TEST_SHA1 $TEST_FILE
setfattr -n trusted.test -v test $TEST_FILE
getfattr -d -m trusted $TEST_FILE

before patch it was listed:

trusted.pfcache="da39a3ee5e6b4b0d3255bfef95601890afd80709"
trusted.test="test"

after - not:

trusted.test="test"

https://jira.sw.ru/browse/PSBM-52180
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 fs/ext4/pfcache.c | 28 ++++++++++++++--------------
 fs/ext4/xattr.c   |  1 +
 fs/ext4/xattr.h   |  1 +
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/fs/ext4/pfcache.c b/fs/ext4/pfcache.c
index ff2300b..5fc6d9f 100644
--- a/fs/ext4/pfcache.c
+++ b/fs/ext4/pfcache.c
@@ -441,8 +441,8 @@ int ext4_load_data_csum(struct inode *inode)
 {
 	int ret;
 
-	ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
-			EXT4_DATA_CSUM_NAME, EXT4_I(inode)->i_data_csum,
+	ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+			"", EXT4_I(inode)->i_data_csum,
 			EXT4_DATA_CSUM_SIZE);
 	if (ret < 0)
 		return ret;
@@ -482,8 +482,8 @@ static int ext4_save_data_csum(struct inode *inode, u8 *csum)
 	if (ret)
 		return ret;
 
-	return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-			EXT4_DATA_CSUM_NAME, EXT4_I(inode)->i_data_csum,
+	return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+			"", EXT4_I(inode)->i_data_csum,
 			EXT4_DATA_CSUM_SIZE, 0);
 }
 
@@ -492,8 +492,8 @@ void ext4_load_dir_csum(struct inode *inode)
 	char value[EXT4_DIR_CSUM_VALUE_LEN];
 	int ret;
 
-	ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
-			     EXT4_DATA_CSUM_NAME, value, sizeof(value));
+	ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+			     "", value, sizeof(value));
 	if (ret == EXT4_DIR_CSUM_VALUE_LEN &&
 	    !strncmp(value, EXT4_DIR_CSUM_VALUE, sizeof(value)))
 		ext4_set_inode_state(inode, EXT4_STATE_PFCACHE_CSUM);
@@ -502,8 +502,8 @@ void ext4_load_dir_csum(struct inode *inode)
 void ext4_save_dir_csum(struct inode *inode)
 {
 	ext4_set_inode_state(inode, EXT4_STATE_PFCACHE_CSUM);
-	ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-			EXT4_DATA_CSUM_NAME,
+	ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+			"",
 			EXT4_DIR_CSUM_VALUE,
 			EXT4_DIR_CSUM_VALUE_LEN, 0);
 }
@@ -516,8 +516,8 @@ void ext4_truncate_data_csum(struct inode *inode, loff_t pos)
 
 	if (EXT4_I(inode)->i_data_csum_end < 0) {
 		WARN_ON(journal_current_handle());
-		ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-				EXT4_DATA_CSUM_NAME, NULL, 0, 0);
+		ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+				"", NULL, 0, 0);
 		ext4_close_pfcache(inode);
 	}
 	spin_lock(&inode->i_lock);
@@ -658,8 +658,8 @@ static int ext4_xattr_trusted_csum_get(struct dentry *dentry, const char *name,
 		return -EPERM;
 
 	if (S_ISDIR(inode->i_mode))
-		return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
-				      EXT4_DATA_CSUM_NAME, buffer, size);
+		return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+				      "", buffer, size);
 
 	if (!S_ISREG(inode->i_mode))
 		return -ENODATA;
@@ -717,8 +717,8 @@ static int ext4_xattr_trusted_csum_set(struct dentry *dentry, const char *name,
 		else
 			return -EINVAL;
 
-		return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-				      EXT4_DATA_CSUM_NAME, value, size, flags);
+		return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+				      "", value, size, flags);
 	}
 
 	if (!S_ISREG(inode->i_mode))
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 5dabf58..81b5534 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -102,6 +102,7 @@ static const struct xattr_handler *ext4_xattr_handler_map[] = {
 #ifdef CONFIG_EXT4_FS_SECURITY
 	[EXT4_XATTR_INDEX_SECURITY]	     = &ext4_xattr_security_handler,
 #endif
+	[EXT4_XATTR_INDEX_TRUSTED_CSUM]	     = &ext4_xattr_trusted_csum_handler,
 };
 
 const struct xattr_handler *ext4_xattr_handlers[] = {
diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
index c767dbd..f6af6c9 100644
--- a/fs/ext4/xattr.h
+++ b/fs/ext4/xattr.h
@@ -23,6 +23,7 @@
 #define EXT4_XATTR_INDEX_SECURITY	        6
 #define EXT4_XATTR_INDEX_SYSTEM			7
 #define EXT4_XATTR_INDEX_RICHACL		8
+#define EXT4_XATTR_INDEX_TRUSTED_CSUM		9
 
 struct ext4_xattr_header {
 	__le32	h_magic;	/* magic number for identification */
-- 
2.5.5



More information about the Devel mailing list