Whamcloud - gitweb
- added a 'dying' head to fix very bad bug in yesterday's request code
[fs/lustre-release.git] / lustre / ptlrpc / rpc.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
23 #define EXPORT_SYMTAB
24
25 #include <linux/module.h>
26
27 #define DEBUG_SUBSYSTEM S_RPC
28
29 #include <linux/lustre_ha.h>
30
31 extern int ptlrpc_init_portals(void);
32 extern void ptlrpc_exit_portals(void);
33
34 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
35 {
36         struct recovd_obd *recovd = &obddev->u.recovd;
37         int err;
38         ENTRY;
39
40         memset(recovd, 0, sizeof(*recovd));
41
42         OBD_ALLOC(recovd->recovd_client, sizeof(*recovd->recovd_client));
43         if (!recovd)
44                 RETURN(-ENOMEM);
45
46         err = recovd_setup(recovd);
47         if (err)
48                 GOTO(err_free, err);
49
50         recovd->recovd_service =
51                 ptlrpc_init_svc(128 * 1024,CONNMGR_REQUEST_PORTAL,
52                                 CONNMGR_REPLY_PORTAL, "self", connmgr_handle);
53         if (!recovd->recovd_service) {
54                 CERROR("failed to start service\n");
55                 GOTO(err_recovd, err = -EINVAL);
56         }
57
58         ptlrpc_init_client(NULL, NULL, CONNMGR_REQUEST_PORTAL, 
59                            CONNMGR_REPLY_PORTAL, recovd->recovd_client);
60
61         err = ptlrpc_start_thread(obddev, recovd->recovd_service, "lustre_connmgr");
62         if (err) {
63                 CERROR("cannot start thread\n");
64                 GOTO(err_svc, err);
65         }
66
67         MOD_INC_USE_COUNT;
68         ptlrpc_connmgr = recovd;
69         RETURN(0);
70
71  err_svc: 
72         rpc_unregister_service(recovd->recovd_service);
73  err_recovd: 
74         recovd_cleanup(recovd); 
75  err_free:
76         if (recovd->recovd_client)
77                 OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
78         RETURN(err);
79 }
80
81 int connmgr_cleanup(struct obd_device *dev)
82 {
83         struct recovd_obd *recovd = &dev->u.recovd;
84         int err;
85
86         err = recovd_cleanup(recovd); 
87         if (err) 
88                 LBUG();
89
90         ptlrpc_stop_all_threads(recovd->recovd_service);
91         rpc_unregister_service(recovd->recovd_service);
92         if (!list_empty(&recovd->recovd_service->srv_reqs)) {
93                 // XXX reply with errors and clean up
94                 CERROR("Request list not empty!\n");
95         }
96
97         OBD_FREE(recovd->recovd_service, sizeof(*recovd->recovd_service));
98         ptlrpc_cleanup_client(recovd->recovd_client);
99         OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
100         MOD_DEC_USE_COUNT;
101         RETURN(0);
102 }
103
104
105 int connmgr_iocontrol(int cmd, struct obd_conn *conn, int len, void *karg,
106                          void *uarg)
107 {
108         struct recovd_obd *recovd = &conn->oc_dev->u.recovd;
109
110         ENTRY;
111         if (cmd == OBD_RECOVD_NEWCONN) { 
112                 spin_lock(&recovd->recovd_lock);
113                 recovd->recovd_flags |= RECOVD_UPCALL_ANSWER;
114                 recovd->recovd_wakeup_flag = 1;
115                 wake_up(&recovd->recovd_waitq);
116                 spin_unlock(&recovd->recovd_lock);
117                 EXIT;
118         }
119         return 0;
120 }
121
122
123 /* use obd ops to offer management infrastructure */
124 static struct obd_ops recovd_obd_ops = {
125         o_setup:       connmgr_setup,
126         o_cleanup:     connmgr_cleanup,
127         o_iocontrol:     connmgr_iocontrol,
128 };
129
130 static int __init ptlrpc_init(void)
131 {
132         int rc; 
133         rc = ptlrpc_init_portals();
134         if (rc) 
135                 RETURN(rc);
136         ptlrpc_init_connection();
137         obd_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
138         return 0;
139 }
140
141 static void __exit ptlrpc_exit(void)
142 {
143         obd_unregister_type(LUSTRE_HA_NAME);
144         ptlrpc_exit_portals();
145         ptlrpc_cleanup_connection();
146 }
147
148 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
149 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
150 MODULE_LICENSE("GPL"); 
151
152 module_init(ptlrpc_init);
153 module_exit(ptlrpc_exit);