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 "../../include/linux/libcfs/libcfs.h"
46 #include <linux/module.h>
47
48 #include "../include/obd.h"
49 #include "../include/obd_class.h"
50 #include "../include/dt_object.h"
51 #include "../include/obd_support.h"
52 #include "../include/lustre_req_layout.h"
53 #include "../include/lustre_fid.h"
54 #include "fid_internal.h"
55
56 /* Format: [0x64BIT_INT - 0x64BIT_INT] + 32 bytes just in case */
57 #define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64))
58 /*
59 * Note: this function is only used for testing, it is no safe for production
60 * use.
61 */
lprocfs_fid_write_common(const char __user * buffer,size_t count,struct lu_seq_range * range)62 static int lprocfs_fid_write_common(const char __user *buffer, size_t count,
63 struct lu_seq_range *range)
64 {
65 struct lu_seq_range tmp;
66 int rc;
67 char kernbuf[MAX_FID_RANGE_STRLEN];
68
69 LASSERT(range != NULL);
70
71 if (count >= sizeof(kernbuf))
72 return -EINVAL;
73
74 if (copy_from_user(kernbuf, buffer, count))
75 return -EFAULT;
76
77 kernbuf[count] = 0;
78
79 if (count == 5 && strcmp(kernbuf, "clear") == 0) {
80 memset(range, 0, sizeof(*range));
81 return count;
82 }
83
84 /* of the form "[0x0000000240000400 - 0x000000028000400]" */
85 rc = sscanf(kernbuf, "[%llx - %llx]\n",
86 (unsigned long long *)&tmp.lsr_start,
87 (unsigned long long *)&tmp.lsr_end);
88 if (!range_is_sane(&tmp) || range_is_zero(&tmp) ||
89 tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
90 return -EINVAL;
91 *range = tmp;
92 return count;
93 }
94
95 /* Client side procfs stuff */
lprocfs_fid_space_seq_write(struct file * file,const char __user * buffer,size_t count,loff_t * off)96 static ssize_t lprocfs_fid_space_seq_write(struct file *file,
97 const char __user *buffer,
98 size_t count, loff_t *off)
99 {
100 struct lu_client_seq *seq;
101 int rc;
102
103 seq = ((struct seq_file *)file->private_data)->private;
104 LASSERT(seq != NULL);
105
106 mutex_lock(&seq->lcs_mutex);
107 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
108
109 if (rc == 0) {
110 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
111 seq->lcs_name, PRANGE(&seq->lcs_space));
112 }
113
114 mutex_unlock(&seq->lcs_mutex);
115
116 return count;
117 }
118
119 static int
lprocfs_fid_space_seq_show(struct seq_file * m,void * unused)120 lprocfs_fid_space_seq_show(struct seq_file *m, void *unused)
121 {
122 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
123
124 LASSERT(seq != NULL);
125
126 mutex_lock(&seq->lcs_mutex);
127 seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space));
128 mutex_unlock(&seq->lcs_mutex);
129
130 return 0;
131 }
132
lprocfs_fid_width_seq_write(struct file * file,const char __user * buffer,size_t count,loff_t * off)133 static ssize_t lprocfs_fid_width_seq_write(struct file *file,
134 const char __user *buffer,
135 size_t count, loff_t *off)
136 {
137 struct lu_client_seq *seq;
138 __u64 max;
139 int rc, val;
140
141 seq = ((struct seq_file *)file->private_data)->private;
142 LASSERT(seq != NULL);
143
144 rc = lprocfs_write_helper(buffer, count, &val);
145 if (rc)
146 return rc;
147
148 mutex_lock(&seq->lcs_mutex);
149 if (seq->lcs_type == LUSTRE_SEQ_DATA)
150 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
151 else
152 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
153
154 if (val <= max && val > 0) {
155 seq->lcs_width = val;
156
157 if (rc == 0) {
158 CDEBUG(D_INFO, "%s: Sequence size: %llu\n",
159 seq->lcs_name, seq->lcs_width);
160 }
161 }
162
163 mutex_unlock(&seq->lcs_mutex);
164
165 return count;
166 }
167
168 static int
lprocfs_fid_width_seq_show(struct seq_file * m,void * unused)169 lprocfs_fid_width_seq_show(struct seq_file *m, void *unused)
170 {
171 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
172
173 LASSERT(seq != NULL);
174
175 mutex_lock(&seq->lcs_mutex);
176 seq_printf(m, "%llu\n", seq->lcs_width);
177 mutex_unlock(&seq->lcs_mutex);
178
179 return 0;
180 }
181
182 static int
lprocfs_fid_fid_seq_show(struct seq_file * m,void * unused)183 lprocfs_fid_fid_seq_show(struct seq_file *m, void *unused)
184 {
185 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
186
187 LASSERT(seq != NULL);
188
189 mutex_lock(&seq->lcs_mutex);
190 seq_printf(m, DFID "\n", PFID(&seq->lcs_fid));
191 mutex_unlock(&seq->lcs_mutex);
192
193 return 0;
194 }
195
196 static int
lprocfs_fid_server_seq_show(struct seq_file * m,void * unused)197 lprocfs_fid_server_seq_show(struct seq_file *m, void *unused)
198 {
199 struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
200 struct client_obd *cli;
201
202 LASSERT(seq != NULL);
203
204 if (seq->lcs_exp != NULL) {
205 cli = &seq->lcs_exp->exp_obd->u.cli;
206 seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
207 } else {
208 seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
209 }
210
211 return 0;
212 }
213
214 LPROC_SEQ_FOPS(lprocfs_fid_space);
215 LPROC_SEQ_FOPS(lprocfs_fid_width);
216 LPROC_SEQ_FOPS_RO(lprocfs_fid_server);
217 LPROC_SEQ_FOPS_RO(lprocfs_fid_fid);
218
219 struct lprocfs_vars seq_client_proc_list[] = {
220 { "space", &lprocfs_fid_space_fops },
221 { "width", &lprocfs_fid_width_fops },
222 { "server", &lprocfs_fid_server_fops },
223 { "fid", &lprocfs_fid_fid_fops },
224 { NULL }
225 };
226