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 #define BACKING_FILE "/tmp/ptlbd-backing-file-la-la-la"
37 static int ptlbd_sv_already_setup = 1;
39 static int ptlbd_sv_attach(struct obd_device *obd, obd_count len, void *buf)
41 struct lprocfs_static_vars lvars;
43 lprocfs_init_vars(ptlbd_sv, &lvars);
44 return lprocfs_obd_attach(obd, lvars.obd_vars);
47 static int ptlbd_sv_detach(struct obd_device *obd)
49 return lprocfs_obd_detach(obd);
52 static int ptlbd_sv_setup(struct obd_device *obd, obd_count len, void *buf)
54 struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
58 ptlbd->filp = filp_open(BACKING_FILE,
59 O_RDWR|O_CREAT|O_LARGEFILE, 0600);
61 if ( IS_ERR(ptlbd->filp) )
62 RETURN(PTR_ERR(ptlbd->filp));
64 ptlbd->ptlbd_service =
65 ptlrpc_init_svc(PTLBD_NBUFS, PTLBD_BUFSIZE, PTLBD_MAXREQSIZE,
66 PTLBD_REQUEST_PORTAL, PTLBD_REPLY_PORTAL, 30000,
67 ptlbd_handle, "ptlbd_sv",
70 if (ptlbd->ptlbd_service == NULL)
71 GOTO(out_filp, rc = -ENOMEM);
73 rc = ptlrpc_start_n_threads(obd, ptlbd->ptlbd_service, 1, "ptldb");
77 ptlbd_sv_already_setup = 1;
82 ptlrpc_unregister_service(ptlbd->ptlbd_service);
84 filp_close(ptlbd->filp, NULL);
88 static int ptlbd_sv_cleanup(struct obd_device *obd, int flags)
90 struct ptlbd_obd *ptlbd = &obd->u.ptlbd;
93 /* XXX check for state */
94 ptlrpc_stop_all_threads(ptlbd->ptlbd_service);
95 ptlrpc_unregister_service(ptlbd->ptlbd_service);
96 if ( ! IS_ERR(ptlbd->filp) )
97 filp_close(ptlbd->filp, NULL);
99 ptlbd_sv_already_setup = 0;
103 static int ptlbd_connect(struct lustre_handle *conn, struct obd_device *obd,
104 struct obd_uuid *cluuid, unsigned long connect_flags)
108 rc = class_connect(conn, obd, cluuid);
112 static struct obd_ops ptlbd_sv_obd_ops = {
113 .o_owner = THIS_MODULE,
114 .o_attach = ptlbd_sv_attach,
115 .o_detach = ptlbd_sv_detach,
116 .o_setup = ptlbd_sv_setup,
117 .o_cleanup = ptlbd_sv_cleanup,
118 .o_connect = ptlbd_connect,
119 .o_disconnect = class_disconnect,
122 static struct lprocfs_vars lprocfs_obd_vars[] = { {0} };
123 static struct lprocfs_vars lprocfs_module_vars[] = { {0} };
124 LPROCFS_INIT_VARS(ptlbd_sv, lprocfs_module_vars, lprocfs_obd_vars)
126 int ptlbd_sv_init(void)
128 struct lprocfs_static_vars lvars;
130 lprocfs_init_vars(ptlbd_sv,&lvars);
131 return class_register_type(&ptlbd_sv_obd_ops, NULL, lvars.module_vars,
132 OBD_PTLBD_SV_DEVICENAME);
135 void ptlbd_sv_exit(void)
137 class_unregister_type(OBD_PTLBD_SV_DEVICENAME);