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) 2011, 2012, Whamcloud, Inc.
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>
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"
65 fld_proc_read_targets(char *page, char **start, off_t off,
66 int count, int *eof, void *data)
68 struct lu_client_fld *fld = (struct lu_client_fld *)data;
69 struct lu_fld_target *target;
75 cfs_spin_lock(&fld->lcf_lock);
76 cfs_list_for_each_entry(target,
77 &fld->lcf_targets, ft_chain)
79 rc = snprintf(page, count, "%s\n",
80 fld_target_name(target));
87 cfs_spin_unlock(&fld->lcf_lock);
92 fld_proc_read_hash(char *page, char **start, off_t off,
93 int count, int *eof, void *data)
95 struct lu_client_fld *fld = (struct lu_client_fld *)data;
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);
110 fld_proc_write_hash(struct file *file, const char *buffer,
111 unsigned long count, void *data)
113 struct lu_client_fld *fld = (struct lu_client_fld *)data;
114 struct lu_fld_hash *hash = NULL;
118 LASSERT(fld != NULL);
120 for (i = 0; fld_hash[i].fh_name != NULL; i++) {
121 if (count != strlen(fld_hash[i].fh_name))
124 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
131 cfs_spin_lock(&fld->lcf_lock);
132 fld->lcf_hash = hash;
133 cfs_spin_unlock(&fld->lcf_lock);
135 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
136 fld->lcf_name, hash->fh_name);
143 fld_proc_write_cache_flush(struct file *file, const char *buffer,
144 unsigned long count, void *data)
146 struct lu_client_fld *fld = (struct lu_client_fld *)data;
149 LASSERT(fld != NULL);
151 fld_cache_flush(fld->lcf_cache);
153 CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
158 struct fld_seq_param {
159 struct lu_env fsp_env;
160 struct dt_it *fsp_it;
163 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
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 struct fld_thread_info *info;
171 if (fld->lsf_obj == NULL)
175 iops = &obj->do_index_ops->dio_it;
177 OBD_ALLOC_PTR(param);
179 return ERR_PTR(-ENOMEM);
181 lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
182 param->fsp_it = iops->init(¶m->fsp_env, obj, 0, NULL);
183 info = lu_context_key_get(¶m->fsp_env.le_ctx,
186 iops->load(¶m->fsp_env, param->fsp_it, *pos);
191 static void fldb_seq_stop(struct seq_file *p, void *v)
193 struct lu_server_fld *fld = p->private;
194 struct dt_object *obj;
195 const struct dt_it_ops *iops;
196 struct fld_seq_param *param = (struct fld_seq_param *)v;
198 if (fld->lsf_obj == NULL)
202 iops = &obj->do_index_ops->dio_it;
203 if (IS_ERR(param) || param == NULL)
206 iops->put(¶m->fsp_env, param->fsp_it);
207 iops->fini(¶m->fsp_env, param->fsp_it);
208 lu_env_fini(¶m->fsp_env);
214 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
216 struct lu_server_fld *fld = p->private;
217 struct dt_object *obj;
218 const struct dt_it_ops *iops;
219 struct fld_seq_param *param = (struct fld_seq_param *)v;
222 if (fld->lsf_obj == NULL)
226 iops = &obj->do_index_ops->dio_it;
228 iops->get(¶m->fsp_env, param->fsp_it,
229 (const struct dt_key *)pos);
231 rc = iops->next(¶m->fsp_env, param->fsp_it);
233 iops->put(¶m->fsp_env, param->fsp_it);
234 iops->fini(¶m->fsp_env, param->fsp_it);
235 lu_env_fini(¶m->fsp_env);
240 *pos = *(loff_t *)iops->key(¶m->fsp_env, param->fsp_it);
245 static int fldb_seq_show(struct seq_file *p, void *v)
247 struct lu_server_fld *fld = p->private;
248 struct dt_object *obj = fld->lsf_obj;
249 struct fld_seq_param *param = (struct fld_seq_param *)v;
250 const struct dt_it_ops *iops;
251 struct fld_thread_info *info;
252 struct lu_seq_range *fld_rec;
255 if (fld->lsf_obj == NULL)
259 iops = &obj->do_index_ops->dio_it;
261 info = lu_context_key_get(¶m->fsp_env.le_ctx,
263 fld_rec = &info->fti_rec;
264 rc = iops->rec(¶m->fsp_env, param->fsp_it,
265 (struct dt_rec *)fld_rec, 0);
267 CERROR("%s:read record error: rc %d\n",
269 } else if (fld_rec->lsr_start != 0) {
270 range_be_to_cpu(fld_rec, fld_rec);
271 rc = seq_printf(p, DRANGE"\n", PRANGE(fld_rec));
274 iops->put(¶m->fsp_env, param->fsp_it);
279 struct seq_operations fldb_sops = {
280 .start = fldb_seq_start,
281 .stop = fldb_seq_stop,
282 .next = fldb_seq_next,
283 .show = fldb_seq_show,
286 static int fldb_seq_open(struct inode *inode, struct file *file)
288 struct proc_dir_entry *dp = PDE(inode);
289 struct seq_file *seq;
292 LPROCFS_ENTRY_AND_CHECK(dp);
293 rc = seq_open(file, &fldb_sops);
299 seq = file->private_data;
300 seq->private = dp->data;
304 struct lprocfs_vars fld_server_proc_list[] = {
307 struct lprocfs_vars fld_client_proc_list[] = {
308 { "targets", fld_proc_read_targets, NULL, NULL },
309 { "hash", fld_proc_read_hash, fld_proc_write_hash, NULL },
310 { "cache_flush", NULL, fld_proc_write_cache_flush, NULL },
313 struct file_operations fld_proc_seq_fops = {
314 .owner = THIS_MODULE,
315 .open = fldb_seq_open,
318 .release = lprocfs_seq_release,