@@ -165,99 +165,82 @@ static const struct file_operations dasd_devices_file_ops = {
165165 .release = seq_release ,
166166};
167167
168- static int
169- dasd_calc_metrics (char * page , char * * start , off_t off ,
170- int count , int * eof , int len )
171- {
172- len = (len > off ) ? len - off : 0 ;
173- if (len > count )
174- len = count ;
175- if (len < count )
176- * eof = 1 ;
177- * start = page + off ;
178- return len ;
179- }
180-
181168#ifdef CONFIG_DASD_PROFILE
182- static char *
183- dasd_statistics_array (char * str , unsigned int * array , int factor )
169+ static void dasd_statistics_array (struct seq_file * m , unsigned int * array , int factor )
184170{
185171 int i ;
186172
187173 for (i = 0 ; i < 32 ; i ++ ) {
188- str += sprintf ( str , "%7d " , array [i ] / factor );
174+ seq_printf ( m , "%7d " , array [i ] / factor );
189175 if (i == 15 )
190- str += sprintf ( str , "\n" );
176+ seq_putc ( m , '\n' );
191177 }
192- str += sprintf (str ,"\n" );
193- return str ;
178+ seq_putc (m , '\n' );
194179}
195180#endif /* CONFIG_DASD_PROFILE */
196181
197- static int
198- dasd_statistics_read (char * page , char * * start , off_t off ,
199- int count , int * eof , void * data )
182+ static int dasd_stats_proc_show (struct seq_file * m , void * v )
200183{
201- unsigned long len ;
202184#ifdef CONFIG_DASD_PROFILE
203185 struct dasd_profile_info_t * prof ;
204- char * str ;
205186 int factor ;
206187
207188 /* check for active profiling */
208189 if (dasd_profile_level == DASD_PROFILE_OFF ) {
209- len = sprintf ( page , "Statistics are off - they might be "
190+ seq_printf ( m , "Statistics are off - they might be "
210191 "switched on using 'echo set on > "
211192 "/proc/dasd/statistics'\n" );
212- return dasd_calc_metrics ( page , start , off , count , eof , len ) ;
193+ return 0 ;
213194 }
214195
215196 prof = & dasd_global_profile ;
216197 /* prevent counter 'overflow' on output */
217198 for (factor = 1 ; (prof -> dasd_io_reqs / factor ) > 9999999 ;
218199 factor *= 10 );
219200
220- str = page ;
221- str += sprintf (str , "%d dasd I/O requests\n" , prof -> dasd_io_reqs );
222- str += sprintf (str , "with %u sectors(512B each)\n" ,
201+ seq_printf (m , "%d dasd I/O requests\n" , prof -> dasd_io_reqs );
202+ seq_printf (m , "with %u sectors(512B each)\n" ,
223203 prof -> dasd_io_sects );
224- str += sprintf ( str , "Scale Factor is %d\n" , factor );
225- str += sprintf ( str ,
204+ seq_printf ( m , "Scale Factor is %d\n" , factor );
205+ seq_printf ( m ,
226206 " __<4 ___8 __16 __32 __64 _128 "
227207 " _256 _512 __1k __2k __4k __8k "
228208 " _16k _32k _64k 128k\n" );
229- str += sprintf ( str ,
209+ seq_printf ( m ,
230210 " _256 _512 __1M __2M __4M __8M "
231211 " _16M _32M _64M 128M 256M 512M "
232212 " __1G __2G __4G " " _>4G\n" );
233213
234- str += sprintf ( str , "Histogram of sizes (512B secs)\n" );
235- str = dasd_statistics_array (str , prof -> dasd_io_secs , factor );
236- str += sprintf ( str , "Histogram of I/O times (microseconds)\n" );
237- str = dasd_statistics_array (str , prof -> dasd_io_times , factor );
238- str += sprintf ( str , "Histogram of I/O times per sector\n" );
239- str = dasd_statistics_array (str , prof -> dasd_io_timps , factor );
240- str += sprintf ( str , "Histogram of I/O time till ssch\n" );
241- str = dasd_statistics_array (str , prof -> dasd_io_time1 , factor );
242- str += sprintf ( str , "Histogram of I/O time between ssch and irq\n" );
243- str = dasd_statistics_array (str , prof -> dasd_io_time2 , factor );
244- str += sprintf ( str , "Histogram of I/O time between ssch "
214+ seq_printf ( m , "Histogram of sizes (512B secs)\n" );
215+ dasd_statistics_array (m , prof -> dasd_io_secs , factor );
216+ seq_printf ( m , "Histogram of I/O times (microseconds)\n" );
217+ dasd_statistics_array (m , prof -> dasd_io_times , factor );
218+ seq_printf ( m , "Histogram of I/O times per sector\n" );
219+ dasd_statistics_array (m , prof -> dasd_io_timps , factor );
220+ seq_printf ( m , "Histogram of I/O time till ssch\n" );
221+ dasd_statistics_array (m , prof -> dasd_io_time1 , factor );
222+ seq_printf ( m , "Histogram of I/O time between ssch and irq\n" );
223+ dasd_statistics_array (m , prof -> dasd_io_time2 , factor );
224+ seq_printf ( m , "Histogram of I/O time between ssch "
245225 "and irq per sector\n" );
246- str = dasd_statistics_array (str , prof -> dasd_io_time2ps , factor );
247- str += sprintf (str , "Histogram of I/O time between irq and end\n" );
248- str = dasd_statistics_array (str , prof -> dasd_io_time3 , factor );
249- str += sprintf (str , "# of req in chanq at enqueuing (1..32) \n" );
250- str = dasd_statistics_array (str , prof -> dasd_io_nr_req , factor );
251- len = str - page ;
226+ dasd_statistics_array (m , prof -> dasd_io_time2ps , factor );
227+ seq_printf (m , "Histogram of I/O time between irq and end\n" );
228+ dasd_statistics_array (m , prof -> dasd_io_time3 , factor );
229+ seq_printf (m , "# of req in chanq at enqueuing (1..32) \n" );
230+ dasd_statistics_array (m , prof -> dasd_io_nr_req , factor );
252231#else
253- len = sprintf ( page , "Statistics are not activated in this kernel\n" );
232+ seq_printf ( m , "Statistics are not activated in this kernel\n" );
254233#endif
255- return dasd_calc_metrics ( page , start , off , count , eof , len ) ;
234+ return 0 ;
256235}
257236
258- static int
259- dasd_statistics_write (struct file * file , const char __user * user_buf ,
260- unsigned long user_len , void * data )
237+ static int dasd_stats_proc_open (struct inode * inode , struct file * file )
238+ {
239+ return single_open (file , dasd_stats_proc_show , NULL );
240+ }
241+
242+ static ssize_t dasd_stats_proc_write (struct file * file ,
243+ const char __user * user_buf , size_t user_len , loff_t * pos )
261244{
262245#ifdef CONFIG_DASD_PROFILE
263246 char * buffer , * str ;
@@ -308,6 +291,15 @@ dasd_statistics_write(struct file *file, const char __user *user_buf,
308291#endif /* CONFIG_DASD_PROFILE */
309292}
310293
294+ static const struct file_operations dasd_stats_proc_fops = {
295+ .owner = THIS_MODULE ,
296+ .open = dasd_stats_proc_open ,
297+ .read = seq_read ,
298+ .llseek = seq_lseek ,
299+ .release = single_release ,
300+ .write = dasd_stats_proc_write ,
301+ };
302+
311303/*
312304 * Create dasd proc-fs entries.
313305 * In case creation failed, cleanup and return -ENOENT.
@@ -324,13 +316,12 @@ dasd_proc_init(void)
324316 & dasd_devices_file_ops );
325317 if (!dasd_devices_entry )
326318 goto out_nodevices ;
327- dasd_statistics_entry = create_proc_entry ("statistics" ,
328- S_IFREG | S_IRUGO | S_IWUSR ,
329- dasd_proc_root_entry );
319+ dasd_statistics_entry = proc_create ("statistics" ,
320+ S_IFREG | S_IRUGO | S_IWUSR ,
321+ dasd_proc_root_entry ,
322+ & dasd_stats_proc_fops );
330323 if (!dasd_statistics_entry )
331324 goto out_nostatistics ;
332- dasd_statistics_entry -> read_proc = dasd_statistics_read ;
333- dasd_statistics_entry -> write_proc = dasd_statistics_write ;
334325 return 0 ;
335326
336327 out_nostatistics :
0 commit comments