Whamcloud - gitweb
LU-14475 log: Rewrite some log messages
[fs/lustre-release.git] / lustre / mgc / lproc_mgc.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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31 #define DEBUG_SUBSYSTEM S_CLASS
32
33 #include <linux/version.h>
34 #include <linux/vfs.h>
35 #include <obd_class.h>
36 #include <lprocfs_status.h>
37 #include "mgc_internal.h"
38
39 #ifdef CONFIG_PROC_FS
40
41 LDEBUGFS_SEQ_FOPS_RO_TYPE(mgc, connect_flags);
42
43 LDEBUGFS_SEQ_FOPS_RO_TYPE(mgc, server_uuid);
44
45 LDEBUGFS_SEQ_FOPS_RO_TYPE(mgc, import);
46
47 LDEBUGFS_SEQ_FOPS_RO_TYPE(mgc, state);
48
49 static int mgc_ir_state_seq_show(struct seq_file *m, void *v)
50 {
51         return lprocfs_mgc_rd_ir_state(m, m->private);
52 }
53
54 LDEBUGFS_SEQ_FOPS_RO(mgc_ir_state);
55
56 struct ldebugfs_vars ldebugfs_mgc_obd_vars[] = {
57         { .name =       "connect_flags",
58           .fops =       &mgc_connect_flags_fops },
59         { .name =       "mgs_server_uuid",
60           .fops =       &mgc_server_uuid_fops   },
61         { .name =       "import",
62           .fops =       &mgc_import_fops        },
63         { .name =       "state",
64           .fops =       &mgc_state_fops         },
65         { .name =       "ir_state",
66           .fops =       &mgc_ir_state_fops      },
67         { NULL }
68 };
69 #endif /* CONFIG_PROC_FS */
70
71 LUSTRE_ATTR(mgs_conn_uuid, 0444, conn_uuid_show, NULL);
72 LUSTRE_RO_ATTR(conn_uuid);
73
74 LUSTRE_RW_ATTR(ping);
75
76 ssize_t dynamic_nids_show(struct kobject *kobj, struct attribute *attr,
77                           char *buf)
78 {
79         struct obd_device *obd = container_of(kobj, struct obd_device,
80                                               obd_kset.kobj);
81         ssize_t count;
82
83         ENTRY;
84         count = snprintf(buf, PAGE_SIZE, "%u\n", obd->obd_dynamic_nids);
85
86         RETURN(count);
87 }
88
89 ssize_t dynamic_nids_store(struct kobject *kobj, struct attribute *attr,
90                            const char *buffer, size_t count)
91 {
92         struct obd_device *obd = container_of(kobj, struct obd_device,
93                                               obd_kset.kobj);
94         bool val;
95         int rc;
96
97         ENTRY;
98         rc = kstrtobool(buffer, &val);
99         if (rc)
100                 return rc;
101
102         spin_lock(&obd->obd_dev_lock);
103         obd->obd_dynamic_nids = val;
104         spin_unlock(&obd->obd_dev_lock);
105
106         RETURN(count);
107 }
108
109 LUSTRE_RW_ATTR(dynamic_nids);
110
111 static struct attribute *mgc_attrs[] = {
112         &lustre_attr_mgs_conn_uuid.attr,
113         &lustre_attr_conn_uuid.attr,
114         &lustre_attr_ping.attr,
115         &lustre_attr_dynamic_nids.attr,
116         NULL,
117 };
118
119 int mgc_tunables_init(struct obd_device *obd)
120 {
121         int rc;
122
123         obd->obd_ktype.default_attrs = mgc_attrs;
124         obd->obd_debugfs_vars = ldebugfs_mgc_obd_vars;
125         rc = lprocfs_obd_setup(obd, true);
126         if (rc)
127                 return rc;
128
129         return sptlrpc_lprocfs_cliobd_attach(obd);
130 }