77322ba5bf312fa9c56bd1d4a910ed4289a10bed
[firefly-linux-kernel-4.4.55.git] / drivers / staging / lustre / lustre / fld / lproc_fld.c
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
46 # include <linux/libcfs/libcfs.h>
47 # include <linux/module.h>
48
49 #include <obd.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"
58
59 #ifdef LPROCFS
60 static int
61 fld_proc_targets_seq_show(struct seq_file *m, void *unused)
62 {
63         struct lu_client_fld *fld = (struct lu_client_fld *)m->private;
64         struct lu_fld_target *target;
65         ENTRY;
66
67         LASSERT(fld != NULL);
68
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);
74
75         RETURN(0);
76 }
77
78 static int
79 fld_proc_hash_seq_show(struct seq_file *m, void *unused)
80 {
81         struct lu_client_fld *fld = (struct lu_client_fld *)m->private;
82         ENTRY;
83
84         LASSERT(fld != NULL);
85
86         spin_lock(&fld->lcf_lock);
87         seq_printf(m, "%s\n", fld->lcf_hash->fh_name);
88         spin_unlock(&fld->lcf_lock);
89
90         RETURN(0);
91 }
92
93 static ssize_t
94 fld_proc_hash_seq_write(struct file *file, const char *buffer,
95                         size_t count, loff_t *off)
96 {
97         struct lu_client_fld *fld = ((struct seq_file *)file->private_data)->private;
98         struct lu_fld_hash *hash = NULL;
99         int i;
100         ENTRY;
101
102         LASSERT(fld != NULL);
103
104         for (i = 0; fld_hash[i].fh_name != NULL; i++) {
105                 if (count != strlen(fld_hash[i].fh_name))
106                         continue;
107
108                 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
109                         hash = &fld_hash[i];
110                         break;
111                 }
112         }
113
114         if (hash != NULL) {
115                 spin_lock(&fld->lcf_lock);
116                 fld->lcf_hash = hash;
117                 spin_unlock(&fld->lcf_lock);
118
119                 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
120                        fld->lcf_name, hash->fh_name);
121         }
122
123         RETURN(count);
124 }
125
126 static ssize_t
127 fld_proc_cache_flush_write(struct file *file, const char __user *buffer,
128                                size_t count, loff_t *pos)
129 {
130         struct lu_client_fld *fld = file->private_data;
131         ENTRY;
132
133         LASSERT(fld != NULL);
134
135         fld_cache_flush(fld->lcf_cache);
136
137         CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
138
139         RETURN(count);
140 }
141
142 static int fld_proc_cache_flush_open(struct inode *inode, struct file *file)
143 {
144         file->private_data = PDE_DATA(inode);
145         return 0;
146 }
147
148 static int fld_proc_cache_flush_release(struct inode *inode, struct file *file)
149 {
150         file->private_data = NULL;
151         return 0;
152 }
153
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,
159 };
160
161 LPROC_SEQ_FOPS_RO(fld_proc_targets);
162 LPROC_SEQ_FOPS(fld_proc_hash);
163
164 struct lprocfs_vars fld_client_proc_list[] = {
165         { "targets", &fld_proc_targets_fops },
166         { "hash", &fld_proc_hash_fops },
167         { "cache_flush", &fld_proc_cache_flush_fops },
168         { NULL }};
169
170 #endif /* LPROCFS */