Whamcloud - gitweb
Merge b_md to HEAD for 0.5.19 release.
[fs/lustre-release.git] / lustre / ptlbd / server.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  */
21
22 #include <linux/version.h>
23 #include <linux/module.h>
24 #include <linux/fs.h>
25
26 #define DEBUG_SUBSYSTEM S_PTLBD
27
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>
33
34 #if 0
35 static int ptlbd_sv_callback(struct ptlrpc_request *req)
36 {
37         int rc;
38         ENTRY;
39
40         rc = ptlbd_parse_request(req);
41
42         rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
43         if ( rc )
44                 GOTO(out, rc);
45
46         printk("callback got a friggin opc %d\n", req->rq_reqmsg->opc);
47
48 out:
49         RETURN(rc);
50 }
51 #endif
52
53 static int ptlbd_sv_already_setup = 1;
54
55 static int ptlbd_sv_setup(struct obd_device *obddev, obd_count len, void *buf)
56 {
57 #if 0
58         struct obd_ioctl_data* data = buf;
59         obd_uuid_t server_uuid;
60 #endif
61         struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
62         int rc;
63         ENTRY;
64
65 #if 0
66         if (data->ioc_inllen1 < 1) {
67                 CERROR("requires a PTLBD server UUID\n");
68                 RETURN(rc = -EINVAL);
69         }
70
71         if (data->ioc_inllen1 > 37) {
72                 CERROR("PTLBD server UUID must be less than 38 characters\n");
73                 RETURN(rc = -EINVAL);
74         }
75
76         memcpy(server_uuid, data->ioc_inlbuf1, MIN(data->ioc_inllen1,
77                                                    sizeof(server_uuid)));
78
79 #endif
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");
85
86         if (!ptlbd->ptlbd_service) {
87                 CERROR("failed to start service\n");
88                 RETURN(rc = -ENOMEM);
89         }
90
91         rc = ptlrpc_start_thread(obddev, ptlbd->ptlbd_service, "ptldb");
92         if (rc) {
93                 CERROR("cannot start PTLBD thread: rc %d\n", rc);
94                 LBUG();
95                 GOTO(out_thread, rc);
96         }
97
98         ptlbd_sv_already_setup = 1;
99
100         RETURN(0);
101
102  out_thread:
103         ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
104         ptlrpc_unregister_service(ptlbd->ptlbd_service);
105
106         return rc;
107 }
108
109 static int ptlbd_sv_cleanup(struct obd_device *obddev)
110 {
111         struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
112         ENTRY;
113
114         /* XXX check for state */
115
116         ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
117         ptlrpc_unregister_service(ptlbd->ptlbd_service);
118
119         ptlbd_sv_already_setup = 0;
120         RETURN(0);
121 }
122
123 #if 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)
127 {
128         return class_connect(conn, src, cluuid);
129 }
130 #endif
131
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,
137 #if 0
138         o_connect:      ptlbd_sv_connect,
139         o_disconnect:   class_disconnect
140 #endif
141 };
142
143 int ptlbd_sv_init(void)
144 {
145         extern struct lprocfs_vars status_class_var[];
146
147         return class_register_type(&ptlbd_sv_obd_ops, status_class_var,
148                                    OBD_PTLBD_SV_DEVICENAME);
149 }
150
151 void ptlbd_sv_exit(void)
152 {
153         class_unregister_type(OBD_PTLBD_SV_DEVICENAME);
154 }