Skip to content

Commit e572ec7

Browse files
author
Al Viro
committed
[PATCH] fix rmmod problems with elevator attributes, clean them up
1 parent 3d1ab40 commit e572ec7

5 files changed

Lines changed: 74 additions & 175 deletions

File tree

‎block/as-iosched.c‎

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ as_var_store(unsigned long *var, const char *page, size_t count)
17251725
return count;
17261726
}
17271727

1728-
static ssize_t as_est_show(elevator_t *e, char *page)
1728+
static ssize_t est_time_show(elevator_t *e, char *page)
17291729
{
17301730
struct as_data *ad = e->elevator_data;
17311731
int pos = 0;
@@ -1748,11 +1748,11 @@ static ssize_t __FUNC(elevator_t *e, char *page) \
17481748
struct as_data *ad = e->elevator_data; \
17491749
return as_var_show(jiffies_to_msecs((__VAR)), (page)); \
17501750
}
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]);
17561756
#undef SHOW_FUNCTION
17571757

17581758
#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX) \
@@ -1767,53 +1767,26 @@ static ssize_t __FUNC(elevator_t *e, const char *page, size_t count) \
17671767
*(__PTR) = msecs_to_jiffies(*(__PTR)); \
17681768
return ret; \
17691769
}
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,
17741774
&ad->batch_expire[REQ_SYNC], 0, INT_MAX);
1775-
STORE_FUNCTION(as_write_batchexpire_store,
1775+
STORE_FUNCTION(as_write_batch_expire_store,
17761776
&ad->batch_expire[REQ_ASYNC], 0, INT_MAX);
17771777
#undef STORE_FUNCTION
17781778

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-
};
1808-
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,
1779+
#define AS_ATTR(name) \
1780+
__ATTR(name, S_IRUGO|S_IWUSR, as_##name##_show, as_##name##_store)
1781+
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
18171790
};
18181791

18191792
static struct elevator_type iosched_as = {

‎block/cfq-iosched.c‎

Lines changed: 20 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,8 +2304,8 @@ SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0);
23042304
SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued, 0);
23052305
SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1);
23062306
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);
23092309
SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1);
23102310
SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1);
23112311
SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1);
@@ -2333,84 +2333,31 @@ STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0);
23332333
STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, UINT_MAX, 0);
23342334
STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1, UINT_MAX, 1);
23352335
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);
23382338
STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1);
23392339
STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1);
23402340
STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1);
23412341
STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1, UINT_MAX, 0);
23422342
STORE_FUNCTION(cfq_max_depth_store, &cfqd->cfq_max_depth, 1, UINT_MAX, 0);
23432343
#undef STORE_FUNCTION
23442344

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-
};
2400-
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,
2345+
#define CFQ_ATTR(name) \
2346+
__ATTR(name, S_IRUGO|S_IWUSR, cfq_##name##_show, cfq_##name##_store)
2347+
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
24142361
};
24152362

24162363
static struct elevator_type iosched_cfq = {

‎block/deadline-iosched.c‎

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,11 @@ static ssize_t __FUNC(elevator_t *e, char *page) \
719719
__data = jiffies_to_msecs(__data); \
720720
return deadline_var_show(__data, (page)); \
721721
}
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);
727727
#undef SHOW_FUNCTION
728728

729729
#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) \
742742
*(__PTR) = __data; \
743743
return ret; \
744744
}
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);
750750
#undef STORE_FUNCTION
751751

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-
};
777-
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,
752+
#define DD_ATTR(name) \
753+
__ATTR(name, S_IRUGO|S_IWUSR, deadline_##name##_show, \
754+
deadline_##name##_store)
755+
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
785763
};
786764

787765
static struct elevator_type iosched_deadline = {

‎block/elevator.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,12 @@ int elv_register_queue(struct request_queue *q)
699699

700700
error = kobject_add(&e->kobj);
701701
if (!error) {
702-
struct attribute **attr = e->elevator_type->elevator_attrs;
702+
struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;
703703
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))
706706
break;
707+
attr++;
707708
}
708709
}
709710
kobject_uevent(&e->kobj, KOBJ_ADD);

‎include/linux/elevator.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ struct elevator_ops
5353

5454
#define ELV_NAME_MAX (16)
5555

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+
5662
/*
5763
* identifies an elevator type, such as AS or deadline
5864
*/
@@ -61,7 +67,7 @@ struct elevator_type
6167
struct list_head list;
6268
struct elevator_ops ops;
6369
struct elevator_type *elevator_type;
64-
struct attribute **elevator_attrs;
70+
struct elv_fs_entry *elevator_attrs;
6571
char elevator_name[ELV_NAME_MAX];
6672
struct module *elevator_owner;
6773
};
@@ -142,12 +148,6 @@ enum {
142148
ELV_MQUEUE_MUST,
143149
};
144150

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-
};
150-
151151
#define rq_end_sector(rq) ((rq)->sector + (rq)->nr_sectors)
152152

153153
#endif

0 commit comments

Comments
 (0)