Whamcloud - gitweb
793354d07d79ec11f58b5c6f4ea82ef78faa1cce
[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 static int ptlbd_sv_already_setup = 1;
36
37 static int ptlbd_sv_setup(struct obd_device *obddev, obd_count len, void *buf)
38 {
39         struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
40         int rc;
41         ENTRY;
42
43         ptlbd->filp = filp_open("/tmp/ptlbd-backing-file-la-la-la", 
44                                         O_RDWR|O_CREAT, 0600);
45         if ( IS_ERR(ptlbd->filp) )
46                 RETURN(PTR_ERR(ptlbd->filp));
47
48         ptlbd->ptlbd_service =
49                 ptlrpc_init_svc(PTLBD_NEVENTS, PTLBD_NBUFS, PTLBD_BUFSIZE,
50                                 PTLBD_MAXREQSIZE, PTLBD_REQUEST_PORTAL,
51                                 PTLBD_REPLY_PORTAL,
52                                 ptlbd_parse_req, "ptlbd_sv");
53
54         if (ptlbd->ptlbd_service == NULL) 
55                 GOTO(out_filp, rc = -ENOMEM);
56
57         rc = ptlrpc_start_thread(obddev, ptlbd->ptlbd_service, "ptldb");
58         if (rc != 0) 
59                 GOTO(out_thread, rc);
60
61         ptlbd_sv_already_setup = 1;
62
63         RETURN(0);
64
65 out_thread:
66         ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
67         ptlrpc_unregister_service(ptlbd->ptlbd_service);
68 out_filp:
69         filp_close(ptlbd->filp, NULL);
70
71         RETURN(rc);
72 }
73
74 static int ptlbd_sv_cleanup(struct obd_device *obddev)
75 {
76         struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
77         ENTRY;
78
79         /* XXX check for state */
80
81         ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
82         ptlrpc_unregister_service(ptlbd->ptlbd_service);
83         if ( ! IS_ERR(ptlbd->filp) )
84                 filp_close(ptlbd->filp, NULL);
85
86         ptlbd_sv_already_setup = 0;
87         RETURN(0);
88 }
89
90 static struct obd_ops ptlbd_sv_obd_ops = {
91         o_owner:        THIS_MODULE,
92         o_setup:        ptlbd_sv_setup,
93         o_cleanup:      ptlbd_sv_cleanup,
94 };
95
96 int ptlbd_sv_init(void)
97 {
98         struct lprocfs_static_vars lvars;
99
100         lprocfs_init_vars(&lvars);
101         return class_register_type(&ptlbd_sv_obd_ops, lvars.module_vars,
102                                    OBD_PTLBD_SV_DEVICENAME);
103 }
104
105 void ptlbd_sv_exit(void)
106 {
107         class_unregister_type(OBD_PTLBD_SV_DEVICENAME);
108 }