diff options
Diffstat (limited to 'fs/ubifs/journal.c')
-rw-r--r-- | fs/ubifs/journal.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index ce55a4807cdc..34b1679e6e3a 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c | |||
@@ -141,14 +141,8 @@ again: | |||
141 | * LEB with some empty space. | 141 | * LEB with some empty space. |
142 | */ | 142 | */ |
143 | lnum = ubifs_find_free_space(c, len, &offs, squeeze); | 143 | lnum = ubifs_find_free_space(c, len, &offs, squeeze); |
144 | if (lnum >= 0) { | 144 | if (lnum >= 0) |
145 | /* Found an LEB, add it to the journal head */ | ||
146 | err = ubifs_add_bud_to_log(c, jhead, lnum, offs); | ||
147 | if (err) | ||
148 | goto out_return; | ||
149 | /* A new bud was successfully allocated and added to the log */ | ||
150 | goto out; | 145 | goto out; |
151 | } | ||
152 | 146 | ||
153 | err = lnum; | 147 | err = lnum; |
154 | if (err != -ENOSPC) | 148 | if (err != -ENOSPC) |
@@ -203,12 +197,23 @@ again: | |||
203 | return 0; | 197 | return 0; |
204 | } | 198 | } |
205 | 199 | ||
206 | err = ubifs_add_bud_to_log(c, jhead, lnum, 0); | ||
207 | if (err) | ||
208 | goto out_return; | ||
209 | offs = 0; | 200 | offs = 0; |
210 | 201 | ||
211 | out: | 202 | out: |
203 | /* | ||
204 | * Make sure we synchronize the write-buffer before we add the new bud | ||
205 | * to the log. Otherwise we may have a power cut after the log | ||
206 | * reference node for the last bud (@lnum) is written but before the | ||
207 | * write-buffer data are written to the next-to-last bud | ||
208 | * (@wbuf->lnum). And the effect would be that the recovery would see | ||
209 | * that there is corruption in the next-to-last bud. | ||
210 | */ | ||
211 | err = ubifs_wbuf_sync_nolock(wbuf); | ||
212 | if (err) | ||
213 | goto out_return; | ||
214 | err = ubifs_add_bud_to_log(c, jhead, lnum, offs); | ||
215 | if (err) | ||
216 | goto out_return; | ||
212 | err = ubifs_wbuf_seek_nolock(wbuf, lnum, offs, wbuf->dtype); | 217 | err = ubifs_wbuf_seek_nolock(wbuf, lnum, offs, wbuf->dtype); |
213 | if (err) | 218 | if (err) |
214 | goto out_unlock; | 219 | goto out_unlock; |