Whamcloud - gitweb
Land b_smallfix onto HEAD (20040416_1638) (more 2.6 build fixes)
[fs/lustre-release.git] / lustre / ptlbd / server.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 #define BACKING_FILE    "/tmp/ptlbd-backing-file-la-la-la"
36
37 static int ptlbd_sv_already_setup = 1;
38
39 static int ptlbd_sv_setup(struct obd_device *obd, obd_count len, void *buf)
40 {
41         struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
42         struct lprocfs_static_vars lvars;
43         int rc;
44         ENTRY;
45
46         ptlbd->filp = filp_open(BACKING_FILE,
47                                         O_RDWR|O_CREAT|O_LARGEFILE, 0600);
48
49         if ( IS_ERR(ptlbd->filp) )
50                 RETURN(PTR_ERR(ptlbd->filp));
51
52         lprocfs_init_vars(ptlbd_sv, &lvars);
53         lprocfs_obd_setup(obd, lvars.obd_vars);
54
55         ptlbd->ptlbd_service =
56                 ptlrpc_init_svc(PTLBD_NBUFS, PTLBD_BUFSIZE, PTLBD_MAXREQSIZE,
57                                 PTLBD_REQUEST_PORTAL, PTLBD_REPLY_PORTAL,
58                                 ptlbd_handle, "ptlbd_sv",
59                                 obd->obd_proc_entry);
60
61         if (ptlbd->ptlbd_service == NULL)
62                 GOTO(out_filp, rc = -ENOMEM);
63
64         rc = ptlrpc_start_n_threads(obd, ptlbd->ptlbd_service, 1, "ptldb");
65         if (rc != 0)
66                 GOTO(out_thread, rc);
67
68         ptlbd_sv_already_setup = 1;
69
70         RETURN(0);
71
72 out_thread:
73         ptlrpc_unregister_service(ptlbd->ptlbd_service);
74 out_filp:
75         filp_close(ptlbd->filp, NULL);
76         lprocfs_obd_cleanup(obd);
77
78         RETURN(rc);
79 }
80
81 static int ptlbd_sv_cleanup(struct obd_device *obd, int flags)
82 {
83         struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
84         ENTRY;
85
86         /* XXX check for state */
87
88         ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
89         ptlrpc_unregister_service(ptlbd->ptlbd_service);
90         if ( ! IS_ERR(ptlbd->filp) )
91                 filp_close(ptlbd->filp, NULL);
92
93         ptlbd_sv_already_setup = 0;
94
95         lprocfs_obd_cleanup(obd);
96
97         RETURN(0);
98 }
99
100 static struct obd_ops ptlbd_sv_obd_ops = {
101         .o_owner        = THIS_MODULE,
102         .o_setup        = ptlbd_sv_setup,
103         .o_cleanup      = ptlbd_sv_cleanup,
104         .o_connect      = class_connect,
105         .o_disconnect   = class_disconnect,
106 };
107
108 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
109 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
110 LPROCFS_INIT_VARS(ptlbd_sv, lprocfs_module_vars, lprocfs_obd_vars)
111
112 int ptlbd_sv_init(void)
113 {
114         struct lprocfs_static_vars lvars;
115
116         lprocfs_init_vars(ptlbd_sv,&lvars);
117         return class_register_type(&ptlbd_sv_obd_ops, lvars.module_vars,
118                                    OBD_PTLBD_SV_DEVICENAME);
119 }
120
121 void ptlbd_sv_exit(void)
122 {
123         class_unregister_type(OBD_PTLBD_SV_DEVICENAME);
124 }