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 "../include/obd_class.h"
40 #include "../include/lprocfs_status.h"
41 #include "mdc_internal.h"
42 
max_rpcs_in_flight_show(struct kobject * kobj,struct attribute * attr,char * buf)43 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
44 				       struct attribute *attr,
45 				       char *buf)
46 {
47 	int len;
48 	struct obd_device *dev = container_of(kobj, struct obd_device,
49 					      obd_kobj);
50 	struct client_obd *cli = &dev->u.cli;
51 
52 	client_obd_list_lock(&cli->cl_loi_list_lock);
53 	len = sprintf(buf, "%u\n", cli->cl_max_rpcs_in_flight);
54 	client_obd_list_unlock(&cli->cl_loi_list_lock);
55 
56 	return len;
57 }
58 
max_rpcs_in_flight_store(struct kobject * kobj,struct attribute * attr,const char * buffer,size_t count)59 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
60 					struct attribute *attr,
61 					const char *buffer,
62 					size_t count)
63 {
64 	struct obd_device *dev = container_of(kobj, struct obd_device,
65 					      obd_kobj);
66 	struct client_obd *cli = &dev->u.cli;
67 	int rc;
68 	unsigned long val;
69 
70 	rc = kstrtoul(buffer, 10, &val);
71 	if (rc)
72 		return rc;
73 
74 	if (val < 1 || val > MDC_MAX_RIF_MAX)
75 		return -ERANGE;
76 
77 	client_obd_list_lock(&cli->cl_loi_list_lock);
78 	cli->cl_max_rpcs_in_flight = val;
79 	client_obd_list_unlock(&cli->cl_loi_list_lock);
80 
81 	return count;
82 }
83 LUSTRE_RW_ATTR(max_rpcs_in_flight);
84 
mdc_kuc_open(struct inode * inode,struct file * file)85 static int mdc_kuc_open(struct inode *inode, struct file *file)
86 {
87 	return single_open(file, NULL, inode->i_private);
88 }
89 
90 /* temporary for testing */
mdc_kuc_write(struct file * file,const char __user * buffer,size_t count,loff_t * off)91 static ssize_t mdc_kuc_write(struct file *file,
92 				const char __user *buffer,
93 				size_t count, loff_t *off)
94 {
95 	struct obd_device *obd =
96 			((struct seq_file *)file->private_data)->private;
97 	struct kuc_hdr		*lh;
98 	struct hsm_action_list	*hal;
99 	struct hsm_action_item	*hai;
100 	int			 len;
101 	int			 fd, rc;
102 
103 	rc = lprocfs_write_helper(buffer, count, &fd);
104 	if (rc)
105 		return rc;
106 
107 	if (fd < 0)
108 		return -ERANGE;
109 	CWARN("message to fd %d\n", fd);
110 
111 	len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
112 		/* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
113 
114 	lh = kzalloc(len, GFP_NOFS);
115 	if (!lh)
116 		return -ENOMEM;
117 
118 	lh->kuc_magic = KUC_MAGIC;
119 	lh->kuc_transport = KUC_TRANSPORT_HSM;
120 	lh->kuc_msgtype = HMT_ACTION_LIST;
121 	lh->kuc_msglen = len;
122 
123 	hal = (struct hsm_action_list *)(lh + 1);
124 	hal->hal_version = HAL_VERSION;
125 	hal->hal_archive_id = 1;
126 	hal->hal_flags = 0;
127 	obd_uuid2fsname(hal->hal_fsname, obd->obd_name, MTI_NAME_MAXLEN);
128 
129 	/* mock up an action list */
130 	hal->hal_count = 2;
131 	hai = hai_zero(hal);
132 	hai->hai_action = HSMA_ARCHIVE;
133 	hai->hai_fid.f_oid = 5;
134 	hai->hai_len = sizeof(*hai);
135 	hai = hai_next(hai);
136 	hai->hai_action = HSMA_RESTORE;
137 	hai->hai_fid.f_oid = 10;
138 	hai->hai_len = sizeof(*hai);
139 
140 	/* This works for either broadcast or unicast to a single fd */
141 	if (fd == 0) {
142 		rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
143 	} else {
144 		struct file *fp = fget(fd);
145 
146 		rc = libcfs_kkuc_msg_put(fp, lh);
147 		fput(fp);
148 	}
149 	kfree(lh);
150 	if (rc < 0)
151 		return rc;
152 	return count;
153 }
154 
155 static struct file_operations mdc_kuc_fops = {
156 	.open		= mdc_kuc_open,
157 	.write		= mdc_kuc_write,
158 	.release	= single_release,
159 };
160 
161 LPROC_SEQ_FOPS_WR_ONLY(mdc, ping);
162 
163 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
164 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
165 LPROC_SEQ_FOPS_RO_TYPE(mdc, conn_uuid);
166 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
167 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
168 
169 /*
170  * Note: below sysfs entry is provided, but not currently in use, instead
171  * sbi->sb_md_brw_size is used, the per obd variable should be used
172  * when DNE is enabled, and dir pages are managed in MDC layer.
173  * Don't forget to enable sysfs store function then.
174  */
max_pages_per_rpc_show(struct kobject * kobj,struct attribute * attr,char * buf)175 static ssize_t max_pages_per_rpc_show(struct kobject *kobj,
176 				      struct attribute *attr,
177 				      char *buf)
178 {
179 	struct obd_device *dev = container_of(kobj, struct obd_device,
180 					      obd_kobj);
181 	struct client_obd *cli = &dev->u.cli;
182 
183 	return sprintf(buf, "%d\n", cli->cl_max_pages_per_rpc);
184 }
185 LUSTRE_RO_ATTR(max_pages_per_rpc);
186 
187 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
188 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
189 
190 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
191 	{ "ping",		&mdc_ping_fops,			NULL, 0222 },
192 	{ "connect_flags",	&mdc_connect_flags_fops,	NULL, 0 },
193 	/*{ "filegroups",	lprocfs_rd_filegroups,		NULL, 0 },*/
194 	{ "mds_server_uuid",	&mdc_server_uuid_fops,		NULL, 0 },
195 	{ "mds_conn_uuid",	&mdc_conn_uuid_fops,		NULL, 0 },
196 	{ "timeouts",		&mdc_timeouts_fops,		NULL, 0 },
197 	{ "import",		&mdc_import_fops,		NULL, 0 },
198 	{ "state",		&mdc_state_fops,		NULL, 0 },
199 	{ "hsm_nl",		&mdc_kuc_fops,			NULL, 0200 },
200 	{ "pinger_recov",	&mdc_pinger_recov_fops,		NULL, 0 },
201 	{ NULL }
202 };
203 
204 static struct attribute *mdc_attrs[] = {
205 	&lustre_attr_max_rpcs_in_flight.attr,
206 	&lustre_attr_max_pages_per_rpc.attr,
207 	NULL,
208 };
209 
210 static struct attribute_group mdc_attr_group = {
211 	.attrs = mdc_attrs,
212 };
213 
lprocfs_mdc_init_vars(struct lprocfs_static_vars * lvars)214 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
215 {
216 	lvars->sysfs_vars   = &mdc_attr_group;
217 	lvars->obd_vars     = lprocfs_mdc_obd_vars;
218 }
219