@@ -29,13 +29,18 @@ static const char *erofs_xattr_prefix(unsigned int idx, struct dentry *dentry);
2929
3030static int erofs_init_inode_xattrs (struct inode * inode )
3131{
32- struct erofs_inode * const vi = EROFS_I (inode );
33- struct erofs_xattr_iter it ;
34- unsigned int i ;
35- struct erofs_xattr_ibody_header * ih ;
32+ struct erofs_buf buf = __EROFS_BUF_INITIALIZER ;
33+ struct erofs_inode * vi = EROFS_I (inode );
3634 struct super_block * sb = inode -> i_sb ;
35+ const struct erofs_xattr_ibody_header * ih ;
36+ __le32 * xattr_id ;
37+ erofs_off_t pos ;
38+ unsigned int i ;
3739 int ret = 0 ;
3840
41+ if (!vi -> xattr_isize )
42+ return - ENODATA ;
43+
3944 /* the most case is that xattrs of this inode are initialized. */
4045 if (test_bit (EROFS_I_EA_INITED_BIT , & vi -> flags )) {
4146 /*
@@ -45,7 +50,6 @@ static int erofs_init_inode_xattrs(struct inode *inode)
4550 smp_mb ();
4651 return 0 ;
4752 }
48-
4953 if (wait_on_bit_lock (& vi -> flags , EROFS_I_BL_XATTR_BIT , TASK_KILLABLE ))
5054 return - ERESTARTSYS ;
5155
@@ -62,66 +66,50 @@ static int erofs_init_inode_xattrs(struct inode *inode)
6266 * undefined right now (maybe use later with some new sb feature).
6367 */
6468 if (vi -> xattr_isize == sizeof (struct erofs_xattr_ibody_header )) {
65- erofs_err (sb ,
66- "xattr_isize %d of nid %llu is not supported yet" ,
69+ erofs_err (sb , "xattr_isize %d of nid %llu is not supported yet" ,
6770 vi -> xattr_isize , vi -> nid );
6871 ret = - EOPNOTSUPP ;
6972 goto out_unlock ;
7073 } else if (vi -> xattr_isize < sizeof (struct erofs_xattr_ibody_header )) {
71- if (vi -> xattr_isize ) {
72- erofs_err (sb , "bogus xattr ibody @ nid %llu" , vi -> nid );
73- DBG_BUGON (1 );
74- ret = - EFSCORRUPTED ;
75- goto out_unlock ; /* xattr ondisk layout error */
76- }
77- ret = - ENODATA ;
74+ erofs_err (sb , "bogus xattr ibody @ nid %llu" , vi -> nid );
75+ DBG_BUGON (1 );
76+ ret = - EFSCORRUPTED ;
7877 goto out_unlock ;
7978 }
8079
81- it .buf = __EROFS_BUF_INITIALIZER ;
82- ret = erofs_init_metabuf (& it .buf , sb , erofs_inode_in_metabox (inode ));
83- if (ret )
84- goto out_unlock ;
85- it .pos = erofs_iloc (inode ) + vi -> inode_isize ;
86-
87- /* read in shared xattr array (non-atomic, see kmalloc below) */
88- it .kaddr = erofs_bread (& it .buf , it .pos , true);
89- if (IS_ERR (it .kaddr )) {
90- ret = PTR_ERR (it .kaddr );
80+ pos = erofs_iloc (inode ) + vi -> inode_isize ;
81+ ih = erofs_read_metabuf (& buf , sb , pos , erofs_inode_in_metabox (inode ));
82+ if (IS_ERR (ih )) {
83+ ret = PTR_ERR (ih );
9184 goto out_unlock ;
9285 }
93-
94- ih = it .kaddr ;
9586 vi -> xattr_name_filter = le32_to_cpu (ih -> h_name_filter );
9687 vi -> xattr_shared_count = ih -> h_shared_count ;
9788 vi -> xattr_shared_xattrs = kmalloc_array (vi -> xattr_shared_count ,
9889 sizeof (uint ), GFP_KERNEL );
9990 if (!vi -> xattr_shared_xattrs ) {
100- erofs_put_metabuf (& it . buf );
91+ erofs_put_metabuf (& buf );
10192 ret = - ENOMEM ;
10293 goto out_unlock ;
10394 }
10495
105- /* let's skip ibody header */
106- it .pos += sizeof (struct erofs_xattr_ibody_header );
107-
96+ /* skip the ibody header and read the shared xattr array */
97+ pos += sizeof (struct erofs_xattr_ibody_header );
10898 for (i = 0 ; i < vi -> xattr_shared_count ; ++ i ) {
109- it . kaddr = erofs_bread (& it . buf , it . pos , true);
110- if (IS_ERR (it . kaddr )) {
99+ xattr_id = erofs_bread (& buf , pos + i * sizeof ( __le32 ) , true);
100+ if (IS_ERR (xattr_id )) {
111101 kfree (vi -> xattr_shared_xattrs );
112102 vi -> xattr_shared_xattrs = NULL ;
113- ret = PTR_ERR (it . kaddr );
103+ ret = PTR_ERR (xattr_id );
114104 goto out_unlock ;
115105 }
116- vi -> xattr_shared_xattrs [i ] = le32_to_cpu (* (__le32 * )it .kaddr );
117- it .pos += sizeof (__le32 );
106+ vi -> xattr_shared_xattrs [i ] = le32_to_cpu (* xattr_id );
118107 }
119- erofs_put_metabuf (& it . buf );
108+ erofs_put_metabuf (& buf );
120109
121110 /* paired with smp_mb() at the beginning of the function. */
122111 smp_mb ();
123112 set_bit (EROFS_I_EA_INITED_BIT , & vi -> flags );
124-
125113out_unlock :
126114 clear_and_wake_up_bit (EROFS_I_BL_XATTR_BIT , & vi -> flags );
127115 return ret ;
0 commit comments