diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-04-29 09:35:46 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-05-13 12:23:56 -0400 |
commit | fe79c05f03777acf87acc54fa3ad357ed5ee3b81 (patch) | |
tree | 2a16b31eb5e71c5133db06d6d8fa04322db6e79c /fs/ubifs/recovery.c | |
parent | 447442139c764fd75cf892905d0feb08a9b983ed (diff) |
UBIFS: refactor ubifs_rcvry_gc_commit
This commits refactors and cleans up 'ubifs_rcvry_gc_commit()' which was quite
untidy, also removes the commentary which was not 100% correct.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs/ubifs/recovery.c')
-rw-r--r-- | fs/ubifs/recovery.c | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c index 11776ae8caf6..d28db1ee2045 100644 --- a/fs/ubifs/recovery.c +++ b/fs/ubifs/recovery.c | |||
@@ -1138,44 +1138,26 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c) | |||
1138 | { | 1138 | { |
1139 | struct ubifs_wbuf *wbuf = &c->jheads[GCHD].wbuf; | 1139 | struct ubifs_wbuf *wbuf = &c->jheads[GCHD].wbuf; |
1140 | struct ubifs_lprops lp; | 1140 | struct ubifs_lprops lp; |
1141 | int lnum, err; | 1141 | int err; |
1142 | 1142 | ||
1143 | c->gc_lnum = -1; | 1143 | c->gc_lnum = -1; |
1144 | if (wbuf->lnum == -1) { | 1144 | if (wbuf->lnum == -1 || wbuf->offs == c->leb_size) { |
1145 | dbg_rcvry("no GC head LEB"); | 1145 | dbg_rcvry("no GC head: wbuf->lnum %d, wbuf->offs %d", |
1146 | return grab_empty_leb(c); | 1146 | wbuf->lnum, wbuf->offs); |
1147 | } | ||
1148 | /* | ||
1149 | * See whether the used space in the dirtiest LEB fits in the GC head | ||
1150 | * LEB. | ||
1151 | */ | ||
1152 | if (wbuf->offs == c->leb_size) { | ||
1153 | dbg_rcvry("no room in GC head LEB"); | ||
1154 | return grab_empty_leb(c); | 1147 | return grab_empty_leb(c); |
1155 | } | 1148 | } |
1149 | |||
1156 | err = ubifs_find_dirty_leb(c, &lp, wbuf->offs, 2); | 1150 | err = ubifs_find_dirty_leb(c, &lp, wbuf->offs, 2); |
1157 | if (err) { | 1151 | if (err) { |
1158 | /* | 1152 | if (err != -ENOSPC) |
1159 | * There are no dirty or empty LEBs subject to here being | 1153 | return err; |
1160 | * enough for the index. Try to use | 1154 | |
1161 | * 'ubifs_find_free_leb_for_idx()', which will return any empty | 1155 | dbg_rcvry("could not find a dirty LEB"); |
1162 | * LEBs (ignoring index requirements). If the index then | 1156 | return grab_empty_leb(c); |
1163 | * doesn't have enough LEBs the recovery commit will fail - | ||
1164 | * which is the same result anyway i.e. recovery fails. So | ||
1165 | * there is no problem ignoring index requirements and just | ||
1166 | * grabbing a free LEB since we have already established there | ||
1167 | * is not a dirty LEB we could have used instead. | ||
1168 | */ | ||
1169 | if (err == -ENOSPC) { | ||
1170 | dbg_rcvry("could not find a dirty LEB"); | ||
1171 | return grab_empty_leb(c); | ||
1172 | } | ||
1173 | return err; | ||
1174 | } | 1157 | } |
1175 | 1158 | ||
1176 | ubifs_assert(!(lp.flags & LPROPS_INDEX)); | 1159 | ubifs_assert(!(lp.flags & LPROPS_INDEX)); |
1177 | ubifs_assert(lp.free + lp.dirty >= wbuf->offs); | 1160 | ubifs_assert(lp.free + lp.dirty >= wbuf->offs); |
1178 | lnum = lp.lnum; | ||
1179 | 1161 | ||
1180 | /* | 1162 | /* |
1181 | * We run the commit before garbage collection otherwise subsequent | 1163 | * We run the commit before garbage collection otherwise subsequent |
@@ -1185,11 +1167,8 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c) | |||
1185 | err = ubifs_run_commit(c); | 1167 | err = ubifs_run_commit(c); |
1186 | if (err) | 1168 | if (err) |
1187 | return err; | 1169 | return err; |
1188 | /* | 1170 | |
1189 | * The data in the dirtiest LEB fits in the GC head LEB, so do the GC | 1171 | dbg_rcvry("GC'ing LEB %d", lp.lnum); |
1190 | * - use locking to keep 'ubifs_assert()' happy. | ||
1191 | */ | ||
1192 | dbg_rcvry("GC'ing LEB %d", lnum); | ||
1193 | mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead); | 1172 | mutex_lock_nested(&wbuf->io_mutex, wbuf->jhead); |
1194 | err = ubifs_garbage_collect_leb(c, &lp); | 1173 | err = ubifs_garbage_collect_leb(c, &lp); |
1195 | if (err >= 0) { | 1174 | if (err >= 0) { |
@@ -1205,14 +1184,16 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c) | |||
1205 | err = -EINVAL; | 1184 | err = -EINVAL; |
1206 | return err; | 1185 | return err; |
1207 | } | 1186 | } |
1208 | if (err != LEB_RETAINED) { | 1187 | |
1209 | dbg_err("GC returned %d", err); | 1188 | ubifs_assert(err == LEB_RETAINED); |
1189 | if (err != LEB_RETAINED) | ||
1210 | return -EINVAL; | 1190 | return -EINVAL; |
1211 | } | 1191 | |
1212 | err = ubifs_leb_unmap(c, c->gc_lnum); | 1192 | err = ubifs_leb_unmap(c, c->gc_lnum); |
1213 | if (err) | 1193 | if (err) |
1214 | return err; | 1194 | return err; |
1215 | dbg_rcvry("allocated LEB %d for GC", lnum); | 1195 | |
1196 | dbg_rcvry("allocated LEB %d for GC", lp.lnum); | ||
1216 | return 0; | 1197 | return 0; |
1217 | } | 1198 | } |
1218 | 1199 | ||