Whamcloud - gitweb
More connection-level hackery for the DLM
[fs/lustre-release.git] / lustre / lib / l_net.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *   Author: Peter J. Braam <braam@clusterfs.com>
6  *   Author: Phil Schwan <phil@clusterfs.com>
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
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.
13  *
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.
18  *
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.
22  *
23  *  Storage Target Handling functions
24  *  Lustre Object Server Module (OST)
25  *
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.)
31  */
32
33 #define EXPORT_SYMTAB
34 #define DEBUG_SUBSYSTEM S_OST
35
36 #include <linux/module.h>
37 #include <linux/obd_ost.h>
38 #include <linux/lustre_net.h>
39 #include <linux/lustre_dlm.h>
40
41 int target_handle_connect(struct ptlrpc_request *req)
42 {
43         struct obd_device *target;
44         struct obd_export *export;
45         struct lustre_handle conn;
46         char *uuid;
47         int rc, i;
48         ENTRY;
49
50         uuid = lustre_msg_buf(req->rq_reqmsg, 0);
51         if (req->rq_reqmsg->buflens[0] > 37) {
52                 /* Invalid UUID */
53                 req->rq_status = -EINVAL;
54                 RETURN(-EINVAL);
55         }
56
57         i = class_uuid2dev(uuid);
58         if (i == -1) {
59                 req->rq_status = -ENODEV;
60                 RETURN(-ENODEV);
61         }
62
63         target = &obd_dev[i];
64         if (!target) {
65                 req->rq_status = -ENODEV;
66                 RETURN(-ENODEV);
67         }
68
69         conn.addr = req->rq_reqmsg->addr;
70         conn.cookie = req->rq_reqmsg->cookie;
71
72         rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
73         if (rc)
74                 RETURN(rc);
75
76         req->rq_status = obd_connect(&conn, target);
77         req->rq_repmsg->addr = conn.addr;
78         req->rq_repmsg->cookie = conn.cookie;
79
80         export = class_conn2export(&conn);
81         if (!export)
82                 LBUG();
83
84         req->rq_export = export;
85         export->exp_connection = req->rq_connection;
86 #warning Peter: is this the right place to upgrade the server connection level?
87         req->rq_connection->c_level = LUSTRE_CONN_FULL;
88         RETURN(0);
89 }
90
91 int target_handle_disconnect(struct ptlrpc_request *req)
92 {
93         struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
94         int rc;
95         ENTRY;
96
97         rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
98         if (rc)
99                 RETURN(rc);
100
101         req->rq_status = obd_disconnect(conn);
102         RETURN(0);
103 }