Whamcloud - gitweb
Merge b_md to HEAD for 0.5.19 release.
[fs/lustre-release.git] / lustre / ptlbd / client.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002 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 #include <linux/version.h>
23 #include <linux/module.h>
24 #include <linux/fs.h>
25
26 #define DEBUG_SUBSYSTEM S_PTLBD
27
28 #include <linux/obd_support.h>
29 #include <linux/obd_class.h>
30 #include <linux/lustre_debug.h>
31 #include <linux/lprocfs_status.h>
32 #include <linux/obd_ptlbd.h>
33
34 static int ptlbd_cl_setup(struct obd_device *obddev, obd_count len, void *buf)
35 {
36         struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
37         struct obd_import *imp = &ptlbd->bd_import;
38         struct obd_ioctl_data* data = buf;
39         obd_uuid_t server_uuid;
40         ENTRY;
41
42         if ( ptlbd->bd_import.imp_connection != NULL )
43                 RETURN(-EALREADY);
44
45         if (data->ioc_inllen1 < 1) {
46                 CERROR("requires a PTLBD server UUID\n");
47                 RETURN(-EINVAL);
48         }
49
50         if (data->ioc_inllen1 > 37) {
51                 CERROR("PTLBD server UUID must be less than 38 characters\n");
52                 RETURN(-EINVAL);
53         }
54
55         memcpy(server_uuid, data->ioc_inlbuf1, MIN(data->ioc_inllen1,
56                                                    sizeof(server_uuid)));
57
58         imp->imp_connection = ptlrpc_uuid_to_connection(server_uuid);
59         if (!imp->imp_connection)
60                 RETURN(-ENOENT);
61
62         INIT_LIST_HEAD(&imp->imp_replay_list);
63         INIT_LIST_HEAD(&imp->imp_sending_list);
64         INIT_LIST_HEAD(&imp->imp_delayed_list);
65         spin_lock_init(&imp->imp_lock);
66         /*
67          * from client_obd_connect.. *shrug*
68          */
69         INIT_LIST_HEAD(&imp->imp_chain);
70         imp->imp_last_xid = 0;
71         imp->imp_max_transno = 0;
72         imp->imp_peer_last_xid = 0;
73         imp->imp_peer_committed_transno = 0;
74         imp->imp_level = LUSTRE_CONN_FULL;
75
76         ptlrpc_init_client(PTLBD_REQUEST_PORTAL, PTLBD_REPLY_PORTAL, 
77                         "ptlbd", &ptlbd->bd_client);
78         imp->imp_client = &ptlbd->bd_client;
79         imp->imp_obd = obddev;
80
81         ptlbd_blk_register(ptlbd);
82
83         RETURN(0);
84 }
85
86 static int ptlbd_cl_cleanup(struct obd_device *obddev)
87 {
88 //        struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
89         ENTRY;
90
91         CERROR("I should be cleaning things up\n");
92
93         RETURN(0);
94 }
95
96 #if 0
97 static int ptlbd_cl_connect(struct lustre_handle *conn, struct obd_device *obd,
98                         obd_uuid_t cluuid, struct recovd_obd *recovd,
99                         ptlrpc_recovery_cb_t recover)
100 {
101         struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
102         struct obd_import *imp = &ptlbd->bd_import;
103         int rc;
104         ENTRY;
105
106         rc = class_connect(conn, obd, cluuid);
107         if (rc) 
108                 RETURN(rc);
109
110         INIT_LIST_HEAD(&imp->imp_chain);
111         imp->imp_last_xid = 0;
112         imp->imp_max_transno = 0;
113         imp->imp_peer_last_xid = 0;
114         imp->imp_peer_committed_transno = 0;
115         imp->imp_level = LUSTRE_CONN_FULL;
116
117         RETURN(0);
118 }
119 #endif
120
121 static struct obd_ops ptlbd_cl_obd_ops = {
122         o_owner:        THIS_MODULE,
123         o_setup:        ptlbd_cl_setup,
124         o_cleanup:      ptlbd_cl_cleanup,
125 #if 0
126         o_connect:      ptlbd_cl_connect,
127         o_disconnect:   class_disconnect
128 #endif
129 };
130
131 int ptlbd_cl_init(void)
132 {
133         extern struct lprocfs_vars status_class_var[];
134
135         return class_register_type(&ptlbd_cl_obd_ops, status_class_var,
136                                    OBD_PTLBD_CL_DEVICENAME);
137 }
138
139 void ptlbd_cl_exit(void)
140 {
141         class_unregister_type(OBD_PTLBD_CL_DEVICENAME);
142 }