[go: nahoru, domu]

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