1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <linux/version.h>
39 #include <linux/vfs.h>
40 #include <obd_class.h>
41 #include <lprocfs_status.h>
42 #include <lustre_log.h>
46 static int mdc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
47 int count, int *eof, void *data)
49 struct obd_device *dev = data;
50 struct client_obd *cli = &dev->u.cli;
53 client_obd_list_lock(&cli->cl_loi_list_lock);
54 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
55 client_obd_list_unlock(&cli->cl_loi_list_lock);
59 static int mdc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
60 unsigned long count, void *data)
62 struct obd_device *dev = data;
63 struct client_obd *cli = &dev->u.cli;
66 rc = lprocfs_write_helper(buffer, count, &val);
70 if (val < 1 || val > MDC_MAX_RIF_MAX)
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);
80 static int mdc_changelog_seq_release(struct inode *inode, struct file *file)
82 struct seq_file *seq = file->private_data;
83 struct changelog_seq_iter *csi = seq->private;
85 if (csi && csi->csi_llh)
86 llog_cat_put(csi->csi_llh);
87 if (csi && csi->csi_ctxt)
88 llog_ctxt_put(csi->csi_ctxt);
90 return (changelog_seq_release(inode, file));
93 static int mdc_changelog_seq_open(struct inode *inode, struct file *file)
95 struct changelog_seq_iter *csi;
99 rc = changelog_seq_open(inode, file, &csi);
103 /* Set up the remote catalog handle */
104 /* Note the proc file is set up with obd in data, not mdc_device */
105 csi->csi_ctxt = llog_get_context((struct obd_device *)csi->csi_dev,
106 LLOG_CHANGELOG_REPL_CTXT);
107 if (csi->csi_ctxt == NULL)
108 GOTO(out, rc = -ENOENT);
109 rc = llog_create(csi->csi_ctxt, &csi->csi_llh, NULL, CHANGELOG_CATALOG);
111 CERROR("llog_create() failed %d\n", rc);
114 rc = llog_init_handle(csi->csi_llh, LLOG_F_IS_CAT, NULL);
116 CERROR("llog_init_handle failed %d\n", rc);
122 mdc_changelog_seq_release(inode, file);
126 static struct file_operations mdc_changelog_fops = {
127 .owner = THIS_MODULE,
128 .open = mdc_changelog_seq_open,
130 .llseek = changelog_seq_lseek,
131 .release = mdc_changelog_seq_release,
134 /* temporary for testing */
135 static int mdc_wr_netlink(struct file *file, const char *buffer,
136 unsigned long count, void *data)
138 struct obd_device *obd = data;
140 struct hsm_action_list *hal;
141 struct hsm_action_item *hai;
145 rc = lprocfs_write_helper(buffer, count, &pid);
151 CWARN("message to pid %d\n", pid);
153 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
154 /* for mockup below */ 2 * size_round(sizeof(*hai));
158 lh->lnl_magic = LNL_MAGIC;
159 lh->lnl_transport = LNL_TRANSPORT_HSM;
160 lh->lnl_msgtype = HMT_ACTION_LIST;
161 lh->lnl_msglen = len;
163 hal = (struct hsm_action_list *)(lh + 1);
164 hal->hal_version = HAL_VERSION;
165 hal->hal_archive_num = 1;
166 obd_uuid2fsname(hal->hal_fsname, obd->obd_name, MTI_NAME_MAXLEN);
168 /* mock up an action list */
171 hai->hai_action = HSMA_ARCHIVE;
172 hai->hai_fid.f_oid = 5;
173 hai->hai_len = sizeof(*hai);
175 hai->hai_action = HSMA_RESTORE;
176 hai->hai_fid.f_oid = 10;
177 hai->hai_len = sizeof(*hai);
179 /* This works for either broadcast or unicast to a single pid */
180 rc = libcfs_klnl_msg_put(pid, pid == 0 ? LNL_GRP_HSM : 0, lh);
188 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
189 { "uuid", lprocfs_rd_uuid, 0, 0 },
190 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
191 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
192 { "blocksize", lprocfs_rd_blksize, 0, 0 },
193 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
194 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
195 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
196 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
197 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
198 /*{ "filegroups", lprocfs_rd_filegroups, 0, 0 },*/
199 { "mds_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
200 { "mds_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
201 { "max_rpcs_in_flight", mdc_rd_max_rpcs_in_flight,
202 mdc_wr_max_rpcs_in_flight, 0 },
203 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
204 { "import", lprocfs_rd_import, 0, 0 },
205 { "state", lprocfs_rd_state, 0, 0 },
206 { "changelog", 0, 0, 0, &mdc_changelog_fops, 0400 },
207 { "netlink", 0, mdc_wr_netlink, 0, 0, 0222 },
211 static struct lprocfs_vars lprocfs_mdc_module_vars[] = {
212 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
216 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
218 lvars->module_vars = lprocfs_mdc_module_vars;
219 lvars->obd_vars = lprocfs_mdc_obd_vars;