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 struct lnl_hdr *changelog_lnl_alloc(int len, int flags)
88 lh->lnl_magic = LNL_MAGIC;
89 lh->lnl_transport = LNL_TRANSPORT_CHANGELOG;
90 lh->lnl_flags = flags;
91 lh->lnl_msgtype = CL_RECORD;
98 static int changelog_show_cb(struct llog_handle *llh, struct llog_rec_hdr *hdr,
101 struct changelog_show *cs = data;
102 struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
107 if ((rec->cr_hdr.lrh_type != CHANGELOG_REC) ||
108 (rec->cr.cr_type >= CL_LAST)) {
109 CERROR("Not a changelog rec %d/%d\n", rec->cr_hdr.lrh_type,
114 if (rec->cr.cr_index < cs->cs_startrec) {
115 /* Skip entries earlier than what we are interested in */
116 CDEBUG(D_CHANGELOG, "rec="LPU64" start="LPU64"\n",
117 rec->cr.cr_index, cs->cs_startrec);
121 CDEBUG(D_CHANGELOG, LPU64" %02d%-5s "LPU64" 0x%x t="DFID" p="DFID
122 " %.*s\n", rec->cr.cr_index, rec->cr.cr_type,
123 changelog_type2str(rec->cr.cr_type), rec->cr.cr_time,
124 rec->cr.cr_flags & CLF_FLAGMASK,
125 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid),
126 rec->cr.cr_namelen, rec->cr.cr_name);
128 len = sizeof(*lh) + sizeof(rec->cr) + rec->cr.cr_namelen;
130 /* Set up the netlink message */
131 lh = changelog_lnl_alloc(len, cs->cs_flags);
134 memcpy(lh + 1, &rec->cr, len - sizeof(*lh));
136 rc = libcfs_klnl_msg_put(cs->cs_pid, 0, lh);
137 CDEBUG(D_CHANGELOG, "nlmsg pid %d len %d rc %d\n", cs->cs_pid, len, rc);
144 static int lproc_mdc_wr_changelog(struct file *file, const char *buffer,
145 unsigned long count, void *data)
147 struct obd_device *obd = data;
148 struct llog_ctxt *ctxt;
149 struct llog_handle *llh;
150 struct lnl_hdr *lnlh;
151 struct changelog_show cs = {};
154 if (count != sizeof(cs))
157 if (cfs_copy_from_user(&cs, buffer, sizeof(cs)))
160 CDEBUG(D_CHANGELOG, "changelog to pid=%d start "LPU64"\n",
161 cs.cs_pid, cs.cs_startrec);
163 /* Set up the remote catalog handle */
164 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
167 rc = llog_create(ctxt, &llh, NULL, CHANGELOG_CATALOG);
169 CERROR("llog_create() failed %d\n", rc);
172 rc = llog_init_handle(llh, LLOG_F_IS_CAT, NULL);
174 CERROR("llog_init_handle failed %d\n", rc);
178 rc = llog_cat_process(llh, changelog_show_cb, &cs, 0, 0);
181 if ((lnlh = changelog_lnl_alloc(sizeof(*lnlh), cs.cs_flags))) {
182 lnlh->lnl_msgtype = CL_EOF;
183 libcfs_klnl_msg_put(cs.cs_pid, 0, lnlh);
184 OBD_FREE(lnlh, sizeof(*lnlh));
197 /* temporary for testing */
198 static int mdc_wr_netlink(struct file *file, const char *buffer,
199 unsigned long count, void *data)
201 struct obd_device *obd = data;
203 struct hsm_action_list *hal;
204 struct hsm_action_item *hai;
208 rc = lprocfs_write_helper(buffer, count, &pid);
214 CWARN("message to pid %d\n", pid);
216 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
217 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
221 lh->lnl_magic = LNL_MAGIC;
222 lh->lnl_transport = LNL_TRANSPORT_HSM;
223 lh->lnl_msgtype = HMT_ACTION_LIST;
224 lh->lnl_msglen = len;
226 hal = (struct hsm_action_list *)(lh + 1);
227 hal->hal_version = HAL_VERSION;
228 hal->hal_archive_num = 1;
229 obd_uuid2fsname(hal->hal_fsname, obd->obd_name, MTI_NAME_MAXLEN);
231 /* mock up an action list */
234 hai->hai_action = HSMA_ARCHIVE;
235 hai->hai_fid.f_oid = 5;
236 hai->hai_len = sizeof(*hai);
238 hai->hai_action = HSMA_RESTORE;
239 hai->hai_fid.f_oid = 10;
240 hai->hai_len = sizeof(*hai);
242 /* This works for either broadcast or unicast to a single pid */
243 rc = libcfs_klnl_msg_put(pid, pid == 0 ? LNL_GRP_HSM : 0, lh);
251 static struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
252 { "uuid", lprocfs_rd_uuid, 0, 0 },
253 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
254 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
255 { "blocksize", lprocfs_rd_blksize, 0, 0 },
256 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
257 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
258 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
259 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
260 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
261 /*{ "filegroups", lprocfs_rd_filegroups, 0, 0 },*/
262 { "mds_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
263 { "mds_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
264 { "max_rpcs_in_flight", mdc_rd_max_rpcs_in_flight,
265 mdc_wr_max_rpcs_in_flight, 0 },
266 { "quota_resend_count", lprocfs_rd_quota_resend_count,
267 lprocfs_wr_quota_resend_count, 0},
268 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
269 { "import", lprocfs_rd_import, 0, 0 },
270 { "state", lprocfs_rd_state, 0, 0 },
271 { "changelog_trigger",0,lproc_mdc_wr_changelog, 0 },
272 { "hsm_nl", 0, mdc_wr_netlink, 0, 0, 0222 },
276 static struct lprocfs_vars lprocfs_mdc_module_vars[] = {
277 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
281 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars)
283 lvars->module_vars = lprocfs_mdc_module_vars;
284 lvars->obd_vars = lprocfs_mdc_obd_vars;