1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Lustre High Availability Daemon
8 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
10 * This code is issued under the GNU General Public License.
11 * See the file COPYING in this distribution
13 * by Peter Braam <braam@clusterfs.com>
17 #define DEBUG_SUBSYSTEM S_RPC
19 #include <linux/kmod.h>
20 #include <linux/lustre_lite.h>
21 #include <linux/lustre_ha.h>
23 static int connmgr_unpack_body(struct ptlrpc_request *req)
25 struct connmgr_body *b = lustre_msg_buf(req->rq_repmsg, 0);
31 b->generation = NTOH__u32(b->generation);
36 int connmgr_connect(struct recovd_obd *recovd, struct ptlrpc_connection *conn)
38 struct ptlrpc_request *req;
39 struct ptlrpc_client *cl;
40 struct connmgr_body *body;
41 int rc, size = sizeof(*body);
45 CERROR("no manager\n");
48 cl = recovd->recovd_client;
50 req = ptlrpc_prep_req(cl, conn, CONNMGR_CONNECT, 1, &size, NULL);
52 GOTO(out, rc = -ENOMEM);
54 body = lustre_msg_buf(req->rq_reqmsg, 0);
55 body->generation = HTON__u32(conn->c_generation);
56 body->conn = (__u64)(unsigned long)conn;
57 body->conn_token = conn->c_token;
58 strncpy(body->conn_uuid, conn->c_local_uuid, sizeof(body->conn_uuid));
60 req->rq_replen = lustre_msg_size(1, &size);
61 req->rq_level = LUSTRE_CONN_NEW;
63 rc = ptlrpc_queue_wait(req);
64 rc = ptlrpc_check_status(req, rc);
66 rc = connmgr_unpack_body(req);
69 body = lustre_msg_buf(req->rq_repmsg, 0);
70 CDEBUG(D_NET, "remote generation: %o\n", body->generation);
71 conn->c_level = LUSTRE_CONN_CON;
72 conn->c_remote_conn = body->conn;
73 conn->c_remote_token = body->conn_token;
74 strncpy(conn->c_remote_uuid, body->conn_uuid,
75 sizeof(conn->c_remote_uuid));
85 static int connmgr_handle_connect(struct ptlrpc_request *req)
87 struct connmgr_body *body;
88 int rc, size = sizeof(*body);
91 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
93 CERROR("connmgr: out of memory\n");
94 req->rq_status = -ENOMEM;
98 body = lustre_msg_buf(req->rq_reqmsg, 0);
99 connmgr_unpack_body(req);
101 req->rq_connection->c_remote_conn = body->conn;
102 req->rq_connection->c_remote_token = body->conn_token;
103 strncpy(req->rq_connection->c_remote_uuid, body->conn_uuid,
104 sizeof(req->rq_connection->c_remote_uuid));
106 CERROR("incoming generation %d\n", body->generation);
107 body = lustre_msg_buf(req->rq_repmsg, 0);
108 body->generation = 4711;
109 body->conn = (__u64)(unsigned long)req->rq_connection;
110 body->conn_token = req->rq_connection->c_token;
112 req->rq_connection->c_level = LUSTRE_CONN_CON;
116 int connmgr_handle(struct obd_device *dev, struct ptlrpc_service *svc,
117 struct ptlrpc_request *req)
122 rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
124 CERROR("Invalid request\n");
128 if (req->rq_reqmsg->type != NTOH__u32(PTL_RPC_MSG_REQUEST)) {
129 CERROR("wrong packet type sent %d\n",
130 req->rq_reqmsg->type);
131 GOTO(out, rc = -EINVAL);
134 switch (req->rq_reqmsg->opc) {
135 case CONNMGR_CONNECT:
136 CDEBUG(D_INODE, "connmgr connect\n");
137 rc = connmgr_handle_connect(req);
141 rc = ptlrpc_error(svc, req);
148 ptlrpc_error(svc, req);
150 CDEBUG(D_NET, "sending reply\n");
151 ptlrpc_reply(svc, req);