1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
23 #define DEBUG_SUBSYSTEM S_RPC
26 # include <linux/module.h>
28 # include <liblustre.h>
30 #include <linux/obd.h>
31 #include <linux/obd_ost.h>
32 #include <linux/lustre_mgmt.h>
33 #include <linux/lustre_net.h>
34 #include <linux/lustre_dlm.h>
36 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
38 struct ptlrpc_connection *conn;
39 struct obd_ioctl_data* data = buf;
40 struct client_obd *cli = &obddev->u.cli;
41 struct obd_import *imp;
42 struct obd_uuid server_uuid;
43 int rq_portal, rp_portal, connect_op;
44 char *name = obddev->obd_type->typ_name;
47 /* In a more perfect world, we would hang a ptlrpc_client off of
48 * obd_type and just use the values from there. */
49 if (!strcmp(name, LUSTRE_OSC_NAME)) {
50 rq_portal = OST_REQUEST_PORTAL;
51 rp_portal = OSC_REPLY_PORTAL;
52 connect_op = OST_CONNECT;
53 } else if (!strcmp(name, LUSTRE_MDC_NAME)) {
54 rq_portal = MDS_REQUEST_PORTAL;
55 rp_portal = MDC_REPLY_PORTAL;
56 connect_op = MDS_CONNECT;
57 } else if (!strcmp(name, LUSTRE_MGMTCLI_NAME)) {
58 rq_portal = MGMT_REQUEST_PORTAL;
59 rp_portal = MGMT_REPLY_PORTAL;
60 connect_op = MGMT_CONNECT;
62 CERROR("unknown client OBD type \"%s\", can't setup\n",
67 if (data->ioc_inllen1 < 1) {
68 CERROR("requires a TARGET UUID\n");
72 if (data->ioc_inllen1 > 37) {
73 CERROR("client UUID must be less than 38 characters\n");
77 if (data->ioc_inllen2 < 1) {
78 CERROR("setup requires a SERVER UUID\n");
82 if (data->ioc_inllen2 > 37) {
83 CERROR("target UUID must be less than 38 characters\n");
87 sema_init(&cli->cl_sem, 1);
88 cli->cl_conn_count = 0;
89 memcpy(server_uuid.uuid, data->ioc_inlbuf2, MIN(data->ioc_inllen2,
90 sizeof(server_uuid)));
92 init_MUTEX(&cli->cl_dirty_sem);
94 cli->cl_dirty_granted = 0;
95 cli->cl_ost_can_grant = 1;
97 conn = ptlrpc_uuid_to_connection(&server_uuid);
101 ptlrpc_init_client(rq_portal, rp_portal, name,
102 &obddev->obd_ldlm_client);
104 imp = class_new_import();
106 ptlrpc_put_connection(conn);
109 imp->imp_connection = conn;
110 imp->imp_client = &obddev->obd_ldlm_client;
111 imp->imp_obd = obddev;
112 imp->imp_connect_op = connect_op;
113 imp->imp_generation = 0;
114 INIT_LIST_HEAD(&imp->imp_pinger_chain);
115 memcpy(imp->imp_target_uuid.uuid, data->ioc_inlbuf1, data->ioc_inllen1);
116 class_import_put(imp);
118 cli->cl_import = imp;
119 cli->cl_max_mds_easize = sizeof(struct lov_mds_md);
120 cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie);
121 cli->cl_sandev = to_kdev_t(0);
123 /* Register with management client if we need to. */
124 if (data->ioc_inllen3 > 0) {
125 char *mgmt_name = data->ioc_inlbuf3;
127 struct obd_device *mgmt_obd;
128 mgmtcli_register_for_events_t register_f;
130 CDEBUG(D_HA, "%s registering with %s for events about %s\n",
131 obddev->obd_name, mgmt_name, server_uuid.uuid);
133 mgmt_obd = class_name2obd(mgmt_name);
135 CERROR("can't find mgmtcli %s to register\n",
137 class_destroy_import(imp);
141 register_f = inter_module_get("mgmtcli_register_for_events");
143 CERROR("can't i_m_g mgmtcli_register_for_events\n");
144 class_destroy_import(imp);
148 rc = register_f(mgmt_obd, obddev, &imp->imp_target_uuid);
149 inter_module_put("mgmtcli_register_for_events");
152 cli->cl_mgmtcli_obd = mgmt_obd;
160 int client_obd_cleanup(struct obd_device *obddev, int flags)
162 struct client_obd *cli = &obddev->u.cli;
166 if (cli->cl_mgmtcli_obd) {
167 mgmtcli_deregister_for_events_t dereg_f;
169 dereg_f = inter_module_get("mgmtcli_deregister_for_events");
170 dereg_f(cli->cl_mgmtcli_obd, obddev);
171 inter_module_put("mgmtcli_deregister_for_events");
173 class_destroy_import(cli->cl_import);
174 cli->cl_import = NULL;