Whamcloud - gitweb
LU-4748 test: get one single qos_threshold_rr number
[fs/lustre-release.git] / lustre / fid / lproc_fid.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  * Copyright (c) 2011, 2013, 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 <libcfs/libcfs.h>
46 #include <linux/module.h>
47 #include <obd.h>
48 #include <obd_class.h>
49 #include <obd_support.h>
50 #include <lustre_fid.h>
51 #include <lprocfs_status.h>
52 #include "fid_internal.h"
53 #include <md_object.h>
54
55 #ifdef LPROCFS
56 /**
57  * Reduce the SEQ range allocated to a node to a strict subset of the range
58  * currently-allocated SEQ range.  If the specified range is "clear", then
59  * drop all allocated sequences and request a new one from the master.
60  *
61  * Note: this function should only be used for testing, it is not necessarily
62  * safe for production use.
63  */
64 static int
65 lprocfs_fid_write_common(const char *buffer, unsigned long count,
66                                 struct lu_seq_range *range)
67 {
68         struct lu_seq_range tmp = { 0, };
69         int rc;
70         ENTRY;
71
72         LASSERT(range != NULL);
73
74         if (count == 5 && strcmp(buffer, "clear") == 0) {
75                 memset(range, 0, sizeof(*range));
76                 RETURN(0);
77         }
78
79         /* of the form "[0x0000000240000400 - 0x000000028000400]" */
80         rc = sscanf(buffer, "[%llx - %llx]\n",
81                     (long long unsigned *)&tmp.lsr_start,
82                     (long long unsigned *)&tmp.lsr_end);
83         if (!range_is_sane(&tmp) || range_is_zero(&tmp) ||
84             tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
85                 RETURN(-EINVAL);
86         *range = tmp;
87         RETURN(0);
88 }
89
90 #ifdef HAVE_SERVER_SUPPORT
91 /*
92  * Server side procfs stuff.
93  */
94 static ssize_t
95 lprocfs_server_fid_space_seq_write(struct file *file, const char *buffer,
96                                         size_t count, loff_t *off)
97 {
98         struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
99         int rc;
100         ENTRY;
101
102         LASSERT(seq != NULL);
103
104         mutex_lock(&seq->lss_mutex);
105         rc = lprocfs_fid_write_common(buffer, count, &seq->lss_space);
106         if (rc == 0) {
107                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
108                         seq->lss_name, PRANGE(&seq->lss_space));
109         }
110         mutex_unlock(&seq->lss_mutex);
111
112         RETURN(count);
113 }
114
115 static int
116 lprocfs_server_fid_space_seq_show(struct seq_file *m, void *unused)
117 {
118         struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
119         int rc;
120         ENTRY;
121
122         LASSERT(seq != NULL);
123
124         mutex_lock(&seq->lss_mutex);
125         rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n",
126                         PRANGE(&seq->lss_space));
127         mutex_unlock(&seq->lss_mutex);
128
129         RETURN(rc);
130 }
131
132 static int
133 lprocfs_server_fid_server_seq_show(struct seq_file *m, void *unused)
134 {
135         struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
136         struct client_obd *cli;
137         int rc;
138         ENTRY;
139
140         LASSERT(seq != NULL);
141
142         if (seq->lss_cli) {
143                 if (seq->lss_cli->lcs_exp != NULL) {
144                         cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
145                         rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
146                 } else {
147                         rc = seq_printf(m, "%s\n",
148                                         seq->lss_cli->lcs_srv->lss_name);
149                 }
150         } else {
151                 rc = seq_printf(m, "<none>\n");
152         }
153
154         RETURN(rc);
155 }
156
157 static ssize_t
158 lprocfs_server_fid_width_seq_write(struct file *file, const char *buffer,
159                                         size_t count, loff_t *off)
160 {
161         struct lu_server_seq *seq = ((struct seq_file *)file->private_data)->private;
162         int rc, val;
163         ENTRY;
164
165         LASSERT(seq != NULL);
166
167         mutex_lock(&seq->lss_mutex);
168
169         rc = lprocfs_write_helper(buffer, count, &val);
170         if (rc != 0) {
171                 CERROR("%s: invalid width.\n", seq->lss_name);
172                 GOTO(out_unlock, count = rc);
173         }
174
175         seq->lss_width = val;
176
177         CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
178                seq->lss_name, seq->lss_width);
179 out_unlock:
180         mutex_unlock(&seq->lss_mutex);
181
182         RETURN(count);
183 }
184
185 static int
186 lprocfs_server_fid_width_seq_show(struct seq_file *m, void *unused)
187 {
188         struct lu_server_seq *seq = (struct lu_server_seq *)m->private;
189         int rc;
190         ENTRY;
191
192         LASSERT(seq != NULL);
193
194         mutex_lock(&seq->lss_mutex);
195         rc = seq_printf(m, LPU64"\n", seq->lss_width);
196         mutex_unlock(&seq->lss_mutex);
197
198         RETURN(rc);
199 }
200
201 LPROC_SEQ_FOPS(lprocfs_server_fid_space);
202 LPROC_SEQ_FOPS(lprocfs_server_fid_width);
203 LPROC_SEQ_FOPS_RO(lprocfs_server_fid_server);
204
205 struct lprocfs_seq_vars seq_server_proc_list[] = {
206         { .name =       "space",
207           .fops =       &lprocfs_server_fid_space_fops  },
208         { .name =       "width",
209           .fops =       &lprocfs_server_fid_width_fops  },
210         { .name =       "server",
211           .fops =       &lprocfs_server_fid_server_fops },
212         { NULL }
213 };
214
215 struct fld_seq_param {
216         struct lu_env           fsp_env;
217         struct dt_it            *fsp_it;
218         struct lu_server_fld    *fsp_fld;
219         struct lu_server_seq    *fsp_seq;
220         unsigned int            fsp_stop:1;
221 };
222
223 /*
224  * XXX: below is a copy of the functions in lustre/fld/lproc_fld.c.
225  * we want to avoid this duplication either by exporting the
226  * functions or merging fid and fld into a single module.
227  */
228 static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
229 {
230         struct fld_seq_param    *param = p->private;
231         struct lu_server_fld    *fld;
232         struct dt_object        *obj;
233         const struct dt_it_ops  *iops;
234         struct dt_key           *key;
235         int                     rc;
236
237         if (param == NULL || param->fsp_stop)
238                 return NULL;
239
240         fld = param->fsp_fld;
241         obj = fld->lsf_obj;
242         LASSERT(obj != NULL);
243         iops = &obj->do_index_ops->dio_it;
244
245         rc = iops->load(&param->fsp_env, param->fsp_it, *pos);
246         if (rc <= 0)
247                 return NULL;
248
249         key = iops->key(&param->fsp_env, param->fsp_it);
250         if (IS_ERR(key))
251                 return NULL;
252
253         *pos = be64_to_cpu(*(__u64 *)key);
254
255         return param;
256 }
257
258 static void fldb_seq_stop(struct seq_file *p, void *v)
259 {
260         struct fld_seq_param    *param = p->private;
261         const struct dt_it_ops  *iops;
262         struct lu_server_fld    *fld;
263         struct dt_object        *obj;
264
265         if (param == NULL)
266                 return;
267
268         fld = param->fsp_fld;
269         obj = fld->lsf_obj;
270         LASSERT(obj != NULL);
271         iops = &obj->do_index_ops->dio_it;
272
273         iops->put(&param->fsp_env, param->fsp_it);
274 }
275
276 static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
277 {
278         struct fld_seq_param    *param = p->private;
279         struct lu_server_fld    *fld;
280         struct dt_object        *obj;
281         const struct dt_it_ops  *iops;
282         int                     rc;
283
284         if (param == NULL || param->fsp_stop)
285                 return NULL;
286
287         fld = param->fsp_fld;
288         obj = fld->lsf_obj;
289         LASSERT(obj != NULL);
290         iops = &obj->do_index_ops->dio_it;
291
292         rc = iops->next(&param->fsp_env, param->fsp_it);
293         if (rc > 0) {
294                 param->fsp_stop = 1;
295                 return NULL;
296         }
297
298         *pos = be64_to_cpu(*(__u64 *)iops->key(&param->fsp_env, param->fsp_it));
299         return param;
300 }
301
302 static int fldb_seq_show(struct seq_file *p, void *v)
303 {
304         struct fld_seq_param    *param = p->private;
305         struct lu_server_fld    *fld;
306         struct dt_object        *obj;
307         const struct dt_it_ops  *iops;
308         struct lu_seq_range      fld_rec;
309         int                     rc;
310
311         if (param == NULL || param->fsp_stop)
312                 return 0;
313
314         fld = param->fsp_fld;
315         obj = fld->lsf_obj;
316         LASSERT(obj != NULL);
317         iops = &obj->do_index_ops->dio_it;
318
319         rc = iops->rec(&param->fsp_env, param->fsp_it,
320                        (struct dt_rec *)&fld_rec, 0);
321         if (rc != 0) {
322                 CERROR("%s: read record error: rc = %d\n",
323                        fld->lsf_name, rc);
324         } else if (fld_rec.lsr_start != 0) {
325                 range_be_to_cpu(&fld_rec, &fld_rec);
326                 rc = seq_printf(p, DRANGE"\n", PRANGE(&fld_rec));
327         }
328
329         return rc;
330 }
331
332 struct seq_operations fldb_sops = {
333         .start = fldb_seq_start,
334         .stop = fldb_seq_stop,
335         .next = fldb_seq_next,
336         .show = fldb_seq_show,
337 };
338
339 static int fldb_seq_open(struct inode *inode, struct file *file)
340 {
341         struct seq_file         *seq;
342         struct lu_server_seq    *ss = (struct lu_server_seq *) PDE_DATA(inode);
343         struct lu_server_fld    *fld;
344         struct dt_object        *obj;
345         const struct dt_it_ops  *iops;
346         struct fld_seq_param    *param = NULL;
347         int                     env_init = 0;
348         int                     rc;
349
350         fld = ss->lss_site->ss_server_fld;
351         LASSERT(fld != NULL);
352
353         LPROCFS_ENTRY_CHECK(PDE(inode));
354         rc = seq_open(file, &fldb_sops);
355         if (rc)
356                 return rc;
357
358         obj = fld->lsf_obj;
359         if (obj == NULL) {
360                 seq = file->private_data;
361                 seq->private = NULL;
362                 return 0;
363         }
364
365         OBD_ALLOC_PTR(param);
366         if (param == NULL)
367                 GOTO(out, rc = -ENOMEM);
368
369         rc = lu_env_init(&param->fsp_env, LCT_MD_THREAD);
370         if (rc != 0)
371                 GOTO(out, rc);
372
373         env_init = 1;
374         iops = &obj->do_index_ops->dio_it;
375         param->fsp_it = iops->init(&param->fsp_env, obj, 0, NULL);
376         if (IS_ERR(param->fsp_it))
377                 GOTO(out, rc = PTR_ERR(param->fsp_it));
378
379         param->fsp_fld = fld;
380         param->fsp_seq = ss;
381         param->fsp_stop = 0;
382
383         seq = file->private_data;
384         seq->private = param;
385 out:
386         if (rc != 0) {
387                 if (env_init == 1)
388                         lu_env_fini(&param->fsp_env);
389                 if (param != NULL)
390                         OBD_FREE_PTR(param);
391         }
392         return rc;
393 }
394
395 static int fldb_seq_release(struct inode *inode, struct file *file)
396 {
397         struct seq_file         *seq = file->private_data;
398         struct fld_seq_param    *param;
399         struct lu_server_fld    *fld;
400         struct dt_object        *obj;
401         const struct dt_it_ops  *iops;
402
403         param = seq->private;
404         if (param == NULL) {
405                 lprocfs_seq_release(inode, file);
406                 return 0;
407         }
408
409         fld = param->fsp_fld;
410         obj = fld->lsf_obj;
411         LASSERT(obj != NULL);
412         iops = &obj->do_index_ops->dio_it;
413
414         LASSERT(iops != NULL);
415         LASSERT(param->fsp_it != NULL);
416         iops->fini(&param->fsp_env, param->fsp_it);
417         lu_env_fini(&param->fsp_env);
418         OBD_FREE_PTR(param);
419         lprocfs_seq_release(inode, file);
420
421         return 0;
422 }
423
424 static ssize_t fldb_seq_write(struct file *file, const char *buf,
425                               size_t len, loff_t *off)
426 {
427         struct seq_file         *seq = file->private_data;
428         struct fld_seq_param    *param;
429         struct lu_seq_range      range;
430         int                      rc = 0;
431         char                    *buffer, *_buffer;
432         ENTRY;
433
434         param = seq->private;
435         if (param == NULL)
436                 RETURN(-EINVAL);
437
438         OBD_ALLOC(buffer, len + 1);
439         if (buffer == NULL)
440                 RETURN(-ENOMEM);
441         memcpy(buffer, buf, len);
442         buffer[len] = 0;
443         _buffer = buffer;
444
445         /*
446          * format - [0x0000000200000007-0x0000000200000008):0:mdt
447          */
448         if (*buffer != '[')
449                 GOTO(out, rc = -EINVAL);
450         buffer++;
451
452         range.lsr_start = simple_strtoull(buffer, &buffer, 0);
453         if (*buffer != '-')
454                 GOTO(out, rc = -EINVAL);
455         buffer++;
456
457         range.lsr_end = simple_strtoull(buffer, &buffer, 0);
458         if (*buffer != ')')
459                 GOTO(out, rc = -EINVAL);
460         buffer++;
461         if (*buffer != ':')
462                 GOTO(out, rc = -EINVAL);
463         buffer++;
464
465         range.lsr_index = simple_strtoul(buffer, &buffer, 0);
466         if (*buffer != ':')
467                 GOTO(out, rc = -EINVAL);
468         buffer++;
469
470         if (strncmp(buffer, "mdt", 3) == 0)
471                 range.lsr_flags = LU_SEQ_RANGE_MDT;
472         else if (strncmp(buffer, "ost", 3) == 0)
473                 range.lsr_flags = LU_SEQ_RANGE_OST;
474         else
475                 GOTO(out, rc = -EINVAL);
476
477         rc = seq_server_alloc_spec(param->fsp_seq->lss_site->ss_control_seq,
478                                    &range, &param->fsp_env);
479
480 out:
481         OBD_FREE(_buffer, len + 1);
482         RETURN(rc < 0 ? rc : len);
483 }
484
485 const struct file_operations seq_fld_proc_seq_fops = {
486         .owner   = THIS_MODULE,
487         .open    = fldb_seq_open,
488         .read    = seq_read,
489         .write   = fldb_seq_write,
490         .release = fldb_seq_release,
491 };
492
493 #endif /* HAVE_SERVER_SUPPORT */
494
495 /* Client side procfs stuff */
496 static ssize_t
497 lprocfs_client_fid_space_seq_write(struct file *file, const char *buffer,
498                                    size_t count, loff_t *off)
499 {
500         struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
501         int rc;
502         ENTRY;
503
504         LASSERT(seq != NULL);
505
506         mutex_lock(&seq->lcs_mutex);
507         rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);
508         if (rc == 0) {
509                 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
510                        seq->lcs_name, PRANGE(&seq->lcs_space));
511         }
512
513         mutex_unlock(&seq->lcs_mutex);
514
515         RETURN(count);
516 }
517
518 static int
519 lprocfs_client_fid_space_seq_show(struct seq_file *m, void *unused)
520 {
521         struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
522         int rc;
523         ENTRY;
524
525         LASSERT(seq != NULL);
526
527         mutex_lock(&seq->lcs_mutex);
528         rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n",
529                         PRANGE(&seq->lcs_space));
530         mutex_unlock(&seq->lcs_mutex);
531
532         RETURN(rc);
533 }
534
535 static ssize_t
536 lprocfs_client_fid_width_seq_write(struct file *file, const char *buffer,
537                                    size_t count, loff_t *off)
538 {
539         struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
540         __u64  max;
541         int rc, val;
542         ENTRY;
543
544         LASSERT(seq != NULL);
545
546         mutex_lock(&seq->lcs_mutex);
547
548         rc = lprocfs_write_helper(buffer, count, &val);
549         if (rc) {
550                 mutex_unlock(&seq->lcs_mutex);
551                 RETURN(rc);
552         }
553
554         if (seq->lcs_type == LUSTRE_SEQ_DATA)
555                 max = LUSTRE_DATA_SEQ_MAX_WIDTH;
556         else
557                 max = LUSTRE_METADATA_SEQ_MAX_WIDTH;
558
559         if (val <= max && val > 0) {
560                 seq->lcs_width = val;
561
562                 if (rc == 0) {
563                         CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n",
564                                seq->lcs_name, seq->lcs_width);
565                 }
566         }
567         mutex_unlock(&seq->lcs_mutex);
568
569         RETURN(count);
570 }
571
572 static int
573 lprocfs_client_fid_width_seq_show(struct seq_file *m, void *unused)
574 {
575         struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
576         int rc;
577         ENTRY;
578
579         LASSERT(seq != NULL);
580
581         mutex_lock(&seq->lcs_mutex);
582         rc = seq_printf(m, LPU64"\n", seq->lcs_width);
583         mutex_unlock(&seq->lcs_mutex);
584
585         RETURN(rc);
586 }
587
588 static int
589 lprocfs_client_fid_fid_seq_show(struct seq_file *m, void *unused)
590 {
591         struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
592         int rc;
593         ENTRY;
594
595         LASSERT(seq != NULL);
596
597         mutex_lock(&seq->lcs_mutex);
598         rc = seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
599         mutex_unlock(&seq->lcs_mutex);
600
601         RETURN(rc);
602 }
603
604 static int
605 lprocfs_client_fid_server_seq_show(struct seq_file *m, void *unused)
606 {
607         struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
608         struct client_obd *cli;
609         int rc;
610         ENTRY;
611
612         LASSERT(seq != NULL);
613
614         if (seq->lcs_exp != NULL) {
615                 cli = &seq->lcs_exp->exp_obd->u.cli;
616                 rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
617         } else {
618                 rc = seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
619         }
620         RETURN(rc);
621 }
622
623 LPROC_SEQ_FOPS(lprocfs_client_fid_space);
624 LPROC_SEQ_FOPS(lprocfs_client_fid_width);
625 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_server);
626 LPROC_SEQ_FOPS_RO(lprocfs_client_fid_fid);
627
628 struct lprocfs_seq_vars seq_client_proc_list[] = {
629         { .name =       "space",
630           .fops =       &lprocfs_client_fid_space_fops  },
631         { .name =       "width",
632           .fops =       &lprocfs_client_fid_width_fops  },
633         { .name =       "server",
634           .fops =       &lprocfs_client_fid_server_fops },
635         { .name =       "fid",
636           .fops =       &lprocfs_client_fid_fid_fops    },
637         { NULL }
638 };
639 #endif