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 | |
6a5b99a4 | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
d7e09d03 | 19 | * |
d7e09d03 PT |
20 | * GPL HEADER END |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. | |
24 | * Use is subject to license terms. | |
25 | * | |
1dc563a6 | 26 | * Copyright (c) 2012, 2015, Intel Corporation. |
d7e09d03 PT |
27 | */ |
28 | /* | |
29 | * This file is part of Lustre, http://www.lustre.org/ | |
30 | * Lustre is a trademark of Sun Microsystems, Inc. | |
31 | * | |
32 | * lustre/fld/lproc_fld.c | |
33 | * | |
34 | * FLD (FIDs Location Database) | |
35 | * | |
36 | * Author: Yury Umanets <umka@clusterfs.com> | |
37 | * Di Wang <di.wang@whamcloud.com> | |
38 | */ | |
39 | ||
40 | #define DEBUG_SUBSYSTEM S_FLD | |
41 | ||
9fdaf8c0 | 42 | #include "../../include/linux/libcfs/libcfs.h" |
0e9ad0ef | 43 | #include <linux/module.h> |
d7e09d03 | 44 | |
0e9ad0ef GKH |
45 | #include "../include/obd.h" |
46 | #include "../include/obd_class.h" | |
0e9ad0ef GKH |
47 | #include "../include/obd_support.h" |
48 | #include "../include/lustre_req_layout.h" | |
49 | #include "../include/lustre_fld.h" | |
50 | #include "../include/lustre_fid.h" | |
d7e09d03 PT |
51 | #include "fld_internal.h" |
52 | ||
d7e09d03 | 53 | static int |
82765049 | 54 | fld_debugfs_targets_seq_show(struct seq_file *m, void *unused) |
d7e09d03 | 55 | { |
73bb1da6 | 56 | struct lu_client_fld *fld = (struct lu_client_fld *)m->private; |
d7e09d03 | 57 | struct lu_fld_target *target; |
d7e09d03 | 58 | |
d7e09d03 | 59 | spin_lock(&fld->lcf_lock); |
cf677593 | 60 | list_for_each_entry(target, &fld->lcf_targets, ft_chain) |
73bb1da6 | 61 | seq_printf(m, "%s\n", fld_target_name(target)); |
d7e09d03 | 62 | spin_unlock(&fld->lcf_lock); |
73bb1da6 | 63 | |
0a3bdb00 | 64 | return 0; |
d7e09d03 PT |
65 | } |
66 | ||
67 | static int | |
82765049 | 68 | fld_debugfs_hash_seq_show(struct seq_file *m, void *unused) |
d7e09d03 | 69 | { |
73bb1da6 | 70 | struct lu_client_fld *fld = (struct lu_client_fld *)m->private; |
d7e09d03 | 71 | |
d7e09d03 | 72 | spin_lock(&fld->lcf_lock); |
73bb1da6 | 73 | seq_printf(m, "%s\n", fld->lcf_hash->fh_name); |
d7e09d03 PT |
74 | spin_unlock(&fld->lcf_lock); |
75 | ||
0a3bdb00 | 76 | return 0; |
d7e09d03 PT |
77 | } |
78 | ||
73bb1da6 | 79 | static ssize_t |
82765049 DE |
80 | fld_debugfs_hash_seq_write(struct file *file, |
81 | const char __user *buffer, | |
82 | size_t count, loff_t *off) | |
d7e09d03 | 83 | { |
48f46e74 | 84 | struct lu_client_fld *fld; |
d7e09d03 | 85 | struct lu_fld_hash *hash = NULL; |
41dff7ac | 86 | char fh_name[8]; |
d7e09d03 | 87 | int i; |
d7e09d03 | 88 | |
41dff7ac | 89 | if (count > sizeof(fh_name)) |
e84962e3 TL |
90 | return -ENAMETOOLONG; |
91 | ||
41dff7ac | 92 | if (copy_from_user(fh_name, buffer, count) != 0) |
e84962e3 TL |
93 | return -EFAULT; |
94 | ||
48f46e74 | 95 | fld = ((struct seq_file *)file->private_data)->private; |
d7e09d03 | 96 | |
6ac49ca5 | 97 | for (i = 0; fld_hash[i].fh_name; i++) { |
d7e09d03 PT |
98 | if (count != strlen(fld_hash[i].fh_name)) |
99 | continue; | |
100 | ||
41dff7ac | 101 | if (!strncmp(fld_hash[i].fh_name, fh_name, count)) { |
d7e09d03 PT |
102 | hash = &fld_hash[i]; |
103 | break; | |
104 | } | |
105 | } | |
106 | ||
6ac49ca5 | 107 | if (hash) { |
d7e09d03 PT |
108 | spin_lock(&fld->lcf_lock); |
109 | fld->lcf_hash = hash; | |
110 | spin_unlock(&fld->lcf_lock); | |
111 | ||
112 | CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n", | |
113 | fld->lcf_name, hash->fh_name); | |
114 | } | |
115 | ||
0a3bdb00 | 116 | return count; |
d7e09d03 PT |
117 | } |
118 | ||
73bb1da6 | 119 | static ssize_t |
82765049 DE |
120 | fld_debugfs_cache_flush_write(struct file *file, const char __user *buffer, |
121 | size_t count, loff_t *pos) | |
d7e09d03 | 122 | { |
73bb1da6 | 123 | struct lu_client_fld *fld = file->private_data; |
d7e09d03 | 124 | |
d7e09d03 PT |
125 | fld_cache_flush(fld->lcf_cache); |
126 | ||
127 | CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name); | |
128 | ||
0a3bdb00 | 129 | return count; |
d7e09d03 PT |
130 | } |
131 | ||
82765049 DE |
132 | static int |
133 | fld_debugfs_cache_flush_release(struct inode *inode, struct file *file) | |
73bb1da6 PT |
134 | { |
135 | file->private_data = NULL; | |
136 | return 0; | |
137 | } | |
138 | ||
82765049 | 139 | static struct file_operations fld_debugfs_cache_flush_fops = { |
73bb1da6 | 140 | .owner = THIS_MODULE, |
92a0616a | 141 | .open = simple_open, |
82765049 DE |
142 | .write = fld_debugfs_cache_flush_write, |
143 | .release = fld_debugfs_cache_flush_release, | |
73bb1da6 PT |
144 | }; |
145 | ||
82765049 DE |
146 | LPROC_SEQ_FOPS_RO(fld_debugfs_targets); |
147 | LPROC_SEQ_FOPS(fld_debugfs_hash); | |
73bb1da6 | 148 | |
82765049 DE |
149 | struct lprocfs_vars fld_client_debugfs_list[] = { |
150 | { "targets", &fld_debugfs_targets_fops }, | |
151 | { "hash", &fld_debugfs_hash_fops }, | |
152 | { "cache_flush", &fld_debugfs_cache_flush_fops }, | |
636e5a65 APON |
153 | { NULL } |
154 | }; |