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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/fld/lproc_fld.c
33 * FLD (FIDs Location Database)
35 * Author: Yury Umanets <umka@clusterfs.com>
36 * Di Wang <di.wang@whamcloud.com>
39 #define DEBUG_SUBSYSTEM S_FLD
41 #include <libcfs/libcfs.h>
42 #include <linux/module.h>
44 #ifdef HAVE_SERVER_SUPPORT
45 #include <dt_object.h>
47 #include <obd_support.h>
48 #include <lustre_fld.h>
49 #include <lustre_fid.h>
50 #include "fld_internal.h"
53 fld_debugfs_targets_seq_show(struct seq_file *m, void *unused)
55 struct lu_client_fld *fld = (struct lu_client_fld *)m->private;
56 struct lu_fld_target *target;
59 spin_lock(&fld->lcf_lock);
60 list_for_each_entry(target, &fld->lcf_targets, ft_chain)
61 seq_printf(m, "%s\n", fld_target_name(target));
62 spin_unlock(&fld->lcf_lock);
68 fld_debugfs_hash_seq_show(struct seq_file *m, void *unused)
70 struct lu_client_fld *fld = (struct lu_client_fld *)m->private;
73 spin_lock(&fld->lcf_lock);
74 seq_printf(m, "%s\n", fld->lcf_hash->fh_name);
75 spin_unlock(&fld->lcf_lock);
81 fld_debugfs_hash_seq_write(struct file *file, const char __user *buffer,
82 size_t count, loff_t *off)
84 struct seq_file *m = file->private_data;
85 struct lu_client_fld *fld = m->private;
86 struct lu_fld_hash *hash = NULL;
90 if (count > sizeof(fh_name))
93 if (copy_from_user(fh_name, buffer, count) != 0)
96 for (i = 0; fld_hash[i].fh_name; i++) {
97 if (count != strlen(fld_hash[i].fh_name))
100 if (!strncmp(fld_hash[i].fh_name, fh_name, count)) {
107 spin_lock(&fld->lcf_lock);
108 fld->lcf_hash = hash;
109 spin_unlock(&fld->lcf_lock);
111 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
112 fld->lcf_name, hash->fh_name);
118 static ssize_t ldebugfs_cache_flush_seq_write(struct file *file,
119 const char __user *buffer,
120 size_t count, loff_t *pos)
122 struct seq_file *m = file->private_data;
123 struct lu_client_fld *fld = m->private;
126 fld_cache_flush(fld->lcf_cache);
128 CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
133 LDEBUGFS_SEQ_FOPS_RO(fld_debugfs_targets);
134 LDEBUGFS_SEQ_FOPS(fld_debugfs_hash);
135 LDEBUGFS_FOPS_WR_ONLY(fld, cache_flush);
137 struct ldebugfs_vars fld_client_debugfs_list[] = {
139 .fops = &fld_debugfs_targets_fops },
141 .fops = &fld_debugfs_hash_fops },
142 { .name = "cache_flush",
143 .fops = &fld_cache_flush_fops },
147 #ifdef HAVE_SERVER_SUPPORT
148 struct fld_seq_param {
149 struct lu_env fsp_env;
150 struct dt_it *fsp_it;
151 struct lu_server_fld *fsp_fld;
152 unsigned int fsp_stop:1;
155 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
157 struct fld_seq_param *param = p->private;
158 struct lu_server_fld *fld;
159 struct dt_object *obj;
160 const struct dt_it_ops *iops;
164 if (param == NULL || param->fsp_stop)
167 fld = param->fsp_fld;
169 LASSERT(obj != NULL);
170 iops = &obj->do_index_ops->dio_it;
172 rc = iops->load(¶m->fsp_env, param->fsp_it, *pos);
176 key = iops->key(¶m->fsp_env, param->fsp_it);
180 *pos = be64_to_cpu(*(__u64 *)key);
185 static void fldb_seq_stop(struct seq_file *p, void *v)
187 struct fld_seq_param *param = p->private;
188 const struct dt_it_ops *iops;
189 struct lu_server_fld *fld;
190 struct dt_object *obj;
195 fld = param->fsp_fld;
197 LASSERT(obj != NULL);
198 iops = &obj->do_index_ops->dio_it;
200 iops->put(¶m->fsp_env, param->fsp_it);
203 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
205 struct fld_seq_param *param = p->private;
206 struct lu_server_fld *fld;
207 struct dt_object *obj;
208 const struct dt_it_ops *iops;
212 if (param == NULL || param->fsp_stop)
215 fld = param->fsp_fld;
217 LASSERT(obj != NULL);
218 iops = &obj->do_index_ops->dio_it;
220 rc = iops->next(¶m->fsp_env, param->fsp_it);
226 *pos = be64_to_cpu(*(__u64 *)iops->key(¶m->fsp_env, param->fsp_it));
230 static int fldb_seq_show(struct seq_file *p, void *v)
232 struct fld_seq_param *param = p->private;
233 struct lu_server_fld *fld;
234 struct dt_object *obj;
235 const struct dt_it_ops *iops;
236 struct fld_thread_info *info;
237 struct lu_seq_range *fld_rec;
240 if (param == NULL || param->fsp_stop)
243 fld = param->fsp_fld;
245 LASSERT(obj != NULL);
246 iops = &obj->do_index_ops->dio_it;
248 info = lu_context_key_get(¶m->fsp_env.le_ctx,
250 fld_rec = &info->fti_rec;
251 rc = iops->rec(¶m->fsp_env, param->fsp_it,
252 (struct dt_rec *)fld_rec, 0);
254 CERROR("%s:read record error: rc %d\n",
256 } else if (fld_rec->lsr_start != 0) {
257 range_be_to_cpu(fld_rec, fld_rec);
258 seq_printf(p, DRANGE"\n", PRANGE(fld_rec));
264 static const struct seq_operations fldb_sops = {
265 .start = fldb_seq_start,
266 .stop = fldb_seq_stop,
267 .next = fldb_seq_next,
268 .show = fldb_seq_show,
271 static int fldb_seq_open(struct inode *inode, struct file *file)
273 struct seq_file *seq;
274 struct lu_server_fld *fld = inode->i_private;
275 struct dt_object *obj;
276 const struct dt_it_ops *iops;
277 struct fld_seq_param *param = NULL;
281 rc = seq_open(file, &fldb_sops);
287 seq = file->private_data;
292 OBD_ALLOC_PTR(param);
294 GOTO(out, rc = -ENOMEM);
296 rc = lu_env_init(¶m->fsp_env, LCT_MD_THREAD);
301 iops = &obj->do_index_ops->dio_it;
302 param->fsp_it = iops->init(¶m->fsp_env, obj, 0);
303 if (IS_ERR(param->fsp_it))
304 GOTO(out, rc = PTR_ERR(param->fsp_it));
306 param->fsp_fld = fld;
309 seq = file->private_data;
310 seq->private = param;
314 lu_env_fini(¶m->fsp_env);
321 static int fldb_seq_release(struct inode *inode, struct file *file)
323 struct seq_file *seq = file->private_data;
324 struct fld_seq_param *param;
325 struct lu_server_fld *fld;
326 struct dt_object *obj;
327 const struct dt_it_ops *iops;
329 param = seq->private;
331 lprocfs_seq_release(inode, file);
335 fld = param->fsp_fld;
337 LASSERT(obj != NULL);
338 iops = &obj->do_index_ops->dio_it;
340 LASSERT(iops != NULL);
341 LASSERT(param->fsp_it != NULL);
342 iops->fini(¶m->fsp_env, param->fsp_it);
343 lu_env_fini(¶m->fsp_env);
345 lprocfs_seq_release(inode, file);
350 const struct file_operations fld_debugfs_seq_fops = {
351 .owner = THIS_MODULE,
352 .open = fldb_seq_open,
354 .release = fldb_seq_release,
357 # endif /* HAVE_SERVER_SUPPORT */