Skip to content

Commit a41f1a4

Browse files
jeffmahoneytorvalds
authored andcommitted
reiserfs: use generic readdir for operations across all xattrs
The current reiserfs xattr implementation open codes reiserfs_readdir and frees the path before calling the filldir function. Typically, the filldir function is something that modifies the file system, such as a chown or an inode deletion that also require reading of an inode associated with each direntry. Since the file system is modified, the path retained becomes invalid for the next run. In addition, it runs backwards in attempt to minimize activity. This is clearly suboptimal from a code cleanliness perspective as well as performance-wise. This patch implements a generic reiserfs_for_each_xattr that uses the generic readdir and a specific filldir routine that simply populates an array of dentries and then performs a specific operation on them. When all files have been operated on, it then calls the operation on the directory itself. The result is a noticable code reduction and better performance. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0ab2621 commit a41f1a4

3 files changed

Lines changed: 131 additions & 300 deletions

File tree

‎fs/reiserfs/dir.c‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry,
4141

4242
#define store_ih(where,what) copy_item_head (where, what)
4343

44-
//
45-
static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
44+
int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
45+
filldir_t filldir, loff_t *pos)
4646
{
47-
struct inode *inode = filp->f_path.dentry->d_inode;
47+
struct inode *inode = dentry->d_inode;
4848
struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
4949
INITIALIZE_PATH(path_to_entry);
5050
struct buffer_head *bh;
@@ -64,13 +64,9 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
6464

6565
/* form key for search the next directory entry using f_pos field of
6666
file structure */
67-
make_cpu_key(&pos_key, inode,
68-
(filp->f_pos) ? (filp->f_pos) : DOT_OFFSET, TYPE_DIRENTRY,
69-
3);
67+
make_cpu_key(&pos_key, inode, *pos ?: DOT_OFFSET, TYPE_DIRENTRY, 3);
7068
next_pos = cpu_key_k_offset(&pos_key);
7169

72-
/* reiserfs_warning (inode->i_sb, "reiserfs_readdir 1: f_pos = %Ld", filp->f_pos); */
73-
7470
path_to_entry.reada = PATH_READA;
7571
while (1) {
7672
research:
@@ -144,7 +140,7 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
144140
/* Ignore the .reiserfs_priv entry */
145141
if (reiserfs_xattrs(inode->i_sb) &&
146142
!old_format_only(inode->i_sb) &&
147-
filp->f_path.dentry == inode->i_sb->s_root &&
143+
dentry == inode->i_sb->s_root &&
148144
REISERFS_SB(inode->i_sb)->priv_root &&
149145
REISERFS_SB(inode->i_sb)->priv_root->d_inode
150146
&& deh_objectid(deh) ==
@@ -156,7 +152,7 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
156152
}
157153

158154
d_off = deh_offset(deh);
159-
filp->f_pos = d_off;
155+
*pos = d_off;
160156
d_ino = deh_objectid(deh);
161157
if (d_reclen <= 32) {
162158
local_buf = small_buf;
@@ -223,15 +219,21 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
223219

224220
} /* while */
225221

226-
end:
227-
filp->f_pos = next_pos;
222+
end:
223+
*pos = next_pos;
228224
pathrelse(&path_to_entry);
229225
reiserfs_check_path(&path_to_entry);
230-
out:
226+
out:
231227
reiserfs_write_unlock(inode->i_sb);
232228
return ret;
233229
}
234230

231+
static int reiserfs_readdir(struct file *file, void *dirent, filldir_t filldir)
232+
{
233+
struct dentry *dentry = file->f_path.dentry;
234+
return reiserfs_readdir_dentry(dentry, dirent, filldir, &file->f_pos);
235+
}
236+
235237
/* compose directory item containing "." and ".." entries (entries are
236238
not aligned to 4 byte boundary) */
237239
/* the last four params are LE */

0 commit comments

Comments
 (0)