aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-04-25 15:25:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-25 15:25:48 -0400
commit7e97b28309edc5669ced2bb1371704e8f8d084e3 (patch)
tree9605694b00b4233a730ad86ea6d395cf59efc905 /fs/jffs2
parent5421d059068341b3f21df1a21c2ba9175e55ebef (diff)
parent3887ed5231fb6f339f36c3a0297c996cd1a1dad9 (diff)
Merge git://git.infradead.org/mtd-2.6
* git://git.infradead.org/mtd-2.6: (82 commits) [MTD] m25p80: Add Support for ATMEL AT25DF641 64-Megabit SPI Flash [MTD] m25p80: add FAST_READ access support to M25Pxx [MTD] [NAND] bf5xx_nand: Avoid crash if bfin_mac is installed. [MTD] [NAND] at91_nand: control NCE signal [MTD] [NAND] AT91 hardware ECC compile fix for at91sam9263 / at91sam9260 [MTD] [NAND] Hardware ECC controller on at91sam9263 / at91sam9260 [JFFS2] Introduce dbg_readinode2 log level, use it to shut read_dnode() up [JFFS2] Fix jffs2_reserve_space() when all blocks are pending erasure. [JFFS2] Add erase_checking_list to hold blocks being marked. UBI: add a message [JFFS2] Return values of jffs2_block_check_erase error paths [MTD] Clean up AR7 partition map support [MTD] [NOR] Fix Intel CFI driver for collie flash [JFFS2] Finally remove redundant ref->__totlen field. [JFFS2] Honour TEST_TOTLEN macro in debugging code. ref->__totlen is going! [JFFS2] Add paranoia debugging for superblock counts [JFFS2] Fix free space leak with in-band cleanmarkers [JFFS2] Self-sufficient #includes in jffs2_fs_i.h: include <linux/mutex.h> [MTD] [NAND] Verify probe by retrying to checking the results match [MTD] [NAND] S3C2410 Allow ECC disable to be specified by the board ...
Diffstat (limited to 'fs/jffs2')
-rw-r--r--fs/jffs2/README.Locking22
-rw-r--r--fs/jffs2/build.c1
-rw-r--r--fs/jffs2/debug.c164
-rw-r--r--fs/jffs2/debug.h6
-rw-r--r--fs/jffs2/dir.c58
-rw-r--r--fs/jffs2/erase.c80
-rw-r--r--fs/jffs2/file.c16
-rw-r--r--fs/jffs2/fs.c42
-rw-r--r--fs/jffs2/gc.c42
-rw-r--r--fs/jffs2/ioctl.c1
-rw-r--r--fs/jffs2/jffs2_fs_i.h4
-rw-r--r--fs/jffs2/jffs2_fs_sb.h7
-rw-r--r--fs/jffs2/nodelist.h2
-rw-r--r--fs/jffs2/nodemgmt.c24
-rw-r--r--fs/jffs2/readinode.c38
-rw-r--r--fs/jffs2/super.c14
-rw-r--r--fs/jffs2/wbuf.c28
-rw-r--r--fs/jffs2/write.c52
18 files changed, 399 insertions, 202 deletions
diff --git a/fs/jffs2/README.Locking b/fs/jffs2/README.Locking
index d14d5a4dc5ac..3ea36554107f 100644
--- a/fs/jffs2/README.Locking
+++ b/fs/jffs2/README.Locking
@@ -14,7 +14,7 @@ be fairly close.
14 alloc_sem 14 alloc_sem
15 --------- 15 ---------
16 16
17The alloc_sem is a per-filesystem semaphore, used primarily to ensure 17The alloc_sem is a per-filesystem mutex, used primarily to ensure
18contiguous allocation of space on the medium. It is automatically 18contiguous allocation of space on the medium. It is automatically
19obtained during space allocations (jffs2_reserve_space()) and freed 19obtained during space allocations (jffs2_reserve_space()) and freed
20upon write completion (jffs2_complete_reservation()). Note that 20upon write completion (jffs2_complete_reservation()). Note that
@@ -41,10 +41,10 @@ if the wbuf is currently holding any data is permitted, though.
41Ordering constraints: See f->sem. 41Ordering constraints: See f->sem.
42 42
43 43
44 File Semaphore f->sem 44 File Mutex f->sem
45 --------------------- 45 ---------------------
46 46
47This is the JFFS2-internal equivalent of the inode semaphore i->i_sem. 47This is the JFFS2-internal equivalent of the inode mutex i->i_sem.
48It protects the contents of the jffs2_inode_info private inode data, 48It protects the contents of the jffs2_inode_info private inode data,
49including the linked list of node fragments (but see the notes below on 49including the linked list of node fragments (but see the notes below on
50erase_completion_lock), etc. 50erase_completion_lock), etc.
@@ -60,14 +60,14 @@ lead to deadlock, unless we played games with unlocking the i_sem
60before calling the space allocation functions. 60before calling the space allocation functions.
61 61
62Instead of playing such games, we just have an extra internal 62Instead of playing such games, we just have an extra internal
63semaphore, which is obtained by the garbage collection code and also 63mutex, which is obtained by the garbage collection code and also
64by the normal file system code _after_ allocation of space. 64by the normal file system code _after_ allocation of space.
65 65
66Ordering constraints: 66Ordering constraints:
67 67
68 1. Never attempt to allocate space or lock alloc_sem with 68 1. Never attempt to allocate space or lock alloc_sem with
69 any f->sem held. 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 No ordering rules have been made for doing so. 71 No ordering rules have been made for doing so.
72 72
73 73
@@ -86,8 +86,8 @@ a simple spin_lock() rather than spin_lock_bh().
86 86
87Note that the per-inode list of physical nodes (f->nodes) is a special 87Note that the per-inode list of physical nodes (f->nodes) is a special
88case. Any changes to _valid_ nodes (i.e. ->flash_offset & 1 == 0) in 88case. Any changes to _valid_ nodes (i.e. ->flash_offset & 1 == 0) in
89the list are protected by the file semaphore f->sem. But the erase 89the list are protected by the file mutex f->sem. But the erase code
90code may remove _obsolete_ nodes from the list while holding only the 90may remove _obsolete_ nodes from the list while holding only the
91erase_completion_lock. So you can walk the list only while holding the 91erase_completion_lock. So you can walk the list only while holding the
92erase_completion_lock, and can drop the lock temporarily mid-walk as 92erase_completion_lock, and can drop the lock temporarily mid-walk as
93long as the pointer you're holding is to a _valid_ node, not an 93long as the pointer you're holding is to a _valid_ node, not an
@@ -124,10 +124,10 @@ Ordering constraints:
124 erase_free_sem 124 erase_free_sem
125 -------------- 125 --------------
126 126
127This semaphore is only used by the erase code which frees obsolete 127This mutex is only used by the erase code which frees obsolete node
128node references and the jffs2_garbage_collect_deletion_dirent() 128references and the jffs2_garbage_collect_deletion_dirent() function.
129function. The latter function on NAND flash must read _obsolete_ nodes 129The latter function on NAND flash must read _obsolete_ nodes to
130to determine whether the 'deletion dirent' under consideration can be 130determine whether the 'deletion dirent' under consideration can be
131discarded or whether it is still required to show that an inode has 131discarded or whether it is still required to show that an inode has
132been unlinked. Because reading from the flash may sleep, the 132been unlinked. Because reading from the flash may sleep, the
133erase_completion_lock cannot be held, so an alternative, more 133erase_completion_lock cannot be held, so an alternative, more
diff --git a/fs/jffs2/build.c b/fs/jffs2/build.c
index 722a6b682951..d58f845ccb85 100644
--- a/fs/jffs2/build.c
+++ b/fs/jffs2/build.c
@@ -345,6 +345,7 @@ int jffs2_do_mount_fs(struct jffs2_sb_info *c)
345 INIT_LIST_HEAD(&c->dirty_list); 345 INIT_LIST_HEAD(&c->dirty_list);
346 INIT_LIST_HEAD(&c->erasable_list); 346 INIT_LIST_HEAD(&c->erasable_list);
347 INIT_LIST_HEAD(&c->erasing_list); 347 INIT_LIST_HEAD(&c->erasing_list);
348 INIT_LIST_HEAD(&c->erase_checking_list);
348 INIT_LIST_HEAD(&c->erase_pending_list); 349 INIT_LIST_HEAD(&c->erase_pending_list);
349 INIT_LIST_HEAD(&c->erasable_pending_wbuf_list); 350 INIT_LIST_HEAD(&c->erasable_pending_wbuf_list);
350 INIT_LIST_HEAD(&c->erase_complete_list); 351 INIT_LIST_HEAD(&c->erase_complete_list);
diff --git a/fs/jffs2/debug.c b/fs/jffs2/debug.c
index 3a32c64ed497..5544d31c066b 100644
--- a/fs/jffs2/debug.c
+++ b/fs/jffs2/debug.c
@@ -62,9 +62,9 @@ __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
62void 62void
63__jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f) 63__jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
64{ 64{
65 down(&f->sem); 65 mutex_lock(&f->sem);
66 __jffs2_dbg_fragtree_paranoia_check_nolock(f); 66 __jffs2_dbg_fragtree_paranoia_check_nolock(f);
67 up(&f->sem); 67 mutex_unlock(&f->sem);
68} 68}
69 69
70void 70void
@@ -153,6 +153,139 @@ __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
153 kfree(buf); 153 kfree(buf);
154} 154}
155 155
156void __jffs2_dbg_superblock_counts(struct jffs2_sb_info *c)
157{
158 struct jffs2_eraseblock *jeb;
159 uint32_t free = 0, dirty = 0, used = 0, wasted = 0,
160 erasing = 0, bad = 0, unchecked = 0;
161 int nr_counted = 0;
162 int dump = 0;
163
164 if (c->gcblock) {
165 nr_counted++;
166 free += c->gcblock->free_size;
167 dirty += c->gcblock->dirty_size;
168 used += c->gcblock->used_size;
169 wasted += c->gcblock->wasted_size;
170 unchecked += c->gcblock->unchecked_size;
171 }
172 if (c->nextblock) {
173 nr_counted++;
174 free += c->nextblock->free_size;
175 dirty += c->nextblock->dirty_size;
176 used += c->nextblock->used_size;
177 wasted += c->nextblock->wasted_size;
178 unchecked += c->nextblock->unchecked_size;
179 }
180 list_for_each_entry(jeb, &c->clean_list, list) {
181 nr_counted++;
182 free += jeb->free_size;
183 dirty += jeb->dirty_size;
184 used += jeb->used_size;
185 wasted += jeb->wasted_size;
186 unchecked += jeb->unchecked_size;
187 }
188 list_for_each_entry(jeb, &c->very_dirty_list, list) {
189 nr_counted++;
190 free += jeb->free_size;
191 dirty += jeb->dirty_size;
192 used += jeb->used_size;
193 wasted += jeb->wasted_size;
194 unchecked += jeb->unchecked_size;
195 }
196 list_for_each_entry(jeb, &c->dirty_list, list) {
197 nr_counted++;
198 free += jeb->free_size;
199 dirty += jeb->dirty_size;
200 used += jeb->used_size;
201 wasted += jeb->wasted_size;
202 unchecked += jeb->unchecked_size;
203 }
204 list_for_each_entry(jeb, &c->erasable_list, list) {
205 nr_counted++;
206 free += jeb->free_size;
207 dirty += jeb->dirty_size;
208 used += jeb->used_size;
209 wasted += jeb->wasted_size;
210 unchecked += jeb->unchecked_size;
211 }
212 list_for_each_entry(jeb, &c->erasable_pending_wbuf_list, list) {
213 nr_counted++;
214 free += jeb->free_size;
215 dirty += jeb->dirty_size;
216 used += jeb->used_size;
217 wasted += jeb->wasted_size;
218 unchecked += jeb->unchecked_size;
219 }
220 list_for_each_entry(jeb, &c->erase_pending_list, list) {
221 nr_counted++;
222 free += jeb->free_size;
223 dirty += jeb->dirty_size;
224 used += jeb->used_size;
225 wasted += jeb->wasted_size;
226 unchecked += jeb->unchecked_size;
227 }
228 list_for_each_entry(jeb, &c->free_list, list) {
229 nr_counted++;
230 free += jeb->free_size;
231 dirty += jeb->dirty_size;
232 used += jeb->used_size;
233 wasted += jeb->wasted_size;
234 unchecked += jeb->unchecked_size;
235 }
236 list_for_each_entry(jeb, &c->bad_used_list, list) {
237 nr_counted++;
238 free += jeb->free_size;
239 dirty += jeb->dirty_size;
240 used += jeb->used_size;
241 wasted += jeb->wasted_size;
242 unchecked += jeb->unchecked_size;
243 }
244
245 list_for_each_entry(jeb, &c->erasing_list, list) {
246 nr_counted++;
247 erasing += c->sector_size;
248 }
249 list_for_each_entry(jeb, &c->erase_checking_list, list) {
250 nr_counted++;
251 erasing += c->sector_size;
252 }
253 list_for_each_entry(jeb, &c->erase_complete_list, list) {
254 nr_counted++;
255 erasing += c->sector_size;
256 }
257 list_for_each_entry(jeb, &c->bad_list, list) {
258 nr_counted++;
259 bad += c->sector_size;
260 }
261
262#define check(sz) \
263 if (sz != c->sz##_size) { \
264 printk(KERN_WARNING #sz "_size mismatch counted 0x%x, c->" #sz "_size 0x%x\n", \
265 sz, c->sz##_size); \
266 dump = 1; \
267 }
268 check(free);
269 check(dirty);
270 check(used);
271 check(wasted);
272 check(unchecked);
273 check(bad);
274 check(erasing);
275#undef check
276
277 if (nr_counted != c->nr_blocks) {
278 printk(KERN_WARNING "%s counted only 0x%x blocks of 0x%x. Where are the others?\n",
279 __func__, nr_counted, c->nr_blocks);
280 dump = 1;
281 }
282
283 if (dump) {
284 __jffs2_dbg_dump_block_lists_nolock(c);
285 BUG();
286 }
287}
288
156/* 289/*
157 * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'. 290 * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'.
158 */ 291 */
@@ -229,6 +362,9 @@ __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
229 } 362 }
230#endif 363#endif
231 364
365 if (!(c->flags & (JFFS2_SB_FLAG_BUILDING|JFFS2_SB_FLAG_SCANNING)))
366 __jffs2_dbg_superblock_counts(c);
367
232 return; 368 return;
233 369
234error: 370error:
@@ -268,7 +404,10 @@ __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
268 404
269 printk(JFFS2_DBG); 405 printk(JFFS2_DBG);
270 for (ref = jeb->first_node; ; ref = ref_next(ref)) { 406 for (ref = jeb->first_node; ; ref = ref_next(ref)) {
271 printk("%#08x(%#x)", ref_offset(ref), ref->__totlen); 407 printk("%#08x", ref_offset(ref));
408#ifdef TEST_TOTLEN
409 printk("(%x)", ref->__totlen);
410#endif
272 if (ref_next(ref)) 411 if (ref_next(ref))
273 printk("->"); 412 printk("->");
274 else 413 else
@@ -447,6 +586,21 @@ __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
447 } 586 }
448 } 587 }
449 } 588 }
589 if (list_empty(&c->erase_checking_list)) {
590 printk(JFFS2_DBG "erase_checking_list: empty\n");
591 } else {
592 struct list_head *this;
593
594 list_for_each(this, &c->erase_checking_list) {
595 struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
596
597 if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
598 printk(JFFS2_DBG "erase_checking_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
599 jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
600 jeb->unchecked_size, jeb->free_size);
601 }
602 }
603 }
450 604
451 if (list_empty(&c->erase_pending_list)) { 605 if (list_empty(&c->erase_pending_list)) {
452 printk(JFFS2_DBG "erase_pending_list: empty\n"); 606 printk(JFFS2_DBG "erase_pending_list: empty\n");
@@ -532,9 +686,9 @@ __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
532void 686void
533__jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f) 687__jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f)
534{ 688{
535 down(&f->sem); 689 mutex_lock(&f->sem);
536 jffs2_dbg_dump_fragtree_nolock(f); 690 jffs2_dbg_dump_fragtree_nolock(f);
537 up(&f->sem); 691 mutex_unlock(&f->sem);
538} 692}
539 693
540void 694void
diff --git a/fs/jffs2/debug.h b/fs/jffs2/debug.h
index 4130adabd76e..9645275023e6 100644
--- a/fs/jffs2/debug.h
+++ b/fs/jffs2/debug.h
@@ -38,6 +38,7 @@
38 38
39#if CONFIG_JFFS2_FS_DEBUG > 1 39#if CONFIG_JFFS2_FS_DEBUG > 1
40#define JFFS2_DBG_FRAGTREE2_MESSAGES 40#define JFFS2_DBG_FRAGTREE2_MESSAGES
41#define JFFS2_DBG_READINODE2_MESSAGES
41#define JFFS2_DBG_MEMALLOC_MESSAGES 42#define JFFS2_DBG_MEMALLOC_MESSAGES
42#endif 43#endif
43 44
@@ -115,6 +116,11 @@
115#else 116#else
116#define dbg_readinode(fmt, ...) 117#define dbg_readinode(fmt, ...)
117#endif 118#endif
119#ifdef JFFS2_DBG_READINODE2_MESSAGES
120#define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
121#else
122#define dbg_readinode2(fmt, ...)
123#endif
118 124
119/* Fragtree build debugging messages */ 125/* Fragtree build debugging messages */
120#ifdef JFFS2_DBG_FRAGTREE_MESSAGES 126#ifdef JFFS2_DBG_FRAGTREE_MESSAGES
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index f948f7e6ec82..c63e7a96af0d 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -86,7 +86,7 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
86 dir_f = JFFS2_INODE_INFO(dir_i); 86 dir_f = JFFS2_INODE_INFO(dir_i);
87 c = JFFS2_SB_INFO(dir_i->i_sb); 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 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */ 91 /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */
92 for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) { 92 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,
99 } 99 }
100 if (fd) 100 if (fd)
101 ino = fd->ino; 101 ino = fd->ino;
102 up(&dir_f->sem); 102 mutex_unlock(&dir_f->sem);
103 if (ino) { 103 if (ino) {
104 inode = jffs2_iget(dir_i->i_sb, ino); 104 inode = jffs2_iget(dir_i->i_sb, ino);
105 if (IS_ERR(inode)) { 105 if (IS_ERR(inode)) {
@@ -146,7 +146,7 @@ static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
146 } 146 }
147 147
148 curofs=1; 148 curofs=1;
149 down(&f->sem); 149 mutex_lock(&f->sem);
150 for (fd = f->dents; fd; fd = fd->next) { 150 for (fd = f->dents; fd; fd = fd->next) {
151 151
152 curofs++; 152 curofs++;
@@ -166,7 +166,7 @@ static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
166 break; 166 break;
167 offset++; 167 offset++;
168 } 168 }
169 up(&f->sem); 169 mutex_unlock(&f->sem);
170 out: 170 out:
171 filp->f_pos = offset; 171 filp->f_pos = offset;
172 return 0; 172 return 0;
@@ -275,9 +275,9 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
275 ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now); 275 ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now);
276 276
277 if (!ret) { 277 if (!ret) {
278 down(&f->sem); 278 mutex_lock(&f->sem);
279 old_dentry->d_inode->i_nlink = ++f->inocache->nlink; 279 old_dentry->d_inode->i_nlink = ++f->inocache->nlink;
280 up(&f->sem); 280 mutex_unlock(&f->sem);
281 d_instantiate(dentry, old_dentry->d_inode); 281 d_instantiate(dentry, old_dentry->d_inode);
282 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 282 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
283 atomic_inc(&old_dentry->d_inode->i_count); 283 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
351 351
352 if (IS_ERR(fn)) { 352 if (IS_ERR(fn)) {
353 /* Eeek. Wave bye bye */ 353 /* Eeek. Wave bye bye */
354 up(&f->sem); 354 mutex_unlock(&f->sem);
355 jffs2_complete_reservation(c); 355 jffs2_complete_reservation(c);
356 jffs2_clear_inode(inode); 356 jffs2_clear_inode(inode);
357 return PTR_ERR(fn); 357 return PTR_ERR(fn);
@@ -361,7 +361,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
361 f->target = kmalloc(targetlen + 1, GFP_KERNEL); 361 f->target = kmalloc(targetlen + 1, GFP_KERNEL);
362 if (!f->target) { 362 if (!f->target) {
363 printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1); 363 printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1);
364 up(&f->sem); 364 mutex_unlock(&f->sem);
365 jffs2_complete_reservation(c); 365 jffs2_complete_reservation(c);
366 jffs2_clear_inode(inode); 366 jffs2_clear_inode(inode);
367 return -ENOMEM; 367 return -ENOMEM;
@@ -374,7 +374,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
374 obsoleted by the first data write 374 obsoleted by the first data write
375 */ 375 */
376 f->metadata = fn; 376 f->metadata = fn;
377 up(&f->sem); 377 mutex_unlock(&f->sem);
378 378
379 jffs2_complete_reservation(c); 379 jffs2_complete_reservation(c);
380 380
@@ -406,7 +406,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
406 } 406 }
407 407
408 dir_f = JFFS2_INODE_INFO(dir_i); 408 dir_f = JFFS2_INODE_INFO(dir_i);
409 down(&dir_f->sem); 409 mutex_lock(&dir_f->sem);
410 410
411 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 411 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
412 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); 412 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
429 as if it were the final unlink() */ 429 as if it were the final unlink() */
430 jffs2_complete_reservation(c); 430 jffs2_complete_reservation(c);
431 jffs2_free_raw_dirent(rd); 431 jffs2_free_raw_dirent(rd);
432 up(&dir_f->sem); 432 mutex_unlock(&dir_f->sem);
433 jffs2_clear_inode(inode); 433 jffs2_clear_inode(inode);
434 return PTR_ERR(fd); 434 return PTR_ERR(fd);
435 } 435 }
@@ -442,7 +442,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
442 one if necessary. */ 442 one if necessary. */
443 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 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 jffs2_complete_reservation(c); 446 jffs2_complete_reservation(c);
447 447
448 d_instantiate(dentry, inode); 448 d_instantiate(dentry, inode);
@@ -507,7 +507,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
507 507
508 if (IS_ERR(fn)) { 508 if (IS_ERR(fn)) {
509 /* Eeek. Wave bye bye */ 509 /* Eeek. Wave bye bye */
510 up(&f->sem); 510 mutex_unlock(&f->sem);
511 jffs2_complete_reservation(c); 511 jffs2_complete_reservation(c);
512 jffs2_clear_inode(inode); 512 jffs2_clear_inode(inode);
513 return PTR_ERR(fn); 513 return PTR_ERR(fn);
@@ -516,7 +516,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
516 obsoleted by the first data write 516 obsoleted by the first data write
517 */ 517 */
518 f->metadata = fn; 518 f->metadata = fn;
519 up(&f->sem); 519 mutex_unlock(&f->sem);
520 520
521 jffs2_complete_reservation(c); 521 jffs2_complete_reservation(c);
522 522
@@ -548,7 +548,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
548 } 548 }
549 549
550 dir_f = JFFS2_INODE_INFO(dir_i); 550 dir_f = JFFS2_INODE_INFO(dir_i);
551 down(&dir_f->sem); 551 mutex_lock(&dir_f->sem);
552 552
553 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 553 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
554 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); 554 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)
571 as if it were the final unlink() */ 571 as if it were the final unlink() */
572 jffs2_complete_reservation(c); 572 jffs2_complete_reservation(c);
573 jffs2_free_raw_dirent(rd); 573 jffs2_free_raw_dirent(rd);
574 up(&dir_f->sem); 574 mutex_unlock(&dir_f->sem);
575 jffs2_clear_inode(inode); 575 jffs2_clear_inode(inode);
576 return PTR_ERR(fd); 576 return PTR_ERR(fd);
577 } 577 }
@@ -585,7 +585,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
585 one if necessary. */ 585 one if necessary. */
586 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 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 jffs2_complete_reservation(c); 589 jffs2_complete_reservation(c);
590 590
591 d_instantiate(dentry, inode); 591 d_instantiate(dentry, inode);
@@ -673,7 +673,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
673 673
674 if (IS_ERR(fn)) { 674 if (IS_ERR(fn)) {
675 /* Eeek. Wave bye bye */ 675 /* Eeek. Wave bye bye */
676 up(&f->sem); 676 mutex_unlock(&f->sem);
677 jffs2_complete_reservation(c); 677 jffs2_complete_reservation(c);
678 jffs2_clear_inode(inode); 678 jffs2_clear_inode(inode);
679 return PTR_ERR(fn); 679 return PTR_ERR(fn);
@@ -682,7 +682,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
682 obsoleted by the first data write 682 obsoleted by the first data write
683 */ 683 */
684 f->metadata = fn; 684 f->metadata = fn;
685 up(&f->sem); 685 mutex_unlock(&f->sem);
686 686
687 jffs2_complete_reservation(c); 687 jffs2_complete_reservation(c);
688 688
@@ -714,7 +714,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
714 } 714 }
715 715
716 dir_f = JFFS2_INODE_INFO(dir_i); 716 dir_f = JFFS2_INODE_INFO(dir_i);
717 down(&dir_f->sem); 717 mutex_lock(&dir_f->sem);
718 718
719 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 719 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
720 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); 720 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
740 as if it were the final unlink() */ 740 as if it were the final unlink() */
741 jffs2_complete_reservation(c); 741 jffs2_complete_reservation(c);
742 jffs2_free_raw_dirent(rd); 742 jffs2_free_raw_dirent(rd);
743 up(&dir_f->sem); 743 mutex_unlock(&dir_f->sem);
744 jffs2_clear_inode(inode); 744 jffs2_clear_inode(inode);
745 return PTR_ERR(fd); 745 return PTR_ERR(fd);
746 } 746 }
@@ -753,7 +753,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
753 one if necessary. */ 753 one if necessary. */
754 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 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 jffs2_complete_reservation(c); 757 jffs2_complete_reservation(c);
758 758
759 d_instantiate(dentry, inode); 759 d_instantiate(dentry, inode);
@@ -780,14 +780,14 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
780 if (S_ISDIR(new_dentry->d_inode->i_mode)) { 780 if (S_ISDIR(new_dentry->d_inode->i_mode)) {
781 struct jffs2_full_dirent *fd; 781 struct jffs2_full_dirent *fd;
782 782
783 down(&victim_f->sem); 783 mutex_lock(&victim_f->sem);
784 for (fd = victim_f->dents; fd; fd = fd->next) { 784 for (fd = victim_f->dents; fd; fd = fd->next) {
785 if (fd->ino) { 785 if (fd->ino) {
786 up(&victim_f->sem); 786 mutex_unlock(&victim_f->sem);
787 return -ENOTEMPTY; 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,9 +816,9 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
816 /* Don't oops if the victim was a dirent pointing to an 816 /* Don't oops if the victim was a dirent pointing to an
817 inode which didn't exist. */ 817 inode which didn't exist. */
818 if (victim_f->inocache) { 818 if (victim_f->inocache) {
819 down(&victim_f->sem); 819 mutex_lock(&victim_f->sem);
820 victim_f->inocache->nlink--; 820 victim_f->inocache->nlink--;
821 up(&victim_f->sem); 821 mutex_unlock(&victim_f->sem);
822 } 822 }
823 } 823 }
824 824
@@ -836,11 +836,11 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
836 if (ret) { 836 if (ret) {
837 /* Oh shit. We really ought to make a single node which can do both atomically */ 837 /* Oh shit. We really ought to make a single node which can do both atomically */
838 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode); 838 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode);
839 down(&f->sem); 839 mutex_lock(&f->sem);
840 inc_nlink(old_dentry->d_inode); 840 inc_nlink(old_dentry->d_inode);
841 if (f->inocache) 841 if (f->inocache)
842 f->inocache->nlink++; 842 f->inocache->nlink++;
843 up(&f->sem); 843 mutex_unlock(&f->sem);
844 844
845 printk(KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n", ret); 845 printk(KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n", ret);
846 /* Might as well let the VFS know */ 846 /* Might as well let the VFS know */
diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
index a1db9180633f..25a640e566d3 100644
--- a/fs/jffs2/erase.c
+++ b/fs/jffs2/erase.c
@@ -50,14 +50,14 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
50 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL); 50 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL);
51 if (!instr) { 51 if (!instr) {
52 printk(KERN_WARNING "kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n"); 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 spin_lock(&c->erase_completion_lock); 54 spin_lock(&c->erase_completion_lock);
55 list_move(&jeb->list, &c->erase_pending_list); 55 list_move(&jeb->list, &c->erase_pending_list);
56 c->erasing_size -= c->sector_size; 56 c->erasing_size -= c->sector_size;
57 c->dirty_size += c->sector_size; 57 c->dirty_size += c->sector_size;
58 jeb->dirty_size = c->sector_size; 58 jeb->dirty_size = c->sector_size;
59 spin_unlock(&c->erase_completion_lock); 59 spin_unlock(&c->erase_completion_lock);
60 up(&c->erase_free_sem); 60 mutex_unlock(&c->erase_free_sem);
61 return; 61 return;
62 } 62 }
63 63
@@ -84,14 +84,14 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
84 if (ret == -ENOMEM || ret == -EAGAIN) { 84 if (ret == -ENOMEM || ret == -EAGAIN) {
85 /* Erase failed immediately. Refile it on the list */ 85 /* Erase failed immediately. Refile it on the list */
86 D1(printk(KERN_DEBUG "Erase at 0x%08x failed: %d. Refiling on erase_pending_list\n", jeb->offset, ret)); 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 spin_lock(&c->erase_completion_lock); 88 spin_lock(&c->erase_completion_lock);
89 list_move(&jeb->list, &c->erase_pending_list); 89 list_move(&jeb->list, &c->erase_pending_list);
90 c->erasing_size -= c->sector_size; 90 c->erasing_size -= c->sector_size;
91 c->dirty_size += c->sector_size; 91 c->dirty_size += c->sector_size;
92 jeb->dirty_size = c->sector_size; 92 jeb->dirty_size = c->sector_size;
93 spin_unlock(&c->erase_completion_lock); 93 spin_unlock(&c->erase_completion_lock);
94 up(&c->erase_free_sem); 94 mutex_unlock(&c->erase_free_sem);
95 return; 95 return;
96 } 96 }
97 97
@@ -107,7 +107,7 @@ void jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count)
107{ 107{
108 struct jffs2_eraseblock *jeb; 108 struct jffs2_eraseblock *jeb;
109 109
110 down(&c->erase_free_sem); 110 mutex_lock(&c->erase_free_sem);
111 111
112 spin_lock(&c->erase_completion_lock); 112 spin_lock(&c->erase_completion_lock);
113 113
@@ -116,9 +116,9 @@ void jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count)
116 116
117 if (!list_empty(&c->erase_complete_list)) { 117 if (!list_empty(&c->erase_complete_list)) {
118 jeb = list_entry(c->erase_complete_list.next, struct jffs2_eraseblock, list); 118 jeb = list_entry(c->erase_complete_list.next, struct jffs2_eraseblock, list);
119 list_del(&jeb->list); 119 list_move(&jeb->list, &c->erase_checking_list);
120 spin_unlock(&c->erase_completion_lock); 120 spin_unlock(&c->erase_completion_lock);
121 up(&c->erase_free_sem); 121 mutex_unlock(&c->erase_free_sem);
122 jffs2_mark_erased_block(c, jeb); 122 jffs2_mark_erased_block(c, jeb);
123 123
124 if (!--count) { 124 if (!--count) {
@@ -139,7 +139,7 @@ void jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count)
139 jffs2_free_jeb_node_refs(c, jeb); 139 jffs2_free_jeb_node_refs(c, jeb);
140 list_add(&jeb->list, &c->erasing_list); 140 list_add(&jeb->list, &c->erasing_list);
141 spin_unlock(&c->erase_completion_lock); 141 spin_unlock(&c->erase_completion_lock);
142 up(&c->erase_free_sem); 142 mutex_unlock(&c->erase_free_sem);
143 143
144 jffs2_erase_block(c, jeb); 144 jffs2_erase_block(c, jeb);
145 145
@@ -149,12 +149,12 @@ void jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count)
149 149
150 /* Be nice */ 150 /* Be nice */
151 yield(); 151 yield();
152 down(&c->erase_free_sem); 152 mutex_lock(&c->erase_free_sem);
153 spin_lock(&c->erase_completion_lock); 153 spin_lock(&c->erase_completion_lock);
154 } 154 }
155 155
156 spin_unlock(&c->erase_completion_lock); 156 spin_unlock(&c->erase_completion_lock);
157 up(&c->erase_free_sem); 157 mutex_unlock(&c->erase_free_sem);
158 done: 158 done:
159 D1(printk(KERN_DEBUG "jffs2_erase_pending_blocks completed\n")); 159 D1(printk(KERN_DEBUG "jffs2_erase_pending_blocks completed\n"));
160} 160}
@@ -162,11 +162,11 @@ void jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count)
162static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) 162static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
163{ 163{
164 D1(printk(KERN_DEBUG "Erase completed successfully at 0x%08x\n", jeb->offset)); 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 spin_lock(&c->erase_completion_lock); 166 spin_lock(&c->erase_completion_lock);
167 list_move_tail(&jeb->list, &c->erase_complete_list); 167 list_move_tail(&jeb->list, &c->erase_complete_list);
168 spin_unlock(&c->erase_completion_lock); 168 spin_unlock(&c->erase_completion_lock);
169 up(&c->erase_free_sem); 169 mutex_unlock(&c->erase_free_sem);
170 /* Ensure that kupdated calls us again to mark them clean */ 170 /* Ensure that kupdated calls us again to mark them clean */
171 jffs2_erase_pending_trigger(c); 171 jffs2_erase_pending_trigger(c);
172} 172}
@@ -180,26 +180,26 @@ static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock
180 failed too many times. */ 180 failed too many times. */
181 if (!jffs2_write_nand_badblock(c, jeb, bad_offset)) { 181 if (!jffs2_write_nand_badblock(c, jeb, bad_offset)) {
182 /* We'd like to give this block another try. */ 182 /* We'd like to give this block another try. */
183 down(&c->erase_free_sem); 183 mutex_lock(&c->erase_free_sem);
184 spin_lock(&c->erase_completion_lock); 184 spin_lock(&c->erase_completion_lock);
185 list_move(&jeb->list, &c->erase_pending_list); 185 list_move(&jeb->list, &c->erase_pending_list);
186 c->erasing_size -= c->sector_size; 186 c->erasing_size -= c->sector_size;
187 c->dirty_size += c->sector_size; 187 c->dirty_size += c->sector_size;
188 jeb->dirty_size = c->sector_size; 188 jeb->dirty_size = c->sector_size;
189 spin_unlock(&c->erase_completion_lock); 189 spin_unlock(&c->erase_completion_lock);
190 up(&c->erase_free_sem); 190 mutex_unlock(&c->erase_free_sem);
191 return; 191 return;
192 } 192 }
193 } 193 }
194 194
195 down(&c->erase_free_sem); 195 mutex_lock(&c->erase_free_sem);
196 spin_lock(&c->erase_completion_lock); 196 spin_lock(&c->erase_completion_lock);
197 c->erasing_size -= c->sector_size; 197 c->erasing_size -= c->sector_size;
198 c->bad_size += c->sector_size; 198 c->bad_size += c->sector_size;
199 list_move(&jeb->list, &c->bad_list); 199 list_move(&jeb->list, &c->bad_list);
200 c->nr_erasing_blocks--; 200 c->nr_erasing_blocks--;
201 spin_unlock(&c->erase_completion_lock); 201 spin_unlock(&c->erase_completion_lock);
202 up(&c->erase_free_sem); 202 mutex_unlock(&c->erase_free_sem);
203 wake_up(&c->erase_wait); 203 wake_up(&c->erase_wait);
204} 204}
205 205
@@ -350,9 +350,11 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl
350 break; 350 break;
351 } while(--retlen); 351 } while(--retlen);
352 c->mtd->unpoint(c->mtd, ebuf, jeb->offset, c->sector_size); 352 c->mtd->unpoint(c->mtd, ebuf, jeb->offset, c->sector_size);
353 if (retlen) 353 if (retlen) {
354 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08tx\n", 354 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08tx\n",
355 *wordebuf, jeb->offset + c->sector_size-retlen*sizeof(*wordebuf)); 355 *wordebuf, jeb->offset + c->sector_size-retlen*sizeof(*wordebuf));
356 return -EIO;
357 }
356 return 0; 358 return 0;
357 } 359 }
358 do_flash_read: 360 do_flash_read:
@@ -373,10 +375,12 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl
373 ret = c->mtd->read(c->mtd, ofs, readlen, &retlen, ebuf); 375 ret = c->mtd->read(c->mtd, ofs, readlen, &retlen, ebuf);
374 if (ret) { 376 if (ret) {
375 printk(KERN_WARNING "Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n", ofs, ret); 377 printk(KERN_WARNING "Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n", ofs, ret);
378 ret = -EIO;
376 goto fail; 379 goto fail;
377 } 380 }
378 if (retlen != readlen) { 381 if (retlen != readlen) {
379 printk(KERN_WARNING "Short read from newly-erased block at 0x%08x. Wanted %d, got %zd\n", ofs, readlen, retlen); 382 printk(KERN_WARNING "Short read from newly-erased block at 0x%08x. Wanted %d, got %zd\n", ofs, readlen, retlen);
383 ret = -EIO;
380 goto fail; 384 goto fail;
381 } 385 }
382 for (i=0; i<readlen; i += sizeof(unsigned long)) { 386 for (i=0; i<readlen; i += sizeof(unsigned long)) {
@@ -385,6 +389,7 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl
385 if (*datum + 1) { 389 if (*datum + 1) {
386 *bad_offset += i; 390 *bad_offset += i;
387 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08x\n", *datum, *bad_offset); 391 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08x\n", *datum, *bad_offset);
392 ret = -EIO;
388 goto fail; 393 goto fail;
389 } 394 }
390 } 395 }
@@ -419,9 +424,6 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
419 if (jffs2_write_nand_cleanmarker(c, jeb)) 424 if (jffs2_write_nand_cleanmarker(c, jeb))
420 goto filebad; 425 goto filebad;
421 } 426 }
422
423 /* Everything else got zeroed before the erase */
424 jeb->free_size = c->sector_size;
425 } else { 427 } else {
426 428
427 struct kvec vecs[1]; 429 struct kvec vecs[1];
@@ -449,48 +451,50 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
449 451
450 goto filebad; 452 goto filebad;
451 } 453 }
452
453 /* Everything else got zeroed before the erase */
454 jeb->free_size = c->sector_size;
455 /* FIXME Special case for cleanmarker in empty block */
456 jffs2_link_node_ref(c, jeb, jeb->offset | REF_NORMAL, c->cleanmarker_size, NULL);
457 } 454 }
455 /* Everything else got zeroed before the erase */
456 jeb->free_size = c->sector_size;
458 457
459 down(&c->erase_free_sem); 458 mutex_lock(&c->erase_free_sem);
460 spin_lock(&c->erase_completion_lock); 459 spin_lock(&c->erase_completion_lock);
460
461 c->erasing_size -= c->sector_size; 461 c->erasing_size -= c->sector_size;
462 c->free_size += jeb->free_size; 462 c->free_size += c->sector_size;
463 c->used_size += jeb->used_size;
464 463
465 jffs2_dbg_acct_sanity_check_nolock(c,jeb); 464 /* Account for cleanmarker now, if it's in-band */
466 jffs2_dbg_acct_paranoia_check_nolock(c, jeb); 465 if (c->cleanmarker_size && !jffs2_cleanmarker_oob(c))
466 jffs2_link_node_ref(c, jeb, jeb->offset | REF_NORMAL, c->cleanmarker_size, NULL);
467 467
468 list_add_tail(&jeb->list, &c->free_list); 468 list_move_tail(&jeb->list, &c->free_list);
469 c->nr_erasing_blocks--; 469 c->nr_erasing_blocks--;
470 c->nr_free_blocks++; 470 c->nr_free_blocks++;
471
472 jffs2_dbg_acct_sanity_check_nolock(c, jeb);
473 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
474
471 spin_unlock(&c->erase_completion_lock); 475 spin_unlock(&c->erase_completion_lock);
472 up(&c->erase_free_sem); 476 mutex_unlock(&c->erase_free_sem);
473 wake_up(&c->erase_wait); 477 wake_up(&c->erase_wait);
474 return; 478 return;
475 479
476filebad: 480filebad:
477 down(&c->erase_free_sem); 481 mutex_lock(&c->erase_free_sem);
478 spin_lock(&c->erase_completion_lock); 482 spin_lock(&c->erase_completion_lock);
479 /* Stick it on a list (any list) so erase_failed can take it 483 /* Stick it on a list (any list) so erase_failed can take it
480 right off again. Silly, but shouldn't happen often. */ 484 right off again. Silly, but shouldn't happen often. */
481 list_add(&jeb->list, &c->erasing_list); 485 list_move(&jeb->list, &c->erasing_list);
482 spin_unlock(&c->erase_completion_lock); 486 spin_unlock(&c->erase_completion_lock);
483 up(&c->erase_free_sem); 487 mutex_unlock(&c->erase_free_sem);
484 jffs2_erase_failed(c, jeb, bad_offset); 488 jffs2_erase_failed(c, jeb, bad_offset);
485 return; 489 return;
486 490
487refile: 491refile:
488 /* Stick it back on the list from whence it came and come back later */ 492 /* Stick it back on the list from whence it came and come back later */
489 jffs2_erase_pending_trigger(c); 493 jffs2_erase_pending_trigger(c);
490 down(&c->erase_free_sem); 494 mutex_lock(&c->erase_free_sem);
491 spin_lock(&c->erase_completion_lock); 495 spin_lock(&c->erase_completion_lock);
492 list_add(&jeb->list, &c->erase_complete_list); 496 list_move(&jeb->list, &c->erase_complete_list);
493 spin_unlock(&c->erase_completion_lock); 497 spin_unlock(&c->erase_completion_lock);
494 up(&c->erase_free_sem); 498 mutex_unlock(&c->erase_free_sem);
495 return; 499 return;
496} 500}
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
index dcc2734e0b5d..5e920343b2c5 100644
--- a/fs/jffs2/file.c
+++ b/fs/jffs2/file.c
@@ -115,9 +115,9 @@ static int jffs2_readpage (struct file *filp, struct page *pg)
115 struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host); 115 struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host);
116 int ret; 116 int ret;
117 117
118 down(&f->sem); 118 mutex_lock(&f->sem);
119 ret = jffs2_do_readpage_unlock(pg->mapping->host, pg); 119 ret = jffs2_do_readpage_unlock(pg->mapping->host, pg);
120 up(&f->sem); 120 mutex_unlock(&f->sem);
121 return ret; 121 return ret;
122} 122}
123 123
@@ -154,7 +154,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
154 if (ret) 154 if (ret)
155 goto out_page; 155 goto out_page;
156 156
157 down(&f->sem); 157 mutex_lock(&f->sem);
158 memset(&ri, 0, sizeof(ri)); 158 memset(&ri, 0, sizeof(ri));
159 159
160 ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 160 ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -181,7 +181,7 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
181 if (IS_ERR(fn)) { 181 if (IS_ERR(fn)) {
182 ret = PTR_ERR(fn); 182 ret = PTR_ERR(fn);
183 jffs2_complete_reservation(c); 183 jffs2_complete_reservation(c);
184 up(&f->sem); 184 mutex_unlock(&f->sem);
185 goto out_page; 185 goto out_page;
186 } 186 }
187 ret = jffs2_add_full_dnode_to_inode(c, f, fn); 187 ret = jffs2_add_full_dnode_to_inode(c, f, fn);
@@ -195,12 +195,12 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
195 jffs2_mark_node_obsolete(c, fn->raw); 195 jffs2_mark_node_obsolete(c, fn->raw);
196 jffs2_free_full_dnode(fn); 196 jffs2_free_full_dnode(fn);
197 jffs2_complete_reservation(c); 197 jffs2_complete_reservation(c);
198 up(&f->sem); 198 mutex_unlock(&f->sem);
199 goto out_page; 199 goto out_page;
200 } 200 }
201 jffs2_complete_reservation(c); 201 jffs2_complete_reservation(c);
202 inode->i_size = pageofs; 202 inode->i_size = pageofs;
203 up(&f->sem); 203 mutex_unlock(&f->sem);
204 } 204 }
205 205
206 /* 206 /*
@@ -209,9 +209,9 @@ static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
209 * case of a short-copy. 209 * case of a short-copy.
210 */ 210 */
211 if (!PageUptodate(pg)) { 211 if (!PageUptodate(pg)) {
212 down(&f->sem); 212 mutex_lock(&f->sem);
213 ret = jffs2_do_readpage_nolock(inode, pg); 213 ret = jffs2_do_readpage_nolock(inode, pg);
214 up(&f->sem); 214 mutex_unlock(&f->sem);
215 if (ret) 215 if (ret)
216 goto out_page; 216 goto out_page;
217 } 217 }
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index e26ea78c7892..3eb1c84b0a33 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -36,6 +36,7 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
36 unsigned int ivalid; 36 unsigned int ivalid;
37 uint32_t alloclen; 37 uint32_t alloclen;
38 int ret; 38 int ret;
39 int alloc_type = ALLOC_NORMAL;
39 40
40 D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino)); 41 D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino));
41 42
@@ -50,20 +51,20 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
50 mdata = (char *)&dev; 51 mdata = (char *)&dev;
51 D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of kdev_t\n", mdatalen)); 52 D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of kdev_t\n", mdatalen));
52 } else if (S_ISLNK(inode->i_mode)) { 53 } else if (S_ISLNK(inode->i_mode)) {
53 down(&f->sem); 54 mutex_lock(&f->sem);
54 mdatalen = f->metadata->size; 55 mdatalen = f->metadata->size;
55 mdata = kmalloc(f->metadata->size, GFP_USER); 56 mdata = kmalloc(f->metadata->size, GFP_USER);
56 if (!mdata) { 57 if (!mdata) {
57 up(&f->sem); 58 mutex_unlock(&f->sem);
58 return -ENOMEM; 59 return -ENOMEM;
59 } 60 }
60 ret = jffs2_read_dnode(c, f, f->metadata, mdata, 0, mdatalen); 61 ret = jffs2_read_dnode(c, f, f->metadata, mdata, 0, mdatalen);
61 if (ret) { 62 if (ret) {
62 up(&f->sem); 63 mutex_unlock(&f->sem);
63 kfree(mdata); 64 kfree(mdata);
64 return ret; 65 return ret;
65 } 66 }
66 up(&f->sem); 67 mutex_unlock(&f->sem);
67 D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of symlink target\n", mdatalen)); 68 D1(printk(KERN_DEBUG "jffs2_setattr(): Writing %d bytes of symlink target\n", mdatalen));
68 } 69 }
69 70
@@ -82,7 +83,7 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
82 kfree(mdata); 83 kfree(mdata);
83 return ret; 84 return ret;
84 } 85 }
85 down(&f->sem); 86 mutex_lock(&f->sem);
86 ivalid = iattr->ia_valid; 87 ivalid = iattr->ia_valid;
87 88
88 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 89 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -115,6 +116,10 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
115 ri->compr = JFFS2_COMPR_ZERO; 116 ri->compr = JFFS2_COMPR_ZERO;
116 ri->dsize = cpu_to_je32(iattr->ia_size - inode->i_size); 117 ri->dsize = cpu_to_je32(iattr->ia_size - inode->i_size);
117 ri->offset = cpu_to_je32(inode->i_size); 118 ri->offset = cpu_to_je32(inode->i_size);
119 } else if (ivalid & ATTR_SIZE && !iattr->ia_size) {
120 /* For truncate-to-zero, treat it as deletion because
121 it'll always be obsoleting all previous nodes */
122 alloc_type = ALLOC_DELETION;
118 } 123 }
119 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 124 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
120 if (mdatalen) 125 if (mdatalen)
@@ -122,14 +127,14 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
122 else 127 else
123 ri->data_crc = cpu_to_je32(0); 128 ri->data_crc = cpu_to_je32(0);
124 129
125 new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, ALLOC_NORMAL); 130 new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, alloc_type);
126 if (S_ISLNK(inode->i_mode)) 131 if (S_ISLNK(inode->i_mode))
127 kfree(mdata); 132 kfree(mdata);
128 133
129 if (IS_ERR(new_metadata)) { 134 if (IS_ERR(new_metadata)) {
130 jffs2_complete_reservation(c); 135 jffs2_complete_reservation(c);
131 jffs2_free_raw_inode(ri); 136 jffs2_free_raw_inode(ri);
132 up(&f->sem); 137 mutex_unlock(&f->sem);
133 return PTR_ERR(new_metadata); 138 return PTR_ERR(new_metadata);
134 } 139 }
135 /* It worked. Update the inode */ 140 /* It worked. Update the inode */
@@ -149,6 +154,7 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
149 if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) { 154 if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) {
150 jffs2_add_full_dnode_to_inode(c, f, new_metadata); 155 jffs2_add_full_dnode_to_inode(c, f, new_metadata);
151 inode->i_size = iattr->ia_size; 156 inode->i_size = iattr->ia_size;
157 inode->i_blocks = (inode->i_size + 511) >> 9;
152 f->metadata = NULL; 158 f->metadata = NULL;
153 } else { 159 } else {
154 f->metadata = new_metadata; 160 f->metadata = new_metadata;
@@ -159,7 +165,7 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
159 } 165 }
160 jffs2_free_raw_inode(ri); 166 jffs2_free_raw_inode(ri);
161 167
162 up(&f->sem); 168 mutex_unlock(&f->sem);
163 jffs2_complete_reservation(c); 169 jffs2_complete_reservation(c);
164 170
165 /* We have to do the vmtruncate() without f->sem held, since 171 /* We have to do the vmtruncate() without f->sem held, since
@@ -167,8 +173,10 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
167 We are protected from a simultaneous write() extending i_size 173 We are protected from a simultaneous write() extending i_size
168 back past iattr->ia_size, because do_truncate() holds the 174 back past iattr->ia_size, because do_truncate() holds the
169 generic inode semaphore. */ 175 generic inode semaphore. */
170 if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) 176 if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
171 vmtruncate(inode, iattr->ia_size); 177 vmtruncate(inode, iattr->ia_size);
178 inode->i_blocks = (inode->i_size + 511) >> 9;
179 }
172 180
173 return 0; 181 return 0;
174} 182}
@@ -248,12 +256,12 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
248 c = JFFS2_SB_INFO(inode->i_sb); 256 c = JFFS2_SB_INFO(inode->i_sb);
249 257
250 jffs2_init_inode_info(f); 258 jffs2_init_inode_info(f);
251 down(&f->sem); 259 mutex_lock(&f->sem);
252 260
253 ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node); 261 ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node);
254 262
255 if (ret) { 263 if (ret) {
256 up(&f->sem); 264 mutex_unlock(&f->sem);
257 iget_failed(inode); 265 iget_failed(inode);
258 return ERR_PTR(ret); 266 return ERR_PTR(ret);
259 } 267 }
@@ -330,7 +338,7 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
330 printk(KERN_WARNING "jffs2_read_inode(): Bogus imode %o for ino %lu\n", inode->i_mode, (unsigned long)inode->i_ino); 338 printk(KERN_WARNING "jffs2_read_inode(): Bogus imode %o for ino %lu\n", inode->i_mode, (unsigned long)inode->i_ino);
331 } 339 }
332 340
333 up(&f->sem); 341 mutex_unlock(&f->sem);
334 342
335 D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n")); 343 D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n"));
336 unlock_new_inode(inode); 344 unlock_new_inode(inode);
@@ -339,7 +347,7 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
339error_io: 347error_io:
340 ret = -EIO; 348 ret = -EIO;
341error: 349error:
342 up(&f->sem); 350 mutex_unlock(&f->sem);
343 jffs2_do_clear_inode(c, f); 351 jffs2_do_clear_inode(c, f);
344 iget_failed(inode); 352 iget_failed(inode);
345 return ERR_PTR(ret); 353 return ERR_PTR(ret);
@@ -380,9 +388,9 @@ int jffs2_remount_fs (struct super_block *sb, int *flags, char *data)
380 Flush the writebuffer, if neccecary, else we loose it */ 388 Flush the writebuffer, if neccecary, else we loose it */
381 if (!(sb->s_flags & MS_RDONLY)) { 389 if (!(sb->s_flags & MS_RDONLY)) {
382 jffs2_stop_garbage_collect_thread(c); 390 jffs2_stop_garbage_collect_thread(c);
383 down(&c->alloc_sem); 391 mutex_lock(&c->alloc_sem);
384 jffs2_flush_wbuf_pad(c); 392 jffs2_flush_wbuf_pad(c);
385 up(&c->alloc_sem); 393 mutex_unlock(&c->alloc_sem);
386 } 394 }
387 395
388 if (!(*flags & MS_RDONLY)) 396 if (!(*flags & MS_RDONLY))
@@ -429,7 +437,7 @@ struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_i
429 437
430 f = JFFS2_INODE_INFO(inode); 438 f = JFFS2_INODE_INFO(inode);
431 jffs2_init_inode_info(f); 439 jffs2_init_inode_info(f);
432 down(&f->sem); 440 mutex_lock(&f->sem);
433 441
434 memset(ri, 0, sizeof(*ri)); 442 memset(ri, 0, sizeof(*ri));
435 /* Set OS-specific defaults for new inodes */ 443 /* Set OS-specific defaults for new inodes */
diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c
index 32ff0373aa04..bad005664e30 100644
--- a/fs/jffs2/gc.c
+++ b/fs/jffs2/gc.c
@@ -126,7 +126,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
126 int ret = 0, inum, nlink; 126 int ret = 0, inum, nlink;
127 int xattr = 0; 127 int xattr = 0;
128 128
129 if (down_interruptible(&c->alloc_sem)) 129 if (mutex_lock_interruptible(&c->alloc_sem))
130 return -EINTR; 130 return -EINTR;
131 131
132 for (;;) { 132 for (;;) {
@@ -143,7 +143,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
143 c->unchecked_size); 143 c->unchecked_size);
144 jffs2_dbg_dump_block_lists_nolock(c); 144 jffs2_dbg_dump_block_lists_nolock(c);
145 spin_unlock(&c->erase_completion_lock); 145 spin_unlock(&c->erase_completion_lock);
146 up(&c->alloc_sem); 146 mutex_unlock(&c->alloc_sem);
147 return -ENOSPC; 147 return -ENOSPC;
148 } 148 }
149 149
@@ -190,7 +190,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
190 made no progress in this case, but that should be OK */ 190 made no progress in this case, but that should be OK */
191 c->checked_ino--; 191 c->checked_ino--;
192 192
193 up(&c->alloc_sem); 193 mutex_unlock(&c->alloc_sem);
194 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock); 194 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
195 return 0; 195 return 0;
196 196
@@ -210,7 +210,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
210 printk(KERN_WARNING "Returned error for crccheck of ino #%u. Expect badness...\n", ic->ino); 210 printk(KERN_WARNING "Returned error for crccheck of ino #%u. Expect badness...\n", ic->ino);
211 211
212 jffs2_set_inocache_state(c, ic, INO_STATE_CHECKEDABSENT); 212 jffs2_set_inocache_state(c, ic, INO_STATE_CHECKEDABSENT);
213 up(&c->alloc_sem); 213 mutex_unlock(&c->alloc_sem);
214 return ret; 214 return ret;
215 } 215 }
216 216
@@ -221,9 +221,15 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
221 jeb = jffs2_find_gc_block(c); 221 jeb = jffs2_find_gc_block(c);
222 222
223 if (!jeb) { 223 if (!jeb) {
224 D1 (printk(KERN_NOTICE "jffs2: Couldn't find erase block to garbage collect!\n")); 224 /* Couldn't find a free block. But maybe we can just erase one and make 'progress'? */
225 if (!list_empty(&c->erase_pending_list)) {
226 spin_unlock(&c->erase_completion_lock);
227 mutex_unlock(&c->alloc_sem);
228 return -EAGAIN;
229 }
230 D1(printk(KERN_NOTICE "jffs2: Couldn't find erase block to garbage collect!\n"));
225 spin_unlock(&c->erase_completion_lock); 231 spin_unlock(&c->erase_completion_lock);
226 up(&c->alloc_sem); 232 mutex_unlock(&c->alloc_sem);
227 return -EIO; 233 return -EIO;
228 } 234 }
229 235
@@ -232,7 +238,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
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)); 238 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 239
234 if (!jeb->used_size) { 240 if (!jeb->used_size) {
235 up(&c->alloc_sem); 241 mutex_unlock(&c->alloc_sem);
236 goto eraseit; 242 goto eraseit;
237 } 243 }
238 244
@@ -248,7 +254,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
248 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size); 254 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size);
249 jeb->gc_node = raw; 255 jeb->gc_node = raw;
250 spin_unlock(&c->erase_completion_lock); 256 spin_unlock(&c->erase_completion_lock);
251 up(&c->alloc_sem); 257 mutex_unlock(&c->alloc_sem);
252 BUG(); 258 BUG();
253 } 259 }
254 } 260 }
@@ -266,7 +272,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
266 /* Just mark it obsolete */ 272 /* Just mark it obsolete */
267 jffs2_mark_node_obsolete(c, raw); 273 jffs2_mark_node_obsolete(c, raw);
268 } 274 }
269 up(&c->alloc_sem); 275 mutex_unlock(&c->alloc_sem);
270 goto eraseit_lock; 276 goto eraseit_lock;
271 } 277 }
272 278
@@ -334,7 +340,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
334 */ 340 */
335 printk(KERN_CRIT "Inode #%u already in state %d in jffs2_garbage_collect_pass()!\n", 341 printk(KERN_CRIT "Inode #%u already in state %d in jffs2_garbage_collect_pass()!\n",
336 ic->ino, ic->state); 342 ic->ino, ic->state);
337 up(&c->alloc_sem); 343 mutex_unlock(&c->alloc_sem);
338 spin_unlock(&c->inocache_lock); 344 spin_unlock(&c->inocache_lock);
339 BUG(); 345 BUG();
340 346
@@ -345,7 +351,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
345 the alloc_sem() (for marking nodes invalid) so we must 351 the alloc_sem() (for marking nodes invalid) so we must
346 drop the alloc_sem before sleeping. */ 352 drop the alloc_sem before sleeping. */
347 353
348 up(&c->alloc_sem); 354 mutex_unlock(&c->alloc_sem);
349 D1(printk(KERN_DEBUG "jffs2_garbage_collect_pass() waiting for ino #%u in state %d\n", 355 D1(printk(KERN_DEBUG "jffs2_garbage_collect_pass() waiting for ino #%u in state %d\n",
350 ic->ino, ic->state)); 356 ic->ino, ic->state));
351 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock); 357 sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
@@ -416,7 +422,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
416 ret = -ENOSPC; 422 ret = -ENOSPC;
417 } 423 }
418 release_sem: 424 release_sem:
419 up(&c->alloc_sem); 425 mutex_unlock(&c->alloc_sem);
420 426
421 eraseit_lock: 427 eraseit_lock:
422 /* If we've finished this block, start it erasing */ 428 /* If we've finished this block, start it erasing */
@@ -445,7 +451,7 @@ static int jffs2_garbage_collect_live(struct jffs2_sb_info *c, struct jffs2_era
445 uint32_t start = 0, end = 0, nrfrags = 0; 451 uint32_t start = 0, end = 0, nrfrags = 0;
446 int ret = 0; 452 int ret = 0;
447 453
448 down(&f->sem); 454 mutex_lock(&f->sem);
449 455
450 /* Now we have the lock for this inode. Check that it's still the one at the head 456 /* Now we have the lock for this inode. Check that it's still the one at the head
451 of the list. */ 457 of the list. */
@@ -525,7 +531,7 @@ static int jffs2_garbage_collect_live(struct jffs2_sb_info *c, struct jffs2_era
525 } 531 }
526 } 532 }
527 upnout: 533 upnout:
528 up(&f->sem); 534 mutex_unlock(&f->sem);
529 535
530 return ret; 536 return ret;
531} 537}
@@ -846,7 +852,7 @@ static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct
846 /* Prevent the erase code from nicking the obsolete node refs while 852 /* Prevent the erase code from nicking the obsolete node refs while
847 we're looking at them. I really don't like this extra lock but 853 we're looking at them. I really don't like this extra lock but
848 can't see any alternative. Suggestions on a postcard to... */ 854 can't see any alternative. Suggestions on a postcard to... */
849 down(&c->erase_free_sem); 855 mutex_lock(&c->erase_free_sem);
850 856
851 for (raw = f->inocache->nodes; raw != (void *)f->inocache; raw = raw->next_in_ino) { 857 for (raw = f->inocache->nodes; raw != (void *)f->inocache; raw = raw->next_in_ino) {
852 858
@@ -899,7 +905,7 @@ static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct
899 /* OK. The name really does match. There really is still an older node on 905 /* OK. The name really does match. There really is still an older node on
900 the flash which our deletion dirent obsoletes. So we have to write out 906 the flash which our deletion dirent obsoletes. So we have to write out
901 a new deletion dirent to replace it */ 907 a new deletion dirent to replace it */
902 up(&c->erase_free_sem); 908 mutex_unlock(&c->erase_free_sem);
903 909
904 D1(printk(KERN_DEBUG "Deletion dirent at %08x still obsoletes real dirent \"%s\" at %08x for ino #%u\n", 910 D1(printk(KERN_DEBUG "Deletion dirent at %08x still obsoletes real dirent \"%s\" at %08x for ino #%u\n",
905 ref_offset(fd->raw), fd->name, ref_offset(raw), je32_to_cpu(rd->ino))); 911 ref_offset(fd->raw), fd->name, ref_offset(raw), je32_to_cpu(rd->ino)));
@@ -908,7 +914,7 @@ static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct
908 return jffs2_garbage_collect_dirent(c, jeb, f, fd); 914 return jffs2_garbage_collect_dirent(c, jeb, f, fd);
909 } 915 }
910 916
911 up(&c->erase_free_sem); 917 mutex_unlock(&c->erase_free_sem);
912 kfree(rd); 918 kfree(rd);
913 } 919 }
914 920
@@ -1081,7 +1087,7 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
1081 return 0; 1087 return 0;
1082} 1088}
1083 1089
1084static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 1090static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *orig_jeb,
1085 struct jffs2_inode_info *f, struct jffs2_full_dnode *fn, 1091 struct jffs2_inode_info *f, struct jffs2_full_dnode *fn,
1086 uint32_t start, uint32_t end) 1092 uint32_t start, uint32_t end)
1087{ 1093{
diff --git a/fs/jffs2/ioctl.c b/fs/jffs2/ioctl.c
index f4d525b0ea53..e2177210f621 100644
--- a/fs/jffs2/ioctl.c
+++ b/fs/jffs2/ioctl.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/fs.h> 12#include <linux/fs.h>
13#include "nodelist.h"
13 14
14int jffs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, 15int jffs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
15 unsigned long arg) 16 unsigned long arg)
diff --git a/fs/jffs2/jffs2_fs_i.h b/fs/jffs2/jffs2_fs_i.h
index a841f4973a74..31559f45fdde 100644
--- a/fs/jffs2/jffs2_fs_i.h
+++ b/fs/jffs2/jffs2_fs_i.h
@@ -15,7 +15,7 @@
15#include <linux/version.h> 15#include <linux/version.h>
16#include <linux/rbtree.h> 16#include <linux/rbtree.h>
17#include <linux/posix_acl.h> 17#include <linux/posix_acl.h>
18#include <linux/semaphore.h> 18#include <linux/mutex.h>
19 19
20struct jffs2_inode_info { 20struct jffs2_inode_info {
21 /* We need an internal mutex similar to inode->i_mutex. 21 /* We need an internal mutex similar to inode->i_mutex.
@@ -24,7 +24,7 @@ struct jffs2_inode_info {
24 before letting GC proceed. Or we'd have to put ugliness 24 before letting GC proceed. Or we'd have to put ugliness
25 into the GC code so it didn't attempt to obtain the i_mutex 25 into the GC code so it didn't attempt to obtain the i_mutex
26 for the inode(s) which are already locked */ 26 for the inode(s) which are already locked */
27 struct semaphore sem; 27 struct mutex sem;
28 28
29 /* The highest (datanode) version number used for this ino */ 29 /* The highest (datanode) version number used for this ino */
30 uint32_t highest_version; 30 uint32_t highest_version;
diff --git a/fs/jffs2/jffs2_fs_sb.h b/fs/jffs2/jffs2_fs_sb.h
index 18fca2b9e531..85ef6dbb1be7 100644
--- a/fs/jffs2/jffs2_fs_sb.h
+++ b/fs/jffs2/jffs2_fs_sb.h
@@ -16,7 +16,7 @@
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/workqueue.h> 17#include <linux/workqueue.h>
18#include <linux/completion.h> 18#include <linux/completion.h>
19#include <linux/semaphore.h> 19#include <linux/mutex.h>
20#include <linux/timer.h> 20#include <linux/timer.h>
21#include <linux/wait.h> 21#include <linux/wait.h>
22#include <linux/list.h> 22#include <linux/list.h>
@@ -44,7 +44,7 @@ struct jffs2_sb_info {
44 struct completion gc_thread_start; /* GC thread start completion */ 44 struct completion gc_thread_start; /* GC thread start completion */
45 struct completion gc_thread_exit; /* GC thread exit completion port */ 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 fields, and also to protect against 48 fields, and also to protect against
49 out-of-order writing of nodes. And GC. */ 49 out-of-order writing of nodes. And GC. */
50 uint32_t cleanmarker_size; /* Size of an _inline_ CLEANMARKER 50 uint32_t cleanmarker_size; /* Size of an _inline_ CLEANMARKER
@@ -87,6 +87,7 @@ struct jffs2_sb_info {
87 struct list_head erasable_list; /* Blocks which are completely dirty, and need erasing */ 87 struct list_head erasable_list; /* Blocks which are completely dirty, and need erasing */
88 struct list_head erasable_pending_wbuf_list; /* Blocks which need erasing but only after the current wbuf is flushed */ 88 struct list_head erasable_pending_wbuf_list; /* Blocks which need erasing but only after the current wbuf is flushed */
89 struct list_head erasing_list; /* Blocks which are currently erasing */ 89 struct list_head erasing_list; /* Blocks which are currently erasing */
90 struct list_head erase_checking_list; /* Blocks which are being checked and marked */
90 struct list_head erase_pending_list; /* Blocks which need erasing now */ 91 struct list_head erase_pending_list; /* Blocks which need erasing now */
91 struct list_head erase_complete_list; /* Blocks which are erased and need the clean marker written to them */ 92 struct list_head erase_complete_list; /* Blocks which are erased and need the clean marker written to them */
92 struct list_head free_list; /* Blocks which are free and ready to be used */ 93 struct list_head free_list; /* Blocks which are free and ready to be used */
@@ -104,7 +105,7 @@ struct jffs2_sb_info {
104 /* Sem to allow jffs2_garbage_collect_deletion_dirent to 105 /* Sem to allow jffs2_garbage_collect_deletion_dirent to
105 drop the erase_completion_lock while it's holding a pointer 106 drop the erase_completion_lock while it's holding a pointer
106 to an obsoleted node. I don't like this. Alternatives welcomed. */ 107 to an obsoleted node. I don't like this. Alternatives welcomed. */
107 struct semaphore erase_free_sem; 108 struct mutex erase_free_sem;
108 109
109 uint32_t wbuf_pagesize; /* 0 for NOR and other flashes with no wbuf */ 110 uint32_t wbuf_pagesize; /* 0 for NOR and other flashes with no wbuf */
110 111
diff --git a/fs/jffs2/nodelist.h b/fs/jffs2/nodelist.h
index ec1aae9e695e..8219df6eb6d8 100644
--- a/fs/jffs2/nodelist.h
+++ b/fs/jffs2/nodelist.h
@@ -87,7 +87,7 @@ struct jffs2_raw_node_ref
87 xattr_ref or xattr_datum instead. The common part of those structures 87 xattr_ref or xattr_datum instead. The common part of those structures
88 has NULL in the first word. See jffs2_raw_ref_to_ic() below */ 88 has NULL in the first word. See jffs2_raw_ref_to_ic() below */
89 uint32_t flash_offset; 89 uint32_t flash_offset;
90#define TEST_TOTLEN 90#undef TEST_TOTLEN
91#ifdef TEST_TOTLEN 91#ifdef TEST_TOTLEN
92 uint32_t __totlen; /* This may die; use ref_totlen(c, jeb, ) below */ 92 uint32_t __totlen; /* This may die; use ref_totlen(c, jeb, ) below */
93#endif 93#endif
diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c
index a0313fa8748e..9df8f3ef20df 100644
--- a/fs/jffs2/nodemgmt.c
+++ b/fs/jffs2/nodemgmt.c
@@ -48,7 +48,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
48 minsize = PAD(minsize); 48 minsize = PAD(minsize);
49 49
50 D1(printk(KERN_DEBUG "jffs2_reserve_space(): Requested 0x%x bytes\n", minsize)); 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 D1(printk(KERN_DEBUG "jffs2_reserve_space(): alloc sem got\n")); 53 D1(printk(KERN_DEBUG "jffs2_reserve_space(): alloc sem got\n"));
54 54
@@ -57,7 +57,6 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
57 /* this needs a little more thought (true <tglx> :)) */ 57 /* this needs a little more thought (true <tglx> :)) */
58 while(ret == -EAGAIN) { 58 while(ret == -EAGAIN) {
59 while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) { 59 while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) {
60 int ret;
61 uint32_t dirty, avail; 60 uint32_t dirty, avail;
62 61
63 /* calculate real dirty size 62 /* calculate real dirty size
@@ -82,7 +81,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
82 dirty, c->unchecked_size, c->sector_size)); 81 dirty, c->unchecked_size, c->sector_size));
83 82
84 spin_unlock(&c->erase_completion_lock); 83 spin_unlock(&c->erase_completion_lock);
85 up(&c->alloc_sem); 84 mutex_unlock(&c->alloc_sem);
86 return -ENOSPC; 85 return -ENOSPC;
87 } 86 }
88 87
@@ -105,11 +104,11 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
105 D1(printk(KERN_DEBUG "max. available size 0x%08x < blocksneeded * sector_size 0x%08x, returning -ENOSPC\n", 104 D1(printk(KERN_DEBUG "max. available size 0x%08x < blocksneeded * sector_size 0x%08x, returning -ENOSPC\n",
106 avail, blocksneeded * c->sector_size)); 105 avail, blocksneeded * c->sector_size));
107 spin_unlock(&c->erase_completion_lock); 106 spin_unlock(&c->erase_completion_lock);
108 up(&c->alloc_sem); 107 mutex_unlock(&c->alloc_sem);
109 return -ENOSPC; 108 return -ENOSPC;
110 } 109 }
111 110
112 up(&c->alloc_sem); 111 mutex_unlock(&c->alloc_sem);
113 112
114 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", 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",
115 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, 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,
@@ -117,7 +116,10 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
117 spin_unlock(&c->erase_completion_lock); 116 spin_unlock(&c->erase_completion_lock);
118 117
119 ret = jffs2_garbage_collect_pass(c); 118 ret = jffs2_garbage_collect_pass(c);
120 if (ret) 119
120 if (ret == -EAGAIN)
121 jffs2_erase_pending_blocks(c, 1);
122 else if (ret)
121 return ret; 123 return ret;
122 124
123 cond_resched(); 125 cond_resched();
@@ -125,7 +127,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
125 if (signal_pending(current)) 127 if (signal_pending(current))
126 return -EINTR; 128 return -EINTR;
127 129
128 down(&c->alloc_sem); 130 mutex_lock(&c->alloc_sem);
129 spin_lock(&c->erase_completion_lock); 131 spin_lock(&c->erase_completion_lock);
130 } 132 }
131 133
@@ -138,7 +140,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
138 if (!ret) 140 if (!ret)
139 ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1); 141 ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1);
140 if (ret) 142 if (ret)
141 up(&c->alloc_sem); 143 mutex_unlock(&c->alloc_sem);
142 return ret; 144 return ret;
143} 145}
144 146
@@ -463,7 +465,7 @@ void jffs2_complete_reservation(struct jffs2_sb_info *c)
463{ 465{
464 D1(printk(KERN_DEBUG "jffs2_complete_reservation()\n")); 466 D1(printk(KERN_DEBUG "jffs2_complete_reservation()\n"));
465 jffs2_garbage_collect_trigger(c); 467 jffs2_garbage_collect_trigger(c);
466 up(&c->alloc_sem); 468 mutex_unlock(&c->alloc_sem);
467} 469}
468 470
469static inline int on_list(struct list_head *obj, struct list_head *head) 471static inline int on_list(struct list_head *obj, struct list_head *head)
@@ -512,7 +514,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
512 any jffs2_raw_node_refs. So we don't need to stop erases from 514 any jffs2_raw_node_refs. So we don't need to stop erases from
513 happening, or protect against people holding an obsolete 515 happening, or protect against people holding an obsolete
514 jffs2_raw_node_ref without the erase_completion_lock. */ 516 jffs2_raw_node_ref without the erase_completion_lock. */
515 down(&c->erase_free_sem); 517 mutex_lock(&c->erase_free_sem);
516 } 518 }
517 519
518 spin_lock(&c->erase_completion_lock); 520 spin_lock(&c->erase_completion_lock);
@@ -715,7 +717,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
715 } 717 }
716 718
717 out_erase_sem: 719 out_erase_sem:
718 up(&c->erase_free_sem); 720 mutex_unlock(&c->erase_free_sem);
719} 721}
720 722
721int jffs2_thread_should_wake(struct jffs2_sb_info *c) 723int jffs2_thread_should_wake(struct jffs2_sb_info *c)
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index e512a93d6249..4cb4d76de07f 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -825,8 +825,9 @@ static inline int read_dnode(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
825 else // normal case... 825 else // normal case...
826 tn->fn->size = je32_to_cpu(rd->dsize); 826 tn->fn->size = je32_to_cpu(rd->dsize);
827 827
828 dbg_readinode("dnode @%08x: ver %u, offset %#04x, dsize %#04x, csize %#04x\n", 828 dbg_readinode2("dnode @%08x: ver %u, offset %#04x, dsize %#04x, csize %#04x\n",
829 ref_offset(ref), je32_to_cpu(rd->version), je32_to_cpu(rd->offset), je32_to_cpu(rd->dsize), csize); 829 ref_offset(ref), je32_to_cpu(rd->version),
830 je32_to_cpu(rd->offset), je32_to_cpu(rd->dsize), csize);
830 831
831 ret = jffs2_add_tn_to_tree(c, rii, tn); 832 ret = jffs2_add_tn_to_tree(c, rii, tn);
832 833
@@ -836,13 +837,13 @@ static inline int read_dnode(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
836 jffs2_free_tmp_dnode_info(tn); 837 jffs2_free_tmp_dnode_info(tn);
837 return ret; 838 return ret;
838 } 839 }
839#ifdef JFFS2_DBG_READINODE_MESSAGES 840#ifdef JFFS2_DBG_READINODE2_MESSAGES
840 dbg_readinode("After adding ver %d:\n", je32_to_cpu(rd->version)); 841 dbg_readinode2("After adding ver %d:\n", je32_to_cpu(rd->version));
841 tn = tn_first(&rii->tn_root); 842 tn = tn_first(&rii->tn_root);
842 while (tn) { 843 while (tn) {
843 dbg_readinode("%p: v %d r 0x%x-0x%x ov %d\n", 844 dbg_readinode2("%p: v %d r 0x%x-0x%x ov %d\n",
844 tn, tn->version, tn->fn->ofs, 845 tn, tn->version, tn->fn->ofs,
845 tn->fn->ofs+tn->fn->size, tn->overlapped); 846 tn->fn->ofs+tn->fn->size, tn->overlapped);
846 tn = tn_next(tn); 847 tn = tn_next(tn);
847 } 848 }
848#endif 849#endif
@@ -1193,7 +1194,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1193 JFFS2_ERROR("failed to read from flash: error %d, %zd of %zd bytes read\n", 1194 JFFS2_ERROR("failed to read from flash: error %d, %zd of %zd bytes read\n",
1194 ret, retlen, sizeof(*latest_node)); 1195 ret, retlen, sizeof(*latest_node));
1195 /* FIXME: If this fails, there seems to be a memory leak. Find it. */ 1196 /* FIXME: If this fails, there seems to be a memory leak. Find it. */
1196 up(&f->sem); 1197 mutex_unlock(&f->sem);
1197 jffs2_do_clear_inode(c, f); 1198 jffs2_do_clear_inode(c, f);
1198 return ret?ret:-EIO; 1199 return ret?ret:-EIO;
1199 } 1200 }
@@ -1202,7 +1203,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1202 if (crc != je32_to_cpu(latest_node->node_crc)) { 1203 if (crc != je32_to_cpu(latest_node->node_crc)) {
1203 JFFS2_ERROR("CRC failed for read_inode of inode %u at physical location 0x%x\n", 1204 JFFS2_ERROR("CRC failed for read_inode of inode %u at physical location 0x%x\n",
1204 f->inocache->ino, ref_offset(rii.latest_ref)); 1205 f->inocache->ino, ref_offset(rii.latest_ref));
1205 up(&f->sem); 1206 mutex_unlock(&f->sem);
1206 jffs2_do_clear_inode(c, f); 1207 jffs2_do_clear_inode(c, f);
1207 return -EIO; 1208 return -EIO;
1208 } 1209 }
@@ -1242,7 +1243,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1242 f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL); 1243 f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL);
1243 if (!f->target) { 1244 if (!f->target) {
1244 JFFS2_ERROR("can't allocate %d bytes of memory for the symlink target path cache\n", je32_to_cpu(latest_node->csize)); 1245 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); 1246 mutex_unlock(&f->sem);
1246 jffs2_do_clear_inode(c, f); 1247 jffs2_do_clear_inode(c, f);
1247 return -ENOMEM; 1248 return -ENOMEM;
1248 } 1249 }
@@ -1255,7 +1256,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1255 ret = -EIO; 1256 ret = -EIO;
1256 kfree(f->target); 1257 kfree(f->target);
1257 f->target = NULL; 1258 f->target = NULL;
1258 up(&f->sem); 1259 mutex_unlock(&f->sem);
1259 jffs2_do_clear_inode(c, f); 1260 jffs2_do_clear_inode(c, f);
1260 return -ret; 1261 return -ret;
1261 } 1262 }
@@ -1273,14 +1274,14 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1273 if (f->metadata) { 1274 if (f->metadata) {
1274 JFFS2_ERROR("Argh. Special inode #%u with mode 0%o had metadata node\n", 1275 JFFS2_ERROR("Argh. Special inode #%u with mode 0%o had metadata node\n",
1275 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 1276 f->inocache->ino, jemode_to_cpu(latest_node->mode));
1276 up(&f->sem); 1277 mutex_unlock(&f->sem);
1277 jffs2_do_clear_inode(c, f); 1278 jffs2_do_clear_inode(c, f);
1278 return -EIO; 1279 return -EIO;
1279 } 1280 }
1280 if (!frag_first(&f->fragtree)) { 1281 if (!frag_first(&f->fragtree)) {
1281 JFFS2_ERROR("Argh. Special inode #%u with mode 0%o has no fragments\n", 1282 JFFS2_ERROR("Argh. Special inode #%u with mode 0%o has no fragments\n",
1282 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 1283 f->inocache->ino, jemode_to_cpu(latest_node->mode));
1283 up(&f->sem); 1284 mutex_unlock(&f->sem);
1284 jffs2_do_clear_inode(c, f); 1285 jffs2_do_clear_inode(c, f);
1285 return -EIO; 1286 return -EIO;
1286 } 1287 }
@@ -1289,7 +1290,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1289 JFFS2_ERROR("Argh. Special inode #%u with mode 0x%x had more than one node\n", 1290 JFFS2_ERROR("Argh. Special inode #%u with mode 0x%x had more than one node\n",
1290 f->inocache->ino, jemode_to_cpu(latest_node->mode)); 1291 f->inocache->ino, jemode_to_cpu(latest_node->mode));
1291 /* FIXME: Deal with it - check crc32, check for duplicate node, check times and discard the older one */ 1292 /* FIXME: Deal with it - check crc32, check for duplicate node, check times and discard the older one */
1292 up(&f->sem); 1293 mutex_unlock(&f->sem);
1293 jffs2_do_clear_inode(c, f); 1294 jffs2_do_clear_inode(c, f);
1294 return -EIO; 1295 return -EIO;
1295 } 1296 }
@@ -1379,12 +1380,13 @@ int jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *i
1379 if (!f) 1380 if (!f)
1380 return -ENOMEM; 1381 return -ENOMEM;
1381 1382
1382 init_MUTEX_LOCKED(&f->sem); 1383 mutex_init(&f->sem);
1384 mutex_lock(&f->sem);
1383 f->inocache = ic; 1385 f->inocache = ic;
1384 1386
1385 ret = jffs2_do_read_inode_internal(c, f, &n); 1387 ret = jffs2_do_read_inode_internal(c, f, &n);
1386 if (!ret) { 1388 if (!ret) {
1387 up(&f->sem); 1389 mutex_unlock(&f->sem);
1388 jffs2_do_clear_inode(c, f); 1390 jffs2_do_clear_inode(c, f);
1389 } 1391 }
1390 kfree (f); 1392 kfree (f);
@@ -1398,7 +1400,7 @@ void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f)
1398 1400
1399 jffs2_clear_acl(f); 1401 jffs2_clear_acl(f);
1400 jffs2_xattr_delete_inode(c, f->inocache); 1402 jffs2_xattr_delete_inode(c, f->inocache);
1401 down(&f->sem); 1403 mutex_lock(&f->sem);
1402 deleted = f->inocache && !f->inocache->nlink; 1404 deleted = f->inocache && !f->inocache->nlink;
1403 1405
1404 if (f->inocache && f->inocache->state != INO_STATE_CHECKING) 1406 if (f->inocache && f->inocache->state != INO_STATE_CHECKING)
@@ -1430,5 +1432,5 @@ void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f)
1430 jffs2_del_ino_cache(c, f->inocache); 1432 jffs2_del_ino_cache(c, f->inocache);
1431 } 1433 }
1432 1434
1433 up(&f->sem); 1435 mutex_unlock(&f->sem);
1434} 1436}
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 4677355996cc..f3353df178e7 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -47,7 +47,7 @@ static void jffs2_i_init_once(struct kmem_cache *cachep, void *foo)
47{ 47{
48 struct jffs2_inode_info *ei = (struct jffs2_inode_info *) foo; 48 struct jffs2_inode_info *ei = (struct jffs2_inode_info *) foo;
49 49
50 init_MUTEX(&ei->sem); 50 mutex_init(&ei->sem);
51 inode_init_once(&ei->vfs_inode); 51 inode_init_once(&ei->vfs_inode);
52} 52}
53 53
@@ -55,9 +55,9 @@ static int jffs2_sync_fs(struct super_block *sb, int wait)
55{ 55{
56 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); 56 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
57 57
58 down(&c->alloc_sem); 58 mutex_lock(&c->alloc_sem);
59 jffs2_flush_wbuf_pad(c); 59 jffs2_flush_wbuf_pad(c);
60 up(&c->alloc_sem); 60 mutex_unlock(&c->alloc_sem);
61 return 0; 61 return 0;
62} 62}
63 63
@@ -95,8 +95,8 @@ static int jffs2_fill_super(struct super_block *sb, void *data, int silent)
95 95
96 /* Initialize JFFS2 superblock locks, the further initialization will 96 /* Initialize JFFS2 superblock locks, the further initialization will
97 * be done later */ 97 * be done later */
98 init_MUTEX(&c->alloc_sem); 98 mutex_init(&c->alloc_sem);
99 init_MUTEX(&c->erase_free_sem); 99 mutex_init(&c->erase_free_sem);
100 init_waitqueue_head(&c->erase_wait); 100 init_waitqueue_head(&c->erase_wait);
101 init_waitqueue_head(&c->inocache_wq); 101 init_waitqueue_head(&c->inocache_wq);
102 spin_lock_init(&c->erase_completion_lock); 102 spin_lock_init(&c->erase_completion_lock);
@@ -125,9 +125,9 @@ static void jffs2_put_super (struct super_block *sb)
125 125
126 D2(printk(KERN_DEBUG "jffs2: jffs2_put_super()\n")); 126 D2(printk(KERN_DEBUG "jffs2: jffs2_put_super()\n"));
127 127
128 down(&c->alloc_sem); 128 mutex_lock(&c->alloc_sem);
129 jffs2_flush_wbuf_pad(c); 129 jffs2_flush_wbuf_pad(c);
130 up(&c->alloc_sem); 130 mutex_unlock(&c->alloc_sem);
131 131
132 jffs2_sum_exit(c); 132 jffs2_sum_exit(c);
133 133
diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index d1d4f27464ba..8de52b607678 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -578,8 +578,8 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
578 if (!jffs2_is_writebuffered(c)) 578 if (!jffs2_is_writebuffered(c))
579 return 0; 579 return 0;
580 580
581 if (!down_trylock(&c->alloc_sem)) { 581 if (mutex_trylock(&c->alloc_sem)) {
582 up(&c->alloc_sem); 582 mutex_unlock(&c->alloc_sem);
583 printk(KERN_CRIT "jffs2_flush_wbuf() called with alloc_sem not locked!\n"); 583 printk(KERN_CRIT "jffs2_flush_wbuf() called with alloc_sem not locked!\n");
584 BUG(); 584 BUG();
585 } 585 }
@@ -702,10 +702,10 @@ int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino)
702 if (!c->wbuf) 702 if (!c->wbuf)
703 return 0; 703 return 0;
704 704
705 down(&c->alloc_sem); 705 mutex_lock(&c->alloc_sem);
706 if (!jffs2_wbuf_pending_for_ino(c, ino)) { 706 if (!jffs2_wbuf_pending_for_ino(c, ino)) {
707 D1(printk(KERN_DEBUG "Ino #%d not pending in wbuf. Returning\n", ino)); 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 return 0; 709 return 0;
710 } 710 }
711 711
@@ -725,14 +725,14 @@ int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino)
725 } else while (old_wbuf_len && 725 } else while (old_wbuf_len &&
726 old_wbuf_ofs == c->wbuf_ofs) { 726 old_wbuf_ofs == c->wbuf_ofs) {
727 727
728 up(&c->alloc_sem); 728 mutex_unlock(&c->alloc_sem);
729 729
730 D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() calls gc pass\n")); 730 D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() calls gc pass\n"));
731 731
732 ret = jffs2_garbage_collect_pass(c); 732 ret = jffs2_garbage_collect_pass(c);
733 if (ret) { 733 if (ret) {
734 /* GC failed. Flush it with padding instead */ 734 /* GC failed. Flush it with padding instead */
735 down(&c->alloc_sem); 735 mutex_lock(&c->alloc_sem);
736 down_write(&c->wbuf_sem); 736 down_write(&c->wbuf_sem);
737 ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING); 737 ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING);
738 /* retry flushing wbuf in case jffs2_wbuf_recover 738 /* retry flushing wbuf in case jffs2_wbuf_recover
@@ -742,12 +742,12 @@ int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino)
742 up_write(&c->wbuf_sem); 742 up_write(&c->wbuf_sem);
743 break; 743 break;
744 } 744 }
745 down(&c->alloc_sem); 745 mutex_lock(&c->alloc_sem);
746 } 746 }
747 747
748 D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() ends...\n")); 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 return ret; 751 return ret;
752} 752}
753 753
@@ -1236,12 +1236,24 @@ int jffs2_dataflash_setup(struct jffs2_sb_info *c) {
1236 if (!c->wbuf) 1236 if (!c->wbuf)
1237 return -ENOMEM; 1237 return -ENOMEM;
1238 1238
1239#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
1240 c->wbuf_verify = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
1241 if (!c->wbuf_verify) {
1242 kfree(c->oobbuf);
1243 kfree(c->wbuf);
1244 return -ENOMEM;
1245 }
1246#endif
1247
1239 printk(KERN_INFO "JFFS2 write-buffering enabled buffer (%d) erasesize (%d)\n", c->wbuf_pagesize, c->sector_size); 1248 printk(KERN_INFO "JFFS2 write-buffering enabled buffer (%d) erasesize (%d)\n", c->wbuf_pagesize, c->sector_size);
1240 1249
1241 return 0; 1250 return 0;
1242} 1251}
1243 1252
1244void jffs2_dataflash_cleanup(struct jffs2_sb_info *c) { 1253void jffs2_dataflash_cleanup(struct jffs2_sb_info *c) {
1254#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
1255 kfree(c->wbuf_verify);
1256#endif
1245 kfree(c->wbuf); 1257 kfree(c->wbuf);
1246} 1258}
1247 1259
diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c
index 776f13cbf2b5..665fce9797d3 100644
--- a/fs/jffs2/write.c
+++ b/fs/jffs2/write.c
@@ -137,12 +137,12 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
137 JFFS2_SUMMARY_INODE_SIZE); 137 JFFS2_SUMMARY_INODE_SIZE);
138 } else { 138 } else {
139 /* Locking pain */ 139 /* Locking pain */
140 up(&f->sem); 140 mutex_unlock(&f->sem);
141 jffs2_complete_reservation(c); 141 jffs2_complete_reservation(c);
142 142
143 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &dummy, 143 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &dummy,
144 alloc_mode, JFFS2_SUMMARY_INODE_SIZE); 144 alloc_mode, JFFS2_SUMMARY_INODE_SIZE);
145 down(&f->sem); 145 mutex_lock(&f->sem);
146 } 146 }
147 147
148 if (!ret) { 148 if (!ret) {
@@ -285,12 +285,12 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
285 JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 285 JFFS2_SUMMARY_DIRENT_SIZE(namelen));
286 } else { 286 } else {
287 /* Locking pain */ 287 /* Locking pain */
288 up(&f->sem); 288 mutex_unlock(&f->sem);
289 jffs2_complete_reservation(c); 289 jffs2_complete_reservation(c);
290 290
291 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &dummy, 291 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &dummy,
292 alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 292 alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
293 down(&f->sem); 293 mutex_lock(&f->sem);
294 } 294 }
295 295
296 if (!ret) { 296 if (!ret) {
@@ -353,7 +353,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
353 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret)); 353 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret));
354 break; 354 break;
355 } 355 }
356 down(&f->sem); 356 mutex_lock(&f->sem);
357 datalen = min_t(uint32_t, writelen, PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1))); 357 datalen = min_t(uint32_t, writelen, PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1)));
358 cdatalen = min_t(uint32_t, alloclen - sizeof(*ri), datalen); 358 cdatalen = min_t(uint32_t, alloclen - sizeof(*ri), datalen);
359 359
@@ -381,7 +381,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
381 381
382 if (IS_ERR(fn)) { 382 if (IS_ERR(fn)) {
383 ret = PTR_ERR(fn); 383 ret = PTR_ERR(fn);
384 up(&f->sem); 384 mutex_unlock(&f->sem);
385 jffs2_complete_reservation(c); 385 jffs2_complete_reservation(c);
386 if (!retried) { 386 if (!retried) {
387 /* Write error to be retried */ 387 /* Write error to be retried */
@@ -403,11 +403,11 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
403 jffs2_mark_node_obsolete(c, fn->raw); 403 jffs2_mark_node_obsolete(c, fn->raw);
404 jffs2_free_full_dnode(fn); 404 jffs2_free_full_dnode(fn);
405 405
406 up(&f->sem); 406 mutex_unlock(&f->sem);
407 jffs2_complete_reservation(c); 407 jffs2_complete_reservation(c);
408 break; 408 break;
409 } 409 }
410 up(&f->sem); 410 mutex_unlock(&f->sem);
411 jffs2_complete_reservation(c); 411 jffs2_complete_reservation(c);
412 if (!datalen) { 412 if (!datalen) {
413 printk(KERN_WARNING "Eep. We didn't actually write any data in jffs2_write_inode_range()\n"); 413 printk(KERN_WARNING "Eep. We didn't actually write any data in jffs2_write_inode_range()\n");
@@ -439,7 +439,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
439 JFFS2_SUMMARY_INODE_SIZE); 439 JFFS2_SUMMARY_INODE_SIZE);
440 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen)); 440 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen));
441 if (ret) { 441 if (ret) {
442 up(&f->sem); 442 mutex_unlock(&f->sem);
443 return ret; 443 return ret;
444 } 444 }
445 445
@@ -454,7 +454,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
454 if (IS_ERR(fn)) { 454 if (IS_ERR(fn)) {
455 D1(printk(KERN_DEBUG "jffs2_write_dnode() failed\n")); 455 D1(printk(KERN_DEBUG "jffs2_write_dnode() failed\n"));
456 /* Eeek. Wave bye bye */ 456 /* Eeek. Wave bye bye */
457 up(&f->sem); 457 mutex_unlock(&f->sem);
458 jffs2_complete_reservation(c); 458 jffs2_complete_reservation(c);
459 return PTR_ERR(fn); 459 return PTR_ERR(fn);
460 } 460 }
@@ -463,7 +463,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
463 */ 463 */
464 f->metadata = fn; 464 f->metadata = fn;
465 465
466 up(&f->sem); 466 mutex_unlock(&f->sem);
467 jffs2_complete_reservation(c); 467 jffs2_complete_reservation(c);
468 468
469 ret = jffs2_init_security(&f->vfs_inode, &dir_f->vfs_inode); 469 ret = jffs2_init_security(&f->vfs_inode, &dir_f->vfs_inode);
@@ -489,7 +489,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
489 return -ENOMEM; 489 return -ENOMEM;
490 } 490 }
491 491
492 down(&dir_f->sem); 492 mutex_lock(&dir_f->sem);
493 493
494 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 494 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
495 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT); 495 rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
@@ -513,7 +513,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
513 /* dirent failed to write. Delete the inode normally 513 /* dirent failed to write. Delete the inode normally
514 as if it were the final unlink() */ 514 as if it were the final unlink() */
515 jffs2_complete_reservation(c); 515 jffs2_complete_reservation(c);
516 up(&dir_f->sem); 516 mutex_unlock(&dir_f->sem);
517 return PTR_ERR(fd); 517 return PTR_ERR(fd);
518 } 518 }
519 519
@@ -522,7 +522,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
522 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 522 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
523 523
524 jffs2_complete_reservation(c); 524 jffs2_complete_reservation(c);
525 up(&dir_f->sem); 525 mutex_unlock(&dir_f->sem);
526 526
527 return 0; 527 return 0;
528} 528}
@@ -551,7 +551,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
551 return ret; 551 return ret;
552 } 552 }
553 553
554 down(&dir_f->sem); 554 mutex_lock(&dir_f->sem);
555 555
556 /* Build a deletion node */ 556 /* Build a deletion node */
557 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 557 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -574,21 +574,21 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
574 574
575 if (IS_ERR(fd)) { 575 if (IS_ERR(fd)) {
576 jffs2_complete_reservation(c); 576 jffs2_complete_reservation(c);
577 up(&dir_f->sem); 577 mutex_unlock(&dir_f->sem);
578 return PTR_ERR(fd); 578 return PTR_ERR(fd);
579 } 579 }
580 580
581 /* File it. This will mark the old one obsolete. */ 581 /* File it. This will mark the old one obsolete. */
582 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 582 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
583 up(&dir_f->sem); 583 mutex_unlock(&dir_f->sem);
584 } else { 584 } else {
585 struct jffs2_full_dirent *fd = dir_f->dents;
586 uint32_t nhash = full_name_hash(name, namelen); 585 uint32_t nhash = full_name_hash(name, namelen);
587 586
587 fd = dir_f->dents;
588 /* We don't actually want to reserve any space, but we do 588 /* We don't actually want to reserve any space, but we do
589 want to be holding the alloc_sem when we write to flash */ 589 want to be holding the alloc_sem when we write to flash */
590 down(&c->alloc_sem); 590 mutex_lock(&c->alloc_sem);
591 down(&dir_f->sem); 591 mutex_lock(&dir_f->sem);
592 592
593 for (fd = dir_f->dents; fd; fd = fd->next) { 593 for (fd = dir_f->dents; fd; fd = fd->next) {
594 if (fd->nhash == nhash && 594 if (fd->nhash == nhash &&
@@ -607,7 +607,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
607 break; 607 break;
608 } 608 }
609 } 609 }
610 up(&dir_f->sem); 610 mutex_unlock(&dir_f->sem);
611 } 611 }
612 612
613 /* dead_f is NULL if this was a rename not a real unlink */ 613 /* dead_f is NULL if this was a rename not a real unlink */
@@ -615,7 +615,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
615 pointing to an inode which didn't exist. */ 615 pointing to an inode which didn't exist. */
616 if (dead_f && dead_f->inocache) { 616 if (dead_f && dead_f->inocache) {
617 617
618 down(&dead_f->sem); 618 mutex_lock(&dead_f->sem);
619 619
620 if (S_ISDIR(OFNI_EDONI_2SFFJ(dead_f)->i_mode)) { 620 if (S_ISDIR(OFNI_EDONI_2SFFJ(dead_f)->i_mode)) {
621 while (dead_f->dents) { 621 while (dead_f->dents) {
@@ -639,7 +639,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
639 639
640 dead_f->inocache->nlink--; 640 dead_f->inocache->nlink--;
641 /* NB: Caller must set inode nlink if appropriate */ 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 jffs2_complete_reservation(c); 645 jffs2_complete_reservation(c);
@@ -666,7 +666,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
666 return ret; 666 return ret;
667 } 667 }
668 668
669 down(&dir_f->sem); 669 mutex_lock(&dir_f->sem);
670 670
671 /* Build a deletion node */ 671 /* Build a deletion node */
672 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 672 rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -691,7 +691,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
691 691
692 if (IS_ERR(fd)) { 692 if (IS_ERR(fd)) {
693 jffs2_complete_reservation(c); 693 jffs2_complete_reservation(c);
694 up(&dir_f->sem); 694 mutex_unlock(&dir_f->sem);
695 return PTR_ERR(fd); 695 return PTR_ERR(fd);
696 } 696 }
697 697
@@ -699,7 +699,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
699 jffs2_add_fd_to_list(c, fd, &dir_f->dents); 699 jffs2_add_fd_to_list(c, fd, &dir_f->dents);
700 700
701 jffs2_complete_reservation(c); 701 jffs2_complete_reservation(c);
702 up(&dir_f->sem); 702 mutex_unlock(&dir_f->sem);
703 703
704 return 0; 704 return 0;
705} 705}