From: Gou Hao gouhao@uniontech.com
uniontech inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I40JRR CVE: NA
--------------
The i_xattr points to a data block that stores extended attributes. extended attribute's opration protected by xattr_rwsem.
Signed-off-by: Gou Hao gouhao@uniontech.com --- fs/eulerfs/euler_def.h | 3 +++ fs/eulerfs/inode.c | 2 ++ fs/eulerfs/nvm_struct.h | 12 ++++++++++++ fs/eulerfs/super.c | 5 ++++- 4 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/fs/eulerfs/euler_def.h b/fs/eulerfs/euler_def.h index 727f1c4cf181..8b7dc403b4e1 100644 --- a/fs/eulerfs/euler_def.h +++ b/fs/eulerfs/euler_def.h @@ -85,6 +85,9 @@ struct eufs_inode_info { /* Protect pointers to leaf nodes (data pages) */ struct mutex i_leaf_lock;
+ struct rw_semaphore xattr_rwsem; + u64 i_xattr; + spinlock_t i_dentry_persist_lock; struct inode vfs_inode; }; diff --git a/fs/eulerfs/inode.c b/fs/eulerfs/inode.c index c3db0750b66f..414ccf6d80a0 100644 --- a/fs/eulerfs/inode.c +++ b/fs/eulerfs/inode.c @@ -50,6 +50,7 @@ static int eufs_read_pinode(struct inode *inode, struct eufs_inode *pi) i_gid_write(inode, eufs_iread_gid(pi)); vi->i_dotdot = eufs_iread_dotdot(pi); vi->i_ext = eufs_iread_ext(pi); + vi->i_xattr = eufs_iread_xattr(pi);
inode->i_generation = eufs_iread_generation(pi); set_nlink(inode, eufs_iread_nlink(pi)); @@ -215,6 +216,7 @@ void eufs_sync_pinode(struct inode *inode, struct eufs_inode *pi, bool evict) eufs_iwrite_atime_nsec(twin_pi, inode->i_atime.tv_nsec); eufs_iwrite_root(twin_pi, pi_root_o); eufs_iwrite_size(twin_pi, inode->i_size); + eufs_iwrite_xattr(twin_pi, vi->i_xattr); eufs_iwrite_tree_blocks(twin_pi, pi_tree_blocks);
eufs_flush_cacheline(twin_pi); diff --git a/fs/eulerfs/nvm_struct.h b/fs/eulerfs/nvm_struct.h index 4818ae6d49bf..337ed50677f2 100644 --- a/fs/eulerfs/nvm_struct.h +++ b/fs/eulerfs/nvm_struct.h @@ -150,7 +150,11 @@ struct eufs_inode { /* 40 ~ 48 */ __le32 i_ctime_nsec; /* nano sec */ /* 48 ~ 56 */ +#ifdef CONFIG_EULER_FS_XATTR + __le64 i_xattr; +#else __le64 padding1; +#endif /* 56 ~ 64 */ __le64 padding2;
@@ -215,6 +219,14 @@ struct eufs_inode { #define eufs_iwrite_ctime_nsec(i, v) ((i)->i_ctime_nsec = cpu_to_le32(v)) #define eufs_iwrite_ext(i, v) ((i)->i_ext = cpu_to_le64(v))
+#ifdef CONFIG_EULER_FS_XATTR +#define eufs_iread_xattr(i) (le64_to_cpu((i)->i_xattr)) +#define eufs_iwrite_xattr(i, v) ((i)->i_xattr = cpu_to_le64(v)) +#else +#define eufs_iread_xattr(i) (0) +#define eufs_iwrite_xattr(i, v) +#endif + #define eufs_writemostly_inode(i) ((i))
#define eufs_iread_generation(i) \ diff --git a/fs/eulerfs/super.c b/fs/eulerfs/super.c index 43fc717002d7..eeec16d10baf 100644 --- a/fs/eulerfs/super.c +++ b/fs/eulerfs/super.c @@ -370,7 +370,7 @@ static struct eufs_inode *eufs_init(struct super_block *sb, unsigned long size)
eufs_iwrite_dict(root_i, p2o(sb, dict)); eufs_iwrite_size(root_i, 0); - + eufs_iwrite_xattr(root_i, 0); root_i->i_fresh = 2; eufs_flush_cacheline(root_i); eufs_flush_cacheline(&root_i->i_fresh); @@ -664,6 +664,9 @@ static struct inode *eufs_alloc_inode(struct super_block *sb) spin_lock_init(&vi->i_dentry_persist_lock); mutex_init(&vi->i_leaf_lock);
+ vi->i_xattr = 0; + init_rwsem(&vi->xattr_rwsem); + return &vi->vfs_inode; }