diff options
author | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-06-07 08:15:30 -0400 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-06-07 08:22:21 -0400 |
commit | 12027f1b3fd69a4e9017e6b13c72547a99c6cf54 (patch) | |
tree | 19b7b41b12f4c1eb0a0efdbd494c58e2381e1dd9 /drivers/mtd | |
parent | 818039c7d597db3b1d30964a8f9489ac42c0642d (diff) |
UBI: correct ubi_wl_flush locking
Commit "62f38455 UBI: modify ubi_wl_flush function to clear work queue for a lnum"
takes the 'work_sem' semaphore in write mode for the entire loop, which is not
very good because it will block other workers for potentially long time. We do
not need to have it in write mode - read mode is enough, and we do not need to
hole it over the entire loop. So this patch turns changes the locking: takes
'work_sem' in read mode and pushes it down to the loop.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/ubi/wl.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 9df100a4ec38..b6be644e7b85 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -1262,11 +1262,11 @@ int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum) | |||
1262 | dbg_wl("flush pending work for LEB %d:%d (%d pending works)", | 1262 | dbg_wl("flush pending work for LEB %d:%d (%d pending works)", |
1263 | vol_id, lnum, ubi->works_count); | 1263 | vol_id, lnum, ubi->works_count); |
1264 | 1264 | ||
1265 | down_write(&ubi->work_sem); | ||
1266 | while (found) { | 1265 | while (found) { |
1267 | struct ubi_work *wrk; | 1266 | struct ubi_work *wrk; |
1268 | found = 0; | 1267 | found = 0; |
1269 | 1268 | ||
1269 | down_read(&ubi->work_sem); | ||
1270 | spin_lock(&ubi->wl_lock); | 1270 | spin_lock(&ubi->wl_lock); |
1271 | list_for_each_entry(wrk, &ubi->works, list) { | 1271 | list_for_each_entry(wrk, &ubi->works, list) { |
1272 | if ((vol_id == UBI_ALL || wrk->vol_id == vol_id) && | 1272 | if ((vol_id == UBI_ALL || wrk->vol_id == vol_id) && |
@@ -1277,18 +1277,27 @@ int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum) | |||
1277 | spin_unlock(&ubi->wl_lock); | 1277 | spin_unlock(&ubi->wl_lock); |
1278 | 1278 | ||
1279 | err = wrk->func(ubi, wrk, 0); | 1279 | err = wrk->func(ubi, wrk, 0); |
1280 | if (err) | 1280 | if (err) { |
1281 | goto out; | 1281 | up_read(&ubi->work_sem); |
1282 | return err; | ||
1283 | } | ||
1284 | |||
1282 | spin_lock(&ubi->wl_lock); | 1285 | spin_lock(&ubi->wl_lock); |
1283 | found = 1; | 1286 | found = 1; |
1284 | break; | 1287 | break; |
1285 | } | 1288 | } |
1286 | } | 1289 | } |
1287 | spin_unlock(&ubi->wl_lock); | 1290 | spin_unlock(&ubi->wl_lock); |
1291 | up_read(&ubi->work_sem); | ||
1288 | } | 1292 | } |
1289 | 1293 | ||
1290 | out: | 1294 | /* |
1295 | * Make sure all the works which have been done in parallel are | ||
1296 | * finished. | ||
1297 | */ | ||
1298 | down_write(&ubi->work_sem); | ||
1291 | up_write(&ubi->work_sem); | 1299 | up_write(&ubi->work_sem); |
1300 | |||
1292 | return err; | 1301 | return err; |
1293 | } | 1302 | } |
1294 | 1303 | ||