Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / ptlrpc / ptlrpc_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  */
21
22 #define EXPORT_SYMTAB
23 #define DEBUG_SUBSYSTEM S_RPC
24
25 #ifdef __KERNEL__
26 # include <linux/module.h>
27 #else 
28 # include <liblustre.h>
29 #endif
30 #include <linux/obd.h>
31 #include <linux/obd_ost.h>
32 #include <linux/lustre_net.h>
33 #include <linux/lustre_dlm.h>
34
35 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
36 {
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;
43         char *name;
44         ENTRY;
45
46         if (obddev->obd_type->typ_ops->o_brw) {
47                 rq_portal = OST_REQUEST_PORTAL;
48                 rp_portal = OSC_REPLY_PORTAL;
49                 name = "osc";
50                 connect_op = OST_CONNECT;
51         } else {
52                 rq_portal = MDS_REQUEST_PORTAL;
53                 rp_portal = MDC_REPLY_PORTAL;
54                 name = "mdc";
55                 connect_op = MDS_CONNECT;
56         }
57
58         if (data->ioc_inllen1 < 1) {
59                 CERROR("requires a TARGET UUID\n");
60                 RETURN(-EINVAL);
61         }
62
63         if (data->ioc_inllen1 > 37) {
64                 CERROR("client UUID must be less than 38 characters\n");
65                 RETURN(-EINVAL);
66         }
67
68         if (data->ioc_inllen2 < 1) {
69                 CERROR("setup requires a SERVER UUID\n");
70                 RETURN(-EINVAL);
71         }
72
73         if (data->ioc_inllen2 > 37) {
74                 CERROR("target UUID must be less than 38 characters\n");
75                 RETURN(-EINVAL);
76         }
77
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)));
82
83         conn = ptlrpc_uuid_to_connection(&server_uuid);
84         if (conn == NULL)
85                 RETURN(-ENOENT);
86
87         ptlrpc_init_client(rq_portal, rp_portal, name,
88                            &obddev->obd_ldlm_client);
89
90         imp = class_new_import();
91         if (imp == NULL) {
92                 ptlrpc_put_connection(conn);
93                 RETURN(-ENOMEM);
94         }
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);
102
103         cli->cl_import = imp;
104         cli->cl_max_mds_easize = sizeof(struct lov_mds_md);
105         cli->cl_sandev = to_kdev_t(0);
106
107         RETURN(0);
108 }
109
110 int client_obd_cleanup(struct obd_device *obddev, int force, int failover)
111 {
112         struct client_obd *client = &obddev->u.cli;
113
114         if (!client->cl_import)
115                 RETURN(-EINVAL);
116         class_destroy_import(client->cl_import);
117         client->cl_import = NULL;
118         RETURN(0);
119 }