blob: d15ca6591f96f1724a3d1c950304996eea15f801 [file] [log] [blame]
Jens Axboefd0928d2008-01-24 08:52:45 +01001#ifndef IOCONTEXT_H
2#define IOCONTEXT_H
3
Jens Axboe4ac845a2008-01-24 08:44:49 +01004#include <linux/radix-tree.h>
Fabio Checconi34e6bbf2008-04-02 14:31:02 +02005#include <linux/rcupdate.h>
Tejun Heob2efa052011-12-14 00:33:39 +01006#include <linux/workqueue.h>
Jens Axboe4ac845a2008-01-24 08:44:49 +01007
Tejun Heodc869002011-12-14 00:33:38 +01008enum {
Tejun Heoc5869802011-12-14 00:33:41 +01009 ICQ_IOPRIO_CHANGED,
10 ICQ_CGROUP_CHANGED,
Tejun Heodc869002011-12-14 00:33:38 +010011};
12
Tejun Heoc5869802011-12-14 00:33:41 +010013struct io_cq {
14 struct request_queue *q;
15 struct io_context *ioc;
Jens Axboefd0928d2008-01-24 08:52:45 +010016
Tejun Heoc5869802011-12-14 00:33:41 +010017 struct list_head q_node;
18 struct hlist_node ioc_node;
Jens Axboefd0928d2008-01-24 08:52:45 +010019
Tejun Heoc5869802011-12-14 00:33:41 +010020 unsigned long changed;
21 struct rcu_head rcu_head;
Jens Axboefd0928d2008-01-24 08:52:45 +010022
Tejun Heoc5869802011-12-14 00:33:41 +010023 void (*exit)(struct io_cq *);
24 void (*release)(struct io_cq *);
Jens Axboefd0928d2008-01-24 08:52:45 +010025};
26
27/*
Jens Axboed38ecf92008-01-24 08:53:35 +010028 * I/O subsystem state of the associated processes. It is refcounted
29 * and kmalloc'ed. These could be shared between processes.
Jens Axboefd0928d2008-01-24 08:52:45 +010030 */
31struct io_context {
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070032 atomic_long_t refcount;
Jens Axboed38ecf92008-01-24 08:53:35 +010033 atomic_t nr_tasks;
34
35 /* all the fields below are protected by this lock */
36 spinlock_t lock;
Jens Axboefd0928d2008-01-24 08:52:45 +010037
38 unsigned short ioprio;
Vivek Goyal31e4c282009-12-03 12:59:42 -050039
Jens Axboefd0928d2008-01-24 08:52:45 +010040 /*
41 * For request batching
42 */
Jens Axboefd0928d2008-01-24 08:52:45 +010043 int nr_batch_requests; /* Number of requests left in the batch */
Richard Kennedy58c24a62010-02-26 14:00:43 +010044 unsigned long last_waited; /* Time last woken after wait for request */
Jens Axboefd0928d2008-01-24 08:52:45 +010045
Tejun Heoc5869802011-12-14 00:33:41 +010046 struct radix_tree_root icq_tree;
47 struct io_cq __rcu *icq_hint;
48 struct hlist_head icq_list;
Tejun Heob2efa052011-12-14 00:33:39 +010049
50 struct work_struct release_work;
Jens Axboefd0928d2008-01-24 08:52:45 +010051};
52
Jens Axboed38ecf92008-01-24 08:53:35 +010053static inline struct io_context *ioc_task_link(struct io_context *ioc)
54{
55 /*
56 * if ref count is zero, don't allow sharing (ioc is going away, it's
57 * a race).
58 */
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070059 if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
Li Zefancbb4f262009-07-31 08:55:48 +020060 atomic_inc(&ioc->nr_tasks);
Jens Axboed38ecf92008-01-24 08:53:35 +010061 return ioc;
Jens Axboed237e5c2008-04-15 09:25:33 +020062 }
Jens Axboed38ecf92008-01-24 08:53:35 +010063
64 return NULL;
65}
66
Louis Rillingb69f2292009-12-04 14:52:42 +010067struct task_struct;
Jens Axboeda9cbc82008-06-30 20:42:08 +020068#ifdef CONFIG_BLOCK
Tejun Heob2efa052011-12-14 00:33:39 +010069void put_io_context(struct io_context *ioc, struct request_queue *locked_q);
Louis Rillingb69f2292009-12-04 14:52:42 +010070void exit_io_context(struct task_struct *task);
Tejun Heo6e736be2011-12-14 00:33:38 +010071struct io_context *get_task_io_context(struct task_struct *task,
72 gfp_t gfp_flags, int node);
Tejun Heodc869002011-12-14 00:33:38 +010073void ioc_ioprio_changed(struct io_context *ioc, int ioprio);
74void ioc_cgroup_changed(struct io_context *ioc);
Jens Axboeda9cbc82008-06-30 20:42:08 +020075#else
Jens Axboeda9cbc82008-06-30 20:42:08 +020076struct io_context;
Tejun Heob2efa052011-12-14 00:33:39 +010077static inline void put_io_context(struct io_context *ioc,
78 struct request_queue *locked_q) { }
Tejun Heo42ec57a2011-12-14 00:33:37 +010079static inline void exit_io_context(struct task_struct *task) { }
Jens Axboeda9cbc82008-06-30 20:42:08 +020080#endif
81
Jens Axboefd0928d2008-01-24 08:52:45 +010082#endif