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