1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Zach Brown <zab@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/version.h>
24 #include <linux/module.h>
27 #define DEBUG_SUBSYSTEM S_PTLBD
29 #include <linux/obd_support.h>
30 #include <linux/obd_class.h>
31 #include <linux/lustre_debug.h>
32 #include <linux/lprocfs_status.h>
33 #include <linux/obd_ptlbd.h>
35 static int ptlbd_cl_setup(struct obd_device *obd, obd_count len, void *buf)
37 struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
38 struct obd_import *imp;
39 struct obd_ioctl_data* data = buf;
42 if (ptlbd->bd_import != NULL)
45 if (data->ioc_inllen1 < 1) {
46 CERROR("requires a PTLBD server UUID\n");
50 if (data->ioc_inllen1 > 37) {
51 CERROR("PTLBD server UUID must be less than 38 characters\n");
55 obd_str2uuid(&ptlbd->bd_server_uuid, data->ioc_inlbuf1);
58 * from client_obd_connect.. *shrug*
60 imp = ptlbd->bd_import = class_new_import();
61 imp->imp_connection = ptlrpc_uuid_to_connection(&ptlbd->bd_server_uuid);
62 if (!imp->imp_connection) {
63 class_destroy_import(imp);
64 class_import_put(imp);
67 imp->imp_level = LUSTRE_CONN_FULL;
69 ptlrpc_init_client(PTLBD_REQUEST_PORTAL, PTLBD_REPLY_PORTAL,
70 "ptlbd", &ptlbd->bd_client);
71 imp->imp_client = &ptlbd->bd_client;
73 memcpy(imp->imp_target_uuid.uuid, data->ioc_inlbuf1, data->ioc_inllen1);
74 ptlbd_blk_register(ptlbd);
79 static int ptlbd_cl_cleanup(struct obd_device *obd, int flags)
81 struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
82 struct obd_import *imp;
85 if ((!ptlbd) || (!(imp = ptlbd->bd_import)))
88 if (!imp->imp_connection)
91 ptlrpc_cleanup_client(imp);
92 ptlrpc_put_connection(imp->imp_connection);
94 class_destroy_import(imp);
95 class_import_put(imp);
101 /* modelled after ptlrpc_import_connect() */
102 int ptlbd_cl_connect(struct lustre_handle *conn, struct obd_device *obd,
103 struct obd_uuid *target_uuid)
105 struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
106 struct obd_import *imp = ptlbd->bd_import;
107 struct obd_export *exp;
108 struct ptlrpc_request *request;
109 int rc, size[] = {sizeof(imp->imp_target_uuid),
110 sizeof(obd->obd_uuid),
112 char *tmp[] = {imp->imp_target_uuid.uuid,
117 if (!conn || !obd || !target_uuid)
120 rc = class_connect(conn, obd, target_uuid);
124 request = ptlrpc_prep_req(imp, PTLBD_CONNECT, 3, size, tmp);
126 GOTO(out_disco, rc = -ENOMEM);
127 request->rq_level = LUSTRE_CONN_NEW;
128 request->rq_replen = lustre_msg_size(0, NULL);
130 imp->imp_dlm_handle = *conn;
132 imp->imp_level = LUSTRE_CONN_CON;
133 rc = ptlrpc_queue_wait(request);
137 exp = class_conn2export(conn);
138 exp->exp_connection = ptlrpc_connection_addref(request->rq_connection);
139 class_export_put(exp);
141 imp->imp_level = LUSTRE_CONN_FULL;
142 imp->imp_remote_handle = request->rq_repmsg->handle;
145 ptlrpc_req_finished(request);
148 class_disconnect(conn, 0);
153 /* modelled after ptlrpc_import_disconnect() */
154 int ptlbd_cl_disconnect(struct lustre_handle *conn, int failover)
156 struct obd_device *obd = class_conn2obd(conn);
157 struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
158 struct obd_import *imp = ptlbd->bd_import;
159 struct ptlrpc_request *request;
166 request = ptlrpc_prep_req(imp, PTLBD_DISCONNECT, 0, NULL, NULL);
168 GOTO(out_req, rc = -ENOMEM);
170 request->rq_replen = lustre_msg_size(0, NULL);
171 request->rq_level = LUSTRE_CONN_RECOVER;
173 rc = ptlrpc_queue_wait(request);
177 ptlrpc_req_finished(request);
178 err = class_disconnect(conn, 0);
179 memset(&imp->imp_remote_handle, 0, sizeof(imp->imp_remote_handle));
186 static struct obd_ops ptlbd_cl_obd_ops = {
187 o_owner: THIS_MODULE,
188 o_setup: ptlbd_cl_setup,
189 o_cleanup: ptlbd_cl_cleanup,
190 o_connect: ptlbd_cl_connect,
191 o_disconnect: ptlbd_cl_disconnect,
194 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
195 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
196 LPROCFS_INIT_VARS(ptlbd_cl, lprocfs_module_vars, lprocfs_obd_vars)
198 int ptlbd_cl_init(void)
200 struct lprocfs_static_vars lvars;
202 lprocfs_init_vars(ptlbd_cl,&lvars);
203 return class_register_type(&ptlbd_cl_obd_ops, lvars.module_vars,
204 OBD_PTLBD_CL_DEVICENAME);
207 void ptlbd_cl_exit(void)
209 class_unregister_type(OBD_PTLBD_CL_DEVICENAME);
214 int ptlbd_do_connect(struct ptlbd_obd *ptlbd)
217 struct obd_device *obd = ptlbd->bd_import->imp_obd;
220 memset(&ptlbd->bd_connect_handle, 0, sizeof(ptlbd->bd_connect_handle));
221 rc = obd_connect(&ptlbd->bd_connect_handle, obd,
222 &ptlbd->bd_server_uuid);
227 int ptlbd_do_disconnect(struct ptlbd_obd *ptlbd)
232 rc = obd_disconnect(&ptlbd->bd_connect_handle, 0);