Whamcloud - gitweb
consity mdo_attr_set() argument
[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 fld_target *target;
57         int total = 0, rc;
58         ENTRY;
59
60         LASSERT(fld != NULL);
61
62         spin_lock(&fld->fld_lock);
63         list_for_each_entry(target,
64                             &fld->fld_targets, fldt_chain)
65         {
66                 struct client_obd *cli = &target->fldt_exp->exp_obd->u.cli;
67                 
68                 rc = snprintf(page, count, "%s\n",
69                               cli->cl_target_uuid.uuid);
70                 page += rc;
71                 count -= rc;
72                 total += rc;
73                 if (count == 0)
74                         break;
75         }
76         spin_unlock(&fld->fld_lock);
77         RETURN(total);
78 }
79
80 static int
81 fld_proc_read_hash(char *page, char **start, off_t off,
82                    int count, int *eof, void *data)
83 {
84         struct lu_client_fld *fld = (struct lu_client_fld *)data;
85         int rc;
86         ENTRY;
87
88         LASSERT(fld != NULL);
89
90         spin_lock(&fld->fld_lock);
91         rc = snprintf(page, count, "%s\n",
92                       fld->fld_hash->fh_name);
93         spin_unlock(&fld->fld_lock);
94
95         RETURN(rc);
96 }
97
98 static int
99 fld_proc_write_hash(struct file *file, const char *buffer,
100                     unsigned long count, void *data)
101 {
102         struct lu_client_fld *fld = (struct lu_client_fld *)data;
103         struct lu_fld_hash *hash = NULL;
104         int i;
105         ENTRY;
106
107         LASSERT(fld != NULL);
108
109         for (i = 0; fld_hash[i].fh_name != NULL; i++) {
110                 if (count != strlen(fld_hash[i].fh_name))
111                         continue;
112                         
113                 if (!strncmp(fld_hash[i].fh_name, buffer, count)) {
114                         hash = &fld_hash[i];
115                         break;
116                 }
117         }
118
119         if (hash != NULL) {
120                 spin_lock(&fld->fld_lock);
121                 fld->fld_hash = hash;
122                 spin_unlock(&fld->fld_lock);
123
124                 CDEBUG(D_WARNING, "FLD(cli): changed hash to \"%s\"\n",
125                        hash->fh_name);
126         }
127         
128         RETURN(count);
129 }
130
131 struct lprocfs_vars fld_server_proc_list[] = {
132         { NULL }};
133
134 struct lprocfs_vars fld_client_proc_list[] = {
135         { "targets", fld_proc_read_targets, NULL, NULL },
136         { "hash",    fld_proc_read_hash, fld_proc_write_hash, NULL },
137         { NULL }};
138 #endif