Commit e572ec7e4e432de7ecf7bd2e62117646fa64e518

Authored by Al Viro
1 parent 3d1ab40f4c

[PATCH] fix rmmod problems with elevator attributes, clean them up

Showing 5 changed files with 74 additions and 175 deletions Side-by-side Diff

... ... @@ -1725,7 +1725,7 @@
1725 1725 return count;
1726 1726 }
1727 1727  
1728   -static ssize_t as_est_show(elevator_t *e, char *page)
  1728 +static ssize_t est_time_show(elevator_t *e, char *page)
1729 1729 {
1730 1730 struct as_data *ad = e->elevator_data;
1731 1731 int pos = 0;
... ... @@ -1748,11 +1748,11 @@
1748 1748 struct as_data *ad = e->elevator_data; \
1749 1749 return as_var_show(jiffies_to_msecs((__VAR)), (page)); \
1750 1750 }
1751   -SHOW_FUNCTION(as_readexpire_show, ad->fifo_expire[REQ_SYNC]);
1752   -SHOW_FUNCTION(as_writeexpire_show, ad->fifo_expire[REQ_ASYNC]);
1753   -SHOW_FUNCTION(as_anticexpire_show, ad->antic_expire);
1754   -SHOW_FUNCTION(as_read_batchexpire_show, ad->batch_expire[REQ_SYNC]);
1755   -SHOW_FUNCTION(as_write_batchexpire_show, ad->batch_expire[REQ_ASYNC]);
  1751 +SHOW_FUNCTION(as_read_expire_show, ad->fifo_expire[REQ_SYNC]);
  1752 +SHOW_FUNCTION(as_write_expire_show, ad->fifo_expire[REQ_ASYNC]);
  1753 +SHOW_FUNCTION(as_antic_expire_show, ad->antic_expire);
  1754 +SHOW_FUNCTION(as_read_batch_expire_show, ad->batch_expire[REQ_SYNC]);
  1755 +SHOW_FUNCTION(as_write_batch_expire_show, ad->batch_expire[REQ_ASYNC]);
1756 1756 #undef SHOW_FUNCTION
1757 1757  
1758 1758 #define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX) \
1759 1759  
1760 1760  
1761 1761  
... ... @@ -1767,53 +1767,26 @@
1767 1767 *(__PTR) = msecs_to_jiffies(*(__PTR)); \
1768 1768 return ret; \
1769 1769 }
1770   -STORE_FUNCTION(as_readexpire_store, &ad->fifo_expire[REQ_SYNC], 0, INT_MAX);
1771   -STORE_FUNCTION(as_writeexpire_store, &ad->fifo_expire[REQ_ASYNC], 0, INT_MAX);
1772   -STORE_FUNCTION(as_anticexpire_store, &ad->antic_expire, 0, INT_MAX);
1773   -STORE_FUNCTION(as_read_batchexpire_store,
  1770 +STORE_FUNCTION(as_read_expire_store, &ad->fifo_expire[REQ_SYNC], 0, INT_MAX);
  1771 +STORE_FUNCTION(as_write_expire_store, &ad->fifo_expire[REQ_ASYNC], 0, INT_MAX);
  1772 +STORE_FUNCTION(as_antic_expire_store, &ad->antic_expire, 0, INT_MAX);
  1773 +STORE_FUNCTION(as_read_batch_expire_store,
1774 1774 &ad->batch_expire[REQ_SYNC], 0, INT_MAX);
1775   -STORE_FUNCTION(as_write_batchexpire_store,
  1775 +STORE_FUNCTION(as_write_batch_expire_store,
1776 1776 &ad->batch_expire[REQ_ASYNC], 0, INT_MAX);
1777 1777 #undef STORE_FUNCTION
1778 1778  
1779   -static struct elv_fs_entry as_est_entry = {
1780   - .attr = {.name = "est_time", .mode = S_IRUGO },
1781   - .show = as_est_show,
1782   -};
1783   -static struct elv_fs_entry as_readexpire_entry = {
1784   - .attr = {.name = "read_expire", .mode = S_IRUGO | S_IWUSR },
1785   - .show = as_readexpire_show,
1786   - .store = as_readexpire_store,
1787   -};
1788   -static struct elv_fs_entry as_writeexpire_entry = {
1789   - .attr = {.name = "write_expire", .mode = S_IRUGO | S_IWUSR },
1790   - .show = as_writeexpire_show,
1791   - .store = as_writeexpire_store,
1792   -};
1793   -static struct elv_fs_entry as_anticexpire_entry = {
1794   - .attr = {.name = "antic_expire", .mode = S_IRUGO | S_IWUSR },
1795   - .show = as_anticexpire_show,
1796   - .store = as_anticexpire_store,
1797   -};
1798   -static struct elv_fs_entry as_read_batchexpire_entry = {
1799   - .attr = {.name = "read_batch_expire", .mode = S_IRUGO | S_IWUSR },
1800   - .show = as_read_batchexpire_show,
1801   - .store = as_read_batchexpire_store,
1802   -};
1803   -static struct elv_fs_entry as_write_batchexpire_entry = {
1804   - .attr = {.name = "write_batch_expire", .mode = S_IRUGO | S_IWUSR },
1805   - .show = as_write_batchexpire_show,
1806   - .store = as_write_batchexpire_store,
1807   -};
  1779 +#define AS_ATTR(name) \
  1780 + __ATTR(name, S_IRUGO|S_IWUSR, as_##name##_show, as_##name##_store)
1808 1781  
1809   -static struct attribute *as_attrs[] = {
1810   - &as_est_entry.attr,
1811   - &as_readexpire_entry.attr,
1812   - &as_writeexpire_entry.attr,
1813   - &as_anticexpire_entry.attr,
1814   - &as_read_batchexpire_entry.attr,
1815   - &as_write_batchexpire_entry.attr,
1816   - NULL,
  1782 +static struct elv_fs_entry as_attrs[] = {
  1783 + __ATTR_RO(est_time),
  1784 + AS_ATTR(read_expire),
  1785 + AS_ATTR(write_expire),
  1786 + AS_ATTR(antic_expire),
  1787 + AS_ATTR(read_batch_expire),
  1788 + AS_ATTR(write_batch_expire),
  1789 + __ATTR_NULL
1817 1790 };
1818 1791  
1819 1792 static struct elevator_type iosched_as = {
... ... @@ -2304,8 +2304,8 @@
2304 2304 SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued, 0);
2305 2305 SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1);
2306 2306 SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1);
2307   -SHOW_FUNCTION(cfq_back_max_show, cfqd->cfq_back_max, 0);
2308   -SHOW_FUNCTION(cfq_back_penalty_show, cfqd->cfq_back_penalty, 0);
  2307 +SHOW_FUNCTION(cfq_back_seek_max_show, cfqd->cfq_back_max, 0);
  2308 +SHOW_FUNCTION(cfq_back_seek_penalty_show, cfqd->cfq_back_penalty, 0);
2309 2309 SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1);
2310 2310 SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1);
2311 2311 SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1);
... ... @@ -2333,8 +2333,8 @@
2333 2333 STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, UINT_MAX, 0);
2334 2334 STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1, UINT_MAX, 1);
2335 2335 STORE_FUNCTION(cfq_fifo_expire_async_store, &cfqd->cfq_fifo_expire[0], 1, UINT_MAX, 1);
2336   -STORE_FUNCTION(cfq_back_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
2337   -STORE_FUNCTION(cfq_back_penalty_store, &cfqd->cfq_back_penalty, 1, UINT_MAX, 0);
  2336 +STORE_FUNCTION(cfq_back_seek_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
  2337 +STORE_FUNCTION(cfq_back_seek_penalty_store, &cfqd->cfq_back_penalty, 1, UINT_MAX, 0);
2338 2338 STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1);
2339 2339 STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1);
2340 2340 STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1);
2341 2341  
... ... @@ -2342,75 +2342,22 @@
2342 2342 STORE_FUNCTION(cfq_max_depth_store, &cfqd->cfq_max_depth, 1, UINT_MAX, 0);
2343 2343 #undef STORE_FUNCTION
2344 2344  
2345   -static struct elv_fs_entry cfq_quantum_entry = {
2346   - .attr = {.name = "quantum", .mode = S_IRUGO | S_IWUSR },
2347   - .show = cfq_quantum_show,
2348   - .store = cfq_quantum_store,
2349   -};
2350   -static struct elv_fs_entry cfq_queued_entry = {
2351   - .attr = {.name = "queued", .mode = S_IRUGO | S_IWUSR },
2352   - .show = cfq_queued_show,
2353   - .store = cfq_queued_store,
2354   -};
2355   -static struct elv_fs_entry cfq_fifo_expire_sync_entry = {
2356   - .attr = {.name = "fifo_expire_sync", .mode = S_IRUGO | S_IWUSR },
2357   - .show = cfq_fifo_expire_sync_show,
2358   - .store = cfq_fifo_expire_sync_store,
2359   -};
2360   -static struct elv_fs_entry cfq_fifo_expire_async_entry = {
2361   - .attr = {.name = "fifo_expire_async", .mode = S_IRUGO | S_IWUSR },
2362   - .show = cfq_fifo_expire_async_show,
2363   - .store = cfq_fifo_expire_async_store,
2364   -};
2365   -static struct elv_fs_entry cfq_back_max_entry = {
2366   - .attr = {.name = "back_seek_max", .mode = S_IRUGO | S_IWUSR },
2367   - .show = cfq_back_max_show,
2368   - .store = cfq_back_max_store,
2369   -};
2370   -static struct elv_fs_entry cfq_back_penalty_entry = {
2371   - .attr = {.name = "back_seek_penalty", .mode = S_IRUGO | S_IWUSR },
2372   - .show = cfq_back_penalty_show,
2373   - .store = cfq_back_penalty_store,
2374   -};
2375   -static struct elv_fs_entry cfq_slice_sync_entry = {
2376   - .attr = {.name = "slice_sync", .mode = S_IRUGO | S_IWUSR },
2377   - .show = cfq_slice_sync_show,
2378   - .store = cfq_slice_sync_store,
2379   -};
2380   -static struct elv_fs_entry cfq_slice_async_entry = {
2381   - .attr = {.name = "slice_async", .mode = S_IRUGO | S_IWUSR },
2382   - .show = cfq_slice_async_show,
2383   - .store = cfq_slice_async_store,
2384   -};
2385   -static struct elv_fs_entry cfq_slice_async_rq_entry = {
2386   - .attr = {.name = "slice_async_rq", .mode = S_IRUGO | S_IWUSR },
2387   - .show = cfq_slice_async_rq_show,
2388   - .store = cfq_slice_async_rq_store,
2389   -};
2390   -static struct elv_fs_entry cfq_slice_idle_entry = {
2391   - .attr = {.name = "slice_idle", .mode = S_IRUGO | S_IWUSR },
2392   - .show = cfq_slice_idle_show,
2393   - .store = cfq_slice_idle_store,
2394   -};
2395   -static struct elv_fs_entry cfq_max_depth_entry = {
2396   - .attr = {.name = "max_depth", .mode = S_IRUGO | S_IWUSR },
2397   - .show = cfq_max_depth_show,
2398   - .store = cfq_max_depth_store,
2399   -};
  2345 +#define CFQ_ATTR(name) \
  2346 + __ATTR(name, S_IRUGO|S_IWUSR, cfq_##name##_show, cfq_##name##_store)
2400 2347  
2401   -static struct attribute *cfq_attrs[] = {
2402   - &cfq_quantum_entry.attr,
2403   - &cfq_queued_entry.attr,
2404   - &cfq_fifo_expire_sync_entry.attr,
2405   - &cfq_fifo_expire_async_entry.attr,
2406   - &cfq_back_max_entry.attr,
2407   - &cfq_back_penalty_entry.attr,
2408   - &cfq_slice_sync_entry.attr,
2409   - &cfq_slice_async_entry.attr,
2410   - &cfq_slice_async_rq_entry.attr,
2411   - &cfq_slice_idle_entry.attr,
2412   - &cfq_max_depth_entry.attr,
2413   - NULL,
  2348 +static struct elv_fs_entry cfq_attrs[] = {
  2349 + CFQ_ATTR(quantum),
  2350 + CFQ_ATTR(queued),
  2351 + CFQ_ATTR(fifo_expire_sync),
  2352 + CFQ_ATTR(fifo_expire_async),
  2353 + CFQ_ATTR(back_seek_max),
  2354 + CFQ_ATTR(back_seek_penalty),
  2355 + CFQ_ATTR(slice_sync),
  2356 + CFQ_ATTR(slice_async),
  2357 + CFQ_ATTR(slice_async_rq),
  2358 + CFQ_ATTR(slice_idle),
  2359 + CFQ_ATTR(max_depth),
  2360 + __ATTR_NULL
2414 2361 };
2415 2362  
2416 2363 static struct elevator_type iosched_cfq = {
block/deadline-iosched.c
... ... @@ -719,11 +719,11 @@
719 719 __data = jiffies_to_msecs(__data); \
720 720 return deadline_var_show(__data, (page)); \
721 721 }
722   -SHOW_FUNCTION(deadline_readexpire_show, dd->fifo_expire[READ], 1);
723   -SHOW_FUNCTION(deadline_writeexpire_show, dd->fifo_expire[WRITE], 1);
724   -SHOW_FUNCTION(deadline_writesstarved_show, dd->writes_starved, 0);
725   -SHOW_FUNCTION(deadline_frontmerges_show, dd->front_merges, 0);
726   -SHOW_FUNCTION(deadline_fifobatch_show, dd->fifo_batch, 0);
  722 +SHOW_FUNCTION(deadline_read_expire_show, dd->fifo_expire[READ], 1);
  723 +SHOW_FUNCTION(deadline_write_expire_show, dd->fifo_expire[WRITE], 1);
  724 +SHOW_FUNCTION(deadline_writes_starved_show, dd->writes_starved, 0);
  725 +SHOW_FUNCTION(deadline_front_merges_show, dd->front_merges, 0);
  726 +SHOW_FUNCTION(deadline_fifo_batch_show, dd->fifo_batch, 0);
727 727 #undef SHOW_FUNCTION
728 728  
729 729 #define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \
730 730  
731 731  
... ... @@ -742,46 +742,24 @@
742 742 *(__PTR) = __data; \
743 743 return ret; \
744 744 }
745   -STORE_FUNCTION(deadline_readexpire_store, &dd->fifo_expire[READ], 0, INT_MAX, 1);
746   -STORE_FUNCTION(deadline_writeexpire_store, &dd->fifo_expire[WRITE], 0, INT_MAX, 1);
747   -STORE_FUNCTION(deadline_writesstarved_store, &dd->writes_starved, INT_MIN, INT_MAX, 0);
748   -STORE_FUNCTION(deadline_frontmerges_store, &dd->front_merges, 0, 1, 0);
749   -STORE_FUNCTION(deadline_fifobatch_store, &dd->fifo_batch, 0, INT_MAX, 0);
  745 +STORE_FUNCTION(deadline_read_expire_store, &dd->fifo_expire[READ], 0, INT_MAX, 1);
  746 +STORE_FUNCTION(deadline_write_expire_store, &dd->fifo_expire[WRITE], 0, INT_MAX, 1);
  747 +STORE_FUNCTION(deadline_writes_starved_store, &dd->writes_starved, INT_MIN, INT_MAX, 0);
  748 +STORE_FUNCTION(deadline_front_merges_store, &dd->front_merges, 0, 1, 0);
  749 +STORE_FUNCTION(deadline_fifo_batch_store, &dd->fifo_batch, 0, INT_MAX, 0);
750 750 #undef STORE_FUNCTION
751 751  
752   -static struct elv_fs_entry deadline_readexpire_entry = {
753   - .attr = {.name = "read_expire", .mode = S_IRUGO | S_IWUSR },
754   - .show = deadline_readexpire_show,
755   - .store = deadline_readexpire_store,
756   -};
757   -static struct elv_fs_entry deadline_writeexpire_entry = {
758   - .attr = {.name = "write_expire", .mode = S_IRUGO | S_IWUSR },
759   - .show = deadline_writeexpire_show,
760   - .store = deadline_writeexpire_store,
761   -};
762   -static struct elv_fs_entry deadline_writesstarved_entry = {
763   - .attr = {.name = "writes_starved", .mode = S_IRUGO | S_IWUSR },
764   - .show = deadline_writesstarved_show,
765   - .store = deadline_writesstarved_store,
766   -};
767   -static struct elv_fs_entry deadline_frontmerges_entry = {
768   - .attr = {.name = "front_merges", .mode = S_IRUGO | S_IWUSR },
769   - .show = deadline_frontmerges_show,
770   - .store = deadline_frontmerges_store,
771   -};
772   -static struct elv_fs_entry deadline_fifobatch_entry = {
773   - .attr = {.name = "fifo_batch", .mode = S_IRUGO | S_IWUSR },
774   - .show = deadline_fifobatch_show,
775   - .store = deadline_fifobatch_store,
776   -};
  752 +#define DD_ATTR(name) \
  753 + __ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \
  754 + deadline_##name##_store)
777 755  
778   -static struct attribute *deadline_attrs[] = {
779   - &deadline_readexpire_entry.attr,
780   - &deadline_writeexpire_entry.attr,
781   - &deadline_writesstarved_entry.attr,
782   - &deadline_frontmerges_entry.attr,
783   - &deadline_fifobatch_entry.attr,
784   - NULL,
  756 +static struct elv_fs_entry deadline_attrs[] = {
  757 + DD_ATTR(read_expire),
  758 + DD_ATTR(write_expire),
  759 + DD_ATTR(writes_starved),
  760 + DD_ATTR(front_merges),
  761 + DD_ATTR(fifo_batch),
  762 + __ATTR_NULL
785 763 };
786 764  
787 765 static struct elevator_type iosched_deadline = {
... ... @@ -699,11 +699,12 @@
699 699  
700 700 error = kobject_add(&e->kobj);
701 701 if (!error) {
702   - struct attribute **attr = e->elevator_type->elevator_attrs;
  702 + struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;
703 703 if (attr) {
704   - while (*attr) {
705   - if (sysfs_create_file(&e->kobj,*attr++))
  704 + while (attr->attr.name) {
  705 + if (sysfs_create_file(&e->kobj, &attr->attr))
706 706 break;
  707 + attr++;
707 708 }
708 709 }
709 710 kobject_uevent(&e->kobj, KOBJ_ADD);
include/linux/elevator.h
... ... @@ -53,6 +53,12 @@
53 53  
54 54 #define ELV_NAME_MAX (16)
55 55  
  56 +struct elv_fs_entry {
  57 + struct attribute attr;
  58 + ssize_t (*show)(elevator_t *, char *);
  59 + ssize_t (*store)(elevator_t *, const char *, size_t);
  60 +};
  61 +
56 62 /*
57 63 * identifies an elevator type, such as AS or deadline
58 64 */
... ... @@ -61,7 +67,7 @@
61 67 struct list_head list;
62 68 struct elevator_ops ops;
63 69 struct elevator_type *elevator_type;
64   - struct attribute **elevator_attrs;
  70 + struct elv_fs_entry *elevator_attrs;
65 71 char elevator_name[ELV_NAME_MAX];
66 72 struct module *elevator_owner;
67 73 };
... ... @@ -140,12 +146,6 @@
140 146 ELV_MQUEUE_MAY,
141 147 ELV_MQUEUE_NO,
142 148 ELV_MQUEUE_MUST,
143   -};
144   -
145   -struct elv_fs_entry {
146   - struct attribute attr;
147   - ssize_t (*show)(elevator_t *, char *);
148   - ssize_t (*store)(elevator_t *, const char *, size_t);
149 149 };
150 150  
151 151 #define rq_end_sector(rq) ((rq)->sector + (rq)->nr_sectors)