Skip to content

Commit ced2207

Browse files
committed
[JFFS2] semaphore->mutex conversion
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
1 parent 52f8301 commit ced2207

14 files changed

Lines changed: 168 additions & 167 deletions

File tree

‎fs/jffs2/README.Locking‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ be fairly close.
1414
alloc_sem
1515
---------
1616

17-
The alloc_sem is a per-filesystem semaphore, used primarily to ensure
17+
The alloc_sem is a per-filesystem mutex, used primarily to ensure
1818
contiguous allocation of space on the medium. It is automatically
1919
obtained during space allocations (jffs2_reserve_space()) and freed
2020
upon write completion (jffs2_complete_reservation()). Note that
@@ -41,10 +41,10 @@ if the wbuf is currently holding any data is permitted, though.
4141
Ordering constraints: See f->sem.
4242

4343

44-
File Semaphore f->sem
44+
File Mutex f->sem
4545
---------------------
4646

47-
This is the JFFS2-internal equivalent of the inode semaphore i->i_sem.
47+
This is the JFFS2-internal equivalent of the inode mutex i->i_sem.
4848
It protects the contents of the jffs2_inode_info private inode data,
4949
including the linked list of node fragments (but see the notes below on
5050
erase_completion_lock), etc.
@@ -60,14 +60,14 @@ lead to deadlock, unless we played games with unlocking the i_sem
6060
before calling the space allocation functions.
6161

6262
Instead of playing such games, we just have an extra internal
63-
semaphore, which is obtained by the garbage collection code and also
63+
mutex, which is obtained by the garbage collection code and also
6464
by the normal file system code _after_ allocation of space.
6565

6666
Ordering constraints:
6767

6868
1. Never attempt to allocate space or lock alloc_sem with
6969
any f->sem held.
70-
2. Never attempt to lock two file semaphores in one thread.
70+
2. Never attempt to lock two file mutexes in one thread.
7171
No ordering rules have been made for doing so.
7272

7373

@@ -86,8 +86,8 @@ a simple spin_lock() rather than spin_lock_bh().
8686

8787
Note that the per-inode list of physical nodes (f->nodes) is a special
8888
case. Any changes to _valid_ nodes (i.e. ->flash_offset & 1 == 0) in
89-
the list are protected by the file semaphore f->sem. But the erase
90-
code may remove _obsolete_ nodes from the list while holding only the
89+
the list are protected by the file mutex f->sem. But the erase code
90+
may remove _obsolete_ nodes from the list while holding only the
9191
erase_completion_lock. So you can walk the list only while holding the
9292
erase_completion_lock, and can drop the lock temporarily mid-walk as
9393
long as the pointer you're holding is to a _valid_ node, not an
@@ -124,10 +124,10 @@ Ordering constraints:
124124
erase_free_sem
125125
--------------
126126

127-
This semaphore is only used by the erase code which frees obsolete
128-
node references and the jffs2_garbage_collect_deletion_dirent()
129-
function. The latter function on NAND flash must read _obsolete_ nodes
130-
to determine whether the 'deletion dirent' under consideration can be
127+
This mutex is only used by the erase code which frees obsolete node
128+
references and the jffs2_garbage_collect_deletion_dirent() function.
129+
The latter function on NAND flash must read _obsolete_ nodes to
130+
determine whether the 'deletion dirent' under consideration can be
131131
discarded or whether it is still required to show that an inode has
132132
been unlinked. Because reading from the flash may sleep, the
133133
erase_completion_lock cannot be held, so an alternative, more

‎fs/jffs2/debug.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
6262
void
6363
__jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
6464
{
65-
down(&f->sem);
65+
mutex_lock(&f->sem);
6666
__jffs2_dbg_fragtree_paranoia_check_nolock(f);
67-
up(&f->sem);
67+
mutex_unlock(&f->sem);
6868
}
6969

7070
void
@@ -532,9 +532,9 @@ __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
532532
void
533533
__jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f)
534534
{
535-
down(&f->sem);
535+
mutex_lock(&f->sem);
536536
jffs2_dbg_dump_fragtree_nolock(f);
537-
up(&f->sem);
537+
mutex_unlock(&f->sem);
538538
}
539539

540540
void

‎fs/jffs2/dir.c‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
8686
dir_f = JFFS2_INODE_INFO(dir_i);
8787
c = JFFS2_SB_INFO(dir_i->i_sb);
8888

89-
down(&dir_f->sem);
89+
mutex_lock(&dir_f->sem);
9090

9191
/* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */
9292
for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) {
@@ -99,7 +99,7 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
9999
}
100100
if (fd)
101101
ino = fd->ino;
102-
up(&dir_f->sem);
102+
mutex_unlock(&dir_f->sem);
103103
if (ino) {
104104
inode = jffs2_iget(dir_i->i_sb, ino);
105105
if (IS_ERR(inode)) {
@@ -146,7 +146,7 @@ static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
146146
}
147147

148148
curofs=1;
149-
down(&f->sem);
149+
mutex_lock(&f->sem);
150150
for (fd = f->dents; fd; fd = fd->next) {
151151

152152
curofs++;
@@ -166,7 +166,7 @@ static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
166166
break;
167167
offset++;
168168
}
169-
up(&f->sem);
169+
mutex_unlock(&f->sem);
170170
out:
171171
filp->f_pos = offset;
172172
return 0;
@@ -275,9 +275,9 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
275275
ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now);
276276

277277
if (!ret) {
278-
down(&f->sem);
278+
mutex_lock(&f->sem);
279279
old_dentry->d_inode->i_nlink = ++f->inocache->nlink;
280-
up(&f->sem);
280+
mutex_unlock(&f->sem);
281281
d_instantiate(dentry, old_dentry->d_inode);
282282
dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
283283
atomic_inc(&old_dentry->d_inode->i_count);
@@ -351,7 +351,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
351351

352352
if (IS_ERR(fn)) {
353353
/* Eeek. Wave bye bye */
354-
up(&f->sem);
354+
mutex_unlock(&f->sem);
355355
jffs2_complete_reservation(c);
356356
jffs2_clear_inode(inode);
357357
return PTR_ERR(fn);
@@ -361,7 +361,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
361361
f->target = kmalloc(targetlen + 1, GFP_KERNEL);
362362
if (!f->target) {
363363
printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1);
364-
up(&f->sem);
364+
mutex_unlock(&f->sem);
365365
jffs2_complete_reservation(c);
366366
jffs2_clear_inode(inode);
367367
return -ENOMEM;
@@ -374,7 +374,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
374374
obsoleted by the first data write
375375
*/
376376
f->metadata = fn;
377-
up(&f->sem);
377+
mutex_unlock(&f->sem);
378378

379379
jffs2_complete_reservation(c);
380380

@@ -406,7 +406,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
406406
}
407407

408408
dir_f = JFFS2_INODE_INFO(dir_i);
409-
down(&dir_f->sem);
409+
mutex_lock(&dir_f->sem);
410410

411411
rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
412412
rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
@@ -429,7 +429,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
429429
as if it were the final unlink() */
430430
jffs2_complete_reservation(c);
431431
jffs2_free_raw_dirent(rd);
432-
up(&dir_f->sem);
432+
mutex_unlock(&dir_f->sem);
433433
jffs2_clear_inode(inode);
434434
return PTR_ERR(fd);
435435
}
@@ -442,7 +442,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
442442
one if necessary. */
443443
jffs2_add_fd_to_list(c, fd, &dir_f->dents);
444444

445-
up(&dir_f->sem);
445+
mutex_unlock(&dir_f->sem);
446446
jffs2_complete_reservation(c);
447447

448448
d_instantiate(dentry, inode);
@@ -507,7 +507,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
507507

508508
if (IS_ERR(fn)) {
509509
/* Eeek. Wave bye bye */
510-
up(&f->sem);
510+
mutex_unlock(&f->sem);
511511
jffs2_complete_reservation(c);
512512
jffs2_clear_inode(inode);
513513
return PTR_ERR(fn);
@@ -516,7 +516,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
516516
obsoleted by the first data write
517517
*/
518518
f->metadata = fn;
519-
up(&f->sem);
519+
mutex_unlock(&f->sem);
520520

521521
jffs2_complete_reservation(c);
522522

@@ -548,7 +548,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
548548
}
549549

550550
dir_f = JFFS2_INODE_INFO(dir_i);
551-
down(&dir_f->sem);
551+
mutex_lock(&dir_f->sem);
552552

553553
rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
554554
rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
@@ -571,7 +571,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
571571
as if it were the final unlink() */
572572
jffs2_complete_reservation(c);
573573
jffs2_free_raw_dirent(rd);
574-
up(&dir_f->sem);
574+
mutex_unlock(&dir_f->sem);
575575
jffs2_clear_inode(inode);
576576
return PTR_ERR(fd);
577577
}
@@ -585,7 +585,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
585585
one if necessary. */
586586
jffs2_add_fd_to_list(c, fd, &dir_f->dents);
587587

588-
up(&dir_f->sem);
588+
mutex_unlock(&dir_f->sem);
589589
jffs2_complete_reservation(c);
590590

591591
d_instantiate(dentry, inode);
@@ -673,7 +673,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
673673

674674
if (IS_ERR(fn)) {
675675
/* Eeek. Wave bye bye */
676-
up(&f->sem);
676+
mutex_unlock(&f->sem);
677677
jffs2_complete_reservation(c);
678678
jffs2_clear_inode(inode);
679679
return PTR_ERR(fn);
@@ -682,7 +682,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
682682
obsoleted by the first data write
683683
*/
684684
f->metadata = fn;
685-
up(&f->sem);
685+
mutex_unlock(&f->sem);
686686

687687
jffs2_complete_reservation(c);
688688

@@ -714,7 +714,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
714714
}
715715

716716
dir_f = JFFS2_INODE_INFO(dir_i);
717-
down(&dir_f->sem);
717+
mutex_lock(&dir_f->sem);
718718

719719
rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
720720
rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
@@ -740,7 +740,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
740740
as if it were the final unlink() */
741741
jffs2_complete_reservation(c);
742742
jffs2_free_raw_dirent(rd);
743-
up(&dir_f->sem);
743+
mutex_unlock(&dir_f->sem);
744744
jffs2_clear_inode(inode);
745745
return PTR_ERR(fd);
746746
}
@@ -753,7 +753,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
753753
one if necessary. */
754754
jffs2_add_fd_to_list(c, fd, &dir_f->dents);
755755

756-
up(&dir_f->sem);
756+
mutex_unlock(&dir_f->sem);
757757
jffs2_complete_reservation(c);
758758

759759
d_instantiate(dentry, inode);
@@ -780,14 +780,14 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
780780
if (S_ISDIR(new_dentry->d_inode->i_mode)) {
781781
struct jffs2_full_dirent *fd;
782782

783-
down(&victim_f->sem);
783+
mutex_lock(&victim_f->sem);
784784
for (fd = victim_f->dents; fd; fd = fd->next) {
785785
if (fd->ino) {
786-
up(&victim_f->sem);
786+
mutex_unlock(&victim_f->sem);
787787
return -ENOTEMPTY;
788788
}
789789
}
790-
up(&victim_f->sem);
790+
mutex_unlock(&victim_f->sem);
791791
}
792792
}
793793

@@ -816,9 +816,9 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
816816
/* Don't oops if the victim was a dirent pointing to an
817817
inode which didn't exist. */
818818
if (victim_f->inocache) {
819-
down(&victim_f->sem);
819+
mutex_lock(&victim_f->sem);
820820
victim_f->inocache->nlink--;
821-
up(&victim_f->sem);
821+
mutex_unlock(&victim_f->sem);
822822
}
823823
}
824824

@@ -836,11 +836,11 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
836836
if (ret) {
837837
/* Oh shit. We really ought to make a single node which can do both atomically */
838838
struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode);
839-
down(&f->sem);
839+
mutex_lock(&f->sem);
840840
inc_nlink(old_dentry->d_inode);
841841
if (f->inocache)
842842
f->inocache->nlink++;
843-
up(&f->sem);
843+
mutex_unlock(&f->sem);
844844

845845
printk(KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n", ret);
846846
/* Might as well let the VFS know */

0 commit comments

Comments
 (0)