Skip to content

Commit 9717a91

Browse files
author
Al Viro
committed
hfs: switch to ->iterate_shared()
exact parallel of hfsplus analogue Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 323ee8f commit 9717a91

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎fs/hfs/catalog.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,13 @@ int hfs_cat_delete(u32 cnid, struct inode *dir, struct qstr *str)
240240
}
241241
}
242242

243+
/* we only need to take spinlock for exclusion with ->release() */
244+
spin_lock(&HFS_I(dir)->open_dir_lock);
243245
list_for_each_entry(rd, &HFS_I(dir)->open_dir_list, list) {
244246
if (fd.tree->keycmp(fd.search_key, (void *)&rd->key) < 0)
245247
rd->file->f_pos--;
246248
}
249+
spin_unlock(&HFS_I(dir)->open_dir_lock);
247250

248251
res = hfs_brec_remove(&fd);
249252
if (res)

‎fs/hfs/dir.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,14 @@ static int hfs_readdir(struct file *file, struct dir_context *ctx)
161161
}
162162
file->private_data = rd;
163163
rd->file = file;
164+
spin_lock(&HFS_I(inode)->open_dir_lock);
164165
list_add(&rd->list, &HFS_I(inode)->open_dir_list);
166+
spin_unlock(&HFS_I(inode)->open_dir_lock);
165167
}
168+
/*
169+
* Can be done after the list insertion; exclusion with
170+
* hfs_delete_cat() is provided by directory lock.
171+
*/
166172
memcpy(&rd->key, &fd.key, sizeof(struct hfs_cat_key));
167173
out:
168174
hfs_find_exit(&fd);
@@ -173,9 +179,9 @@ static int hfs_dir_release(struct inode *inode, struct file *file)
173179
{
174180
struct hfs_readdir_data *rd = file->private_data;
175181
if (rd) {
176-
inode_lock(inode);
182+
spin_lock(&HFS_I(inode)->open_dir_lock);
177183
list_del(&rd->list);
178-
inode_unlock(inode);
184+
spin_unlock(&HFS_I(inode)->open_dir_lock);
179185
kfree(rd);
180186
}
181187
return 0;
@@ -303,7 +309,7 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry,
303309

304310
const struct file_operations hfs_dir_operations = {
305311
.read = generic_read_dir,
306-
.iterate = hfs_readdir,
312+
.iterate_shared = hfs_readdir,
307313
.llseek = generic_file_llseek,
308314
.release = hfs_dir_release,
309315
};

‎fs/hfs/hfs_fs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct hfs_inode_info {
6969
struct hfs_cat_key cat_key;
7070

7171
struct list_head open_dir_list;
72+
spinlock_t open_dir_lock;
7273
struct inode *rsrc_inode;
7374

7475
struct mutex extents_lock;

‎fs/hfs/inode.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ struct inode *hfs_new_inode(struct inode *dir, struct qstr *name, umode_t mode)
187187

188188
mutex_init(&HFS_I(inode)->extents_lock);
189189
INIT_LIST_HEAD(&HFS_I(inode)->open_dir_list);
190+
spin_lock_init(&HFS_I(inode)->open_dir_lock);
190191
hfs_cat_build_key(sb, (btree_key *)&HFS_I(inode)->cat_key, dir->i_ino, name);
191192
inode->i_ino = HFS_SB(sb)->next_id++;
192193
inode->i_mode = mode;
@@ -318,6 +319,7 @@ static int hfs_read_inode(struct inode *inode, void *data)
318319
HFS_I(inode)->rsrc_inode = NULL;
319320
mutex_init(&HFS_I(inode)->extents_lock);
320321
INIT_LIST_HEAD(&HFS_I(inode)->open_dir_list);
322+
spin_lock_init(&HFS_I(inode)->open_dir_lock);
321323

322324
/* Initialize the inode */
323325
inode->i_uid = hsb->s_uid;

0 commit comments

Comments
 (0)