1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
7 * Author: Mike Shaver <shaver@clusterfs.com>
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Target-common OBD method implementations and utility functions.
28 #define DEBUG_SUBSYSTEM S_OST /* XXX WRONG */
30 #include <linux/module.h>
31 #include <linux/obd_ost.h>
32 #include <linux/lustre_net.h>
33 #include <linux/lustre_dlm.h>
35 int target_handle_reconnect(struct lustre_handle *conn, struct obd_export *exp,
38 if (exp->exp_connection) {
39 struct lustre_handle *hdl;
40 hdl = &exp->exp_ldlm_data.led_import.imp_handle;
41 /* Might be a re-connect after a partition. */
42 if (!memcmp(conn, hdl, sizeof *conn)) {
43 CERROR("%s reconnecting\n", cluuid);
44 conn->addr = (__u64) (unsigned long)exp;
45 conn->cookie = exp->exp_cookie;
48 CERROR("%s reconnecting from %s, "
49 "handle mismatch (ours "LPX64"/"LPX64", "
50 "theirs "LPX64"/"LPX64")\n", cluuid,
51 exp->exp_connection->c_remote_uuid, hdl->addr,
52 hdl->cookie, conn->addr, conn->cookie);
53 /* XXX disconnect them here? */
54 memset(conn, 0, sizeof *conn);
55 /* This is a little scary, but right now we build this
56 * file separately into each server module, so I won't
57 * go _immediately_ to hell.
63 conn->addr = (__u64) (unsigned long)exp;
64 conn->cookie = exp->exp_cookie;
65 CDEBUG(D_INFO, "existing export for UUID '%s' at %p\n", cluuid, exp);
66 CDEBUG(D_IOCTL,"connect: addr %Lx cookie %Lx\n",
67 (long long)conn->addr, (long long)conn->cookie);
71 int target_handle_connect(struct ptlrpc_request *req)
73 struct obd_device *target;
74 struct obd_export *export;
75 struct obd_import *dlmimp;
76 struct lustre_handle conn;
77 char *tgtuuid, *cluuid;
81 tgtuuid = lustre_msg_buf(req->rq_reqmsg, 0);
82 if (req->rq_reqmsg->buflens[0] > 37) {
83 CERROR("bad target UUID for connect\n");
84 GOTO(out, rc = -EINVAL);
87 cluuid = lustre_msg_buf(req->rq_reqmsg, 1);
88 if (req->rq_reqmsg->buflens[1] > 37) {
89 CERROR("bad client UUID for connect\n");
90 GOTO(out, rc = -EINVAL);
93 i = class_uuid2dev(tgtuuid);
95 CERROR("UUID '%s' not found for connect\n", tgtuuid);
96 GOTO(out, rc = -ENODEV);
101 GOTO(out, rc = -ENODEV);
103 conn.addr = req->rq_reqmsg->addr;
104 conn.cookie = req->rq_reqmsg->cookie;
106 rc = obd_connect(&conn, target, cluuid, ptlrpc_recovd,
107 target_revoke_connection);
108 /* EALREADY indicates a reconnection, send the reply normally. */
109 if (rc && rc != EALREADY)
112 /* If all else goes well, this is our RPC return code. */
115 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
118 req->rq_repmsg->addr = conn.addr;
119 req->rq_repmsg->cookie = conn.cookie;
121 export = class_conn2export(&conn);
124 req->rq_export = export;
125 export->exp_connection = ptlrpc_get_connection(&req->rq_peer, cluuid);
126 if (req->rq_connection != NULL)
127 ptlrpc_put_connection(req->rq_connection);
128 req->rq_connection = ptlrpc_connection_addref(export->exp_connection);
130 spin_lock(&export->exp_connection->c_lock);
131 list_add(&export->exp_conn_chain, &export->exp_connection->c_exports);
132 spin_unlock(&export->exp_connection->c_lock);
133 recovd_conn_manage(export->exp_connection, ptlrpc_recovd,
134 target_revoke_connection);
136 dlmimp = &export->exp_ldlm_data.led_import;
137 dlmimp->imp_connection = req->rq_connection;
138 dlmimp->imp_client = &export->exp_obd->obd_ldlm_client;
139 dlmimp->imp_handle.addr = req->rq_reqmsg->addr;
140 dlmimp->imp_handle.cookie = req->rq_reqmsg->cookie;
141 dlmimp->imp_obd = /* LDLM! */ NULL;
142 dlmimp->imp_recover = NULL;
143 INIT_LIST_HEAD(&dlmimp->imp_replay_list);
144 INIT_LIST_HEAD(&dlmimp->imp_sending_list);
145 INIT_LIST_HEAD(&dlmimp->imp_delayed_list);
146 spin_lock_init(&dlmimp->imp_lock);
147 dlmimp->imp_level = LUSTRE_CONN_FULL;
154 int target_handle_disconnect(struct ptlrpc_request *req)
156 struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
160 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
164 req->rq_status = obd_disconnect(conn);
169 static int target_disconnect_client(struct ptlrpc_connection *conn)
171 struct list_head *expiter, *n;
172 struct lustre_handle hdl;
173 struct obd_export *exp;
177 list_for_each_safe(expiter, n, &conn->c_exports) {
178 exp = list_entry(expiter, struct obd_export, exp_conn_chain);
180 hdl.addr = (__u64)(unsigned long)exp;
181 hdl.cookie = exp->exp_cookie;
182 rc = obd_disconnect(&hdl);
184 CERROR("disconnecting export %p failed: %d\n", exp, rc);
187 /* XXX spank the connection (it's frozen in _RECOVD for now!) */
191 static int target_fence_failed_connection(struct ptlrpc_connection *conn)
195 conn->c_recovd_data.rd_phase = RD_PREPARED;
200 int target_revoke_connection(struct recovd_data *rd, int phase)
202 struct ptlrpc_connection *conn = class_rd2conn(rd);
208 case PTLRPC_RECOVD_PHASE_PREPARE:
209 RETURN(target_fence_failed_connection(conn));
210 case PTLRPC_RECOVD_PHASE_RECOVER:
211 RETURN(target_disconnect_client(conn));
212 case PTLRPC_RECOVD_PHASE_FAILURE: