Whamcloud - gitweb
b=17167 libcfs: ensure all libcfs exported symbols to have cfs_ prefix
[fs/lustre-release.git] / lustre / fld / lproc_fld.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/fld/lproc_fld.c
37  *
38  * FLD (FIDs Location Database)
39  *
40  * Author: Yury Umanets <umka@clusterfs.com>
41  */
42
43 #ifndef EXPORT_SYMTAB
44 # define EXPORT_SYMTAB
45 #endif
46 #define DEBUG_SUBSYSTEM S_FLD
47
48 #ifdef __KERNEL__
49 # include <libcfs/libcfs.h>
50 # include <linux/module.h>
51 #else /* __KERNEL__ */
52 # include <liblustre.h>
53 #endif
54
55 #include <obd.h>
56 #include <obd_class.h>
57 #include <dt_object.h>
58 #include <md_object.h>
59 #include <obd_support.h>
60 #include <lustre_req_layout.h>
61 #include <lustre_fld.h>
62 #include "fld_internal.h"
63
64 #ifdef LPROCFS
65 static int
66 fld_proc_read_targets(char *page, char **start, off_t off,
67                       int count, int *eof, void *data)
68 {
69         struct lu_client_fld *fld = (struct lu_client_fld *)data;
70         struct lu_fld_target *target;
71         int total = 0, rc;
72         ENTRY;
73
74         LASSERT(fld != NULL);
75
76         cfs_spin_lock(&fld->lcf_lock);
77         cfs_list_for_each_entry(target,
78                                 &fld->lcf_targets, ft_chain)
79         {
80                 rc = snprintf(page, count, "%s\n",
81                               fld_target_name(target));
82                 page += rc;
83                 count -= rc;
84                 total += rc;
85                 if (count == 0)
86                         break;
87         }
88         cfs_spin_unlock(&fld->lcf_lock);
89         RETURN(total);
90 }
91
92 static int
93 fld_proc_read_hash(char *page, char **start, off_t off,
94                    int count, int *eof, void *data)
95 {
96         struct lu_client_fld *fld = (struct lu_client_fld *)data;
97         int rc;
98         ENTRY;
99
100         LASSERT(fld != NULL);
101
102         cfs_spin_lock(&fld->lcf_lock);
103         rc = snprintf(page, count, "%s\n",
104                       fld->lcf_hash->fh_name);
105         cfs_spin_unlock(&fld->lcf_lock);
106
107         RETURN(rc);
108 }
109
110 static int
111 fld_proc_write_hash(struct file *file, const char *buffer,
112                     unsigned long count, void *data)
113 {
114         struct lu_client_fld *fld = (struct lu_client_fld *)data;
115         struct lu_fld_hash *hash = NULL;
116         int i;
117         ENTRY;
118
119         LASSERT(fld != NULL);
120
121         for (i = 0; fld_hash[i].fh_name != NULL; i++) {
122                 if (count != strlen(fld_hash[i].fh_name))
123                         continue;
124
125                 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
126                         hash = &fld_hash[i];
127                         break;
128                 }
129         }
130
131         if (hash != NULL) {
132                 cfs_spin_lock(&fld->lcf_lock);
133                 fld->lcf_hash = hash;
134                 cfs_spin_unlock(&fld->lcf_lock);
135
136                 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
137                        fld->lcf_name, hash->fh_name);
138         }
139         
140         RETURN(count);
141 }
142
143 static int
144 fld_proc_write_cache_flush(struct file *file, const char *buffer,
145                            unsigned long count, void *data)
146 {
147         struct lu_client_fld *fld = (struct lu_client_fld *)data;
148         ENTRY;
149
150         LASSERT(fld != NULL);
151
152         fld_cache_flush(fld->lcf_cache);
153
154         CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
155         
156         RETURN(count);
157 }
158
159 struct lprocfs_vars fld_server_proc_list[] = {
160         { NULL }};
161
162 struct lprocfs_vars fld_client_proc_list[] = {
163         { "targets",     fld_proc_read_targets, NULL, NULL },
164         { "hash",        fld_proc_read_hash, fld_proc_write_hash, NULL },
165         { "cache_flush", NULL, fld_proc_write_cache_flush, NULL },
166         { NULL }};
167 #endif