Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[JFFS2] semaphore->mutex conversion

Signed-off-by: David Woodhouse <dwmw2@infradead.org>

+168 -167
+11 -11
fs/jffs2/README.Locking
··· 14 14 alloc_sem 15 15 --------- 16 16 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 18 18 contiguous allocation of space on the medium. It is automatically 19 19 obtained during space allocations (jffs2_reserve_space()) and freed 20 20 upon write completion (jffs2_complete_reservation()). Note that ··· 41 41 Ordering constraints: See f->sem. 42 42 43 43 44 - File Semaphore f->sem 44 + File Mutex f->sem 45 45 --------------------- 46 46 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. 48 48 It protects the contents of the jffs2_inode_info private inode data, 49 49 including the linked list of node fragments (but see the notes below on 50 50 erase_completion_lock), etc. ··· 60 60 before calling the space allocation functions. 61 61 62 62 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 64 64 by the normal file system code _after_ allocation of space. 65 65 66 66 Ordering constraints: 67 67 68 68 1. Never attempt to allocate space or lock alloc_sem with 69 69 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. 71 71 No ordering rules have been made for doing so. 72 72 73 73 ··· 86 86 87 87 Note that the per-inode list of physical nodes (f->nodes) is a special 88 88 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 91 91 erase_completion_lock. So you can walk the list only while holding the 92 92 erase_completion_lock, and can drop the lock temporarily mid-walk as 93 93 long as the pointer you're holding is to a _valid_ node, not an ··· 124 124 erase_free_sem 125 125 -------------- 126 126 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 131 131 discarded or whether it is still required to show that an inode has 132 132 been unlinked. Because reading from the flash may sleep, the 133 133 erase_completion_lock cannot be held, so an alternative, more
+4 -4
fs/jffs2/debug.c
··· 62 62 void 63 63 __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f) 64 64 { 65 - down(&f->sem); 65 + mutex_lock(&f->sem); 66 66 __jffs2_dbg_fragtree_paranoia_check_nolock(f); 67 - up(&f->sem); 67 + mutex_unlock(&f->sem); 68 68 } 69 69 70 70 void ··· 532 532 void 533 533 __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f) 534 534 { 535 - down(&f->sem); 535 + mutex_lock(&f->sem); 536 536 jffs2_dbg_dump_fragtree_nolock(f); 537 - up(&f->sem); 537 + mutex_unlock(&f->sem); 538 538 } 539 539 540 540 void
+29 -29
fs/jffs2/dir.c
··· 86 86 dir_f = JFFS2_INODE_INFO(dir_i); 87 87 c = JFFS2_SB_INFO(dir_i->i_sb); 88 88 89 - down(&dir_f->sem); 89 + mutex_lock(&dir_f->sem); 90 90 91 91 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */ 92 92 for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) { ··· 99 99 } 100 100 if (fd) 101 101 ino = fd->ino; 102 - up(&dir_f->sem); 102 + mutex_unlock(&dir_f->sem); 103 103 if (ino) { 104 104 inode = jffs2_iget(dir_i->i_sb, ino); 105 105 if (IS_ERR(inode)) { ··· 146 146 } 147 147 148 148 curofs=1; 149 - down(&f->sem); 149 + mutex_lock(&f->sem); 150 150 for (fd = f->dents; fd; fd = fd->next) { 151 151 152 152 curofs++; ··· 166 166 break; 167 167 offset++; 168 168 } 169 - up(&f->sem); 169 + mutex_unlock(&f->sem); 170 170 out: 171 171 filp->f_pos = offset; 172 172 return 0; ··· 275 275 ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now); 276 276 277 277 if (!ret) { 278 - down(&f->sem); 278 + mutex_lock(&f->sem); 279 279 old_dentry->d_inode->i_nlink = ++f->inocache->nlink; 280 - up(&f->sem); 280 + mutex_unlock(&f->sem); 281 281 d_instantiate(dentry, old_dentry->d_inode); 282 282 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 283 283 atomic_inc(&old_dentry->d_inode->i_count); ··· 351 351 352 352 if (IS_ERR(fn)) { 353 353 /* Eeek. Wave bye bye */ 354 - up(&f->sem); 354 + mutex_unlock(&f->sem); 355 355 jffs2_complete_reservation(c); 356 356 jffs2_clear_inode(inode); 357 357 return PTR_ERR(fn); ··· 361 361 f->target = kmalloc(targetlen + 1, GFP_KERNEL); 362 362 if (!f->target) { 363 363 printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1); 364 - up(&f->sem); 364 + mutex_unlock(&f->sem); 365 365 jffs2_complete_reservation(c); 366 366 jffs2_clear_inode(inode); 367 367 return -ENOMEM; ··· 374 374 obsoleted by the first data write 375 375 */ 376 376 f->metadata = fn; 377 - up(&f->sem); 377 + mutex_unlock(&f->sem); 378 378 379 379 jffs2_complete_reservation(c); 380 380 ··· 406 406 } 407 407 408 408 dir_f = JFFS2_INODE_INFO(dir_i); 409 - down(&dir_f->sem); 409 + mutex_lock(&dir_f->sem); 410 410 411 411 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 412 412 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); ··· 429 429 as if it were the final unlink() */ 430 430 jffs2_complete_reservation(c); 431 431 jffs2_free_raw_dirent(rd); 432 - up(&dir_f->sem); 432 + mutex_unlock(&dir_f->sem); 433 433 jffs2_clear_inode(inode); 434 434 return PTR_ERR(fd); 435 435 } ··· 442 442 one if necessary. */ 443 443 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 444 444 445 - up(&dir_f->sem); 445 + mutex_unlock(&dir_f->sem); 446 446 jffs2_complete_reservation(c); 447 447 448 448 d_instantiate(dentry, inode); ··· 507 507 508 508 if (IS_ERR(fn)) { 509 509 /* Eeek. Wave bye bye */ 510 - up(&f->sem); 510 + mutex_unlock(&f->sem); 511 511 jffs2_complete_reservation(c); 512 512 jffs2_clear_inode(inode); 513 513 return PTR_ERR(fn); ··· 516 516 obsoleted by the first data write 517 517 */ 518 518 f->metadata = fn; 519 - up(&f->sem); 519 + mutex_unlock(&f->sem); 520 520 521 521 jffs2_complete_reservation(c); 522 522 ··· 548 548 } 549 549 550 550 dir_f = JFFS2_INODE_INFO(dir_i); 551 - down(&dir_f->sem); 551 + mutex_lock(&dir_f->sem); 552 552 553 553 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 554 554 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); ··· 571 571 as if it were the final unlink() */ 572 572 jffs2_complete_reservation(c); 573 573 jffs2_free_raw_dirent(rd); 574 - up(&dir_f->sem); 574 + mutex_unlock(&dir_f->sem); 575 575 jffs2_clear_inode(inode); 576 576 return PTR_ERR(fd); 577 577 } ··· 585 585 one if necessary. */ 586 586 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 587 587 588 - up(&dir_f->sem); 588 + mutex_unlock(&dir_f->sem); 589 589 jffs2_complete_reservation(c); 590 590 591 591 d_instantiate(dentry, inode); ··· 673 673 674 674 if (IS_ERR(fn)) { 675 675 /* Eeek. Wave bye bye */ 676 - up(&f->sem); 676 + mutex_unlock(&f->sem); 677 677 jffs2_complete_reservation(c); 678 678 jffs2_clear_inode(inode); 679 679 return PTR_ERR(fn); ··· 682 682 obsoleted by the first data write 683 683 */ 684 684 f->metadata = fn; 685 - up(&f->sem); 685 + mutex_unlock(&f->sem); 686 686 687 687 jffs2_complete_reservation(c); 688 688 ··· 714 714 } 715 715 716 716 dir_f = JFFS2_INODE_INFO(dir_i); 717 - down(&dir_f->sem); 717 + mutex_lock(&dir_f->sem); 718 718 719 719 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 720 720 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); ··· 740 740 as if it were the final unlink() */ 741 741 jffs2_complete_reservation(c); 742 742 jffs2_free_raw_dirent(rd); 743 - up(&dir_f->sem); 743 + mutex_unlock(&dir_f->sem); 744 744 jffs2_clear_inode(inode); 745 745 return PTR_ERR(fd); 746 746 } ··· 753 753 one if necessary. */ 754 754 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 755 755 756 - up(&dir_f->sem); 756 + mutex_unlock(&dir_f->sem); 757 757 jffs2_complete_reservation(c); 758 758 759 759 d_instantiate(dentry, inode); ··· 780 780 if (S_ISDIR(new_dentry->d_inode->i_mode)) { 781 781 struct jffs2_full_dirent *fd; 782 782 783 - down(&victim_f->sem); 783 + mutex_lock(&victim_f->sem); 784 784 for (fd = victim_f->dents; fd; fd = fd->next) { 785 785 if (fd->ino) { 786 - up(&victim_f->sem); 786 + mutex_unlock(&victim_f->sem); 787 787 return -ENOTEMPTY; 788 788 } 789 789 } 790 - up(&victim_f->sem); 790 + mutex_unlock(&victim_f->sem); 791 791 } 792 792 } 793 793 ··· 816 816 /* Don't oops if the victim was a dirent pointing to an 817 817 inode which didn't exist. */ 818 818 if (victim_f->inocache) { 819 - down(&victim_f->sem); 819 + mutex_lock(&victim_f->sem); 820 820 victim_f->inocache->nlink--; 821 - up(&victim_f->sem); 821 + mutex_unlock(&victim_f->sem); 822 822 } 823 823 } 824 824 ··· 836 836 if (ret) { 837 837 /* Oh shit. We really ought to make a single node which can do both atomically */ 838 838 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode); 839 - down(&f->sem); 839 + mutex_lock(&f->sem); 840 840 inc_nlink(old_dentry->d_inode); 841 841 if (f->inocache) 842 842 f->inocache->nlink++; 843 - up(&f->sem); 843 + mutex_unlock(&f->sem); 844 844 845 845 printk(KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n", ret); 846 846 /* Might as well let the VFS know */
+21 -21
fs/jffs2/erase.c
··· 50 50 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL); 51 51 if (!instr) { 52 52 printk(KERN_WARNING "kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n"); 53 - down(&c->erase_free_sem); 53 + mutex_lock(&c->erase_free_sem); 54 54 spin_lock(&c->erase_completion_lock); 55 55 list_move(&jeb->list, &c->erase_pending_list); 56 56 c->erasing_size -= c->sector_size; 57 57 c->dirty_size += c->sector_size; 58 58 jeb->dirty_size = c->sector_size; 59 59 spin_unlock(&c->erase_completion_lock); 60 - up(&c->erase_free_sem); 60 + mutex_unlock(&c->erase_free_sem); 61 61 return; 62 62 } 63 63 ··· 84 84 if (ret == -ENOMEM || ret == -EAGAIN) { 85 85 /* Erase failed immediately. Refile it on the list */ 86 86 D1(printk(KERN_DEBUG "Erase at 0x%08x failed: %d. Refiling on erase_pending_list\n", jeb->offset, ret)); 87 - down(&c->erase_free_sem); 87 + mutex_lock(&c->erase_free_sem); 88 88 spin_lock(&c->erase_completion_lock); 89 89 list_move(&jeb->list, &c->erase_pending_list); 90 90 c->erasing_size -= c->sector_size; 91 91 c->dirty_size += c->sector_size; 92 92 jeb->dirty_size = c->sector_size; 93 93 spin_unlock(&c->erase_completion_lock); 94 - up(&c->erase_free_sem); 94 + mutex_unlock(&c->erase_free_sem); 95 95 return; 96 96 } 97 97 ··· 107 107 { 108 108 struct jffs2_eraseblock *jeb; 109 109 110 - down(&c->erase_free_sem); 110 + mutex_lock(&c->erase_free_sem); 111 111 112 112 spin_lock(&c->erase_completion_lock); 113 113 ··· 118 118 jeb = list_entry(c->erase_complete_list.next, struct jffs2_eraseblock, list); 119 119 list_del(&jeb->list); 120 120 spin_unlock(&c->erase_completion_lock); 121 - up(&c->erase_free_sem); 121 + mutex_unlock(&c->erase_free_sem); 122 122 jffs2_mark_erased_block(c, jeb); 123 123 124 124 if (!--count) { ··· 139 139 jffs2_free_jeb_node_refs(c, jeb); 140 140 list_add(&jeb->list, &c->erasing_list); 141 141 spin_unlock(&c->erase_completion_lock); 142 - up(&c->erase_free_sem); 142 + mutex_unlock(&c->erase_free_sem); 143 143 144 144 jffs2_erase_block(c, jeb); 145 145 ··· 149 149 150 150 /* Be nice */ 151 151 yield(); 152 - down(&c->erase_free_sem); 152 + mutex_lock(&c->erase_free_sem); 153 153 spin_lock(&c->erase_completion_lock); 154 154 } 155 155 156 156 spin_unlock(&c->erase_completion_lock); 157 - up(&c->erase_free_sem); 157 + mutex_unlock(&c->erase_free_sem); 158 158 done: 159 159 D1(printk(KERN_DEBUG "jffs2_erase_pending_blocks completed\n")); 160 160 } ··· 162 162 static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) 163 163 { 164 164 D1(printk(KERN_DEBUG "Erase completed successfully at 0x%08x\n", jeb->offset)); 165 - down(&c->erase_free_sem); 165 + mutex_lock(&c->erase_free_sem); 166 166 spin_lock(&c->erase_completion_lock); 167 167 list_move_tail(&jeb->list, &c->erase_complete_list); 168 168 spin_unlock(&c->erase_completion_lock); 169 - up(&c->erase_free_sem); 169 + mutex_unlock(&c->erase_free_sem); 170 170 /* Ensure that kupdated calls us again to mark them clean */ 171 171 jffs2_erase_pending_trigger(c); 172 172 } ··· 180 180 failed too many times. */ 181 181 if (!jffs2_write_nand_badblock(c, jeb, bad_offset)) { 182 182 /* We'd like to give this block another try. */ 183 - down(&c->erase_free_sem); 183 + mutex_lock(&c->erase_free_sem); 184 184 spin_lock(&c->erase_completion_lock); 185 185 list_move(&jeb->list, &c->erase_pending_list); 186 186 c->erasing_size -= c->sector_size; 187 187 c->dirty_size += c->sector_size; 188 188 jeb->dirty_size = c->sector_size; 189 189 spin_unlock(&c->erase_completion_lock); 190 - up(&c->erase_free_sem); 190 + mutex_unlock(&c->erase_free_sem); 191 191 return; 192 192 } 193 193 } 194 194 195 - down(&c->erase_free_sem); 195 + mutex_lock(&c->erase_free_sem); 196 196 spin_lock(&c->erase_completion_lock); 197 197 c->erasing_size -= c->sector_size; 198 198 c->bad_size += c->sector_size; 199 199 list_move(&jeb->list, &c->bad_list); 200 200 c->nr_erasing_blocks--; 201 201 spin_unlock(&c->erase_completion_lock); 202 - up(&c->erase_free_sem); 202 + mutex_unlock(&c->erase_free_sem); 203 203 wake_up(&c->erase_wait); 204 204 } 205 205 ··· 456 456 jffs2_link_node_ref(c, jeb, jeb->offset | REF_NORMAL, c->cleanmarker_size, NULL); 457 457 } 458 458 459 - down(&c->erase_free_sem); 459 + mutex_lock(&c->erase_free_sem); 460 460 spin_lock(&c->erase_completion_lock); 461 461 c->erasing_size -= c->sector_size; 462 462 c->free_size += jeb->free_size; ··· 469 469 c->nr_erasing_blocks--; 470 470 c->nr_free_blocks++; 471 471 spin_unlock(&c->erase_completion_lock); 472 - up(&c->erase_free_sem); 472 + mutex_unlock(&c->erase_free_sem); 473 473 wake_up(&c->erase_wait); 474 474 return; 475 475 476 476 filebad: 477 - down(&c->erase_free_sem); 477 + mutex_lock(&c->erase_free_sem); 478 478 spin_lock(&c->erase_completion_lock); 479 479 /* Stick it on a list (any list) so erase_failed can take it 480 480 right off again. Silly, but shouldn't happen often. */ 481 481 list_add(&jeb->list, &c->erasing_list); 482 482 spin_unlock(&c->erase_completion_lock); 483 - up(&c->erase_free_sem); 483 + mutex_unlock(&c->erase_free_sem); 484 484 jffs2_erase_failed(c, jeb, bad_offset); 485 485 return; 486 486 487 487 refile: 488 488 /* Stick it back on the list from whence it came and come back later */ 489 489 jffs2_erase_pending_trigger(c); 490 - down(&c->erase_free_sem); 490 + mutex_lock(&c->erase_free_sem); 491 491 spin_lock(&c->erase_completion_lock); 492 492 list_add(&jeb->list, &c->erase_complete_list); 493 493 spin_unlock(&c->erase_completion_lock); 494 - up(&c->erase_free_sem); 494 + mutex_unlock(&c->erase_free_sem); 495 495 return; 496 496 }
+8 -8
fs/jffs2/file.c
··· 115 115 struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host); 116 116 int ret; 117 117 118 - down(&f->sem); 118 + mutex_lock(&f->sem); 119 119 ret = jffs2_do_readpage_unlock(pg->mapping->host, pg); 120 - up(&f->sem); 120 + mutex_unlock(&f->sem); 121 121 return ret; 122 122 } 123 123 ··· 154 154 if (ret) 155 155 goto out_page; 156 156 157 - down(&f->sem); 157 + mutex_lock(&f->sem); 158 158 memset(&ri, 0, sizeof(ri)); 159 159 160 160 ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); ··· 181 181 if (IS_ERR(fn)) { 182 182 ret = PTR_ERR(fn); 183 183 jffs2_complete_reservation(c); 184 - up(&f->sem); 184 + mutex_unlock(&f->sem); 185 185 goto out_page; 186 186 } 187 187 ret = jffs2_add_full_dnode_to_inode(c, f, fn); ··· 195 195 jffs2_mark_node_obsolete(c, fn->raw); 196 196 jffs2_free_full_dnode(fn); 197 197 jffs2_complete_reservation(c); 198 - up(&f->sem); 198 + mutex_unlock(&f->sem); 199 199 goto out_page; 200 200 } 201 201 jffs2_complete_reservation(c); 202 202 inode->i_size = pageofs; 203 - up(&f->sem); 203 + mutex_unlock(&f->sem); 204 204 } 205 205 206 206 /* ··· 209 209 * case of a short-copy. 210 210 */ 211 211 if (!PageUptodate(pg)) { 212 - down(&f->sem); 212 + mutex_lock(&f->sem); 213 213 ret = jffs2_do_readpage_nolock(inode, pg); 214 - up(&f->sem); 214 + mutex_unlock(&f->sem); 215 215 if (ret) 216 216 goto out_page; 217 217 }
+14 -14
fs/jffs2/fs.c
··· 51 51 mdata = (char *)&dev; 52 52 D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of kdev_t\n", mdatalen)); 53 53 } else if (S_ISLNK(inode->i_mode)) { 54 - down(&f->sem); 54 + mutex_lock(&f->sem); 55 55 mdatalen = f->metadata->size; 56 56 mdata = kmalloc(f->metadata->size, GFP_USER); 57 57 if (!mdata) { 58 - up(&f->sem); 58 + mutex_unlock(&f->sem); 59 59 return -ENOMEM; 60 60 } 61 61 ret = jffs2_read_dnode(c, f, f->metadata, mdata, 0, mdatalen); 62 62 if (ret) { 63 - up(&f->sem); 63 + mutex_unlock(&f->sem); 64 64 kfree(mdata); 65 65 return ret; 66 66 } 67 - up(&f->sem); 67 + mutex_unlock(&f->sem); 68 68 D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of symlink target\n", mdatalen)); 69 69 } 70 70 ··· 83 83 kfree(mdata); 84 84 return ret; 85 85 } 86 - down(&f->sem); 86 + mutex_lock(&f->sem); 87 87 ivalid = iattr->ia_valid; 88 88 89 89 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); ··· 134 134 if (IS_ERR(new_metadata)) { 135 135 jffs2_complete_reservation(c); 136 136 jffs2_free_raw_inode(ri); 137 - up(&f->sem); 137 + mutex_unlock(&f->sem); 138 138 return PTR_ERR(new_metadata); 139 139 } 140 140 /* It worked. Update the inode */ ··· 165 165 } 166 166 jffs2_free_raw_inode(ri); 167 167 168 - up(&f->sem); 168 + mutex_unlock(&f->sem); 169 169 jffs2_complete_reservation(c); 170 170 171 171 /* We have to do the vmtruncate() without f->sem held, since ··· 256 256 c = JFFS2_SB_INFO(inode->i_sb); 257 257 258 258 jffs2_init_inode_info(f); 259 - down(&f->sem); 259 + mutex_lock(&f->sem); 260 260 261 261 ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node); 262 262 263 263 if (ret) { 264 - up(&f->sem); 264 + mutex_unlock(&f->sem); 265 265 iget_failed(inode); 266 266 return ERR_PTR(ret); 267 267 } ··· 338 338 printk(KERN_WARNING "jffs2_read_inode(): Bogus imode %o for ino %lu\n", inode->i_mode, (unsigned long)inode->i_ino); 339 339 } 340 340 341 - up(&f->sem); 341 + mutex_unlock(&f->sem); 342 342 343 343 D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n")); 344 344 unlock_new_inode(inode); ··· 347 347 error_io: 348 348 ret = -EIO; 349 349 error: 350 - up(&f->sem); 350 + mutex_unlock(&f->sem); 351 351 jffs2_do_clear_inode(c, f); 352 352 iget_failed(inode); 353 353 return ERR_PTR(ret); ··· 388 388 Flush the writebuffer, if neccecary, else we loose it */ 389 389 if (!(sb->s_flags & MS_RDONLY)) { 390 390 jffs2_stop_garbage_collect_thread(c); 391 - down(&c->alloc_sem); 391 + mutex_lock(&c->alloc_sem); 392 392 jffs2_flush_wbuf_pad(c); 393 - up(&c->alloc_sem); 393 + mutex_unlock(&c->alloc_sem); 394 394 } 395 395 396 396 if (!(*flags & MS_RDONLY)) ··· 437 437 438 438 f = JFFS2_INODE_INFO(inode); 439 439 jffs2_init_inode_info(f); 440 - down(&f->sem); 440 + mutex_lock(&f->sem); 441 441 442 442 memset(ri, 0, sizeof(*ri)); 443 443 /* Set OS-specific defaults for new inodes */
+16 -16
fs/jffs2/gc.c
··· 126 126 int ret = 0, inum, nlink; 127 127 int xattr = 0; 128 128 129 - if (down_interruptible(&c->alloc_sem)) 129 + if (mutex_lock_interruptible(&c->alloc_sem)) 130 130 return -EINTR; 131 131 132 132 for (;;) { ··· 143 143 c->unchecked_size); 144 144 jffs2_dbg_dump_block_lists_nolock(c); 145 145 spin_unlock(&c->erase_completion_lock); 146 - up(&c->alloc_sem); 146 + mutex_unlock(&c->alloc_sem); 147 147 return -ENOSPC; 148 148 } 149 149 ··· 190 190 made no progress in this case, but that should be OK */ 191 191 c->checked_ino--; 192 192 193 - up(&c->alloc_sem); 193 + mutex_unlock(&c->alloc_sem); 194 194 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock); 195 195 return 0; 196 196 ··· 210 210 printk(KERN_WARNING "Returned error for crccheck of ino #%u. Expect badness...\n", ic->ino); 211 211 212 212 jffs2_set_inocache_state(c, ic, INO_STATE_CHECKEDABSENT); 213 - up(&c->alloc_sem); 213 + mutex_unlock(&c->alloc_sem); 214 214 return ret; 215 215 } 216 216 ··· 223 223 if (!jeb) { 224 224 D1 (printk(KERN_NOTICE "jffs2: Couldn't find erase block to garbage collect!\n")); 225 225 spin_unlock(&c->erase_completion_lock); 226 - up(&c->alloc_sem); 226 + mutex_unlock(&c->alloc_sem); 227 227 return -EIO; 228 228 } 229 229 ··· 232 232 printk(KERN_DEBUG "Nextblock at %08x, used_size %08x, dirty_size %08x, wasted_size %08x, free_size %08x\n", c->nextblock->offset, c->nextblock->used_size, c->nextblock->dirty_size, c->nextblock->wasted_size, c->nextblock->free_size)); 233 233 234 234 if (!jeb->used_size) { 235 - up(&c->alloc_sem); 235 + mutex_unlock(&c->alloc_sem); 236 236 goto eraseit; 237 237 } 238 238 ··· 248 248 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size); 249 249 jeb->gc_node = raw; 250 250 spin_unlock(&c->erase_completion_lock); 251 - up(&c->alloc_sem); 251 + mutex_unlock(&c->alloc_sem); 252 252 BUG(); 253 253 } 254 254 } ··· 266 266 /* Just mark it obsolete */ 267 267 jffs2_mark_node_obsolete(c, raw); 268 268 } 269 - up(&c->alloc_sem); 269 + mutex_unlock(&c->alloc_sem); 270 270 goto eraseit_lock; 271 271 } 272 272 ··· 334 334 */ 335 335 printk(KERN_CRIT "Inode #%u already in state %d in jffs2_garbage_collect_pass()!\n", 336 336 ic->ino, ic->state); 337 - up(&c->alloc_sem); 337 + mutex_unlock(&c->alloc_sem); 338 338 spin_unlock(&c->inocache_lock); 339 339 BUG(); 340 340 ··· 345 345 the alloc_sem() (for marking nodes invalid) so we must 346 346 drop the alloc_sem before sleeping. */ 347 347 348 - up(&c->alloc_sem); 348 + mutex_unlock(&c->alloc_sem); 349 349 D1(printk(KERN_DEBUG "jffs2_garbage_collect_pass() waiting for ino #%u in state %d\n", 350 350 ic->ino, ic->state)); 351 351 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock); ··· 416 416 ret = -ENOSPC; 417 417 } 418 418 release_sem: 419 - up(&c->alloc_sem); 419 + mutex_unlock(&c->alloc_sem); 420 420 421 421 eraseit_lock: 422 422 /* If we've finished this block, start it erasing */ ··· 445 445 uint32_t start = 0, end = 0, nrfrags = 0; 446 446 int ret = 0; 447 447 448 - down(&f->sem); 448 + mutex_lock(&f->sem); 449 449 450 450 /* Now we have the lock for this inode. Check that it's still the one at the head 451 451 of the list. */ ··· 525 525 } 526 526 } 527 527 upnout: 528 - up(&f->sem); 528 + mutex_unlock(&f->sem); 529 529 530 530 return ret; 531 531 } ··· 846 846 /* Prevent the erase code from nicking the obsolete node refs while 847 847 we're looking at them. I really don't like this extra lock but 848 848 can't see any alternative. Suggestions on a postcard to... */ 849 - down(&c->erase_free_sem); 849 + mutex_lock(&c->erase_free_sem); 850 850 851 851 for (raw = f->inocache->nodes; raw != (void *)f->inocache; raw = raw->next_in_ino) { 852 852 ··· 899 899 /* OK. The name really does match. There really is still an older node on 900 900 the flash which our deletion dirent obsoletes. So we have to write out 901 901 a new deletion dirent to replace it */ 902 - up(&c->erase_free_sem); 902 + mutex_unlock(&c->erase_free_sem); 903 903 904 904 D1(printk(KERN_DEBUG "Deletion dirent at %08x still obsoletes real dirent \"%s\" at %08x for ino #%u\n", 905 905 ref_offset(fd->raw), fd->name, ref_offset(raw), je32_to_cpu(rd->ino))); ··· 908 908 return jffs2_garbage_collect_dirent(c, jeb, f, fd); 909 909 } 910 910 911 - up(&c->erase_free_sem); 911 + mutex_unlock(&c->erase_free_sem); 912 912 kfree(rd); 913 913 } 914 914
+1 -1
fs/jffs2/jffs2_fs_i.h
··· 24 24 before letting GC proceed. Or we'd have to put ugliness 25 25 into the GC code so it didn't attempt to obtain the i_mutex 26 26 for the inode(s) which are already locked */ 27 - struct semaphore sem; 27 + struct mutex sem; 28 28 29 29 /* The highest (datanode) version number used for this ino */ 30 30 uint32_t highest_version;
+3 -3
fs/jffs2/jffs2_fs_sb.h
··· 16 16 #include <linux/spinlock.h> 17 17 #include <linux/workqueue.h> 18 18 #include <linux/completion.h> 19 - #include <linux/semaphore.h> 19 + #include <linux/mutex.h> 20 20 #include <linux/timer.h> 21 21 #include <linux/wait.h> 22 22 #include <linux/list.h> ··· 44 44 struct completion gc_thread_start; /* GC thread start completion */ 45 45 struct completion gc_thread_exit; /* GC thread exit completion port */ 46 46 47 - struct semaphore alloc_sem; /* Used to protect all the following 47 + struct mutex alloc_sem; /* Used to protect all the following 48 48 fields, and also to protect against 49 49 out-of-order writing of nodes. And GC. */ 50 50 uint32_t cleanmarker_size; /* Size of an _inline_ CLEANMARKER ··· 104 104 /* Sem to allow jffs2_garbage_collect_deletion_dirent to 105 105 drop the erase_completion_lock while it's holding a pointer 106 106 to an obsoleted node. I don't like this. Alternatives welcomed. */ 107 - struct semaphore erase_free_sem; 107 + struct mutex erase_free_sem; 108 108 109 109 uint32_t wbuf_pagesize; /* 0 for NOR and other flashes with no wbuf */ 110 110
+9 -9
fs/jffs2/nodemgmt.c
··· 48 48 minsize = PAD(minsize); 49 49 50 50 D1(printk(KERN_DEBUG "jffs2_reserve_space(): Requested 0x%x bytes\n", minsize)); 51 - down(&c->alloc_sem); 51 + mutex_lock(&c->alloc_sem); 52 52 53 53 D1(printk(KERN_DEBUG "jffs2_reserve_space(): alloc sem got\n")); 54 54 ··· 81 81 dirty, c->unchecked_size, c->sector_size)); 82 82 83 83 spin_unlock(&c->erase_completion_lock); 84 - up(&c->alloc_sem); 84 + mutex_unlock(&c->alloc_sem); 85 85 return -ENOSPC; 86 86 } 87 87 ··· 104 104 D1(printk(KERN_DEBUG "max. available size 0x%08x < blocksneeded * sector_size 0x%08x, returning -ENOSPC\n", 105 105 avail, blocksneeded * c->sector_size)); 106 106 spin_unlock(&c->erase_completion_lock); 107 - up(&c->alloc_sem); 107 + mutex_unlock(&c->alloc_sem); 108 108 return -ENOSPC; 109 109 } 110 110 111 - up(&c->alloc_sem); 111 + mutex_unlock(&c->alloc_sem); 112 112 113 113 D1(printk(KERN_DEBUG "Triggering GC pass. nr_free_blocks %d, nr_erasing_blocks %d, free_size 0x%08x, dirty_size 0x%08x, wasted_size 0x%08x, used_size 0x%08x, erasing_size 0x%08x, bad_size 0x%08x (total 0x%08x of 0x%08x)\n", 114 114 c->nr_free_blocks, c->nr_erasing_blocks, c->free_size, c->dirty_size, c->wasted_size, c->used_size, c->erasing_size, c->bad_size, ··· 124 124 if (signal_pending(current)) 125 125 return -EINTR; 126 126 127 - down(&c->alloc_sem); 127 + mutex_lock(&c->alloc_sem); 128 128 spin_lock(&c->erase_completion_lock); 129 129 } 130 130 ··· 137 137 if (!ret) 138 138 ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1); 139 139 if (ret) 140 - up(&c->alloc_sem); 140 + mutex_unlock(&c->alloc_sem); 141 141 return ret; 142 142 } 143 143 ··· 462 462 { 463 463 D1(printk(KERN_DEBUG "jffs2_complete_reservation()\n")); 464 464 jffs2_garbage_collect_trigger(c); 465 - up(&c->alloc_sem); 465 + mutex_unlock(&c->alloc_sem); 466 466 } 467 467 468 468 static inline int on_list(struct list_head *obj, struct list_head *head) ··· 511 511 any jffs2_raw_node_refs. So we don't need to stop erases from 512 512 happening, or protect against people holding an obsolete 513 513 jffs2_raw_node_ref without the erase_completion_lock. */ 514 - down(&c->erase_free_sem); 514 + mutex_lock(&c->erase_free_sem); 515 515 } 516 516 517 517 spin_lock(&c->erase_completion_lock); ··· 714 714 } 715 715 716 716 out_erase_sem: 717 - up(&c->erase_free_sem); 717 + mutex_unlock(&c->erase_free_sem); 718 718 } 719 719 720 720 int jffs2_thread_should_wake(struct jffs2_sb_info *c)
+12 -11
fs/jffs2/readinode.c
··· 1193 1193 JFFS2_ERROR("failed to read from flash: error %d, %zd of %zd bytes read\n", 1194 1194 ret, retlen, sizeof(*latest_node)); 1195 1195 /* FIXME: If this fails, there seems to be a memory leak. Find it. */ 1196 - up(&f->sem); 1196 + mutex_unlock(&f->sem); 1197 1197 jffs2_do_clear_inode(c, f); 1198 1198 return ret?ret:-EIO; 1199 1199 } ··· 1202 1202 if (crc != je32_to_cpu(latest_node->node_crc)) { 1203 1203 JFFS2_ERROR("CRC failed for read_inode of inode %u at physical location 0x%x\n", 1204 1204 f->inocache->ino, ref_offset(rii.latest_ref)); 1205 - up(&f->sem); 1205 + mutex_unlock(&f->sem); 1206 1206 jffs2_do_clear_inode(c, f); 1207 1207 return -EIO; 1208 1208 } ··· 1242 1242 f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL); 1243 1243 if (!f->target) { 1244 1244 JFFS2_ERROR("can't allocate %d bytes of memory for the symlink target path cache\n", je32_to_cpu(latest_node->csize)); 1245 - up(&f->sem); 1245 + mutex_unlock(&f->sem); 1246 1246 jffs2_do_clear_inode(c, f); 1247 1247 return -ENOMEM; 1248 1248 } ··· 1255 1255 ret = -EIO; 1256 1256 kfree(f->target); 1257 1257 f->target = NULL; 1258 - up(&f->sem); 1258 + mutex_unlock(&f->sem); 1259 1259 jffs2_do_clear_inode(c, f); 1260 1260 return -ret; 1261 1261 } ··· 1273 1273 if (f->metadata) { 1274 1274 JFFS2_ERROR("Argh. Special inode #%u with mode 0%o had metadata node\n", 1275 1275 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 1276 - up(&f->sem); 1276 + mutex_unlock(&f->sem); 1277 1277 jffs2_do_clear_inode(c, f); 1278 1278 return -EIO; 1279 1279 } 1280 1280 if (!frag_first(&f->fragtree)) { 1281 1281 JFFS2_ERROR("Argh. Special inode #%u with mode 0%o has no fragments\n", 1282 1282 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 1283 - up(&f->sem); 1283 + mutex_unlock(&f->sem); 1284 1284 jffs2_do_clear_inode(c, f); 1285 1285 return -EIO; 1286 1286 } ··· 1289 1289 JFFS2_ERROR("Argh. Special inode #%u with mode 0x%x had more than one node\n", 1290 1290 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 1291 1291 /* FIXME: Deal with it - check crc32, check for duplicate node, check times and discard the older one */ 1292 - up(&f->sem); 1292 + mutex_unlock(&f->sem); 1293 1293 jffs2_do_clear_inode(c, f); 1294 1294 return -EIO; 1295 1295 } ··· 1379 1379 if (!f) 1380 1380 return -ENOMEM; 1381 1381 1382 - init_MUTEX_LOCKED(&f->sem); 1382 + mutex_init(&f->sem); 1383 + mutex_lock(&f->sem); 1383 1384 f->inocache = ic; 1384 1385 1385 1386 ret = jffs2_do_read_inode_internal(c, f, &n); 1386 1387 if (!ret) { 1387 - up(&f->sem); 1388 + mutex_unlock(&f->sem); 1388 1389 jffs2_do_clear_inode(c, f); 1389 1390 } 1390 1391 kfree (f); ··· 1399 1398 1400 1399 jffs2_clear_acl(f); 1401 1400 jffs2_xattr_delete_inode(c, f->inocache); 1402 - down(&f->sem); 1401 + mutex_lock(&f->sem); 1403 1402 deleted = f->inocache && !f->inocache->nlink; 1404 1403 1405 1404 if (f->inocache && f->inocache->state != INO_STATE_CHECKING) ··· 1431 1430 jffs2_del_ino_cache(c, f->inocache); 1432 1431 } 1433 1432 1434 - up(&f->sem); 1433 + mutex_unlock(&f->sem); 1435 1434 }
+7 -7
fs/jffs2/super.c
··· 47 47 { 48 48 struct jffs2_inode_info *ei = (struct jffs2_inode_info *) foo; 49 49 50 - init_MUTEX(&ei->sem); 50 + mutex_init(&ei->sem); 51 51 inode_init_once(&ei->vfs_inode); 52 52 } 53 53 ··· 55 55 { 56 56 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); 57 57 58 - down(&c->alloc_sem); 58 + mutex_lock(&c->alloc_sem); 59 59 jffs2_flush_wbuf_pad(c); 60 - up(&c->alloc_sem); 60 + mutex_unlock(&c->alloc_sem); 61 61 return 0; 62 62 } 63 63 ··· 95 95 96 96 /* Initialize JFFS2 superblock locks, the further initialization will 97 97 * be done later */ 98 - init_MUTEX(&c->alloc_sem); 99 - init_MUTEX(&c->erase_free_sem); 98 + mutex_init(&c->alloc_sem); 99 + mutex_init(&c->erase_free_sem); 100 100 init_waitqueue_head(&c->erase_wait); 101 101 init_waitqueue_head(&c->inocache_wq); 102 102 spin_lock_init(&c->erase_completion_lock); ··· 125 125 126 126 D2(printk(KERN_DEBUG "jffs2: jffs2_put_super()\n")); 127 127 128 - down(&c->alloc_sem); 128 + mutex_lock(&c->alloc_sem); 129 129 jffs2_flush_wbuf_pad(c); 130 - up(&c->alloc_sem); 130 + mutex_unlock(&c->alloc_sem); 131 131 132 132 jffs2_sum_exit(c); 133 133
+8 -8
fs/jffs2/wbuf.c
··· 578 578 if (!jffs2_is_writebuffered(c)) 579 579 return 0; 580 580 581 - if (!down_trylock(&c->alloc_sem)) { 582 - up(&c->alloc_sem); 581 + if (mutex_trylock(&c->alloc_sem)) { 582 + mutex_unlock(&c->alloc_sem); 583 583 printk(KERN_CRIT "jffs2_flush_wbuf() called with alloc_sem not locked!\n"); 584 584 BUG(); 585 585 } ··· 702 702 if (!c->wbuf) 703 703 return 0; 704 704 705 - down(&c->alloc_sem); 705 + mutex_lock(&c->alloc_sem); 706 706 if (!jffs2_wbuf_pending_for_ino(c, ino)) { 707 707 D1(printk(KERN_DEBUG "Ino #%d not pending in wbuf. Returning\n", ino)); 708 - up(&c->alloc_sem); 708 + mutex_unlock(&c->alloc_sem); 709 709 return 0; 710 710 } 711 711 ··· 725 725 } else while (old_wbuf_len && 726 726 old_wbuf_ofs == c->wbuf_ofs) { 727 727 728 - up(&c->alloc_sem); 728 + mutex_unlock(&c->alloc_sem); 729 729 730 730 D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() calls gc pass\n")); 731 731 732 732 ret = jffs2_garbage_collect_pass(c); 733 733 if (ret) { 734 734 /* GC failed. Flush it with padding instead */ 735 - down(&c->alloc_sem); 735 + mutex_lock(&c->alloc_sem); 736 736 down_write(&c->wbuf_sem); 737 737 ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING); 738 738 /* retry flushing wbuf in case jffs2_wbuf_recover ··· 742 742 up_write(&c->wbuf_sem); 743 743 break; 744 744 } 745 - down(&c->alloc_sem); 745 + mutex_lock(&c->alloc_sem); 746 746 } 747 747 748 748 D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() ends...\n")); 749 749 750 - up(&c->alloc_sem); 750 + mutex_unlock(&c->alloc_sem); 751 751 return ret; 752 752 } 753 753
+25 -25
fs/jffs2/write.c
··· 137 137 JFFS2_SUMMARY_INODE_SIZE); 138 138 } else { 139 139 /* Locking pain */ 140 - up(&f->sem); 140 + mutex_unlock(&f->sem); 141 141 jffs2_complete_reservation(c); 142 142 143 143 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &dummy, 144 144 alloc_mode, JFFS2_SUMMARY_INODE_SIZE); 145 - down(&f->sem); 145 + mutex_lock(&f->sem); 146 146 } 147 147 148 148 if (!ret) { ··· 285 285 JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 286 286 } else { 287 287 /* Locking pain */ 288 - up(&f->sem); 288 + mutex_unlock(&f->sem); 289 289 jffs2_complete_reservation(c); 290 290 291 291 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &dummy, 292 292 alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 293 - down(&f->sem); 293 + mutex_lock(&f->sem); 294 294 } 295 295 296 296 if (!ret) { ··· 353 353 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret)); 354 354 break; 355 355 } 356 - down(&f->sem); 356 + mutex_lock(&f->sem); 357 357 datalen = min_t(uint32_t, writelen, PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1))); 358 358 cdatalen = min_t(uint32_t, alloclen - sizeof(*ri), datalen); 359 359 ··· 381 381 382 382 if (IS_ERR(fn)) { 383 383 ret = PTR_ERR(fn); 384 - up(&f->sem); 384 + mutex_unlock(&f->sem); 385 385 jffs2_complete_reservation(c); 386 386 if (!retried) { 387 387 /* Write error to be retried */ ··· 403 403 jffs2_mark_node_obsolete(c, fn->raw); 404 404 jffs2_free_full_dnode(fn); 405 405 406 - up(&f->sem); 406 + mutex_unlock(&f->sem); 407 407 jffs2_complete_reservation(c); 408 408 break; 409 409 } 410 - up(&f->sem); 410 + mutex_unlock(&f->sem); 411 411 jffs2_complete_reservation(c); 412 412 if (!datalen) { 413 413 printk(KERN_WARNING "Eep. We didn't actually write any data in jffs2_write_inode_range()\n"); ··· 439 439 JFFS2_SUMMARY_INODE_SIZE); 440 440 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen)); 441 441 if (ret) { 442 - up(&f->sem); 442 + mutex_unlock(&f->sem); 443 443 return ret; 444 444 } 445 445 ··· 454 454 if (IS_ERR(fn)) { 455 455 D1(printk(KERN_DEBUG "jffs2_write_dnode() failed\n")); 456 456 /* Eeek. Wave bye bye */ 457 - up(&f->sem); 457 + mutex_unlock(&f->sem); 458 458 jffs2_complete_reservation(c); 459 459 return PTR_ERR(fn); 460 460 } ··· 463 463 */ 464 464 f->metadata = fn; 465 465 466 - up(&f->sem); 466 + mutex_unlock(&f->sem); 467 467 jffs2_complete_reservation(c); 468 468 469 469 ret = jffs2_init_security(&f->vfs_inode, &dir_f->vfs_inode); ··· 489 489 return -ENOMEM; 490 490 } 491 491 492 - down(&dir_f->sem); 492 + mutex_lock(&dir_f->sem); 493 493 494 494 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 495 495 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); ··· 513 513 /* dirent failed to write. Delete the inode normally 514 514 as if it were the final unlink() */ 515 515 jffs2_complete_reservation(c); 516 - up(&dir_f->sem); 516 + mutex_unlock(&dir_f->sem); 517 517 return PTR_ERR(fd); 518 518 } 519 519 ··· 522 522 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 523 523 524 524 jffs2_complete_reservation(c); 525 - up(&dir_f->sem); 525 + mutex_unlock(&dir_f->sem); 526 526 527 527 return 0; 528 528 } ··· 551 551 return ret; 552 552 } 553 553 554 - down(&dir_f->sem); 554 + mutex_lock(&dir_f->sem); 555 555 556 556 /* Build a deletion node */ 557 557 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); ··· 574 574 575 575 if (IS_ERR(fd)) { 576 576 jffs2_complete_reservation(c); 577 - up(&dir_f->sem); 577 + mutex_unlock(&dir_f->sem); 578 578 return PTR_ERR(fd); 579 579 } 580 580 581 581 /* File it. This will mark the old one obsolete. */ 582 582 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 583 - up(&dir_f->sem); 583 + mutex_unlock(&dir_f->sem); 584 584 } else { 585 585 uint32_t nhash = full_name_hash(name, namelen); 586 586 587 587 fd = dir_f->dents; 588 588 /* We don't actually want to reserve any space, but we do 589 589 want to be holding the alloc_sem when we write to flash */ 590 - down(&c->alloc_sem); 591 - down(&dir_f->sem); 590 + mutex_lock(&c->alloc_sem); 591 + mutex_lock(&dir_f->sem); 592 592 593 593 for (fd = dir_f->dents; fd; fd = fd->next) { 594 594 if (fd->nhash == nhash && ··· 607 607 break; 608 608 } 609 609 } 610 - up(&dir_f->sem); 610 + mutex_unlock(&dir_f->sem); 611 611 } 612 612 613 613 /* dead_f is NULL if this was a rename not a real unlink */ ··· 615 615 pointing to an inode which didn't exist. */ 616 616 if (dead_f && dead_f->inocache) { 617 617 618 - down(&dead_f->sem); 618 + mutex_lock(&dead_f->sem); 619 619 620 620 if (S_ISDIR(OFNI_EDONI_2SFFJ(dead_f)->i_mode)) { 621 621 while (dead_f->dents) { ··· 639 639 640 640 dead_f->inocache->nlink--; 641 641 /* NB: Caller must set inode nlink if appropriate */ 642 - up(&dead_f->sem); 642 + mutex_unlock(&dead_f->sem); 643 643 } 644 644 645 645 jffs2_complete_reservation(c); ··· 666 666 return ret; 667 667 } 668 668 669 - down(&dir_f->sem); 669 + mutex_lock(&dir_f->sem); 670 670 671 671 /* Build a deletion node */ 672 672 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); ··· 691 691 692 692 if (IS_ERR(fd)) { 693 693 jffs2_complete_reservation(c); 694 - up(&dir_f->sem); 694 + mutex_unlock(&dir_f->sem); 695 695 return PTR_ERR(fd); 696 696 } 697 697 ··· 699 699 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 700 700 701 701 jffs2_complete_reservation(c); 702 - up(&dir_f->sem); 702 + mutex_unlock(&dir_f->sem); 703 703 704 704 return 0; 705 705 }