Re: [PATCH V2] UBI: add ubi_lnum_purge function to clear work queuefor a lnum

From: Joel Reardon
Date: Sat May 19 2012 - 05:47:08 EST


> Take the work_sem at the beginning. Release at the very end.
>
> Then you can do something like this:
>
> int found = 1;
>
> while (found) {
> found = 0;
>
> spin_lock(&ubi->wl_lock);
> list_for_each_entry(wrk, tmp, &ubi->works, list) {
> if (wrk->lnum == lnum) {
> list_del(&wrk->list);
> ubi->works_count -= 1;
> ubi_assert(ubi->works_count >= 0);
> spin_unlock(&ubi->wl_lock);
>
> err = wrk->func(ubi, wrk, 0);
> if (err)
> return err;
>
> spin_lock(&ubi->wl_lock);
> found = 1;
> break;
> }
> spin_unlock(&ubi->wl_lock);
> }
>


If I use list_for_each_entry_safe(), it protects against deleting as it
iterates. If I take the work_sem first, is it okay to do a simple
traversal instead of one traversal per removed item? Even if another
thread adds new work for the same vol_id/lnum, its okay, because the
caller of this function only cares about vol_id/lnums erasures that
it knows are currently on the worklist.

Cheers,
Joel Reardon
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/