Whamcloud - gitweb
changed ioctl 'cmd' type from 'long' to 'int'
[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         recovd->recovd_client->cli_name = "connmgr"; 
61
62         err = ptlrpc_start_thread(obddev, recovd->recovd_service, "lustre_connmgr");
63         if (err) {
64                 CERROR("cannot start thread\n");
65                 GOTO(err_svc, err);
66         }
67
68         MOD_INC_USE_COUNT;
69         ptlrpc_connmgr = recovd;
70         RETURN(0);
71
72  err_svc: 
73         rpc_unregister_service(recovd->recovd_service);
74  err_recovd: 
75         recovd_cleanup(recovd); 
76  err_free:
77         if (recovd->recovd_client)
78                 OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
79         RETURN(err);
80 }
81
82 int connmgr_cleanup(struct obd_device *dev)
83 {
84         struct recovd_obd *recovd = &dev->u.recovd;
85         int err;
86
87         err = recovd_cleanup(recovd); 
88         if (err) 
89                 LBUG();
90
91         ptlrpc_stop_all_threads(recovd->recovd_service);
92         rpc_unregister_service(recovd->recovd_service);
93         if (!list_empty(&recovd->recovd_service->srv_reqs)) {
94                 // XXX reply with errors and clean up
95                 CERROR("Request list not empty!\n");
96         }
97
98         OBD_FREE(recovd->recovd_service, sizeof(*recovd->recovd_service));
99         ptlrpc_cleanup_client(recovd->recovd_client);
100         OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
101         MOD_DEC_USE_COUNT;
102         RETURN(0);
103 }
104
105
106 int connmgr_iocontrol(long cmd, struct obd_conn *conn, int len, void *karg,
107                       void *uarg)
108 {
109         struct recovd_obd *recovd = &conn->oc_dev->u.recovd;
110
111         ENTRY;
112         if (cmd == OBD_RECOVD_NEWCONN) { 
113                 spin_lock(&recovd->recovd_lock);
114                 recovd->recovd_flags |= RECOVD_UPCALL_ANSWER;
115                 recovd->recovd_wakeup_flag = 1;
116                 wake_up(&recovd->recovd_waitq);
117                 spin_unlock(&recovd->recovd_lock);
118                 EXIT;
119         }
120         return 0;
121 }
122
123
124 /* use obd ops to offer management infrastructure */
125 static struct obd_ops recovd_obd_ops = {
126         o_setup:       connmgr_setup,
127         o_cleanup:     connmgr_cleanup,
128         o_iocontrol:     connmgr_iocontrol,
129 };
130
131 static int __init ptlrpc_init(void)
132 {
133         int rc; 
134         rc = ptlrpc_init_portals();
135         if (rc) 
136                 RETURN(rc);
137         ptlrpc_init_connection();
138         obd_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
139         return 0;
140 }
141
142 static void __exit ptlrpc_exit(void)
143 {
144         obd_unregister_type(LUSTRE_HA_NAME);
145         ptlrpc_exit_portals();
146         ptlrpc_cleanup_connection();
147 }
148
149 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
150 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
151 MODULE_LICENSE("GPL"); 
152
153 module_init(ptlrpc_init);
154 module_exit(ptlrpc_exit);