[PATCH] elevator_t lifetime rules and sysfs fixes
[pandora-kernel.git] / block / cfq-iosched.c
index 2949920..6dc156e 100644 (file)
@@ -6,21 +6,13 @@
  *
  *  Copyright (C) 2003 Jens Axboe <axboe@suse.de>
  */
-#include <linux/kernel.h>
-#include <linux/fs.h>
-#include <linux/blkdev.h>
-#include <linux/elevator.h>
-#include <linux/bio.h>
 #include <linux/config.h>
 #include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/init.h>
-#include <linux/compiler.h>
+#include <linux/blkdev.h>
+#include <linux/elevator.h>
 #include <linux/hash.h>
 #include <linux/rbtree.h>
-#include <linux/mempool.h>
 #include <linux/ioprio.h>
-#include <linux/writeback.h>
 
 /*
  * tunables
@@ -114,7 +106,6 @@ static struct completion *ioc_gone;
  * Per block device queue structure
  */
 struct cfq_data {
-       atomic_t ref;
        request_queue_t *queue;
 
        /*
@@ -295,7 +286,6 @@ CFQ_CRQ_FNS(is_sync);
 
 static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned int, unsigned short);
 static void cfq_dispatch_insert(request_queue_t *, struct cfq_rq *);
-static void cfq_put_cfqd(struct cfq_data *cfqd);
 static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, unsigned int key, struct task_struct *tsk, gfp_t gfp_mask);
 
 #define process_sync(tsk)      ((tsk)->flags & PF_SYNCWRITE)
@@ -1168,8 +1158,6 @@ static void cfq_put_queue(struct cfq_queue *cfqq)
        if (unlikely(cfqd->active_queue == cfqq))
                __cfq_slice_expired(cfqd, cfqq, 0);
 
-       cfq_put_cfqd(cfqq->cfqd);
-
        /*
         * it's on the empty list and still hashed
         */
@@ -1262,10 +1250,6 @@ static void cfq_exit_single_io_context(struct cfq_io_context *cic)
        spin_unlock(q->queue_lock);
 }
 
-/*
- * Another task may update the task cic list, if it is doing a queue lookup
- * on its behalf. cfq_cic_lock excludes such concurrent updates
- */
 static void cfq_exit_io_context(struct cfq_io_context *cic)
 {
        struct cfq_io_context *__cic;
@@ -1442,7 +1426,6 @@ retry:
                hlist_add_head(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]);
                atomic_set(&cfqq->ref, 0);
                cfqq->cfqd = cfqd;
-               atomic_inc(&cfqd->ref);
                cfqq->service_last = 0;
                /*
                 * set ->slice_left to allow preemption for a new process
@@ -2144,19 +2127,6 @@ static void cfq_shutdown_timer_wq(struct cfq_data *cfqd)
        blk_sync_queue(cfqd->queue);
 }
 
-static void cfq_put_cfqd(struct cfq_data *cfqd)
-{
-       if (!atomic_dec_and_test(&cfqd->ref))
-               return;
-
-       cfq_shutdown_timer_wq(cfqd);
-
-       mempool_destroy(cfqd->crq_pool);
-       kfree(cfqd->crq_hash);
-       kfree(cfqd->cfq_hash);
-       kfree(cfqd);
-}
-
 static void cfq_exit_queue(elevator_t *e)
 {
        struct cfq_data *cfqd = e->elevator_data;
@@ -2184,7 +2154,13 @@ static void cfq_exit_queue(elevator_t *e)
        }
        spin_unlock_irq(q->queue_lock);
        write_unlock(&cfq_exit_lock);
-       cfq_put_cfqd(cfqd);
+
+       cfq_shutdown_timer_wq(cfqd);
+
+       mempool_destroy(cfqd->crq_pool);
+       kfree(cfqd->crq_hash);
+       kfree(cfqd->cfq_hash);
+       kfree(cfqd);
 }
 
 static int cfq_init_queue(request_queue_t *q, elevator_t *e)
@@ -2241,8 +2217,6 @@ static int cfq_init_queue(request_queue_t *q, elevator_t *e)
 
        INIT_WORK(&cfqd->unplug_work, cfq_kick_queue, q);
 
-       atomic_set(&cfqd->ref, 1);
-
        cfqd->cfq_queued = cfq_queued;
        cfqd->cfq_quantum = cfq_quantum;
        cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0];
@@ -2301,11 +2275,6 @@ fail:
 /*
  * sysfs parts below -->
  */
-struct cfq_fs_entry {
-       struct attribute attr;
-       ssize_t (*show)(struct cfq_data *, char *);
-       ssize_t (*store)(struct cfq_data *, const char *, size_t);
-};
 
 static ssize_t
 cfq_var_show(unsigned int var, char *page)
@@ -2323,8 +2292,9 @@ cfq_var_store(unsigned int *var, const char *page, size_t count)
 }
 
 #define SHOW_FUNCTION(__FUNC, __VAR, __CONV)                           \
-static ssize_t __FUNC(struct cfq_data *cfqd, char *page)               \
+static ssize_t __FUNC(elevator_t *e, char *page)                       \
 {                                                                      \
+       struct cfq_data *cfqd = e->elevator_data;                       \
        unsigned int __data = __VAR;                                    \
        if (__CONV)                                                     \
                __data = jiffies_to_msecs(__data);                      \
@@ -2344,8 +2314,9 @@ SHOW_FUNCTION(cfq_max_depth_show, cfqd->cfq_max_depth, 0);
 #undef SHOW_FUNCTION
 
 #define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV)                        \
-static ssize_t __FUNC(struct cfq_data *cfqd, const char *page, size_t count)   \
+static ssize_t __FUNC(elevator_t *e, const char *page, size_t count)   \
 {                                                                      \
+       struct cfq_data *cfqd = e->elevator_data;                       \
        unsigned int __data;                                            \
        int ret = cfq_var_store(&__data, (page), count);                \
        if (__data < (MIN))                                             \
@@ -2371,63 +2342,63 @@ STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1, UINT_MAX,
 STORE_FUNCTION(cfq_max_depth_store, &cfqd->cfq_max_depth, 1, UINT_MAX, 0);
 #undef STORE_FUNCTION
 
-static struct cfq_fs_entry cfq_quantum_entry = {
+static struct elv_fs_entry cfq_quantum_entry = {
        .attr = {.name = "quantum", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_quantum_show,
        .store = cfq_quantum_store,
 };
-static struct cfq_fs_entry cfq_queued_entry = {
+static struct elv_fs_entry cfq_queued_entry = {
        .attr = {.name = "queued", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_queued_show,
        .store = cfq_queued_store,
 };
-static struct cfq_fs_entry cfq_fifo_expire_sync_entry = {
+static struct elv_fs_entry cfq_fifo_expire_sync_entry = {
        .attr = {.name = "fifo_expire_sync", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_fifo_expire_sync_show,
        .store = cfq_fifo_expire_sync_store,
 };
-static struct cfq_fs_entry cfq_fifo_expire_async_entry = {
+static struct elv_fs_entry cfq_fifo_expire_async_entry = {
        .attr = {.name = "fifo_expire_async", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_fifo_expire_async_show,
        .store = cfq_fifo_expire_async_store,
 };
-static struct cfq_fs_entry cfq_back_max_entry = {
+static struct elv_fs_entry cfq_back_max_entry = {
        .attr = {.name = "back_seek_max", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_back_max_show,
        .store = cfq_back_max_store,
 };
-static struct cfq_fs_entry cfq_back_penalty_entry = {
+static struct elv_fs_entry cfq_back_penalty_entry = {
        .attr = {.name = "back_seek_penalty", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_back_penalty_show,
        .store = cfq_back_penalty_store,
 };
-static struct cfq_fs_entry cfq_slice_sync_entry = {
+static struct elv_fs_entry cfq_slice_sync_entry = {
        .attr = {.name = "slice_sync", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_slice_sync_show,
        .store = cfq_slice_sync_store,
 };
-static struct cfq_fs_entry cfq_slice_async_entry = {
+static struct elv_fs_entry cfq_slice_async_entry = {
        .attr = {.name = "slice_async", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_slice_async_show,
        .store = cfq_slice_async_store,
 };
-static struct cfq_fs_entry cfq_slice_async_rq_entry = {
+static struct elv_fs_entry cfq_slice_async_rq_entry = {
        .attr = {.name = "slice_async_rq", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_slice_async_rq_show,
        .store = cfq_slice_async_rq_store,
 };
-static struct cfq_fs_entry cfq_slice_idle_entry = {
+static struct elv_fs_entry cfq_slice_idle_entry = {
        .attr = {.name = "slice_idle", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_slice_idle_show,
        .store = cfq_slice_idle_store,
 };
-static struct cfq_fs_entry cfq_max_depth_entry = {
+static struct elv_fs_entry cfq_max_depth_entry = {
        .attr = {.name = "max_depth", .mode = S_IRUGO | S_IWUSR },
        .show = cfq_max_depth_show,
        .store = cfq_max_depth_store,
 };
 
-static struct attribute *default_attrs[] = {
+static struct attribute *cfq_attrs[] = {
        &cfq_quantum_entry.attr,
        &cfq_queued_entry.attr,
        &cfq_fifo_expire_sync_entry.attr,
@@ -2442,43 +2413,6 @@ static struct attribute *default_attrs[] = {
        NULL,
 };
 
-#define to_cfq(atr) container_of((atr), struct cfq_fs_entry, attr)
-
-static ssize_t
-cfq_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
-{
-       elevator_t *e = container_of(kobj, elevator_t, kobj);
-       struct cfq_fs_entry *entry = to_cfq(attr);
-
-       if (!entry->show)
-               return -EIO;
-
-       return entry->show(e->elevator_data, page);
-}
-
-static ssize_t
-cfq_attr_store(struct kobject *kobj, struct attribute *attr,
-              const char *page, size_t length)
-{
-       elevator_t *e = container_of(kobj, elevator_t, kobj);
-       struct cfq_fs_entry *entry = to_cfq(attr);
-
-       if (!entry->store)
-               return -EIO;
-
-       return entry->store(e->elevator_data, page, length);
-}
-
-static struct sysfs_ops cfq_sysfs_ops = {
-       .show   = cfq_attr_show,
-       .store  = cfq_attr_store,
-};
-
-static struct kobj_type cfq_ktype = {
-       .sysfs_ops      = &cfq_sysfs_ops,
-       .default_attrs  = default_attrs,
-};
-
 static struct elevator_type iosched_cfq = {
        .ops = {
                .elevator_merge_fn =            cfq_merge,
@@ -2499,7 +2433,7 @@ static struct elevator_type iosched_cfq = {
                .elevator_exit_fn =             cfq_exit_queue,
                .trim =                         cfq_trim,
        },
-       .elevator_ktype =       &cfq_ktype,
+       .elevator_attrs =       cfq_attrs,
        .elevator_name =        "cfq",
        .elevator_owner =       THIS_MODULE,
 };