[PATCH] fix rmmod problems with elevator attributes, clean them up
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 19 Mar 2006 03:27:18 +0000 (22:27 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 19 Mar 2006 03:27:18 +0000 (22:27 -0500)
block/as-iosched.c
block/cfq-iosched.c
block/deadline-iosched.c
block/elevator.c
include/linux/elevator.h

index 3fb60eb..296708c 100644 (file)
@@ -1725,7 +1725,7 @@ as_var_store(unsigned long *var, const char *page, size_t count)
        return count;
 }
 
-static ssize_t as_est_show(elevator_t *e, char *page)
+static ssize_t est_time_show(elevator_t *e, char *page)
 {
        struct as_data *ad = e->elevator_data;
        int pos = 0;
@@ -1748,11 +1748,11 @@ static ssize_t __FUNC(elevator_t *e, char *page)                \
        struct as_data *ad = e->elevator_data;                  \
        return as_var_show(jiffies_to_msecs((__VAR)), (page));  \
 }
-SHOW_FUNCTION(as_readexpire_show, ad->fifo_expire[REQ_SYNC]);
-SHOW_FUNCTION(as_writeexpire_show, ad->fifo_expire[REQ_ASYNC]);
-SHOW_FUNCTION(as_anticexpire_show, ad->antic_expire);
-SHOW_FUNCTION(as_read_batchexpire_show, ad->batch_expire[REQ_SYNC]);
-SHOW_FUNCTION(as_write_batchexpire_show, ad->batch_expire[REQ_ASYNC]);
+SHOW_FUNCTION(as_read_expire_show, ad->fifo_expire[REQ_SYNC]);
+SHOW_FUNCTION(as_write_expire_show, ad->fifo_expire[REQ_ASYNC]);
+SHOW_FUNCTION(as_antic_expire_show, ad->antic_expire);
+SHOW_FUNCTION(as_read_batch_expire_show, ad->batch_expire[REQ_SYNC]);
+SHOW_FUNCTION(as_write_batch_expire_show, ad->batch_expire[REQ_ASYNC]);
 #undef SHOW_FUNCTION
 
 #define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX)                                \
@@ -1767,53 +1767,26 @@ static ssize_t __FUNC(elevator_t *e, const char *page, size_t count)    \
        *(__PTR) = msecs_to_jiffies(*(__PTR));                          \
        return ret;                                                     \
 }
-STORE_FUNCTION(as_readexpire_store, &ad->fifo_expire[REQ_SYNC], 0, INT_MAX);
-STORE_FUNCTION(as_writeexpire_store, &ad->fifo_expire[REQ_ASYNC], 0, INT_MAX);
-STORE_FUNCTION(as_anticexpire_store, &ad->antic_expire, 0, INT_MAX);
-STORE_FUNCTION(as_read_batchexpire_store,
+STORE_FUNCTION(as_read_expire_store, &ad->fifo_expire[REQ_SYNC], 0, INT_MAX);
+STORE_FUNCTION(as_write_expire_store, &ad->fifo_expire[REQ_ASYNC], 0, INT_MAX);
+STORE_FUNCTION(as_antic_expire_store, &ad->antic_expire, 0, INT_MAX);
+STORE_FUNCTION(as_read_batch_expire_store,
                        &ad->batch_expire[REQ_SYNC], 0, INT_MAX);
-STORE_FUNCTION(as_write_batchexpire_store,
+STORE_FUNCTION(as_write_batch_expire_store,
                        &ad->batch_expire[REQ_ASYNC], 0, INT_MAX);
 #undef STORE_FUNCTION
 
-static struct elv_fs_entry as_est_entry = {
-       .attr = {.name = "est_time", .mode = S_IRUGO },
-       .show = as_est_show,
-};
-static struct elv_fs_entry as_readexpire_entry = {
-       .attr = {.name = "read_expire", .mode = S_IRUGO | S_IWUSR },
-       .show = as_readexpire_show,
-       .store = as_readexpire_store,
-};
-static struct elv_fs_entry as_writeexpire_entry = {
-       .attr = {.name = "write_expire", .mode = S_IRUGO | S_IWUSR },
-       .show = as_writeexpire_show,
-       .store = as_writeexpire_store,
-};
-static struct elv_fs_entry as_anticexpire_entry = {
-       .attr = {.name = "antic_expire", .mode = S_IRUGO | S_IWUSR },
-       .show = as_anticexpire_show,
-       .store = as_anticexpire_store,
-};
-static struct elv_fs_entry as_read_batchexpire_entry = {
-       .attr = {.name = "read_batch_expire", .mode = S_IRUGO | S_IWUSR },
-       .show = as_read_batchexpire_show,
-       .store = as_read_batchexpire_store,
-};
-static struct elv_fs_entry as_write_batchexpire_entry = {
-       .attr = {.name = "write_batch_expire", .mode = S_IRUGO | S_IWUSR },
-       .show = as_write_batchexpire_show,
-       .store = as_write_batchexpire_store,
-};
-
-static struct attribute *as_attrs[] = {
-       &as_est_entry.attr,
-       &as_readexpire_entry.attr,
-       &as_writeexpire_entry.attr,
-       &as_anticexpire_entry.attr,
-       &as_read_batchexpire_entry.attr,
-       &as_write_batchexpire_entry.attr,
-       NULL,
+#define AS_ATTR(name) \
+       __ATTR(name, S_IRUGO|S_IWUSR, as_##name##_show, as_##name##_store)
+
+static struct elv_fs_entry as_attrs[] = {
+       __ATTR_RO(est_time),
+       AS_ATTR(read_expire),
+       AS_ATTR(write_expire),
+       AS_ATTR(antic_expire),
+       AS_ATTR(read_batch_expire),
+       AS_ATTR(write_batch_expire),
+       __ATTR_NULL
 };
 
 static struct elevator_type iosched_as = {
index 6dc156e..c4a0d5d 100644 (file)
@@ -2304,8 +2304,8 @@ SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0);
 SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued, 0);
 SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1);
 SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1);
-SHOW_FUNCTION(cfq_back_max_show, cfqd->cfq_back_max, 0);
-SHOW_FUNCTION(cfq_back_penalty_show, cfqd->cfq_back_penalty, 0);
+SHOW_FUNCTION(cfq_back_seek_max_show, cfqd->cfq_back_max, 0);
+SHOW_FUNCTION(cfq_back_seek_penalty_show, cfqd->cfq_back_penalty, 0);
 SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1);
 SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1);
 SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1);
@@ -2333,8 +2333,8 @@ STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0);
 STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, UINT_MAX, 0);
 STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1, UINT_MAX, 1);
 STORE_FUNCTION(cfq_fifo_expire_async_store, &cfqd->cfq_fifo_expire[0], 1, UINT_MAX, 1);
-STORE_FUNCTION(cfq_back_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
-STORE_FUNCTION(cfq_back_penalty_store, &cfqd->cfq_back_penalty, 1, UINT_MAX, 0);
+STORE_FUNCTION(cfq_back_seek_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
+STORE_FUNCTION(cfq_back_seek_penalty_store, &cfqd->cfq_back_penalty, 1, UINT_MAX, 0);
 STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1);
 STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1);
 STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1);
@@ -2342,75 +2342,22 @@ 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 elv_fs_entry cfq_quantum_entry = {
-       .attr = {.name = "quantum", .mode = S_IRUGO | S_IWUSR },
-       .show = cfq_quantum_show,
-       .store = cfq_quantum_store,
-};
-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 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 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 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 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 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 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 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 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 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 *cfq_attrs[] = {
-       &cfq_quantum_entry.attr,
-       &cfq_queued_entry.attr,
-       &cfq_fifo_expire_sync_entry.attr,
-       &cfq_fifo_expire_async_entry.attr,
-       &cfq_back_max_entry.attr,
-       &cfq_back_penalty_entry.attr,
-       &cfq_slice_sync_entry.attr,
-       &cfq_slice_async_entry.attr,
-       &cfq_slice_async_rq_entry.attr,
-       &cfq_slice_idle_entry.attr,
-       &cfq_max_depth_entry.attr,
-       NULL,
+#define CFQ_ATTR(name) \
+       __ATTR(name, S_IRUGO|S_IWUSR, cfq_##name##_show, cfq_##name##_store)
+
+static struct elv_fs_entry cfq_attrs[] = {
+       CFQ_ATTR(quantum),
+       CFQ_ATTR(queued),
+       CFQ_ATTR(fifo_expire_sync),
+       CFQ_ATTR(fifo_expire_async),
+       CFQ_ATTR(back_seek_max),
+       CFQ_ATTR(back_seek_penalty),
+       CFQ_ATTR(slice_sync),
+       CFQ_ATTR(slice_async),
+       CFQ_ATTR(slice_async_rq),
+       CFQ_ATTR(slice_idle),
+       CFQ_ATTR(max_depth),
+       __ATTR_NULL
 };
 
 static struct elevator_type iosched_cfq = {
index a3e3ff1..399fa1e 100644 (file)
@@ -719,11 +719,11 @@ static ssize_t __FUNC(elevator_t *e, char *page)                  \
                __data = jiffies_to_msecs(__data);                      \
        return deadline_var_show(__data, (page));                       \
 }
-SHOW_FUNCTION(deadline_readexpire_show, dd->fifo_expire[READ], 1);
-SHOW_FUNCTION(deadline_writeexpire_show, dd->fifo_expire[WRITE], 1);
-SHOW_FUNCTION(deadline_writesstarved_show, dd->writes_starved, 0);
-SHOW_FUNCTION(deadline_frontmerges_show, dd->front_merges, 0);
-SHOW_FUNCTION(deadline_fifobatch_show, dd->fifo_batch, 0);
+SHOW_FUNCTION(deadline_read_expire_show, dd->fifo_expire[READ], 1);
+SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[WRITE], 1);
+SHOW_FUNCTION(deadline_writes_starved_show, dd->writes_starved, 0);
+SHOW_FUNCTION(deadline_front_merges_show, dd->front_merges, 0);
+SHOW_FUNCTION(deadline_fifo_batch_show, dd->fifo_batch, 0);
 #undef SHOW_FUNCTION
 
 #define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV)                        \
@@ -742,46 +742,24 @@ static ssize_t __FUNC(elevator_t *e, const char *page, size_t count)      \
                *(__PTR) = __data;                                      \
        return ret;                                                     \
 }
-STORE_FUNCTION(deadline_readexpire_store, &dd->fifo_expire[READ], 0, INT_MAX, 1);
-STORE_FUNCTION(deadline_writeexpire_store, &dd->fifo_expire[WRITE], 0, INT_MAX, 1);
-STORE_FUNCTION(deadline_writesstarved_store, &dd->writes_starved, INT_MIN, INT_MAX, 0);
-STORE_FUNCTION(deadline_frontmerges_store, &dd->front_merges, 0, 1, 0);
-STORE_FUNCTION(deadline_fifobatch_store, &dd->fifo_batch, 0, INT_MAX, 0);
+STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, INT_MAX, 1);
+STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], 0, INT_MAX, 1);
+STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, INT_MIN, INT_MAX, 0);
+STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, 0);
+STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, INT_MAX, 0);
 #undef STORE_FUNCTION
 
-static struct elv_fs_entry deadline_readexpire_entry = {
-       .attr = {.name = "read_expire", .mode = S_IRUGO | S_IWUSR },
-       .show = deadline_readexpire_show,
-       .store = deadline_readexpire_store,
-};
-static struct elv_fs_entry deadline_writeexpire_entry = {
-       .attr = {.name = "write_expire", .mode = S_IRUGO | S_IWUSR },
-       .show = deadline_writeexpire_show,
-       .store = deadline_writeexpire_store,
-};
-static struct elv_fs_entry deadline_writesstarved_entry = {
-       .attr = {.name = "writes_starved", .mode = S_IRUGO | S_IWUSR },
-       .show = deadline_writesstarved_show,
-       .store = deadline_writesstarved_store,
-};
-static struct elv_fs_entry deadline_frontmerges_entry = {
-       .attr = {.name = "front_merges", .mode = S_IRUGO | S_IWUSR },
-       .show = deadline_frontmerges_show,
-       .store = deadline_frontmerges_store,
-};
-static struct elv_fs_entry deadline_fifobatch_entry = {
-       .attr = {.name = "fifo_batch", .mode = S_IRUGO | S_IWUSR },
-       .show = deadline_fifobatch_show,
-       .store = deadline_fifobatch_store,
-};
-
-static struct attribute *deadline_attrs[] = {
-       &deadline_readexpire_entry.attr,
-       &deadline_writeexpire_entry.attr,
-       &deadline_writesstarved_entry.attr,
-       &deadline_frontmerges_entry.attr,
-       &deadline_fifobatch_entry.attr,
-       NULL,
+#define DD_ATTR(name) \
+       __ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \
+                                     deadline_##name##_store)
+
+static struct elv_fs_entry deadline_attrs[] = {
+       DD_ATTR(read_expire),
+       DD_ATTR(write_expire),
+       DD_ATTR(writes_starved),
+       DD_ATTR(front_merges),
+       DD_ATTR(fifo_batch),
+       __ATTR_NULL
 };
 
 static struct elevator_type iosched_deadline = {
index 0d2db53..db3d0d8 100644 (file)
@@ -699,11 +699,12 @@ int elv_register_queue(struct request_queue *q)
 
        error = kobject_add(&e->kobj);
        if (!error) {
-               struct attribute **attr = e->elevator_type->elevator_attrs;
+               struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;
                if (attr) {
-                       while (*attr) {
-                               if (sysfs_create_file(&e->kobj,*attr++))
+                       while (attr->attr.name) {
+                               if (sysfs_create_file(&e->kobj, &attr->attr))
                                        break;
+                               attr++;
                        }
                }
                kobject_uevent(&e->kobj, KOBJ_ADD);
index 4d0a80f..ad133fc 100644 (file)
@@ -53,6 +53,12 @@ struct elevator_ops
 
 #define ELV_NAME_MAX   (16)
 
+struct elv_fs_entry {
+       struct attribute attr;
+       ssize_t (*show)(elevator_t *, char *);
+       ssize_t (*store)(elevator_t *, const char *, size_t);
+};
+
 /*
  * identifies an elevator type, such as AS or deadline
  */
@@ -61,7 +67,7 @@ struct elevator_type
        struct list_head list;
        struct elevator_ops ops;
        struct elevator_type *elevator_type;
-       struct attribute **elevator_attrs;
+       struct elv_fs_entry *elevator_attrs;
        char elevator_name[ELV_NAME_MAX];
        struct module *elevator_owner;
 };
@@ -142,12 +148,6 @@ enum {
        ELV_MQUEUE_MUST,
 };
 
-struct elv_fs_entry {
-       struct attribute attr;
-       ssize_t (*show)(elevator_t *, char *);
-       ssize_t (*store)(elevator_t *, const char *, size_t);
-};
-
 #define rq_end_sector(rq)      ((rq)->sector + (rq)->nr_sectors)
 
 #endif