@@ -182,6 +182,9 @@ struct as_rq {
182182
183183static kmem_cache_t * arq_pool ;
184184
185+ static atomic_t ioc_count = ATOMIC_INIT (0 );
186+ static struct completion * ioc_gone ;
187+
185188static void as_move_to_dispatch (struct as_data * ad , struct as_rq * arq );
186189static void as_antic_stop (struct as_data * ad );
187190
@@ -193,6 +196,15 @@ static void as_antic_stop(struct as_data *ad);
193196static void free_as_io_context (struct as_io_context * aic )
194197{
195198 kfree (aic );
199+ if (atomic_dec_and_test (& ioc_count ) && ioc_gone )
200+ complete (ioc_gone );
201+ }
202+
203+ static void as_trim (struct io_context * ioc )
204+ {
205+ if (ioc -> aic )
206+ free_as_io_context (ioc -> aic );
207+ ioc -> aic = NULL ;
196208}
197209
198210/* Called when the task exits */
@@ -220,6 +232,7 @@ static struct as_io_context *alloc_as_io_context(void)
220232 ret -> seek_total = 0 ;
221233 ret -> seek_samples = 0 ;
222234 ret -> seek_mean = 0 ;
235+ atomic_inc (& ioc_count );
223236 }
224237
225238 return ret ;
@@ -1696,11 +1709,6 @@ static int as_init_queue(request_queue_t *q, elevator_t *e)
16961709/*
16971710 * sysfs parts below
16981711 */
1699- struct as_fs_entry {
1700- struct attribute attr ;
1701- ssize_t (* show )(struct as_data * , char * );
1702- ssize_t (* store )(struct as_data * , const char * , size_t );
1703- };
17041712
17051713static ssize_t
17061714as_var_show (unsigned int var , char * page )
@@ -1717,8 +1725,9 @@ as_var_store(unsigned long *var, const char *page, size_t count)
17171725 return count ;
17181726}
17191727
1720- static ssize_t as_est_show ( struct as_data * ad , char * page )
1728+ static ssize_t est_time_show ( elevator_t * e , char * page )
17211729{
1730+ struct as_data * ad = e -> elevator_data ;
17221731 int pos = 0 ;
17231732
17241733 pos += sprintf (page + pos , "%lu %% exit probability\n" ,
@@ -1734,112 +1743,50 @@ static ssize_t as_est_show(struct as_data *ad, char *page)
17341743}
17351744
17361745#define SHOW_FUNCTION (__FUNC , __VAR ) \
1737- static ssize_t __FUNC(struct as_data *ad , char *page) \
1746+ static ssize_t __FUNC(elevator_t *e , char *page) \
17381747{ \
1748+ struct as_data *ad = e->elevator_data; \
17391749 return as_var_show(jiffies_to_msecs((__VAR)), (page)); \
17401750}
1741- SHOW_FUNCTION (as_readexpire_show , ad -> fifo_expire [REQ_SYNC ]);
1742- SHOW_FUNCTION (as_writeexpire_show , ad -> fifo_expire [REQ_ASYNC ]);
1743- SHOW_FUNCTION (as_anticexpire_show , ad -> antic_expire );
1744- SHOW_FUNCTION (as_read_batchexpire_show , ad -> batch_expire [REQ_SYNC ]);
1745- 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 ]);
17461756#undef SHOW_FUNCTION
17471757
17481758#define STORE_FUNCTION (__FUNC , __PTR , MIN , MAX ) \
1749- static ssize_t __FUNC(struct as_data *ad , const char *page, size_t count) \
1759+ static ssize_t __FUNC(elevator_t *e , const char *page, size_t count) \
17501760{ \
1751- int ret = as_var_store(__PTR, (page), count); \
1761+ struct as_data *ad = e->elevator_data; \
1762+ int ret = as_var_store(__PTR, (page), count); \
17521763 if (*(__PTR) < (MIN)) \
17531764 *(__PTR) = (MIN); \
17541765 else if (*(__PTR) > (MAX)) \
17551766 *(__PTR) = (MAX); \
17561767 *(__PTR) = msecs_to_jiffies(*(__PTR)); \
17571768 return ret; \
17581769}
1759- STORE_FUNCTION (as_readexpire_store , & ad -> fifo_expire [REQ_SYNC ], 0 , INT_MAX );
1760- STORE_FUNCTION (as_writeexpire_store , & ad -> fifo_expire [REQ_ASYNC ], 0 , INT_MAX );
1761- STORE_FUNCTION (as_anticexpire_store , & ad -> antic_expire , 0 , INT_MAX );
1762- 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 ,
17631774 & ad -> batch_expire [REQ_SYNC ], 0 , INT_MAX );
1764- STORE_FUNCTION (as_write_batchexpire_store ,
1775+ STORE_FUNCTION (as_write_batch_expire_store ,
17651776 & ad -> batch_expire [REQ_ASYNC ], 0 , INT_MAX );
17661777#undef STORE_FUNCTION
17671778
1768- static struct as_fs_entry as_est_entry = {
1769- .attr = {.name = "est_time" , .mode = S_IRUGO },
1770- .show = as_est_show ,
1771- };
1772- static struct as_fs_entry as_readexpire_entry = {
1773- .attr = {.name = "read_expire" , .mode = S_IRUGO | S_IWUSR },
1774- .show = as_readexpire_show ,
1775- .store = as_readexpire_store ,
1776- };
1777- static struct as_fs_entry as_writeexpire_entry = {
1778- .attr = {.name = "write_expire" , .mode = S_IRUGO | S_IWUSR },
1779- .show = as_writeexpire_show ,
1780- .store = as_writeexpire_store ,
1781- };
1782- static struct as_fs_entry as_anticexpire_entry = {
1783- .attr = {.name = "antic_expire" , .mode = S_IRUGO | S_IWUSR },
1784- .show = as_anticexpire_show ,
1785- .store = as_anticexpire_store ,
1786- };
1787- static struct as_fs_entry as_read_batchexpire_entry = {
1788- .attr = {.name = "read_batch_expire" , .mode = S_IRUGO | S_IWUSR },
1789- .show = as_read_batchexpire_show ,
1790- .store = as_read_batchexpire_store ,
1791- };
1792- static struct as_fs_entry as_write_batchexpire_entry = {
1793- .attr = {.name = "write_batch_expire" , .mode = S_IRUGO | S_IWUSR },
1794- .show = as_write_batchexpire_show ,
1795- .store = as_write_batchexpire_store ,
1796- };
1797-
1798- static struct attribute * default_attrs [] = {
1799- & as_est_entry .attr ,
1800- & as_readexpire_entry .attr ,
1801- & as_writeexpire_entry .attr ,
1802- & as_anticexpire_entry .attr ,
1803- & as_read_batchexpire_entry .attr ,
1804- & as_write_batchexpire_entry .attr ,
1805- NULL ,
1806- };
1807-
1808- #define to_as (atr ) container_of((atr), struct as_fs_entry, attr)
1809-
1810- static ssize_t
1811- as_attr_show (struct kobject * kobj , struct attribute * attr , char * page )
1812- {
1813- elevator_t * e = container_of (kobj , elevator_t , kobj );
1814- struct as_fs_entry * entry = to_as (attr );
1815-
1816- if (!entry -> show )
1817- return - EIO ;
1818-
1819- return entry -> show (e -> elevator_data , page );
1820- }
1821-
1822- static ssize_t
1823- as_attr_store (struct kobject * kobj , struct attribute * attr ,
1824- const char * page , size_t length )
1825- {
1826- elevator_t * e = container_of (kobj , elevator_t , kobj );
1827- struct as_fs_entry * entry = to_as (attr );
1828-
1829- if (!entry -> store )
1830- return - EIO ;
1831-
1832- return entry -> store (e -> elevator_data , page , length );
1833- }
1834-
1835- static struct sysfs_ops as_sysfs_ops = {
1836- .show = as_attr_show ,
1837- .store = as_attr_store ,
1838- };
1839-
1840- static struct kobj_type as_ktype = {
1841- .sysfs_ops = & as_sysfs_ops ,
1842- .default_attrs = default_attrs ,
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
18431790};
18441791
18451792static struct elevator_type iosched_as = {
@@ -1860,9 +1807,10 @@ static struct elevator_type iosched_as = {
18601807 .elevator_may_queue_fn = as_may_queue ,
18611808 .elevator_init_fn = as_init_queue ,
18621809 .elevator_exit_fn = as_exit_queue ,
1810+ .trim = as_trim ,
18631811 },
18641812
1865- .elevator_ktype = & as_ktype ,
1813+ .elevator_attrs = as_attrs ,
18661814 .elevator_name = "anticipatory" ,
18671815 .elevator_owner = THIS_MODULE ,
18681816};
@@ -1893,7 +1841,13 @@ static int __init as_init(void)
18931841
18941842static void __exit as_exit (void )
18951843{
1844+ DECLARE_COMPLETION (all_gone );
18961845 elv_unregister (& iosched_as );
1846+ ioc_gone = & all_gone ;
1847+ barrier ();
1848+ if (atomic_read (& ioc_count ))
1849+ complete (ioc_gone );
1850+ synchronize_rcu ();
18971851 kmem_cache_destroy (arq_pool );
18981852}
18991853
0 commit comments