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>
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Storage Target Handling functions
24 * Lustre Object Server Module (OST)
26 * This server is single threaded at present (but can easily be multi
27 * threaded). For testing and management it is treated as an
28 * obd_device, although it does not export a full OBD method table
29 * (the requests are coming in over the wire, so object target
30 * modules do not have a full method table.)
34 #define DEBUG_SUBSYSTEM S_OST
36 #include <linux/module.h>
37 #include <linux/obd_ost.h>
38 #include <linux/lustre_net.h>
39 #include <linux/lustre_dlm.h>
41 struct client_obd *client_conn2cli(struct lustre_handle *conn)
43 struct obd_export *export = class_conn2export(conn);
46 return &export->exp_obd->u.cli;
48 extern struct recovd_obd *ptlrpc_connmgr;
50 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
52 struct obd_ioctl_data* data = buf;
53 int rq_portal = (obddev->obd_type->typ_ops->o_getattr) ? OST_REQUEST_PORTAL : MDS_REQUEST_PORTAL;
54 int rp_portal = (obddev->obd_type->typ_ops->o_getattr) ? OSC_REPLY_PORTAL : MDC_REPLY_PORTAL;
55 struct client_obd *mdc = &obddev->u.cli;
60 if (data->ioc_inllen1 < 1) {
61 CERROR("requires a TARGET UUID\n");
65 if (data->ioc_inllen1 > 37) {
66 CERROR("client UUID must be less than 38 characters\n");
70 if (data->ioc_inllen2 < 1) {
71 CERROR("setup requires a SERVER UUID\n");
75 if (data->ioc_inllen2 > 37) {
76 CERROR("target UUID must be less than 38 characters\n");
80 sema_init(&mdc->cl_sem, 1);
81 mdc->cl_conn_count = 0;
82 memcpy(mdc->cl_target_uuid, data->ioc_inlbuf1, data->ioc_inllen1);
83 memcpy(server_uuid, data->ioc_inlbuf2, MIN(data->ioc_inllen2,
84 sizeof(server_uuid)));
86 mdc->cl_conn = ptlrpc_uuid_to_connection(server_uuid);
90 OBD_ALLOC(mdc->cl_client, sizeof(*mdc->cl_client));
91 if (mdc->cl_client == NULL)
92 GOTO(out_conn, rc = -ENOMEM);
94 OBD_ALLOC(mdc->cl_ldlm_client, sizeof(*mdc->cl_ldlm_client));
95 if (mdc->cl_ldlm_client == NULL)
96 GOTO(out_client, rc = -ENOMEM);
98 /* XXX get recovery hooked in here again */
99 //ptlrpc_init_client(ptlrpc_connmgr, ll_recover,...
101 ptlrpc_init_client(ptlrpc_connmgr, NULL, rq_portal, rp_portal,
103 /* XXXshaver Should the LDLM have its own recover function? Probably. */
104 ptlrpc_init_client(ptlrpc_connmgr, NULL, LDLM_REQUEST_PORTAL,
105 LDLM_REPLY_PORTAL, mdc->cl_ldlm_client);
106 mdc->cl_client->cli_name = "mdc";
107 mdc->cl_ldlm_client->cli_name = "ldlm";
108 mdc->cl_max_mdsize = sizeof(struct lov_mds_md);
114 OBD_FREE(mdc->cl_client, sizeof(*mdc->cl_client));
116 ptlrpc_put_connection(mdc->cl_conn);
120 int client_obd_cleanup(struct obd_device * obddev)
122 struct client_obd *mdc = &obddev->u.cli;
124 ptlrpc_cleanup_client(mdc->cl_client);
125 OBD_FREE(mdc->cl_client, sizeof(*mdc->cl_client));
126 ptlrpc_cleanup_client(mdc->cl_ldlm_client);
127 OBD_FREE(mdc->cl_ldlm_client, sizeof(*mdc->cl_ldlm_client));
128 ptlrpc_put_connection(mdc->cl_conn);
134 int client_obd_connect(struct lustre_handle *conn, struct obd_device *obd,
137 struct client_obd *cli = &obd->u.cli;
138 struct ptlrpc_request *request;
139 int rc, size[] = {sizeof(cli->cl_target_uuid),
140 sizeof(obd->obd_uuid) };
141 char *tmp[] = {cli->cl_target_uuid, obd->obd_uuid};
142 int rq_opc = (obd->obd_type->typ_ops->o_getattr) ? OST_CONNECT : MDS_CONNECT;
147 rc = class_connect(conn, obd, cluuid);
153 cli->cl_conn_count++;
154 if (cli->cl_conn_count > 1)
157 obd->obd_namespace = ldlm_namespace_new(obd->obd_name,
158 LDLM_NAMESPACE_CLIENT);
159 if (obd->obd_namespace == NULL)
160 GOTO(out_disco, rc = -ENOMEM);
162 request = ptlrpc_prep_req(cli->cl_client, cli->cl_conn, rq_opc, 2, size,
165 GOTO(out_ldlm, rc = -ENOMEM);
167 request->rq_level = LUSTRE_CONN_NEW;
168 request->rq_replen = lustre_msg_size(0, NULL);
169 // This handle may be important if a callback needs
170 // to find the mdc/osc
171 // request->rq_reqmsg->addr = conn->addr;
172 // request->rq_reqmsg->cookie = conn->cookie;
174 rc = ptlrpc_queue_wait(request);
175 rc = ptlrpc_check_status(request, rc);
179 request->rq_connection->c_level = LUSTRE_CONN_FULL;
180 cli->cl_exporth = *(struct lustre_handle *)request->rq_repmsg;
184 ptlrpc_free_req(request);
187 ldlm_namespace_free(obd->obd_namespace);
188 obd->obd_namespace = NULL;
190 class_disconnect(conn);
198 int client_obd_disconnect(struct lustre_handle *conn)
200 struct obd_device *obd = class_conn2obd(conn);
201 struct client_obd *cli = &obd->u.cli;
202 int rq_opc = (obd->obd_type->typ_ops->o_getattr) ? OST_DISCONNECT : MDS_DISCONNECT;
203 struct ptlrpc_request *request = NULL;
208 if (!cli->cl_conn_count) {
209 CERROR("disconnecting disconnected device (%s)\n",
211 GOTO(out_sem, rc = -EINVAL);
214 cli->cl_conn_count--;
215 if (cli->cl_conn_count)
216 GOTO(out_disco, rc = 0);
218 ldlm_namespace_free(obd->obd_namespace);
219 obd->obd_namespace = NULL;
220 request = ptlrpc_prep_req2(conn, rq_opc, 0, NULL, NULL);
222 GOTO(out_disco, rc = -ENOMEM);
224 request->rq_replen = lustre_msg_size(0, NULL);
226 rc = ptlrpc_queue_wait(request);
233 ptlrpc_free_req(request);
235 err = class_disconnect(conn);
244 int target_handle_connect(struct ptlrpc_request *req)
246 struct obd_device *target;
247 struct obd_export *export;
248 struct lustre_handle conn;
249 char *tgtuuid, *cluuid;
253 tgtuuid = lustre_msg_buf(req->rq_reqmsg, 0);
254 if (req->rq_reqmsg->buflens[0] > 37) {
255 CERROR("bad target UUID for connect\n");
256 GOTO(out, rc = -EINVAL);
259 cluuid = lustre_msg_buf(req->rq_reqmsg, 1);
260 if (req->rq_reqmsg->buflens[1] > 37) {
261 CERROR("bad client UUID for connect\n");
262 GOTO(out, rc = -EINVAL);
265 i = class_uuid2dev(tgtuuid);
267 CERROR("UUID '%s' not found for connect\n", tgtuuid);
268 GOTO(out, rc = -ENODEV);
271 target = &obd_dev[i];
273 GOTO(out, rc = -ENODEV);
275 conn.addr = req->rq_reqmsg->addr;
276 conn.cookie = req->rq_reqmsg->cookie;
278 rc = lustre_pack_msg(0,
279 NULL, NULL, &req->rq_replen, &req->rq_repmsg);
283 rc = obd_connect(&conn, target, cluuid);
286 req->rq_repmsg->addr = conn.addr;
287 req->rq_repmsg->cookie = conn.cookie;
289 export = class_conn2export(&conn);
292 req->rq_export = export;
293 export->exp_connection = req->rq_connection;
294 #warning Peter: is this the right place to upgrade the server connection level?
295 req->rq_connection->c_level = LUSTRE_CONN_FULL;
301 int target_handle_disconnect(struct ptlrpc_request *req)
303 struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
307 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
311 req->rq_status = obd_disconnect(conn);