1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/version.h>
23 #include <linux/module.h>
26 #define DEBUG_SUBSYSTEM S_PTLBD
28 #include <linux/obd_support.h>
29 #include <linux/obd_class.h>
30 #include <linux/lustre_debug.h>
31 #include <linux/lprocfs_status.h>
32 #include <linux/obd_ptlbd.h>
35 static int ptlbd_sv_callback(struct ptlrpc_request *req)
40 rc = ptlbd_parse_request(req);
42 rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
46 printk("callback got a friggin opc %d\n", req->rq_reqmsg->opc);
53 static int ptlbd_sv_already_setup = 1;
55 static int ptlbd_sv_setup(struct obd_device *obddev, obd_count len, void *buf)
58 struct obd_ioctl_data* data = buf;
59 obd_uuid_t server_uuid;
61 struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
66 if (data->ioc_inllen1 < 1) {
67 CERROR("requires a PTLBD server UUID\n");
71 if (data->ioc_inllen1 > 37) {
72 CERROR("PTLBD server UUID must be less than 38 characters\n");
76 memcpy(server_uuid, data->ioc_inlbuf1, MIN(data->ioc_inllen1,
77 sizeof(server_uuid)));
80 ptlbd->ptlbd_service =
81 ptlrpc_init_svc(PTLBD_NEVENTS, PTLBD_NBUFS, PTLBD_BUFSIZE,
82 PTLBD_MAXREQSIZE, PTLBD_REQUEST_PORTAL,
83 PTLBD_REPLY_PORTAL, "self",
84 ptlbd_parse_req, "ptlbd_sv");
86 if (!ptlbd->ptlbd_service) {
87 CERROR("failed to start service\n");
91 rc = ptlrpc_start_thread(obddev, ptlbd->ptlbd_service, "ptldb");
93 CERROR("cannot start PTLBD thread: rc %d\n", rc);
98 ptlbd_sv_already_setup = 1;
103 ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
104 ptlrpc_unregister_service(ptlbd->ptlbd_service);
109 static int ptlbd_sv_cleanup(struct obd_device *obddev)
111 struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
114 /* XXX check for state */
116 ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
117 ptlrpc_unregister_service(ptlbd->ptlbd_service);
119 ptlbd_sv_already_setup = 0;
124 static int ptlbd_sv_connect(struct lustre_handle *conn, struct obd_device *src,
125 obd_uuid_t cluuid, struct recovd_obd *recovd,
126 ptlrpc_recovery_cb_t recover)
128 return class_connect(conn, src, cluuid);
132 static struct obd_ops ptlbd_sv_obd_ops = {
133 o_owner: THIS_MODULE,
134 /* o_iocontrol: ptlbd_iocontrol,*/
135 o_setup: ptlbd_sv_setup,
136 o_cleanup: ptlbd_sv_cleanup,
138 o_connect: ptlbd_sv_connect,
139 o_disconnect: class_disconnect
143 int ptlbd_sv_init(void)
145 extern struct lprocfs_vars status_class_var[];
147 return class_register_type(&ptlbd_sv_obd_ops, status_class_var,
148 OBD_PTLBD_SV_DEVICENAME);
151 void ptlbd_sv_exit(void)
153 class_unregister_type(OBD_PTLBD_SV_DEVICENAME);