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_net.h>
33 #include <linux/lustre_dlm.h>
35 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
37 struct ptlrpc_connection *conn;
38 struct obd_ioctl_data* data = buf;
39 struct client_obd *cli = &obddev->u.cli;
40 struct obd_import *imp;
41 struct obd_uuid server_uuid;
42 int rq_portal, rp_portal, connect_op;
46 if (obddev->obd_type->typ_ops->o_brw) {
47 rq_portal = OST_REQUEST_PORTAL;
48 rp_portal = OSC_REPLY_PORTAL;
50 connect_op = OST_CONNECT;
52 rq_portal = MDS_REQUEST_PORTAL;
53 rp_portal = MDC_REPLY_PORTAL;
55 connect_op = MDS_CONNECT;
58 if (data->ioc_inllen1 < 1) {
59 CERROR("requires a TARGET UUID\n");
63 if (data->ioc_inllen1 > 37) {
64 CERROR("client UUID must be less than 38 characters\n");
68 if (data->ioc_inllen2 < 1) {
69 CERROR("setup requires a SERVER UUID\n");
73 if (data->ioc_inllen2 > 37) {
74 CERROR("target UUID must be less than 38 characters\n");
78 sema_init(&cli->cl_sem, 1);
79 cli->cl_conn_count = 0;
80 memcpy(server_uuid.uuid, data->ioc_inlbuf2, MIN(data->ioc_inllen2,
81 sizeof(server_uuid)));
83 conn = ptlrpc_uuid_to_connection(&server_uuid);
87 ptlrpc_init_client(rq_portal, rp_portal, name,
88 &obddev->obd_ldlm_client);
90 imp = class_new_import();
92 ptlrpc_put_connection(conn);
95 imp->imp_connection = conn;
96 imp->imp_client = &obddev->obd_ldlm_client;
97 imp->imp_obd = obddev;
98 imp->imp_connect_op = connect_op;
99 imp->imp_generation = 0;
100 memcpy(imp->imp_target_uuid.uuid, data->ioc_inlbuf1, data->ioc_inllen1);
101 class_import_put(imp);
103 cli->cl_import = imp;
104 cli->cl_max_mds_easize = sizeof(struct lov_mds_md);
105 cli->cl_sandev = to_kdev_t(0);
110 int client_obd_cleanup(struct obd_device *obddev, int force, int failover)
112 struct client_obd *client = &obddev->u.cli;
114 if (!client->cl_import)
116 class_destroy_import(client->cl_import);
117 client->cl_import = NULL;