Whamcloud - gitweb
Merge b_md into HEAD
[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, 2003 Cluster File Systems, Inc.
5  *   Author: Zach Brown <zab@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <linux/version.h>
24 #include <linux/module.h>
25 #include <linux/fs.h>
26
27 #define DEBUG_SUBSYSTEM S_PTLBD
28
29 #include <linux/obd_support.h>
30 #include <linux/obd_class.h>
31 #include <linux/lustre_debug.h>
32 #include <linux/lprocfs_status.h>
33 #include <linux/obd_ptlbd.h>
34
35 static int ptlbd_cl_setup(struct obd_device *obddev, obd_count len, void *buf)
36 {
37         struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
38         struct obd_import *imp = &ptlbd->bd_import;
39         struct obd_ioctl_data* data = buf;
40         struct obd_uuid server_uuid;
41         ENTRY;
42
43         if ( ptlbd->bd_import.imp_connection != NULL )
44                 RETURN(-EALREADY);
45
46         if (data->ioc_inllen1 < 1) {
47                 CERROR("requires a PTLBD server UUID\n");
48                 RETURN(-EINVAL);
49         }
50
51         if (data->ioc_inllen1 > 37) {
52                 CERROR("PTLBD server UUID must be less than 38 characters\n");
53                 RETURN(-EINVAL);
54         }
55
56         obd_str2uuid(&server_uuid, data->ioc_inlbuf1);
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_committed_transno = 0;
73         imp->imp_level = LUSTRE_CONN_FULL;
74
75         ptlrpc_init_client(PTLBD_REQUEST_PORTAL, PTLBD_REPLY_PORTAL, 
76                         "ptlbd", &ptlbd->bd_client);
77         imp->imp_client = &ptlbd->bd_client;
78         imp->imp_obd = obddev;
79
80         ptlbd_blk_register(ptlbd);
81
82         RETURN(0);
83 }
84
85 static int ptlbd_cl_cleanup(struct obd_device *obddev)
86 {
87 //        struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
88         ENTRY;
89
90         CERROR("I should be cleaning things up\n");
91
92         RETURN(0);
93 }
94
95 #if 0
96 static int ptlbd_cl_connect(struct lustre_handle *conn, struct obd_device *obd,
97                         struct obd_uuid cluuid, struct recovd_obd *recovd,
98                         ptlrpc_recovery_cb_t recover)
99 {
100         struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
101         struct obd_import *imp = &ptlbd->bd_import;
102         int rc;
103         ENTRY;
104
105         rc = class_connect(conn, obd, cluuid);
106         if (rc)
107                 RETURN(rc);
108
109         INIT_LIST_HEAD(&imp->imp_chain);
110         imp->imp_last_xid = 0;
111         imp->imp_max_transno = 0;
112         imp->imp_peer_last_xid = 0;
113         imp->imp_peer_committed_transno = 0;
114         imp->imp_level = LUSTRE_CONN_FULL;
115
116         RETURN(0);
117 }
118 #endif
119
120 static struct obd_ops ptlbd_cl_obd_ops = {
121         o_owner:        THIS_MODULE,
122         o_setup:        ptlbd_cl_setup,
123         o_cleanup:      ptlbd_cl_cleanup,
124 #if 0
125         o_connect:      ptlbd_cl_connect,
126         o_disconnect:   class_disconnect
127 #endif
128 };
129
130 int ptlbd_cl_init(void)
131 {
132         struct lprocfs_static_vars lvars;
133
134         lprocfs_init_vars(&lvars);
135         return class_register_type(&ptlbd_cl_obd_ops, lvars.module_vars,
136                                    OBD_PTLBD_CL_DEVICENAME);
137 }
138
139 void ptlbd_cl_exit(void)
140 {
141         class_unregister_type(OBD_PTLBD_CL_DEVICENAME);
142 }