Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / fld / lproc_fld.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/fld/lproc_fld.c
5  *  FLD (FIDs Location Database)
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Yury Umanets <umka@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
13  *   You may have signed or agreed to another license before downloading
14  *   this software.  If so, you are bound by the terms and conditions
15  *   of that agreement, and the following does not apply to you.  See the
16  *   LICENSE file included with this distribution for more information.
17  *
18  *   If you did not agree to a different license, then this copy of Lustre
19  *   is open source software; you can redistribute it and/or modify it
20  *   under the terms of version 2 of the GNU General Public License as
21  *   published by the Free Software Foundation.
22  *
23  *   In either case, Lustre is distributed in the hope that it will be
24  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *   license text for more details.
27  */
28
29 #ifndef EXPORT_SYMTAB
30 # define EXPORT_SYMTAB
31 #endif
32 #define DEBUG_SUBSYSTEM S_FLD
33
34 #ifdef __KERNEL__
35 # include <libcfs/libcfs.h>
36 # include <linux/module.h>
37 #else /* __KERNEL__ */
38 # include <liblustre.h>
39 #endif
40
41 #include <obd.h>
42 #include <obd_class.h>
43 #include <dt_object.h>
44 #include <md_object.h>
45 #include <obd_support.h>
46 #include <lustre_req_layout.h>
47 #include <lustre_fld.h>
48 #include "fld_internal.h"
49
50 #ifdef LPROCFS
51 static int
52 fld_proc_read_targets(char *page, char **start, off_t off,
53                       int count, int *eof, void *data)
54 {
55         struct lu_client_fld *fld = (struct lu_client_fld *)data;
56         struct lu_fld_target *target;
57         int total = 0, rc;
58         ENTRY;
59
60         LASSERT(fld != NULL);
61
62         spin_lock(&fld->lcf_lock);
63         list_for_each_entry(target,
64                             &fld->lcf_targets, ft_chain)
65         {
66                 rc = snprintf(page, count, "%s\n",
67                               fld_target_name(target));
68                 page += rc;
69                 count -= rc;
70                 total += rc;
71                 if (count == 0)
72                         break;
73         }
74         spin_unlock(&fld->lcf_lock);
75         RETURN(total);
76 }
77
78 static int
79 fld_proc_read_hash(char *page, char **start, off_t off,
80                    int count, int *eof, void *data)
81 {
82         struct lu_client_fld *fld = (struct lu_client_fld *)data;
83         int rc;
84         ENTRY;
85
86         LASSERT(fld != NULL);
87
88         spin_lock(&fld->lcf_lock);
89         rc = snprintf(page, count, "%s\n",
90                       fld->lcf_hash->fh_name);
91         spin_unlock(&fld->lcf_lock);
92
93         RETURN(rc);
94 }
95
96 static int
97 fld_proc_write_hash(struct file *file, const char *buffer,
98                     unsigned long count, void *data)
99 {
100         struct lu_client_fld *fld = (struct lu_client_fld *)data;
101         struct lu_fld_hash *hash = NULL;
102         int i;
103         ENTRY;
104
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
111                 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
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         
126         RETURN(count);
127 }
128
129 static int
130 fld_proc_write_cache_flush(struct file *file, const char *buffer,
131                            unsigned long count, void *data)
132 {
133         struct lu_client_fld *fld = (struct lu_client_fld *)data;
134         ENTRY;
135
136         LASSERT(fld != NULL);
137
138         fld_cache_flush(fld->lcf_cache);
139
140         CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
141         
142         RETURN(count);
143 }
144
145 struct lprocfs_vars fld_server_proc_list[] = {
146         { NULL }};
147
148 struct lprocfs_vars fld_client_proc_list[] = {
149         { "targets",     fld_proc_read_targets, NULL, NULL },
150         { "hash",        fld_proc_read_hash, fld_proc_write_hash, NULL },
151         { "cache_flush", NULL, fld_proc_write_cache_flush, NULL },
152         { NULL }};
153 #endif