staging: lustre: remove ENTRY macro
[firefly-linux-kernel-4.4.55.git] / drivers / staging / lustre / lustre / mdc / lproc_mdc.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) 2002, 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 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/vfs.h>
39 #include <obd_class.h>
40 #include <lprocfs_status.h>
41
42 #ifdef LPROCFS
43
44 static int mdc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
45 {
46         struct obd_device *dev = m->private;
47         struct client_obd *cli = &dev->u.cli;
48         int rc;
49
50         client_obd_list_lock(&cli->cl_loi_list_lock);
51         rc = seq_printf(m, "%u\n", cli->cl_max_rpcs_in_flight);
52         client_obd_list_unlock(&cli->cl_loi_list_lock);
53         return rc;
54 }
55
56 static ssize_t mdc_max_rpcs_in_flight_seq_write(struct file *file,
57                                                 const char *buffer,
58                                                 size_t count,
59                                                 loff_t *off)
60 {
61         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
62         struct client_obd *cli = &dev->u.cli;
63         int val, rc;
64
65         rc = lprocfs_write_helper(buffer, count, &val);
66         if (rc)
67                 return rc;
68
69         if (val < 1 || val > MDC_MAX_RIF_MAX)
70                 return -ERANGE;
71
72         client_obd_list_lock(&cli->cl_loi_list_lock);
73         cli->cl_max_rpcs_in_flight = val;
74         client_obd_list_unlock(&cli->cl_loi_list_lock);
75
76         return count;
77 }
78 LPROC_SEQ_FOPS(mdc_max_rpcs_in_flight);
79
80 static int mdc_kuc_open(struct inode *inode, struct file *file)
81 {
82         return single_open(file, NULL, PDE_DATA(inode));
83 }
84
85 /* temporary for testing */
86 static ssize_t mdc_kuc_write(struct file *file, const char *buffer,
87                              size_t count, loff_t *off)
88 {
89         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
90         struct kuc_hdr          *lh;
91         struct hsm_action_list  *hal;
92         struct hsm_action_item  *hai;
93         int                      len;
94         int                      fd, rc;
95
96         rc = lprocfs_write_helper(buffer, count, &fd);
97         if (rc)
98                 RETURN(rc);
99
100         if (fd < 0)
101                 RETURN(-ERANGE);
102         CWARN("message to fd %d\n", fd);
103
104         len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
105                 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
106
107         OBD_ALLOC(lh, len);
108
109         lh->kuc_magic = KUC_MAGIC;
110         lh->kuc_transport = KUC_TRANSPORT_HSM;
111         lh->kuc_msgtype = HMT_ACTION_LIST;
112         lh->kuc_msglen = len;
113
114         hal = (struct hsm_action_list *)(lh + 1);
115         hal->hal_version = HAL_VERSION;
116         hal->hal_archive_id = 1;
117         hal->hal_flags = 0;
118         obd_uuid2fsname(hal->hal_fsname, obd->obd_name, MTI_NAME_MAXLEN);
119
120         /* mock up an action list */
121         hal->hal_count = 2;
122         hai = hai_zero(hal);
123         hai->hai_action = HSMA_ARCHIVE;
124         hai->hai_fid.f_oid = 5;
125         hai->hai_len = sizeof(*hai);
126         hai = hai_next(hai);
127         hai->hai_action = HSMA_RESTORE;
128         hai->hai_fid.f_oid = 10;
129         hai->hai_len = sizeof(*hai);
130
131         /* This works for either broadcast or unicast to a single fd */
132         if (fd == 0) {
133                 rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
134         } else {
135                 struct file *fp = fget(fd);
136
137                 rc = libcfs_kkuc_msg_put(fp, lh);
138                 fput(fp);
139         }
140         OBD_FREE(lh, len);
141         if (rc < 0)
142                 RETURN(rc);
143         RETURN(count);
144 }
145
146 struct file_operations mdc_kuc_fops = {
147         .open           = mdc_kuc_open,
148         .write          = mdc_kuc_write,
149         .release        = single_release,
150 };
151
152 LPROC_SEQ_FOPS_WR_ONLY(mdc, ping);
153
154 LPROC_SEQ_FOPS_RO_TYPE(mdc, uuid);
155 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
156 LPROC_SEQ_FOPS_RO_TYPE(mdc, blksize);
157 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytestotal);
158 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytesfree);
159 LPROC_SEQ_FOPS_RO_TYPE(mdc, kbytesavail);
160 LPROC_SEQ_FOPS_RO_TYPE(mdc, filestotal);
161 LPROC_SEQ_FOPS_RO_TYPE(mdc, filesfree);
162 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
163 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
164 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
165 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
166
167 static int mdc_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
168 {
169         return lprocfs_obd_rd_max_pages_per_rpc(m, m->private);
170 }
171 LPROC_SEQ_FOPS_RO(mdc_obd_max_pages_per_rpc);
172
173 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
174 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
175
176 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
177         { "uuid",           &mdc_uuid_fops,             0, 0 },
178         { "ping",           &mdc_ping_fops,             0, 0222 },
179         { "connect_flags",  &mdc_connect_flags_fops,    0, 0 },
180         { "blocksize",      &mdc_blksize_fops,          0, 0 },
181         { "kbytestotal",    &mdc_kbytestotal_fops,      0, 0 },
182         { "kbytesfree",     &mdc_kbytesfree_fops,       0, 0 },
183         { "kbytesavail",    &mdc_kbytesavail_fops,      0, 0 },
184         { "filestotal",     &mdc_filestotal_fops,       0, 0 },
185         { "filesfree",      &mdc_filesfree_fops,        0, 0 },
186         /*{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },*/
187         { "mds_server_uuid", &mdc_server_uuid_fops,     0, 0 },
188         { "mds_conn_uuid",  &mdc_conn_uuid_fops,        0, 0 },
189         /*
190          * FIXME: below proc entry is provided, but not in used, instead
191          * sbi->sb_md_brw_size is used, the per obd variable should be used
192          * when CMD is enabled, and dir pages are managed in MDC layer.
193          * Remember to enable proc write function.
194          */
195         { "max_pages_per_rpc",  &mdc_obd_max_pages_per_rpc_fops, 0, 0 },
196         { "max_rpcs_in_flight", &mdc_max_rpcs_in_flight_fops, 0, 0 },
197         { "timeouts",           &mdc_timeouts_fops,    0, 0 },
198         { "import",             &mdc_import_fops, 0 },
199         { "state",              &mdc_state_fops, 0, 0 },
200         { "hsm_nl",             &mdc_kuc_fops, 0, 0200 },
201         { "pinger_recov",       &mdc_pinger_recov_fops, 0, 0 },
202         { 0 }
203 };
204
205 LPROC_SEQ_FOPS_RO_TYPE(mdc, numrefs);
206
207 static struct lprocfs_vars lprocfs_mdc_module_vars[] = {
208         { "num_refs",   &mdc_numrefs_fops,     0, 0 },
209         { 0 }
210 };
211
212 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
213 {
214     lvars->module_vars  = lprocfs_mdc_module_vars;
215     lvars->obd_vars     = lprocfs_mdc_obd_vars;
216 }
217 #endif /* LPROCFS */