Whamcloud - gitweb
LU-1808 build: Lustre build does not support FC15.
[fs/lustre-release.git] / lustre / fld / lproc_fld.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Whamcloud, Inc.
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  *      Di Wang <di.wang@whamcloud.com>
42  */
43
44 #define DEBUG_SUBSYSTEM S_FLD
45
46 #ifdef __KERNEL__
47 # include <libcfs/libcfs.h>
48 # include <linux/module.h>
49 #else /* __KERNEL__ */
50 # include <liblustre.h>
51 #endif
52
53 #include <obd.h>
54 #include <obd_class.h>
55 #include <dt_object.h>
56 #include <md_object.h>
57 #include <obd_support.h>
58 #include <lustre_req_layout.h>
59 #include <lustre_fld.h>
60 #include <lustre_fid.h>
61 #include "fld_internal.h"
62
63 #ifdef LPROCFS
64 static int
65 fld_proc_read_targets(char *page, char **start, off_t off,
66                       int count, int *eof, void *data)
67 {
68         struct lu_client_fld *fld = (struct lu_client_fld *)data;
69         struct lu_fld_target *target;
70         int total = 0, rc;
71         ENTRY;
72
73         LASSERT(fld != NULL);
74
75         cfs_spin_lock(&fld->lcf_lock);
76         cfs_list_for_each_entry(target,
77                                 &fld->lcf_targets, ft_chain)
78         {
79                 rc = snprintf(page, count, "%s\n",
80                               fld_target_name(target));
81                 page += rc;
82                 count -= rc;
83                 total += rc;
84                 if (count == 0)
85                         break;
86         }
87         cfs_spin_unlock(&fld->lcf_lock);
88         RETURN(total);
89 }
90
91 static int
92 fld_proc_read_hash(char *page, char **start, off_t off,
93                    int count, int *eof, void *data)
94 {
95         struct lu_client_fld *fld = (struct lu_client_fld *)data;
96         int rc;
97         ENTRY;
98
99         LASSERT(fld != NULL);
100
101         cfs_spin_lock(&fld->lcf_lock);
102         rc = snprintf(page, count, "%s\n",
103                       fld->lcf_hash->fh_name);
104         cfs_spin_unlock(&fld->lcf_lock);
105
106         RETURN(rc);
107 }
108
109 static int
110 fld_proc_write_hash(struct file *file, const char *buffer,
111                     unsigned long count, void *data)
112 {
113         struct lu_client_fld *fld = (struct lu_client_fld *)data;
114         struct lu_fld_hash *hash = NULL;
115         int i;
116         ENTRY;
117
118         LASSERT(fld != NULL);
119
120         for (i = 0; fld_hash[i].fh_name != NULL; i++) {
121                 if (count != strlen(fld_hash[i].fh_name))
122                         continue;
123
124                 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
125                         hash = &fld_hash[i];
126                         break;
127                 }
128         }
129
130         if (hash != NULL) {
131                 cfs_spin_lock(&fld->lcf_lock);
132                 fld->lcf_hash = hash;
133                 cfs_spin_unlock(&fld->lcf_lock);
134
135                 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
136                        fld->lcf_name, hash->fh_name);
137         }
138
139         RETURN(count);
140 }
141
142 static int
143 fld_proc_write_cache_flush(struct file *file, const char *buffer,
144                            unsigned long count, void *data)
145 {
146         struct lu_client_fld *fld = (struct lu_client_fld *)data;
147         ENTRY;
148
149         LASSERT(fld != NULL);
150
151         fld_cache_flush(fld->lcf_cache);
152
153         CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
154
155         RETURN(count);
156 }
157
158 struct fld_seq_param {
159         struct lu_env  fsp_env;
160         struct dt_it  *fsp_it;
161 };
162
163 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
164 {
165         struct lu_server_fld    *fld = p->private;
166         struct dt_object        *obj;
167         const struct dt_it_ops  *iops;
168         struct fld_seq_param    *param;
169
170         if (fld->lsf_obj == NULL)
171                 return NULL;
172
173         obj = fld->lsf_obj;
174         iops = &obj->do_index_ops->dio_it;
175
176         OBD_ALLOC_PTR(param);
177         if (param == NULL)
178                 return ERR_PTR(-ENOMEM);
179
180         lu_env_init(&param->fsp_env, LCT_MD_THREAD);
181         param->fsp_it = iops->init(&param->fsp_env, obj, 0, NULL);
182
183         iops->load(&param->fsp_env, param->fsp_it, *pos);
184
185         return param;
186 }
187
188 static void fldb_seq_stop(struct seq_file *p, void *v)
189 {
190         struct lu_server_fld    *fld = p->private;
191         struct dt_object        *obj;
192         const struct dt_it_ops  *iops;
193         struct fld_seq_param    *param = (struct fld_seq_param *)v;
194
195         if (fld->lsf_obj == NULL)
196                 return;
197
198         obj = fld->lsf_obj;
199         iops = &obj->do_index_ops->dio_it;
200         if (IS_ERR(param) || param == NULL)
201                 return;
202
203         iops->put(&param->fsp_env, param->fsp_it);
204         iops->fini(&param->fsp_env, param->fsp_it);
205         lu_env_fini(&param->fsp_env);
206         OBD_FREE_PTR(param);
207
208         return;
209 }
210
211 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
212 {
213         struct lu_server_fld    *fld = p->private;
214         struct dt_object        *obj;
215         const struct dt_it_ops  *iops;
216         struct fld_seq_param    *param = (struct fld_seq_param *)v;
217         int                     rc;
218
219         if (fld->lsf_obj == NULL)
220                 return NULL;
221
222         obj = fld->lsf_obj;
223         iops = &obj->do_index_ops->dio_it;
224
225         iops->get(&param->fsp_env, param->fsp_it,
226                   (const struct dt_key *)pos);
227
228         rc = iops->next(&param->fsp_env, param->fsp_it);
229         if (rc > 0) {
230                 iops->put(&param->fsp_env, param->fsp_it);
231                 iops->fini(&param->fsp_env, param->fsp_it);
232                 lu_env_fini(&param->fsp_env);
233                 OBD_FREE_PTR(param);
234                 return NULL;
235         }
236
237         *pos = *(loff_t *)iops->key(&param->fsp_env, param->fsp_it);
238
239         return param;
240 }
241
242 static int fldb_seq_show(struct seq_file *p, void *v)
243 {
244         struct lu_server_fld    *fld = p->private;
245         struct dt_object        *obj = fld->lsf_obj;
246         struct fld_seq_param    *param = (struct fld_seq_param *)v;
247         const struct dt_it_ops  *iops;
248         struct fld_thread_info  *info;
249         struct lu_seq_range     *fld_rec;
250         int                     rc;
251
252         if (fld->lsf_obj == NULL)
253                 return 0;
254
255         obj = fld->lsf_obj;
256         iops = &obj->do_index_ops->dio_it;
257
258         info = lu_context_key_get(&param->fsp_env.le_ctx,
259                                   &fld_thread_key);
260         fld_rec = &info->fti_rec;
261         rc = iops->rec(&param->fsp_env, param->fsp_it,
262                        (struct dt_rec *)fld_rec, 0);
263         if (rc != 0) {
264                 CERROR("%s:read record error: rc %d\n",
265                        fld->lsf_name, rc);
266         } else if (fld_rec->lsr_start != 0) {
267                 range_be_to_cpu(fld_rec, fld_rec);
268                 rc = seq_printf(p, DRANGE"\n", PRANGE(fld_rec));
269         }
270
271         iops->put(&param->fsp_env, param->fsp_it);
272
273         return rc;
274 }
275
276 struct seq_operations fldb_sops = {
277         .start = fldb_seq_start,
278         .stop = fldb_seq_stop,
279         .next = fldb_seq_next,
280         .show = fldb_seq_show,
281 };
282
283 static int fldb_seq_open(struct inode *inode, struct file *file)
284 {
285         struct proc_dir_entry *dp = PDE(inode);
286         struct seq_file *seq;
287         int rc;
288
289         LPROCFS_ENTRY_AND_CHECK(dp);
290         rc = seq_open(file, &fldb_sops);
291         if (rc) {
292                 LPROCFS_EXIT();
293                 return rc;
294         }
295
296         seq = file->private_data;
297         seq->private = dp->data;
298         return 0;
299 }
300
301 struct lprocfs_vars fld_server_proc_list[] = {
302         { NULL }};
303
304 struct lprocfs_vars fld_client_proc_list[] = {
305         { "targets",     fld_proc_read_targets, NULL, NULL },
306         { "hash",        fld_proc_read_hash, fld_proc_write_hash, NULL },
307         { "cache_flush", NULL, fld_proc_write_cache_flush, NULL },
308         { NULL }};
309
310 struct file_operations fld_proc_seq_fops = {
311         .owner   = THIS_MODULE,
312         .open    = fldb_seq_open,
313         .read    = seq_read,
314         .llseek  = seq_lseek,
315         .release = lprocfs_seq_release,
316 };
317
318 #endif