blob: 8262809dfa8b700d430a4613dba9fd398fd49437 [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.
10 */
11
12#ifndef _LINUX_SLOW_WORK_H
13#define _LINUX_SLOW_WORK_H
14
15#ifdef CONFIG_SLOW_WORK
16
David Howells12e22c52009-04-03 16:42:35 +010017#include <linux/sysctl.h>
18
David Howells07fe7cb2009-04-03 16:42:35 +010019struct slow_work;
20
21/*
22 * The operations used to support slow work items
23 */
24struct slow_work_ops {
25 /* get a ref on a work item
26 * - return 0 if successful, -ve if not
27 */
28 int (*get_ref)(struct slow_work *work);
29
30 /* discard a ref to a work item */
31 void (*put_ref)(struct slow_work *work);
32
33 /* execute a work item */
34 void (*execute)(struct slow_work *work);
35};
36
37/*
38 * A slow work item
39 * - A reference is held on the parent object by the thread pool when it is
40 * queued
41 */
42struct slow_work {
43 unsigned long flags;
44#define SLOW_WORK_PENDING 0 /* item pending (further) execution */
45#define SLOW_WORK_EXECUTING 1 /* item currently executing */
46#define SLOW_WORK_ENQ_DEFERRED 2 /* item enqueue deferred */
47#define SLOW_WORK_VERY_SLOW 3 /* item is very slow */
48 const struct slow_work_ops *ops; /* operations table for this item */
49 struct list_head link; /* link in queue */
50};
51
52/**
53 * slow_work_init - Initialise a slow work item
54 * @work: The work item to initialise
55 * @ops: The operations to use to handle the slow work item
56 *
57 * Initialise a slow work item.
58 */
59static inline void slow_work_init(struct slow_work *work,
60 const struct slow_work_ops *ops)
61{
62 work->flags = 0;
63 work->ops = ops;
64 INIT_LIST_HEAD(&work->link);
65}
66
67/**
68 * slow_work_init - Initialise a very slow work item
69 * @work: The work item to initialise
70 * @ops: The operations to use to handle the slow work item
71 *
72 * Initialise a very slow work item. This item will be restricted such that
73 * only a certain number of the pool threads will be able to execute items of
74 * this type.
75 */
76static inline void vslow_work_init(struct slow_work *work,
77 const struct slow_work_ops *ops)
78{
79 work->flags = 1 << SLOW_WORK_VERY_SLOW;
80 work->ops = ops;
81 INIT_LIST_HEAD(&work->link);
82}
83
84extern int slow_work_enqueue(struct slow_work *work);
85extern int slow_work_register_user(void);
86extern void slow_work_unregister_user(void);
87
David Howells12e22c52009-04-03 16:42:35 +010088#ifdef CONFIG_SYSCTL
89extern ctl_table slow_work_sysctls[];
90#endif
David Howells07fe7cb2009-04-03 16:42:35 +010091
92#endif /* CONFIG_SLOW_WORK */
93#endif /* _LINUX_SLOW_WORK_H */