Skip to content

Commit 28e53bd

Browse files
Oleg NesterovLinus Torvalds
authored andcommitted
unify flush_work/flush_work_keventd and rename it to cancel_work_sync
flush_work(wq, work) doesn't need the first parameter, we can use cwq->wq (this was possible from the very beginnig, I missed this). So we can unify flush_work_keventd and flush_work. Also, rename flush_work() to cancel_work_sync() and fix all callers. Perhaps this is not the best name, but "flush_work" is really bad. (akpm: this is why the earlier patches bypassed maintainers) Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Cc: Jeff Garzik <jeff@garzik.org> Cc: "David S. Miller" <davem@davemloft.net> Cc: Jens Axboe <jens.axboe@oracle.com> Cc: Tejun Heo <htejun@gmail.com> Cc: Auke Kok <auke-jan.h.kok@intel.com>, Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5830c59 commit 28e53bd

9 files changed

Lines changed: 41 additions & 40 deletions

File tree

‎block/ll_rw_blk.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3633,7 +3633,7 @@ EXPORT_SYMBOL(kblockd_schedule_work);
36333633

36343634
void kblockd_flush_work(struct work_struct *work)
36353635
{
3636-
flush_work(kblockd_workqueue, work);
3636+
cancel_work_sync(work);
36373637
}
36383638
EXPORT_SYMBOL(kblockd_flush_work);
36393639

‎drivers/ata/libata-core.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ void ata_port_flush_task(struct ata_port *ap)
13161316
spin_unlock_irqrestore(ap->lock, flags);
13171317

13181318
DPRINTK("flush #1\n");
1319-
flush_work(ata_wq, &ap->port_task.work); /* akpm: seems unneeded */
1319+
cancel_work_sync(&ap->port_task.work); /* akpm: seems unneeded */
13201320

13211321
/*
13221322
* At this point, if a task is running, it's guaranteed to see
@@ -1327,7 +1327,7 @@ void ata_port_flush_task(struct ata_port *ap)
13271327
if (ata_msg_ctl(ap))
13281328
ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n",
13291329
__FUNCTION__);
1330-
flush_work(ata_wq, &ap->port_task.work);
1330+
cancel_work_sync(&ap->port_task.work);
13311331
}
13321332

13331333
spin_lock_irqsave(ap->lock, flags);
@@ -6475,9 +6475,9 @@ void ata_port_detach(struct ata_port *ap)
64756475
/* Flush hotplug task. The sequence is similar to
64766476
* ata_port_flush_task().
64776477
*/
6478-
flush_work(ata_aux_wq, &ap->hotplug_task.work); /* akpm: why? */
6478+
cancel_work_sync(&ap->hotplug_task.work); /* akpm: why? */
64796479
cancel_delayed_work(&ap->hotplug_task);
6480-
flush_work(ata_aux_wq, &ap->hotplug_task.work);
6480+
cancel_work_sync(&ap->hotplug_task.work);
64816481

64826482
skip_eh:
64836483
/* remove the associated SCSI host */

‎drivers/net/e1000/e1000_main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ e1000_remove(struct pci_dev *pdev)
12141214
int i;
12151215
#endif
12161216

1217-
flush_work_keventd(&adapter->reset_task);
1217+
cancel_work_sync(&adapter->reset_task);
12181218

12191219
e1000_release_manageability(adapter);
12201220

‎drivers/net/phy/phy.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,9 @@ int phy_stop_interrupts(struct phy_device *phydev)
663663

664664
/*
665665
* Finish any pending work; we might have been scheduled to be called
666-
* from keventd ourselves, but flush_work_keventd() handles that.
666+
* from keventd ourselves, but cancel_work_sync() handles that.
667667
*/
668-
flush_work_keventd(&phydev->phy_queue);
668+
cancel_work_sync(&phydev->phy_queue);
669669

670670
free_irq(phydev->irq, phydev);
671671

‎drivers/net/tg3.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7386,7 +7386,7 @@ static int tg3_close(struct net_device *dev)
73867386
{
73877387
struct tg3 *tp = netdev_priv(dev);
73887388

7389-
flush_work_keventd(&tp->reset_task);
7389+
cancel_work_sync(&tp->reset_task);
73907390

73917391
netif_stop_queue(dev);
73927392

‎fs/aio.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void fastcall exit_aio(struct mm_struct *mm)
348348
/*
349349
* Ensure we don't leave the ctx on the aio_wq
350350
*/
351-
flush_work(aio_wq, &ctx->wq.work);
351+
cancel_work_sync(&ctx->wq.work);
352352

353353
if (1 != atomic_read(&ctx->users))
354354
printk(KERN_DEBUG
@@ -371,7 +371,7 @@ void fastcall __put_ioctx(struct kioctx *ctx)
371371
BUG_ON(ctx->reqs_active);
372372

373373
cancel_delayed_work(&ctx->wq);
374-
flush_work(aio_wq, &ctx->wq.work);
374+
cancel_work_sync(&ctx->wq.work);
375375
aio_free_ring(ctx);
376376
mmdrop(ctx->mm);
377377
ctx->mm = NULL;

‎include/linux/workqueue.h‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,33 @@ extern struct workqueue_struct *__create_workqueue(const char *name,
128128
extern void destroy_workqueue(struct workqueue_struct *wq);
129129

130130
extern int FASTCALL(queue_work(struct workqueue_struct *wq, struct work_struct *work));
131-
extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay));
131+
extern int FASTCALL(queue_delayed_work(struct workqueue_struct *wq,
132+
struct delayed_work *work, unsigned long delay));
132133
extern int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
133-
struct delayed_work *work, unsigned long delay);
134+
struct delayed_work *work, unsigned long delay);
135+
134136
extern void FASTCALL(flush_workqueue(struct workqueue_struct *wq));
135-
extern void flush_work(struct workqueue_struct *wq, struct work_struct *work);
136-
extern void flush_work_keventd(struct work_struct *work);
137+
extern void flush_scheduled_work(void);
137138

138139
extern int FASTCALL(schedule_work(struct work_struct *work));
139-
extern int FASTCALL(schedule_delayed_work(struct delayed_work *work, unsigned long delay));
140-
141-
extern int schedule_delayed_work_on(int cpu, struct delayed_work *work, unsigned long delay);
140+
extern int FASTCALL(schedule_delayed_work(struct delayed_work *work,
141+
unsigned long delay));
142+
extern int schedule_delayed_work_on(int cpu, struct delayed_work *work,
143+
unsigned long delay);
142144
extern int schedule_on_each_cpu(work_func_t func);
143-
extern void flush_scheduled_work(void);
144145
extern int current_is_keventd(void);
145146
extern int keventd_up(void);
146147

147148
extern void init_workqueues(void);
148149
int execute_in_process_context(work_func_t fn, struct execute_work *);
149150

151+
extern void cancel_work_sync(struct work_struct *work);
152+
150153
/*
151154
* Kill off a pending schedule_delayed_work(). Note that the work callback
152155
* function may still be running on return from cancel_delayed_work(), unless
153156
* it returns 1 and the work doesn't re-arm itself. Run flush_workqueue() or
154-
* flush_work() or cancel_work_sync() to wait on it.
157+
* cancel_work_sync() to wait on it.
155158
*/
156159
static inline int cancel_delayed_work(struct delayed_work *work)
157160
{

‎kernel/workqueue.c‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -413,23 +413,23 @@ static void wait_on_work(struct cpu_workqueue_struct *cwq,
413413
}
414414

415415
/**
416-
* flush_work - block until a work_struct's callback has terminated
417-
* @wq: the workqueue on which the work is queued
416+
* cancel_work_sync - block until a work_struct's callback has terminated
418417
* @work: the work which is to be flushed
419418
*
420-
* flush_work() will attempt to cancel the work if it is queued. If the work's
421-
* callback appears to be running, flush_work() will block until it has
422-
* completed.
419+
* cancel_work_sync() will attempt to cancel the work if it is queued. If the
420+
* work's callback appears to be running, cancel_work_sync() will block until
421+
* it has completed.
423422
*
424-
* flush_work() is designed to be used when the caller is tearing down data
425-
* structures which the callback function operates upon. It is expected that,
426-
* prior to calling flush_work(), the caller has arranged for the work to not
427-
* be requeued.
423+
* cancel_work_sync() is designed to be used when the caller is tearing down
424+
* data structures which the callback function operates upon. It is expected
425+
* that, prior to calling cancel_work_sync(), the caller has arranged for the
426+
* work to not be requeued.
428427
*/
429-
void flush_work(struct workqueue_struct *wq, struct work_struct *work)
428+
void cancel_work_sync(struct work_struct *work)
430429
{
431-
const cpumask_t *cpu_map = wq_cpu_map(wq);
432430
struct cpu_workqueue_struct *cwq;
431+
struct workqueue_struct *wq;
432+
const cpumask_t *cpu_map;
433433
int cpu;
434434

435435
might_sleep();
@@ -448,10 +448,13 @@ void flush_work(struct workqueue_struct *wq, struct work_struct *work)
448448
work_clear_pending(work);
449449
spin_unlock_irq(&cwq->lock);
450450

451+
wq = cwq->wq;
452+
cpu_map = wq_cpu_map(wq);
453+
451454
for_each_cpu_mask(cpu, *cpu_map)
452455
wait_on_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
453456
}
454-
EXPORT_SYMBOL_GPL(flush_work);
457+
EXPORT_SYMBOL_GPL(cancel_work_sync);
455458

456459

457460
static struct workqueue_struct *keventd_wq;
@@ -540,18 +543,13 @@ void flush_scheduled_work(void)
540543
}
541544
EXPORT_SYMBOL(flush_scheduled_work);
542545

543-
void flush_work_keventd(struct work_struct *work)
544-
{
545-
flush_work(keventd_wq, work);
546-
}
547-
EXPORT_SYMBOL(flush_work_keventd);
548-
549546
/**
550547
* cancel_rearming_delayed_work - kill off a delayed work whose handler rearms the delayed work.
551548
* @dwork: the delayed work struct
552549
*
553550
* Note that the work callback function may still be running on return from
554-
* cancel_delayed_work(). Run flush_workqueue() or flush_work() to wait on it.
551+
* cancel_delayed_work(). Run flush_workqueue() or cancel_work_sync() to wait
552+
* on it.
555553
*/
556554
void cancel_rearming_delayed_work(struct delayed_work *dwork)
557555
{

‎net/ipv4/ipvs/ip_vs_ctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ void ip_vs_control_cleanup(void)
23872387
EnterFunction(2);
23882388
ip_vs_trash_cleanup();
23892389
cancel_rearming_delayed_work(&defense_work);
2390-
flush_work_keventd(&defense_work.work);
2390+
cancel_work_sync(&defense_work.work);
23912391
ip_vs_kill_estimator(&ip_vs_stats);
23922392
unregister_sysctl_table(sysctl_header);
23932393
proc_net_remove("ip_vs_stats");

0 commit comments

Comments
 (0)