Whamcloud - gitweb
- commented ->delete_inode for a while
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22 #define DEBUG_SUBSYSTEM S_LLITE
23
24 #include <linux/version.h>
25 #include <linux/lustre_lite.h>
26 #include <linux/lprocfs_status.h>
27 #include <linux/seq_file.h>
28 #include <linux/obd_support.h>
29
30 #include "llite_internal.h"
31
32 /* /proc/lustre/llite mount point registration */
33 struct proc_dir_entry *proc_lustre_fs_root;
34 struct file_operations llite_dump_pgcache_fops;
35
36 #ifndef LPROCFS
37 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
38                                 struct super_block *sb, char *osc, char *mdc)
39 {
40         return 0;
41 }
42 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi){}
43 #else
44
45 long long mnt_instance;
46
47 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
48                          int *eof, void *data)
49 {
50         struct super_block *sb = (struct super_block *)data;
51         struct obd_statfs osfs;
52         int rc;
53
54         LASSERT(sb != NULL);
55         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
56         if (!rc) {
57               *eof = 1;
58               rc = snprintf(page, count, "%u\n", osfs.os_bsize);
59         }
60
61         return rc;
62 }
63
64 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
65                              int *eof, void *data)
66 {
67         struct super_block *sb = (struct super_block *)data;
68         struct obd_statfs osfs;
69         int rc;
70
71         LASSERT(sb != NULL);
72         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
73         if (!rc) {
74                 __u32 blk_size = osfs.os_bsize >> 10;
75                 __u64 result = osfs.os_blocks;
76
77                 while (blk_size >>= 1)
78                         result <<= 1;
79
80                 *eof = 1;
81                 rc = snprintf(page, count, LPU64"\n", result);
82         }
83         return rc;
84
85 }
86
87 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
88                             int *eof, void *data)
89 {
90         struct super_block *sb = (struct super_block *)data;
91         struct obd_statfs osfs;
92         int rc;
93
94         LASSERT(sb != NULL);
95         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
96         if (!rc) {
97                 __u32 blk_size = osfs.os_bsize >> 10;
98                 __u64 result = osfs.os_bfree;
99
100                 while (blk_size >>= 1)
101                         result <<= 1;
102
103                 *eof = 1;
104                 rc = snprintf(page, count, LPU64"\n", result);
105         }
106         return rc;
107 }
108
109 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
110                              int *eof, void *data)
111 {
112         struct super_block *sb = (struct super_block *)data;
113         struct obd_statfs osfs;
114         int rc;
115
116         LASSERT(sb != NULL);
117         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
118         if (!rc) {
119                 __u32 blk_size = osfs.os_bsize >> 10;
120                 __u64 result = osfs.os_bavail;
121
122                 while (blk_size >>= 1)
123                         result <<= 1;
124
125                 *eof = 1;
126                 rc = snprintf(page, count, LPU64"\n", result);
127         }
128         return rc;
129 }
130
131 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
132                             int *eof, void *data)
133 {
134         struct super_block *sb = (struct super_block *)data;
135         struct obd_statfs osfs;
136         int rc;
137
138         LASSERT(sb != NULL);
139         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
140         if (!rc) {
141                  *eof = 1;
142                  rc = snprintf(page, count, LPU64"\n", osfs.os_files);
143         }
144         return rc;
145 }
146
147 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
148                            int *eof, void *data)
149 {
150         struct super_block *sb = (struct super_block *)data;
151         struct obd_statfs osfs;
152         int rc;
153
154         LASSERT(sb != NULL);
155         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
156         if (!rc) {
157                  *eof = 1;
158                  rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
159         }
160         return rc;
161
162 }
163
164 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
165                         int *eof, void *data)
166 {
167         struct super_block *sb = (struct super_block*)data;
168
169         LASSERT(sb != NULL);
170         *eof = 1;
171         return snprintf(page, count, "%s\n", sb->s_type->name);
172 }
173
174 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
175                          int *eof, void *data)
176 {
177         struct super_block *sb = (struct super_block *)data;
178
179         LASSERT(sb != NULL);
180         *eof = 1;
181         return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
182 }
183
184 static int ll_rd_read_ahead(char *page, char **start, off_t off, int count,
185                             int *eof, void *data)
186 {
187         struct super_block *sb = (struct super_block*)data;
188         struct ll_sb_info *sbi = ll_s2sbi(sb);
189         int val, rc;
190         ENTRY;
191
192         *eof = 1;
193         val = (sbi->ll_flags & LL_SBI_READAHEAD) ? 1 : 0;
194         rc = snprintf(page, count, "%d\n", val);
195         RETURN(rc);
196 }
197
198 static int ll_wr_read_ahead(struct file *file, const char *buffer,
199                             unsigned long count, void *data)
200 {
201         struct super_block *sb = (struct super_block*)data;
202         struct ll_sb_info *sbi = ll_s2sbi(sb);
203         int readahead;
204         ENTRY;
205
206         if (1 != sscanf(buffer, "%d", &readahead))
207                 RETURN(-EINVAL);
208
209         if (readahead)
210                 sbi->ll_flags |= LL_SBI_READAHEAD;
211         else
212                 sbi->ll_flags &= ~LL_SBI_READAHEAD;
213
214         RETURN(count);
215 }
216
217 static int ll_wr_config_update(struct file *file, const char *buffer,
218                                unsigned long count, void *data)
219 {
220         struct super_block *sb = (struct super_block*)data;
221         struct ll_sb_info *sbi = ll_s2sbi(sb);
222         ENTRY;
223
224         RETURN(ll_process_config_update(sbi, 0));
225 }
226
227 static int ll_rd_max_read_ahead_mb(char *page, char **start, off_t off,
228                                    int count, int *eof, void *data)
229 {
230         struct super_block *sb = data;
231         struct ll_sb_info *sbi = ll_s2sbi(sb);
232         unsigned val;
233
234         spin_lock(&sbi->ll_lock);
235         val = (sbi->ll_max_read_ahead_pages << PAGE_CACHE_SHIFT) >> 20;
236         spin_unlock(&sbi->ll_lock);
237
238         return snprintf(page, count, "%u\n", val);
239 }
240
241 static int ll_wr_max_read_ahead_mb(struct file *file, const char *buffer,
242                                    unsigned long count, void *data)
243 {
244         struct super_block *sb = data;
245         struct ll_sb_info *sbi = ll_s2sbi(sb);
246         int val, rc;
247
248         rc = lprocfs_write_helper(buffer, count, &val);
249         if (rc)
250                 return rc;
251
252         if (val < 0 || val > (num_physpages << PAGE_SHIFT) >> 20)
253                 return -ERANGE;
254
255         spin_lock(&sbi->ll_lock);
256         sbi->ll_max_read_ahead_pages = (val << 20) >> PAGE_CACHE_SHIFT;
257         spin_unlock(&sbi->ll_lock);
258
259         return count;
260 }
261
262 static struct lprocfs_vars lprocfs_obd_vars[] = {
263         { "uuid",         ll_rd_sb_uuid,          0, 0 },
264         //{ "mntpt_path",   ll_rd_path,             0, 0 },
265         { "fstype",       ll_rd_fstype,           0, 0 },
266         { "blocksize",    ll_rd_blksize,          0, 0 },
267         { "kbytestotal",  ll_rd_kbytestotal,      0, 0 },
268         { "kbytesfree",   ll_rd_kbytesfree,       0, 0 },
269         { "kbytesavail",  ll_rd_kbytesavail,      0, 0 },
270         { "filestotal",   ll_rd_filestotal,       0, 0 },
271         { "filesfree",    ll_rd_filesfree,        0, 0 },
272         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
273         { "read_ahead",   ll_rd_read_ahead, ll_wr_read_ahead, 0 },
274         { "config_update", 0, ll_wr_config_update, 0 },
275         { "max_read_ahead_mb", ll_rd_max_read_ahead_mb,
276                                ll_wr_max_read_ahead_mb, 0 },
277         { 0 }
278 };
279
280 #define MAX_STRING_SIZE 128
281
282 struct llite_file_opcode {
283         __u32       opcode;
284         __u32       type;
285         const char *opname;
286 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
287         /* file operation */
288         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
289         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
290         { LPROC_LL_WB_WRITEPAGE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
291                                    "writeback_from_writepage" },
292         { LPROC_LL_WB_PRESSURE,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
293                                    "writeback_from_pressure" },
294         { LPROC_LL_WB_OK,          LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
295                                    "writeback_ok_pages" },
296         { LPROC_LL_WB_FAIL,        LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
297                                    "writeback_failed_pages" },
298         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
299                                    "read_bytes" },
300         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
301                                    "write_bytes" },
302         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
303                                    "brw_read" },
304         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
305                                    "brw_write" },
306
307         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
308         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
309         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
310         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
311         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
312         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
313         /* inode operation */
314         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
315         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "punch" },
316 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
317         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
318 #else
319         { LPROC_LL_REVALIDATE,     LPROCFS_TYPE_REGS, "getattr" },
320 #endif
321         /* special inode operation */
322         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
323         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
324         { LPROC_LL_DIRECT_READ,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
325                                    "direct_read" },
326         { LPROC_LL_DIRECT_WRITE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
327                                    "direct_write" },
328
329 };
330
331 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
332                                 struct super_block *sb, char *osc, char *mdc)
333 {
334         struct lprocfs_vars lvars[2];
335         struct ll_sb_info *sbi = ll_s2sbi(sb);
336         struct obd_device *obd;
337         char name[MAX_STRING_SIZE + 1];
338         int err, id;
339         struct lprocfs_stats *svc_stats = NULL;
340         struct proc_dir_entry *entry;
341         ENTRY;
342
343         memset(lvars, 0, sizeof(lvars));
344
345         name[MAX_STRING_SIZE] = '\0';
346         lvars[0].name = name;
347
348         LASSERT(sbi != NULL);
349         LASSERT(mdc != NULL);
350         LASSERT(osc != NULL);
351
352         /* Mount info */
353         snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
354
355         mnt_instance++;
356         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
357         if (IS_ERR(sbi->ll_proc_root)) {
358                 err = PTR_ERR(sbi->ll_proc_root);
359                 sbi->ll_proc_root = NULL;
360                 RETURN(err);
361         }
362
363         entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
364         if (entry == NULL)
365                 GOTO(out, err = -ENOMEM);
366         entry->proc_fops = &llite_dump_pgcache_fops;
367         entry->data = sbi;
368
369         svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
370         if (svc_stats == NULL) {
371                 err = -ENOMEM;
372                 goto out;
373         }
374         /* do counter init */
375         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
376                 __u32 type = llite_opcode_table[id].type;
377                 void *ptr = NULL;
378                 if (type & LPROCFS_TYPE_REGS)
379                         ptr = "regs";
380                 else {
381                         if (type & LPROCFS_TYPE_BYTES)
382                                 ptr = "bytes";
383                         else {
384                                 if (type & LPROCFS_TYPE_PAGES)
385                                         ptr = "pages";
386                         }
387                 }
388                 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
389                                      (type & LPROCFS_CNTR_AVGMINMAX),
390                                      llite_opcode_table[id].opname, ptr);
391         }
392         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
393         if (err)
394                 goto out;
395         else
396                 sbi->ll_stats = svc_stats;
397         /* need place to keep svc_stats */
398
399         /* Static configuration info */
400         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
401         if (err)
402                 goto out;
403
404         /* MDC info */
405         obd = class_name2obd(mdc);
406
407         LASSERT(obd != NULL);
408         LASSERT(obd->obd_type != NULL);
409         LASSERT(obd->obd_type->typ_name != NULL);
410
411         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
412                  obd->obd_type->typ_name);
413         lvars[0].read_fptr = lprocfs_rd_name;
414         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
415         if (err)
416                 goto out;
417
418         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
419         lvars[0].read_fptr = lprocfs_rd_uuid;
420         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
421         if (err)
422                 goto out;
423
424         /* OSC */
425         obd = class_name2obd(osc);
426
427         LASSERT(obd != NULL);
428         LASSERT(obd->obd_type != NULL);
429         LASSERT(obd->obd_type->typ_name != NULL);
430
431         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
432                  obd->obd_type->typ_name);
433         lvars[0].read_fptr = lprocfs_rd_name;
434         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
435         if (err)
436                 goto out;
437
438         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
439         lvars[0].read_fptr = lprocfs_rd_uuid;
440         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
441 out:
442         if (err) {
443                 if (svc_stats)
444                         lprocfs_free_stats(svc_stats);
445                 if (sbi->ll_proc_root)
446                         lprocfs_remove(sbi->ll_proc_root);
447         }
448         RETURN(err);
449 }
450
451 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
452 {
453         if (sbi->ll_proc_root) {
454                 struct proc_dir_entry *file_stats =
455                         lprocfs_srch(sbi->ll_proc_root, "stats");
456
457                 if (file_stats) {
458                         lprocfs_free_stats(sbi->ll_stats);
459                         lprocfs_remove(file_stats);
460                 }
461         }
462 }
463 #undef MAX_STRING_SIZE
464
465 static struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
466                                                     struct list_head *list)
467 {
468         struct ll_async_page *llap;
469         struct list_head *pos;
470
471         list_for_each(pos, list) {
472                 if (pos == &sbi->ll_pglist)
473                         return NULL;
474                 llap = list_entry(pos, struct ll_async_page, llap_proc_item);
475                 if (llap->llap_page == NULL)
476                         continue;
477                 return llap;
478         }
479         LBUG();
480         return NULL;
481 }
482
483 #define seq_page_flag(seq, page, flag, has_flags) do {                  \
484                 if (test_bit(PG_##flag, &(page)->flags)) {              \
485                         if (!has_flags)                                 \
486                                 has_flags = 1;                          \
487                         else                                            \
488                                 seq_putc(seq, '|');                     \
489                         seq_puts(seq, #flag);                           \
490                 }                                                       \
491         } while(0);
492
493 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
494 {
495         struct ll_async_page *llap, *dummy_llap = seq->private;
496         struct ll_sb_info *sbi = dummy_llap->llap_cookie;
497
498         /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
499          * it in our own state */
500         if (dummy_llap->llap_magic == 0) {
501                 seq_printf(seq, "generation | llap .cookie | page ");
502                 seq_printf(seq, "inode .index [ page flags ]\n");
503                 return 0;
504         }
505
506         spin_lock(&sbi->ll_lock);
507
508         llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
509         if (llap != NULL)  {
510                 int has_flags = 0;
511                 struct page *page = llap->llap_page;
512
513                 seq_printf(seq, "%lu | %p %p | %p %p %lu [",
514                                 sbi->ll_pglist_gen,
515                                 llap, llap->llap_cookie,
516                                 page, page->mapping->host, page->index);
517                 seq_page_flag(seq, page, locked, has_flags);
518                 seq_page_flag(seq, page, error, has_flags);
519                 seq_page_flag(seq, page, referenced, has_flags);
520                 seq_page_flag(seq, page, uptodate, has_flags);
521                 seq_page_flag(seq, page, dirty, has_flags);
522                 seq_page_flag(seq, page, highmem, has_flags);
523                 if (!has_flags)
524                         seq_puts(seq, "-]\n");
525                 else
526                         seq_puts(seq, "]\n");
527         }
528
529         spin_unlock(&sbi->ll_lock);
530
531         return 0;
532 }
533
534 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
535 {
536         struct ll_async_page *llap = seq->private;
537
538         if (llap->llap_magic == 2)
539                 return NULL;
540
541         return (void *)1;
542 }
543
544 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
545                                          loff_t *pos)
546 {
547         struct ll_async_page *llap, *dummy_llap = seq->private;
548         struct ll_sb_info *sbi = dummy_llap->llap_cookie;
549
550         /* bail if we just displayed the banner */
551         if (dummy_llap->llap_magic == 0) {
552                 dummy_llap->llap_magic = 1;
553                 return dummy_llap;
554         }
555
556         /* we've just displayed the llap that is after us in the list.
557          * we advance to a position beyond it, returning null if there
558          * isn't another llap in the list beyond that new position. */
559         spin_lock(&sbi->ll_lock);
560         llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
561         list_del_init(&dummy_llap->llap_proc_item);
562         if (llap) {
563                 list_add(&dummy_llap->llap_proc_item, &llap->llap_proc_item);
564                 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
565         }
566         spin_unlock(&sbi->ll_lock);
567
568         ++*pos;
569         if (llap == NULL) {
570                 dummy_llap->llap_magic = 2;
571                 return NULL;
572         }
573         return dummy_llap;
574 }
575
576 static void llite_dump_pgcache_seq_stop(struct seq_file *seq, void *v)
577 {
578 }
579
580 struct seq_operations llite_dump_pgcache_seq_sops = {
581         .start = llite_dump_pgcache_seq_start,
582         .stop = llite_dump_pgcache_seq_stop,
583         .next = llite_dump_pgcache_seq_next,
584         .show = llite_dump_pgcache_seq_show,
585 };
586
587 /* we're displaying llaps in a list_head list.  we don't want to hold a lock
588  * while we walk the entire list, and we don't want to have to seek into
589  * the right position in the list as an app advances with many syscalls.  we
590  * allocate a dummy llap and hang it off file->private.  its position in
591  * the list records where the app is currently displaying.  this way our
592  * seq .start and .stop don't actually do anything.  .next returns null
593  * when the dummy hits the end of the list which eventually leads to .release
594  * where we tear down.  this kind of displaying is super-racey, so we put
595  * a generation counter on the list so the output shows when the list
596  * changes between reads.
597  */
598 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
599 {
600         struct proc_dir_entry *dp = PDE(inode);
601         struct ll_async_page *llap;
602         struct seq_file *seq;
603         struct ll_sb_info *sbi = dp->data;
604         int rc;
605
606         OBD_ALLOC_GFP(llap, sizeof(*llap), GFP_KERNEL);
607         if (llap == NULL)
608                 return -ENOMEM;
609         llap->llap_page = NULL;
610         llap->llap_cookie = sbi;
611         llap->llap_magic = 0;
612
613         rc = seq_open(file, &llite_dump_pgcache_seq_sops);
614         if (rc) {
615                 OBD_FREE(llap, sizeof(*llap));
616                 return rc;
617         }
618         seq = file->private_data;
619         seq->private = llap;
620
621         spin_lock(&sbi->ll_lock);
622         list_add(&llap->llap_proc_item, &sbi->ll_pglist);
623         spin_unlock(&sbi->ll_lock);
624
625         return 0;
626 }
627
628 static int llite_dump_pgcache_seq_release(struct inode *inode,
629                                           struct file *file)
630 {
631         struct seq_file *seq = file->private_data;
632         struct ll_async_page *llap = seq->private;
633         struct ll_sb_info *sbi = llap->llap_cookie;
634
635         spin_lock(&sbi->ll_lock);
636         if (!list_empty(&llap->llap_proc_item))
637                 list_del_init(&llap->llap_proc_item);
638         spin_unlock(&sbi->ll_lock);
639         OBD_FREE(llap, sizeof(*llap));
640
641         return seq_release(inode, file);
642 }
643
644 struct file_operations llite_dump_pgcache_fops = {
645         .owner   = THIS_MODULE,
646         .open    = llite_dump_pgcache_seq_open,
647         .read    = seq_read,
648         .release = llite_dump_pgcache_seq_release,
649 };
650
651 #endif /* LPROCFS */