Commit | Line | Data |
---|---|---|
d7e09d03 PT |
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) 2012, 2013, Intel Corporation. | |
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 | ||
9fdaf8c0 | 46 | #include "../../include/linux/libcfs/libcfs.h" |
0e9ad0ef | 47 | #include <linux/module.h> |
d7e09d03 | 48 | |
0e9ad0ef GKH |
49 | #include "../include/obd.h" |
50 | #include "../include/obd_class.h" | |
0e9ad0ef GKH |
51 | #include "../include/obd_support.h" |
52 | #include "../include/lustre_req_layout.h" | |
53 | #include "../include/lustre_fld.h" | |
54 | #include "../include/lustre_fid.h" | |
d7e09d03 PT |
55 | #include "fld_internal.h" |
56 | ||
d7e09d03 | 57 | static int |
82765049 | 58 | fld_debugfs_targets_seq_show(struct seq_file *m, void *unused) |
d7e09d03 | 59 | { |
73bb1da6 | 60 | struct lu_client_fld *fld = (struct lu_client_fld *)m->private; |
d7e09d03 | 61 | struct lu_fld_target *target; |
d7e09d03 PT |
62 | |
63 | LASSERT(fld != NULL); | |
64 | ||
65 | spin_lock(&fld->lcf_lock); | |
66 | list_for_each_entry(target, | |
67 | &fld->lcf_targets, ft_chain) | |
73bb1da6 | 68 | seq_printf(m, "%s\n", fld_target_name(target)); |
d7e09d03 | 69 | spin_unlock(&fld->lcf_lock); |
73bb1da6 | 70 | |
0a3bdb00 | 71 | return 0; |
d7e09d03 PT |
72 | } |
73 | ||
74 | static int | |
82765049 | 75 | fld_debugfs_hash_seq_show(struct seq_file *m, void *unused) |
d7e09d03 | 76 | { |
73bb1da6 | 77 | struct lu_client_fld *fld = (struct lu_client_fld *)m->private; |
d7e09d03 PT |
78 | |
79 | LASSERT(fld != NULL); | |
80 | ||
81 | spin_lock(&fld->lcf_lock); | |
73bb1da6 | 82 | seq_printf(m, "%s\n", fld->lcf_hash->fh_name); |
d7e09d03 PT |
83 | spin_unlock(&fld->lcf_lock); |
84 | ||
0a3bdb00 | 85 | return 0; |
d7e09d03 PT |
86 | } |
87 | ||
73bb1da6 | 88 | static ssize_t |
82765049 DE |
89 | fld_debugfs_hash_seq_write(struct file *file, |
90 | const char __user *buffer, | |
91 | size_t count, loff_t *off) | |
d7e09d03 | 92 | { |
48f46e74 | 93 | struct lu_client_fld *fld; |
d7e09d03 | 94 | struct lu_fld_hash *hash = NULL; |
41dff7ac | 95 | char fh_name[8]; |
d7e09d03 | 96 | int i; |
d7e09d03 | 97 | |
41dff7ac | 98 | if (count > sizeof(fh_name)) |
e84962e3 TL |
99 | return -ENAMETOOLONG; |
100 | ||
41dff7ac | 101 | if (copy_from_user(fh_name, buffer, count) != 0) |
e84962e3 TL |
102 | return -EFAULT; |
103 | ||
48f46e74 | 104 | fld = ((struct seq_file *)file->private_data)->private; |
d7e09d03 PT |
105 | LASSERT(fld != NULL); |
106 | ||
107 | for (i = 0; fld_hash[i].fh_name != NULL; i++) { | |
108 | if (count != strlen(fld_hash[i].fh_name)) | |
109 | continue; | |
110 | ||
41dff7ac | 111 | if (!strncmp(fld_hash[i].fh_name, fh_name, count)) { |
d7e09d03 PT |
112 | hash = &fld_hash[i]; |
113 | break; | |
114 | } | |
115 | } | |
116 | ||
117 | if (hash != NULL) { | |
118 | spin_lock(&fld->lcf_lock); | |
119 | fld->lcf_hash = hash; | |
120 | spin_unlock(&fld->lcf_lock); | |
121 | ||
122 | CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n", | |
123 | fld->lcf_name, hash->fh_name); | |
124 | } | |
125 | ||
0a3bdb00 | 126 | return count; |
d7e09d03 PT |
127 | } |
128 | ||
73bb1da6 | 129 | static ssize_t |
82765049 DE |
130 | fld_debugfs_cache_flush_write(struct file *file, const char __user *buffer, |
131 | size_t count, loff_t *pos) | |
d7e09d03 | 132 | { |
73bb1da6 | 133 | struct lu_client_fld *fld = file->private_data; |
d7e09d03 PT |
134 | |
135 | LASSERT(fld != NULL); | |
136 | ||
137 | fld_cache_flush(fld->lcf_cache); | |
138 | ||
139 | CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name); | |
140 | ||
0a3bdb00 | 141 | return count; |
d7e09d03 PT |
142 | } |
143 | ||
82765049 DE |
144 | static int |
145 | fld_debugfs_cache_flush_release(struct inode *inode, struct file *file) | |
73bb1da6 PT |
146 | { |
147 | file->private_data = NULL; | |
148 | return 0; | |
149 | } | |
150 | ||
82765049 | 151 | static struct file_operations fld_debugfs_cache_flush_fops = { |
73bb1da6 | 152 | .owner = THIS_MODULE, |
92a0616a | 153 | .open = simple_open, |
82765049 DE |
154 | .write = fld_debugfs_cache_flush_write, |
155 | .release = fld_debugfs_cache_flush_release, | |
73bb1da6 PT |
156 | }; |
157 | ||
82765049 DE |
158 | LPROC_SEQ_FOPS_RO(fld_debugfs_targets); |
159 | LPROC_SEQ_FOPS(fld_debugfs_hash); | |
73bb1da6 | 160 | |
82765049 DE |
161 | struct lprocfs_vars fld_client_debugfs_list[] = { |
162 | { "targets", &fld_debugfs_targets_fops }, | |
163 | { "hash", &fld_debugfs_hash_fops }, | |
164 | { "cache_flush", &fld_debugfs_cache_flush_fops }, | |
636e5a65 APON |
165 | { NULL } |
166 | }; |