Merge branch 'pm-cpuidle'
[linux-block.git] / drivers / staging / lustre / lustre / fid / lproc_fid.c
CommitLineData
d7e09d03
PT
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) 2011, 2012, 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/fid/lproc_fid.c
37 *
38 * Lustre Sequence Manager
39 *
40 * Author: Yury Umanets <umka@clusterfs.com>
41 */
42
43#define DEBUG_SUBSYSTEM S_FID
44
45# include <linux/libcfs/libcfs.h>
46# include <linux/module.h>
47
48#include <obd.h>
49#include <obd_class.h>
50#include <dt_object.h>
51#include <md_object.h>
52#include <obd_support.h>
53#include <lustre_req_layout.h>
54#include <lustre_fid.h>
55#include "fid_internal.h"
56
57#ifdef LPROCFS
58/*
59 * Note: this function is only used for testing, it is no safe for production
60 * use.
61 */
62static int
73bb1da6
PT
63lprocfs_fid_write_common(const char *buffer, unsigned long count,
64 struct lu_seq_range *range)
d7e09d03
PT
65{
66 struct lu_seq_range tmp;
67 int rc;
d7e09d03
PT
68
69 LASSERT(range != NULL);
70
71 rc = sscanf(buffer, "[%llx - %llx]\n",
72 (long long unsigned *)&tmp.lsr_start,
73 (long long unsigned *)&tmp.lsr_end);
74 if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
0a3bdb00 75 return -EINVAL;
d7e09d03 76 *range = tmp;
0a3bdb00 77 return 0;
d7e09d03
PT
78}
79
d7e09d03 80/* Client side procfs stuff */
73bb1da6
PT
81static ssize_t
82lprocfs_fid_space_seq_write(struct file *file, const char *buffer,
83 size_t count, loff_t *off)
d7e09d03 84{
73bb1da6 85 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
d7e09d03 86 int rc;
d7e09d03
PT
87
88 LASSERT(seq != NULL);
89
90 mutex_lock(&seq->lcs_mutex);
73bb1da6 91 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
d7e09d03
PT
92
93 if (rc == 0) {
94 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
95 seq->lcs_name, PRANGE(&seq->lcs_space));
96 }
97
98 mutex_unlock(&seq->lcs_mutex);
99
0a3bdb00 100 return count;
d7e09d03
PT
101}
102
103static int
73bb1da6 104lprocfs_fid_space_seq_show(struct seq_file *m, void *unused)
d7e09d03 105{
73bb1da6 106 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
d7e09d03 107 int rc;
d7e09d03
PT
108
109 LASSERT(seq != NULL);
110
111 mutex_lock(&seq->lcs_mutex);
73bb1da6 112 rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n", PRANGE(&seq->lcs_space));
d7e09d03
PT
113 mutex_unlock(&seq->lcs_mutex);
114
0a3bdb00 115 return rc;
d7e09d03
PT
116}
117
73bb1da6
PT
118static ssize_t
119lprocfs_fid_width_seq_write(struct file *file, const char *buffer,
120 size_t count, loff_t *off)
d7e09d03 121{
73bb1da6 122 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
d7e09d03
PT
123 __u64 max;
124 int rc, val;
d7e09d03
PT
125
126 LASSERT(seq != NULL);
127
d7e09d03 128 rc = lprocfs_write_helper(buffer, count, &val);
73bb1da6 129 if (rc)
0a3bdb00 130 return rc;
d7e09d03 131
73bb1da6 132 mutex_lock(&seq->lcs_mutex);
d7e09d03
PT
133 if (seq->lcs_type == LUSTRE_SEQ_DATA)
134 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
135 else
136 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
137
138 if (val <= max && val > 0) {
139 seq->lcs_width = val;
140
141 if (rc == 0) {
142 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
143 seq->lcs_name, seq->lcs_width);
144 }
145 }
146
147 mutex_unlock(&seq->lcs_mutex);
148
0a3bdb00 149 return count;
d7e09d03
PT
150}
151
152static int
73bb1da6 153lprocfs_fid_width_seq_show(struct seq_file *m, void *unused)
d7e09d03 154{
73bb1da6 155 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
d7e09d03 156 int rc;
d7e09d03
PT
157
158 LASSERT(seq != NULL);
159
160 mutex_lock(&seq->lcs_mutex);
73bb1da6 161 rc = seq_printf(m, LPU64"\n", seq->lcs_width);
d7e09d03
PT
162 mutex_unlock(&seq->lcs_mutex);
163
0a3bdb00 164 return rc;
d7e09d03
PT
165}
166
167static int
73bb1da6 168lprocfs_fid_fid_seq_show(struct seq_file *m, void *unused)
d7e09d03 169{
73bb1da6 170 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
d7e09d03 171 int rc;
d7e09d03
PT
172
173 LASSERT(seq != NULL);
174
175 mutex_lock(&seq->lcs_mutex);
73bb1da6 176 rc = seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
d7e09d03
PT
177 mutex_unlock(&seq->lcs_mutex);
178
0a3bdb00 179 return rc;
d7e09d03
PT
180}
181
182static int
73bb1da6 183lprocfs_fid_server_seq_show(struct seq_file *m, void *unused)
d7e09d03 184{
73bb1da6 185 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
d7e09d03
PT
186 struct client_obd *cli;
187 int rc;
d7e09d03
PT
188
189 LASSERT(seq != NULL);
190
191 if (seq->lcs_exp != NULL) {
192 cli = &seq->lcs_exp->exp_obd->u.cli;
73bb1da6 193 rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
d7e09d03 194 } else {
73bb1da6 195 rc = seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
d7e09d03 196 }
0a3bdb00 197 return rc;
d7e09d03
PT
198}
199
73bb1da6
PT
200LPROC_SEQ_FOPS(lprocfs_fid_space);
201LPROC_SEQ_FOPS(lprocfs_fid_width);
202LPROC_SEQ_FOPS_RO(lprocfs_fid_server);
203LPROC_SEQ_FOPS_RO(lprocfs_fid_fid);
d7e09d03
PT
204
205struct lprocfs_vars seq_client_proc_list[] = {
73bb1da6
PT
206 { "space", &lprocfs_fid_space_fops },
207 { "width", &lprocfs_fid_width_fops },
208 { "server", &lprocfs_fid_server_fops },
209 { "fid", &lprocfs_fid_fid_fops },
210 { NULL }
211};
d7e09d03 212#endif