blob: eef20182d5b438749aca25e5f6133b0008fec7ef [file] [log] [blame]
David Howells07fe7cb2009-04-03 16:42:35 +01001/* Worker thread pool for slow items, such as filesystem lookups or mkdirs
2 *
3 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
David Howells8f0aa2f2009-04-03 16:42:35 +010010 *
11 * See Documentation/slow-work.txt
David Howells07fe7cb2009-04-03 16:42:35 +010012 */
13
14#ifndef _LINUX_SLOW_WORK_H
15#define _LINUX_SLOW_WORK_H
16
17#ifdef CONFIG_SLOW_WORK
18
David Howells12e22c52009-04-03 16:42:35 +010019#include <linux/sysctl.h>
20
David Howells07fe7cb2009-04-03 16:42:35 +010021struct slow_work;
22
23/*
24 * The operations used to support slow work items
25 */
26struct slow_work_ops {
David Howells3d7a6412009-11-19 18:10:23 +000027 /* owner */
28 struct module *owner;
29
David Howells07fe7cb2009-04-03 16:42:35 +010030 /* get a ref on a work item
31 * - return 0 if successful, -ve if not
32 */
33 int (*get_ref)(struct slow_work *work);
34
35 /* discard a ref to a work item */
36 void (*put_ref)(struct slow_work *work);
37
38 /* execute a work item */
39 void (*execute)(struct slow_work *work);
40};
41
42/*
43 * A slow work item
44 * - A reference is held on the parent object by the thread pool when it is
45 * queued
46 */
47struct slow_work {
David Howells3d7a6412009-11-19 18:10:23 +000048 struct module *owner; /* the owning module */
David Howells07fe7cb2009-04-03 16:42:35 +010049 unsigned long flags;
50#define SLOW_WORK_PENDING 0 /* item pending (further) execution */
51#define SLOW_WORK_EXECUTING 1 /* item currently executing */
52#define SLOW_WORK_ENQ_DEFERRED 2 /* item enqueue deferred */
53#define SLOW_WORK_VERY_SLOW 3 /* item is very slow */
Jens Axboe01609502009-11-19 18:10:43 +000054#define SLOW_WORK_CANCELLING 4 /* item is being cancelled, don't enqueue */
David Howells07fe7cb2009-04-03 16:42:35 +010055 const struct slow_work_ops *ops; /* operations table for this item */
56 struct list_head link; /* link in queue */
57};
58
59/**
60 * slow_work_init - Initialise a slow work item
61 * @work: The work item to initialise
62 * @ops: The operations to use to handle the slow work item
63 *
64 * Initialise a slow work item.
65 */
66static inline void slow_work_init(struct slow_work *work,
67 const struct slow_work_ops *ops)
68{
69 work->flags = 0;
70 work->ops = ops;
71 INIT_LIST_HEAD(&work->link);
72}
73
74/**
Jonathan Corbet5dd559f2009-04-21 16:30:32 -060075 * vslow_work_init - Initialise a very slow work item
David Howells07fe7cb2009-04-03 16:42:35 +010076 * @work: The work item to initialise
77 * @ops: The operations to use to handle the slow work item
78 *
79 * Initialise a very slow work item. This item will be restricted such that
80 * only a certain number of the pool threads will be able to execute items of
81 * this type.
82 */
83static inline void vslow_work_init(struct slow_work *work,
84 const struct slow_work_ops *ops)
85{
86 work->flags = 1 << SLOW_WORK_VERY_SLOW;
87 work->ops = ops;
88 INIT_LIST_HEAD(&work->link);
89}
90
91extern int slow_work_enqueue(struct slow_work *work);
Jens Axboe01609502009-11-19 18:10:43 +000092extern void slow_work_cancel(struct slow_work *work);
David Howells3d7a6412009-11-19 18:10:23 +000093extern int slow_work_register_user(struct module *owner);
94extern void slow_work_unregister_user(struct module *owner);
David Howells07fe7cb2009-04-03 16:42:35 +010095
David Howells12e22c52009-04-03 16:42:35 +010096#ifdef CONFIG_SYSCTL
97extern ctl_table slow_work_sysctls[];
98#endif
David Howells07fe7cb2009-04-03 16:42:35 +010099
100#endif /* CONFIG_SLOW_WORK */
101#endif /* _LINUX_SLOW_WORK_H */