4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/fld/lproc_fld.c
38 * FLD (FIDs Location Database)
40 * Author: Yury Umanets <umka@clusterfs.com>
41 * Di Wang <di.wang@whamcloud.com>
44 #define DEBUG_SUBSYSTEM S_FLD
47 # include <libcfs/libcfs.h>
48 # include <linux/module.h>
49 #else /* __KERNEL__ */
50 # include <liblustre.h>
53 #include <dt_object.h>
54 #include <obd_support.h>
55 #include <lustre_fld.h>
56 #include <lustre_fid.h>
57 #include "fld_internal.h"
58 #include <md_object.h>
62 fld_proc_read_targets(char *page, char **start, off_t off,
63 int count, int *eof, void *data)
65 struct lu_client_fld *fld = (struct lu_client_fld *)data;
66 struct lu_fld_target *target;
72 spin_lock(&fld->lcf_lock);
73 cfs_list_for_each_entry(target,
74 &fld->lcf_targets, ft_chain)
76 rc = snprintf(page, count, "%s\n",
77 fld_target_name(target));
84 spin_unlock(&fld->lcf_lock);
89 fld_proc_read_hash(char *page, char **start, off_t off,
90 int count, int *eof, void *data)
92 struct lu_client_fld *fld = (struct lu_client_fld *)data;
98 spin_lock(&fld->lcf_lock);
99 rc = snprintf(page, count, "%s\n", fld->lcf_hash->fh_name);
100 spin_unlock(&fld->lcf_lock);
106 fld_proc_write_hash(struct file *file, const char *buffer,
107 unsigned long count, void *data)
109 struct lu_client_fld *fld = (struct lu_client_fld *)data;
110 struct lu_fld_hash *hash = NULL;
114 LASSERT(fld != NULL);
116 for (i = 0; fld_hash[i].fh_name != NULL; i++) {
117 if (count != strlen(fld_hash[i].fh_name))
120 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
127 spin_lock(&fld->lcf_lock);
128 fld->lcf_hash = hash;
129 spin_unlock(&fld->lcf_lock);
131 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
132 fld->lcf_name, hash->fh_name);
139 fld_proc_write_cache_flush(struct file *file, const char *buffer,
140 unsigned long count, void *data)
142 struct lu_client_fld *fld = (struct lu_client_fld *)data;
145 LASSERT(fld != NULL);
147 fld_cache_flush(fld->lcf_cache);
149 CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
154 struct fld_seq_param {
155 struct lu_env fsp_env;
156 struct dt_it *fsp_it;
157 struct lu_server_fld *fsp_fld;
158 unsigned int fsp_stop:1;
161 struct lprocfs_vars fld_client_proc_list[] = {
162 { "targets", fld_proc_read_targets, NULL, NULL },
163 { "hash", fld_proc_read_hash, fld_proc_write_hash, NULL },
164 { "cache_flush", NULL, fld_proc_write_cache_flush, NULL },
168 # ifdef HAVE_SERVER_SUPPORT
169 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
171 struct fld_seq_param *param = p->private;
172 struct lu_server_fld *fld;
173 struct dt_object *obj;
174 const struct dt_it_ops *iops;
176 if (param == NULL || param->fsp_stop)
179 fld = param->fsp_fld;
181 LASSERT(obj != NULL);
182 iops = &obj->do_index_ops->dio_it;
184 iops->load(¶m->fsp_env, param->fsp_it, *pos);
186 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
190 static void fldb_seq_stop(struct seq_file *p, void *v)
192 struct fld_seq_param *param = p->private;
193 const struct dt_it_ops *iops;
194 struct lu_server_fld *fld;
195 struct dt_object *obj;
200 fld = param->fsp_fld;
202 LASSERT(obj != NULL);
203 iops = &obj->do_index_ops->dio_it;
205 iops->put(¶m->fsp_env, param->fsp_it);
208 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
210 struct fld_seq_param *param = p->private;
211 struct lu_server_fld *fld;
212 struct dt_object *obj;
213 const struct dt_it_ops *iops;
216 if (param == NULL || param->fsp_stop)
219 fld = param->fsp_fld;
221 LASSERT(obj != NULL);
222 iops = &obj->do_index_ops->dio_it;
224 rc = iops->next(¶m->fsp_env, param->fsp_it);
230 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
234 static int fldb_seq_show(struct seq_file *p, void *v)
236 struct fld_seq_param *param = p->private;
237 struct lu_server_fld *fld;
238 struct dt_object *obj;
239 const struct dt_it_ops *iops;
240 struct fld_thread_info *info;
241 struct lu_seq_range *fld_rec;
244 if (param == NULL || param->fsp_stop)
247 fld = param->fsp_fld;
249 LASSERT(obj != NULL);
250 iops = &obj->do_index_ops->dio_it;
252 info = lu_context_key_get(¶m->fsp_env.le_ctx,
254 fld_rec = &info->fti_rec;
255 rc = iops->rec(¶m->fsp_env, param->fsp_it,
256 (struct dt_rec *)fld_rec, 0);
258 CERROR("%s:read record error: rc %d\n",
260 } else if (fld_rec->lsr_start != 0) {
261 range_be_to_cpu(fld_rec, fld_rec);
262 rc = seq_printf(p, DRANGE"\n", PRANGE(fld_rec));
268 struct seq_operations fldb_sops = {
269 .start = fldb_seq_start,
270 .stop = fldb_seq_stop,
271 .next = fldb_seq_next,
272 .show = fldb_seq_show,
275 static int fldb_seq_open(struct inode *inode, struct file *file)
277 struct proc_dir_entry *dp = PDE(inode);
278 struct seq_file *seq;
279 struct lu_server_fld *fld = (struct lu_server_fld *)dp->data;
280 struct dt_object *obj;
281 const struct dt_it_ops *iops;
282 struct fld_seq_param *param = NULL;
286 LPROCFS_ENTRY_CHECK(dp);
287 rc = seq_open(file, &fldb_sops);
293 seq = file->private_data;
298 OBD_ALLOC_PTR(param);
300 GOTO(out, rc = -ENOMEM);
302 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
307 iops = &obj->do_index_ops->dio_it;
308 param->fsp_it = iops->init(¶m->fsp_env, obj, 0, NULL);
309 if (IS_ERR(param->fsp_it))
310 GOTO(out, rc = PTR_ERR(param->fsp_it));
312 param->fsp_fld = fld;
315 seq = file->private_data;
316 seq->private = param;
320 lu_env_fini(¶m->fsp_env);
327 static int fldb_seq_release(struct inode *inode, struct file *file)
329 struct seq_file *seq = file->private_data;
330 struct fld_seq_param *param;
331 struct lu_server_fld *fld;
332 struct dt_object *obj;
333 const struct dt_it_ops *iops;
335 param = seq->private;
337 lprocfs_seq_release(inode, file);
341 fld = param->fsp_fld;
343 LASSERT(obj != NULL);
344 iops = &obj->do_index_ops->dio_it;
346 LASSERT(iops != NULL);
347 LASSERT(obj != NULL);
348 LASSERT(param->fsp_it != NULL);
349 iops->fini(¶m->fsp_env, param->fsp_it);
350 lu_env_fini(¶m->fsp_env);
352 lprocfs_seq_release(inode, file);
357 const struct file_operations fld_proc_seq_fops = {
358 .owner = THIS_MODULE,
359 .open = fldb_seq_open,
361 .release = fldb_seq_release,
364 struct lprocfs_vars fld_server_proc_list[] = {
368 # endif /* HAVE_SERVER_SUPPORT */