1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 klonal_data_t klonal_data;
26 ptl_handle_ni_t klonal_ni;
30 klonal_cmd (struct portals_cfg *pcfg, void *private)
32 LASSERT (pcfg != NULL);
34 switch (pcfg->pcfg_command) {
35 case NAL_CMD_REGISTER_MYNID:
36 CDEBUG (D_IOCTL, "setting NID to "LPX64" (was "LPX64")\n",
37 pcfg->pcfg_nid, klonal_lib.libnal_ni.ni_pid.nid);
38 klonal_lib.libnal_ni.ni_pid.nid = pcfg->pcfg_nid;
47 klonal_shutdown(nal_t *nal)
49 /* NB The first ref was this module! */
50 if (nal->nal_refct != 0)
53 CDEBUG (D_NET, "shutdown\n");
54 LASSERT (nal == &klonal_api);
56 switch (klonal_data.klo_init)
62 libcfs_nal_cmd_unregister(LONAL);
66 lib_fini (&klonal_lib);
69 case KLO_INIT_NOTHING:
73 memset(&klonal_data, 0, sizeof (klonal_data));
75 CDEBUG (D_MALLOC, "done kmem %d\n", atomic_read(&portal_kmemory));
77 printk (KERN_INFO "Lustre: LO NAL unloaded (final mem %d)\n",
78 atomic_read(&portal_kmemory));
83 klonal_startup (nal_t *nal, ptl_pid_t requested_pid,
84 ptl_ni_limits_t *requested_limits,
85 ptl_ni_limits_t *actual_limits)
88 ptl_process_id_t my_process_id;
89 int pkmem = atomic_read(&portal_kmemory);
91 LASSERT (nal == &klonal_api);
93 if (nal->nal_refct != 0) {
94 if (actual_limits != NULL)
95 *actual_limits = klonal_lib.libnal_ni.ni_actual_limits;
99 LASSERT (klonal_data.klo_init == KLO_INIT_NOTHING);
101 CDEBUG (D_MALLOC, "start kmem %d\n", atomic_read(&portal_kmemory));
103 /* ensure all pointers NULL etc */
104 memset (&klonal_data, 0, sizeof (klonal_data));
106 my_process_id.nid = 0;
107 my_process_id.pid = requested_pid;
109 rc = lib_init(&klonal_lib, nal, my_process_id,
110 requested_limits, actual_limits);
112 CERROR ("lib_init failed %d\n", rc);
113 klonal_shutdown (nal);
117 klonal_data.klo_init = KLO_INIT_LIB;
119 rc = libcfs_nal_cmd_register (LONAL, &klonal_cmd, NULL);
121 CERROR ("Can't initialise command interface (rc = %d)\n", rc);
122 klonal_shutdown (nal);
126 klonal_data.klo_init = KLO_INIT_ALL;
128 printk(KERN_INFO "Lustre: LO NAL (initial mem %d)\n", pkmem);
135 klonal_finalise (void)
137 PtlNIFini(klonal_ni);
139 ptl_unregister_nal(LONAL);
143 klonal_initialise (void)
147 klonal_api.nal_ni_init = klonal_startup;
148 klonal_api.nal_ni_fini = klonal_shutdown;
150 rc = ptl_register_nal(LONAL, &klonal_api);
152 CERROR("Can't register LONAL: %d\n", rc);
153 return (-ENOMEM); /* or something... */
159 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
160 MODULE_DESCRIPTION("Loopback NAL v0.01");
161 MODULE_LICENSE("GPL");
163 module_init (klonal_initialise);
164 module_exit (klonal_finalise);