mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 14:49:24 +01:00
wiphy: make wiphy work queue reentrant
In some situations its convenient for the same work item to be inserted (rescheduled) while its in progress. FT for example does this now if a roam fails. The same ft_work item gets re-inserted which, currently, is not safe to do since the item is modified and removed once completed. Fix this by introducing wiphy_radio_work_reschedule which is an explicit API for re-inserting work items from within the do_work callback. The wiphy work logic was changed around slightly to remove the item at the head of the queue prior to starting and note the ID going into do_work. If do_work signaled done and ID changed we know it was re-inserted and can skip the destroy logic and move onto the next item. If the item is not done continue as normal but set the priority to INT_MIN, as usual, to prevent other items from getting to the head of the queue.
This commit is contained in:
parent
0f5da071fa
commit
109cb70f22
45
src/wiphy.c
45
src/wiphy.c
@ -2574,16 +2574,13 @@ static void wiphy_radio_work_next(struct wiphy *wiphy)
|
|||||||
{
|
{
|
||||||
struct wiphy_radio_work_item *work;
|
struct wiphy_radio_work_item *work;
|
||||||
bool done;
|
bool done;
|
||||||
|
uint32_t id;
|
||||||
|
|
||||||
work = l_queue_peek_head(wiphy->work);
|
work = l_queue_pop_head(wiphy->work);
|
||||||
if (!work)
|
if (!work)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
id = work->id;
|
||||||
* Ensures no other work item will get inserted before this one while
|
|
||||||
* the work is being done.
|
|
||||||
*/
|
|
||||||
work->priority = INT_MIN;
|
|
||||||
|
|
||||||
l_debug("Starting work item %u", work->id);
|
l_debug("Starting work item %u", work->id);
|
||||||
|
|
||||||
@ -2592,15 +2589,25 @@ static void wiphy_radio_work_next(struct wiphy *wiphy)
|
|||||||
wiphy->work_in_callback = false;
|
wiphy->work_in_callback = false;
|
||||||
|
|
||||||
if (done) {
|
if (done) {
|
||||||
work->id = 0;
|
/* Item was rescheduled, don't destroy */
|
||||||
|
if (work->id != id)
|
||||||
|
goto next;
|
||||||
|
|
||||||
l_queue_remove(wiphy->work, work);
|
work->id = 0;
|
||||||
|
|
||||||
wiphy->work_in_callback = true;
|
wiphy->work_in_callback = true;
|
||||||
destroy_work(work);
|
destroy_work(work);
|
||||||
wiphy->work_in_callback = false;
|
wiphy->work_in_callback = false;
|
||||||
|
|
||||||
|
next:
|
||||||
wiphy_radio_work_next(wiphy);
|
wiphy_radio_work_next(wiphy);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Ensures no other work item will get inserted before this one
|
||||||
|
* while the work is being done.
|
||||||
|
*/
|
||||||
|
work->priority = INT_MIN;
|
||||||
|
l_queue_push_head(wiphy->work, work);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2684,6 +2691,28 @@ int wiphy_radio_work_is_running(struct wiphy *wiphy, uint32_t id)
|
|||||||
return item == l_queue_peek_head(wiphy->work) ? 1 : 0;
|
return item == l_queue_peek_head(wiphy->work) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t wiphy_radio_work_reschedule(struct wiphy *wiphy,
|
||||||
|
struct wiphy_radio_work_item *item)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* This should only be called from within the do_work callback, meaning
|
||||||
|
* the item should not be in the queue. Any re-insertion on a running
|
||||||
|
* item after do_work is not allowed.
|
||||||
|
*/
|
||||||
|
if (L_WARN_ON(wiphy_radio_work_is_running(wiphy, item->id) != -ENOENT))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
work_ids++;
|
||||||
|
|
||||||
|
l_debug("Rescheduling work item %u, new id %u", item->id, work_ids);
|
||||||
|
|
||||||
|
item->id = work_ids;
|
||||||
|
|
||||||
|
l_queue_insert(wiphy->work, item, insert_by_priority, NULL);
|
||||||
|
|
||||||
|
return item->id;
|
||||||
|
}
|
||||||
|
|
||||||
static int wiphy_init(void)
|
static int wiphy_init(void)
|
||||||
{
|
{
|
||||||
struct l_genl *genl = iwd_get_genl();
|
struct l_genl *genl = iwd_get_genl();
|
||||||
|
@ -168,3 +168,5 @@ uint32_t wiphy_radio_work_insert(struct wiphy *wiphy,
|
|||||||
const struct wiphy_radio_work_item_ops *ops);
|
const struct wiphy_radio_work_item_ops *ops);
|
||||||
void wiphy_radio_work_done(struct wiphy *wiphy, uint32_t id);
|
void wiphy_radio_work_done(struct wiphy *wiphy, uint32_t id);
|
||||||
int wiphy_radio_work_is_running(struct wiphy *wiphy, uint32_t id);
|
int wiphy_radio_work_is_running(struct wiphy *wiphy, uint32_t id);
|
||||||
|
uint32_t wiphy_radio_work_reschedule(struct wiphy *wiphy,
|
||||||
|
struct wiphy_radio_work_item *item);
|
||||||
|
Loading…
Reference in New Issue
Block a user