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
46 # include <linux/libcfs/libcfs.h>
47 # include <linux/module.h>
50 #include <obd_class.h>
51 #include <dt_object.h>
52 #include <md_object.h>
53 #include <obd_support.h>
54 #include <lustre_req_layout.h>
55 #include <lustre_fld.h>
56 #include <lustre_fid.h>
57 #include "fld_internal.h"
61 fld_proc_targets_seq_show(struct seq_file *m, void *unused)
63 struct lu_client_fld *fld = (struct lu_client_fld *)m->private;
64 struct lu_fld_target *target;
69 spin_lock(&fld->lcf_lock);
70 list_for_each_entry(target,
71 &fld->lcf_targets, ft_chain)
72 seq_printf(m, "%s\n", fld_target_name(target));
73 spin_unlock(&fld->lcf_lock);
79 fld_proc_hash_seq_show(struct seq_file *m, void *unused)
81 struct lu_client_fld *fld = (struct lu_client_fld *)m->private;
86 spin_lock(&fld->lcf_lock);
87 seq_printf(m, "%s\n", fld->lcf_hash->fh_name);
88 spin_unlock(&fld->lcf_lock);
94 fld_proc_hash_seq_write(struct file *file, const char *buffer,
95 size_t count, loff_t *off)
97 struct lu_client_fld *fld = ((struct seq_file *)file->private_data)->private;
98 struct lu_fld_hash *hash = NULL;
102 LASSERT(fld != NULL);
104 for (i = 0; fld_hash[i].fh_name != NULL; i++) {
105 if (count != strlen(fld_hash[i].fh_name))
108 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
115 spin_lock(&fld->lcf_lock);
116 fld->lcf_hash = hash;
117 spin_unlock(&fld->lcf_lock);
119 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
120 fld->lcf_name, hash->fh_name);
127 fld_proc_cache_flush_write(struct file *file, const char __user *buffer,
128 size_t count, loff_t *pos)
130 struct lu_client_fld *fld = file->private_data;
133 LASSERT(fld != NULL);
135 fld_cache_flush(fld->lcf_cache);
137 CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
142 static int fld_proc_cache_flush_open(struct inode *inode, struct file *file)
144 file->private_data = PDE_DATA(inode);
148 static int fld_proc_cache_flush_release(struct inode *inode, struct file *file)
150 file->private_data = NULL;
154 struct file_operations fld_proc_cache_flush_fops = {
155 .owner = THIS_MODULE,
156 .open = fld_proc_cache_flush_open,
157 .write = fld_proc_cache_flush_write,
158 .release = fld_proc_cache_flush_release,
161 struct fld_seq_param {
162 struct lu_env fsp_env;
163 struct dt_it *fsp_it;
164 struct lu_server_fld *fsp_fld;
165 unsigned int fsp_stop:1;
168 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
170 struct fld_seq_param *param = p->private;
171 struct lu_server_fld *fld;
172 struct dt_object *obj;
173 const struct dt_it_ops *iops;
175 if (param == NULL || param->fsp_stop)
178 fld = param->fsp_fld;
180 LASSERT(obj != NULL);
181 iops = &obj->do_index_ops->dio_it;
183 iops->load(¶m->fsp_env, param->fsp_it, *pos);
185 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
189 static void fldb_seq_stop(struct seq_file *p, void *v)
191 struct fld_seq_param *param = p->private;
192 const struct dt_it_ops *iops;
193 struct lu_server_fld *fld;
194 struct dt_object *obj;
199 fld = param->fsp_fld;
201 LASSERT(obj != NULL);
202 iops = &obj->do_index_ops->dio_it;
204 iops->put(¶m->fsp_env, param->fsp_it);
207 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
209 struct fld_seq_param *param = p->private;
210 struct lu_server_fld *fld;
211 struct dt_object *obj;
212 const struct dt_it_ops *iops;
215 if (param == NULL || param->fsp_stop)
218 fld = param->fsp_fld;
220 LASSERT(obj != NULL);
221 iops = &obj->do_index_ops->dio_it;
223 rc = iops->next(¶m->fsp_env, param->fsp_it);
229 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
233 static int fldb_seq_show(struct seq_file *p, void *v)
235 struct fld_seq_param *param = p->private;
236 struct lu_server_fld *fld;
237 struct dt_object *obj;
238 const struct dt_it_ops *iops;
239 struct fld_thread_info *info;
240 struct lu_seq_range *fld_rec;
243 if (param == NULL || param->fsp_stop)
246 fld = param->fsp_fld;
248 LASSERT(obj != NULL);
249 iops = &obj->do_index_ops->dio_it;
251 info = lu_context_key_get(¶m->fsp_env.le_ctx,
253 fld_rec = &info->fti_rec;
254 rc = iops->rec(¶m->fsp_env, param->fsp_it,
255 (struct dt_rec *)fld_rec, 0);
257 CERROR("%s:read record error: rc %d\n",
259 } else if (fld_rec->lsr_start != 0) {
260 range_be_to_cpu(fld_rec, fld_rec);
261 rc = seq_printf(p, DRANGE"\n", PRANGE(fld_rec));
267 struct seq_operations fldb_sops = {
268 .start = fldb_seq_start,
269 .stop = fldb_seq_stop,
270 .next = fldb_seq_next,
271 .show = fldb_seq_show,
274 static int fldb_seq_open(struct inode *inode, struct file *file)
276 struct seq_file *seq;
277 struct lu_server_fld *fld = (struct lu_server_fld *)PDE_DATA(inode);
278 struct dt_object *obj;
279 const struct dt_it_ops *iops;
280 struct fld_seq_param *param = NULL;
284 rc = seq_open(file, &fldb_sops);
290 seq = file->private_data;
295 OBD_ALLOC_PTR(param);
297 GOTO(out, rc = -ENOMEM);
299 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
304 iops = &obj->do_index_ops->dio_it;
305 param->fsp_it = iops->init(¶m->fsp_env, obj, 0, NULL);
306 if (IS_ERR(param->fsp_it))
307 GOTO(out, rc = PTR_ERR(param->fsp_it));
309 param->fsp_fld = fld;
312 seq = file->private_data;
313 seq->private = param;
317 lu_env_fini(¶m->fsp_env);
324 static int fldb_seq_release(struct inode *inode, struct file *file)
326 struct seq_file *seq = file->private_data;
327 struct fld_seq_param *param;
328 struct lu_server_fld *fld;
329 struct dt_object *obj;
330 const struct dt_it_ops *iops;
332 param = seq->private;
334 lprocfs_seq_release(inode, file);
338 fld = param->fsp_fld;
340 LASSERT(obj != NULL);
341 iops = &obj->do_index_ops->dio_it;
343 LASSERT(iops != NULL);
344 LASSERT(obj != NULL);
345 LASSERT(param->fsp_it != NULL);
346 iops->fini(¶m->fsp_env, param->fsp_it);
347 lu_env_fini(¶m->fsp_env);
349 lprocfs_seq_release(inode, file);
354 struct lprocfs_vars fld_server_proc_list[] = {
357 LPROC_SEQ_FOPS_RO(fld_proc_targets);
358 LPROC_SEQ_FOPS(fld_proc_hash);
360 struct lprocfs_vars fld_client_proc_list[] = {
361 { "targets", &fld_proc_targets_fops },
362 { "hash", &fld_proc_hash_fops },
363 { "cache_flush", &fld_proc_cache_flush_fops },
366 struct file_operations fld_proc_seq_fops = {
367 .owner = THIS_MODULE,
368 .open = fldb_seq_open,
370 .release = fldb_seq_release,