Whamcloud - gitweb
09024dd142c3db99a1ee76dab15d25e366b84e05
[fs/lustre-release.git] / 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 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lustre/fld/lproc_fld.c
35  *
36  * FLD (FIDs Location Database)
37  *
38  * Author: Yury Umanets <umka@clusterfs.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_FLD
42
43 #ifdef __KERNEL__
44 # include <libcfs/libcfs.h>
45 # include <linux/module.h>
46 #else /* __KERNEL__ */
47 # include <liblustre.h>
48 #endif
49
50 #include <obd.h>
51 #include <obd_class.h>
52 #include <dt_object.h>
53 #include <md_object.h>
54 #include <obd_support.h>
55 #include <lustre_req_layout.h>
56 #include <lustre_fld.h>
57 #include "fld_internal.h"
58
59 #ifdef LPROCFS
60 static int
61 fld_proc_read_targets(char *page, char **start, off_t off,
62                       int count, int *eof, void *data)
63 {
64         struct lu_client_fld *fld = (struct lu_client_fld *)data;
65         struct lu_fld_target *target;
66         int total = 0, rc;
67         ENTRY;
68
69         LASSERT(fld != NULL);
70
71         cfs_spin_lock(&fld->lcf_lock);
72         cfs_list_for_each_entry(target,
73                                 &fld->lcf_targets, ft_chain)
74         {
75                 rc = snprintf(page, count, "%s\n",
76                               fld_target_name(target));
77                 page += rc;
78                 count -= rc;
79                 total += rc;
80                 if (count == 0)
81                         break;
82         }
83         cfs_spin_unlock(&fld->lcf_lock);
84         RETURN(total);
85 }
86
87 static int
88 fld_proc_read_hash(char *page, char **start, off_t off,
89                    int count, int *eof, void *data)
90 {
91         struct lu_client_fld *fld = (struct lu_client_fld *)data;
92         int rc;
93         ENTRY;
94
95         LASSERT(fld != NULL);
96
97         cfs_spin_lock(&fld->lcf_lock);
98         rc = snprintf(page, count, "%s\n",
99                       fld->lcf_hash->fh_name);
100         cfs_spin_unlock(&fld->lcf_lock);
101
102         RETURN(rc);
103 }
104
105 static int
106 fld_proc_write_hash(struct file *file, const char *buffer,
107                     unsigned long count, void *data)
108 {
109         struct lu_client_fld *fld = (struct lu_client_fld *)data;
110         struct lu_fld_hash *hash = NULL;
111         int i;
112         ENTRY;
113
114         LASSERT(fld != NULL);
115
116         for (i = 0; fld_hash[i].fh_name != NULL; i++) {
117                 if (count != strlen(fld_hash[i].fh_name))
118                         continue;
119
120                 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
121                         hash = &fld_hash[i];
122                         break;
123                 }
124         }
125
126         if (hash != NULL) {
127                 cfs_spin_lock(&fld->lcf_lock);
128                 fld->lcf_hash = hash;
129                 cfs_spin_unlock(&fld->lcf_lock);
130
131                 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
132                        fld->lcf_name, hash->fh_name);
133         }
134         
135         RETURN(count);
136 }
137
138 static int
139 fld_proc_write_cache_flush(struct file *file, const char *buffer,
140                            unsigned long count, void *data)
141 {
142         struct lu_client_fld *fld = (struct lu_client_fld *)data;
143         ENTRY;
144
145         LASSERT(fld != NULL);
146
147         fld_cache_flush(fld->lcf_cache);
148
149         CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
150         
151         RETURN(count);
152 }
153
154 struct lprocfs_vars fld_server_proc_list[] = {
155         { NULL }};
156
157 struct lprocfs_vars fld_client_proc_list[] = {
158         { "targets",     fld_proc_read_targets, NULL, NULL },
159         { "hash",        fld_proc_read_hash, fld_proc_write_hash, NULL },
160         { "cache_flush", NULL, fld_proc_write_cache_flush, NULL },
161         { NULL }};
162 #endif