1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Zach Brown <zab@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
23 #include <linux/version.h>
24 #include <linux/module.h>
27 #define DEBUG_SUBSYSTEM S_PTLBD
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>
35 static int ptlbd_sv_already_setup = 1;
37 static int ptlbd_sv_setup(struct obd_device *obddev, obd_count len, void *buf)
39 struct obd_uuid self_uuid = { "self" };
40 struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
44 ptlbd->filp = filp_open("/tmp/ptlbd-backing-file-la-la-la",
45 O_RDWR|O_CREAT, 0600);
46 if ( IS_ERR(ptlbd->filp) )
47 RETURN(PTR_ERR(ptlbd->filp));
49 ptlbd->ptlbd_service =
50 ptlrpc_init_svc(PTLBD_NEVENTS, PTLBD_NBUFS, PTLBD_BUFSIZE,
51 PTLBD_MAXREQSIZE, PTLBD_REQUEST_PORTAL,
52 PTLBD_REPLY_PORTAL, &self_uuid,
53 ptlbd_parse_req, "ptlbd_sv");
55 if (ptlbd->ptlbd_service == NULL)
56 GOTO(out_filp, rc = -ENOMEM);
58 rc = ptlrpc_start_thread(obddev, ptlbd->ptlbd_service, "ptldb");
62 ptlbd_sv_already_setup = 1;
67 ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
68 ptlrpc_unregister_service(ptlbd->ptlbd_service);
70 filp_close(ptlbd->filp, NULL);
75 static int ptlbd_sv_cleanup(struct obd_device *obddev)
77 struct ptlbd_obd *ptlbd = &obddev->u.ptlbd;
80 /* XXX check for state */
82 ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
83 ptlrpc_unregister_service(ptlbd->ptlbd_service);
84 if ( ! IS_ERR(ptlbd->filp) )
85 filp_close(ptlbd->filp, NULL);
87 ptlbd_sv_already_setup = 0;
91 static struct obd_ops ptlbd_sv_obd_ops = {
93 o_setup: ptlbd_sv_setup,
94 o_cleanup: ptlbd_sv_cleanup,
97 int ptlbd_sv_init(void)
99 struct lprocfs_static_vars lvars;
101 lprocfs_init_vars(&lvars);
102 return class_register_type(&ptlbd_sv_obd_ops, lvars.module_vars,
103 OBD_PTLBD_SV_DEVICENAME);
106 void ptlbd_sv_exit(void)
108 class_unregister_type(OBD_PTLBD_SV_DEVICENAME);