source: gpfs_3.1_ker2.6.20/lpp/mmfs/src/gpl-linux/gplInit.c @ 214

Last change on this file since 214 was 16, checked in by rock, 17 years ago
File size: 12.0 KB
Line 
1/***************************************************************************
2 *
3 * Copyright (C) 2001 International Business Machines
4 * All rights reserved.
5 *
6 * This file is part of the GPFS mmfslinux kernel module.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 *  1. Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *  2. Redistributions in binary form must reproduce the above copyright
15 *     notice, this list of conditions and the following disclaimer in the
16 *     documentation and/or other materials provided with the distribution.
17 *  3. The name of the author may not be used to endorse or promote products
18 *     derived from this software without specific prior written
19 *     permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *************************************************************************** */
33/* @(#)68       1.66.1.13  src/avs/fs/mmfs/ts/kernext/gpl-linux/gplInit.c, mmfs, avs_rgpfs24, rgpfs24s012a 4/6/07 16:11:44 */
34/*
35 * Initialize the linux module
36 *
37 */
38
39#include <Shark-gpl.h>
40
41#include <linux/types.h>
42#include <linux/string.h>
43#include <linux/version.h>
44#include <linux/kernel.h>
45#include <linux/module.h>
46#include <linux/init.h>
47
48#include <verdep.h>
49#include <cxiSystem.h>
50#include <cxi2gpfs.h>
51#include <linux2gpfs.h>
52#include <cxiIOBuffer.h>
53#include <cxiSharedSeg.h>
54#include <Trace.h>
55
56extern char *prog_path;
57
58struct gpfs_operations gpfs_ops;
59
60/* This string must match (in the strcmp sense) PRODUCT_VERSION defined
61   in prodname.h.  It is used to make sure that mmfslinux module matches
62   the rest of the code. */
63#define PRODUCT_VERSION "3.1.0.12 "
64
65#ifdef MODULE
66
67#if (LINUX_KERNEL_VERSION >= 2040900)
68MODULE_LICENSE("GPL");
69MODULE_DESCRIPTION ("GPFS portability layer");
70MODULE_AUTHOR ("IBM <gpfs@us.ibm.com>");
71#endif
72
73/* The module pointer for the mmfs module.  Exported
74 * to the mmfs portability layer module.  Its reference
75 * counts are updated via cxiIncModuleCounter().
76 */
77static struct module *ibmModule = 0;
78static struct module *ibmModuleLoaded = 0;
79
80void 
81cxiExportModuleStruct(void *modAddr)
82{
83  ibmModule = (struct module *)modAddr;
84}
85
86void 
87cxiIncModuleCounter(int up)
88{
89  TRACE2(TRACE_VNODE, 1, TRCID_CXIINC_COUNTER,
90         "cxiIncModuleCounter: ibmModule 0x%X up %d\n",
91         ibmModule, up);
92
93  if (ibmModule)
94  {
95    if (up)
96    {
97      MODULE_INCREMENT(ibmModule);
98      ibmModuleLoaded = ibmModule;
99    }
100    else if (ibmModuleLoaded)
101      MODULE_DECREMENT(ibmModule);
102  }
103}
104
105#else /* ! MODULE */
106
107static void *ibmModule = 0;
108void cxiExportModuleStruct(void *modAddr) {};
109void cxiIncModuleCounter(int up) {};
110
111#endif /* MODULE */
112
113extern char bin_path[CXI_MAXPATHLEN+1];
114extern char mmfs_path[CXI_MAXPATHLEN+1];
115extern int mmfsd_module_active;
116
117
118/* Dummy operations for initializing gpfs_operations table.
119   Using this dummy operation instead of storing a NULL function pointer
120   avoids having to check for NULL before each call. */
121void 
122gpfs_void_op()
123{
124}
125
126int 
127gpfs_enosys_op()
128{
129  return ENOSYS;
130}
131
132int 
133gpfs_zero_op()
134{
135  return 0;
136}
137
138void *
139gpfs_nullptr_op()
140{
141  return NULL;
142}
143
144typedef void   (*VoidFnP)();
145typedef int    (*IntFnP)();
146typedef void * (*PtrFnP)();
147
148/* initialize gpfs_operations table */
149void
150reset_gpfs_operations()
151{
152  gpfs_ops.mmfs = 0;
153  * (IntFnP *) & gpfs_ops.gpfsMount = (IntFnP)gpfs_enosys_op;
154  * (IntFnP *) & gpfs_ops.gpfsStatfs = (IntFnP)gpfs_enosys_op;
155  * (IntFnP *) & gpfs_ops.gpfsSyncfs = (IntFnP)gpfs_enosys_op;
156  * (IntFnP *) & gpfs_ops.gpfsFsync = (IntFnP)gpfs_enosys_op;
157  * (IntFnP *) & gpfs_ops.gpfsSyncNFS = (IntFnP)gpfs_enosys_op;
158  * (IntFnP *) & gpfs_ops.gpfsMkdir = (IntFnP)gpfs_enosys_op;
159  * (IntFnP *) & gpfs_ops.gpfsLink = (IntFnP)gpfs_enosys_op;
160  * (IntFnP *) & gpfs_ops.gpfsOpen = (IntFnP)gpfs_enosys_op;
161  * (IntFnP *) & gpfs_ops.gpfsInodeRead = (IntFnP)gpfs_enosys_op;
162  * (IntFnP *) & gpfs_ops.gpfsInodeDelete = (IntFnP)gpfs_enosys_op;
163  * (IntFnP *) & gpfs_ops.gpfsInodeFindActor = (IntFnP)gpfs_zero_op;
164  * (IntFnP *) & gpfs_ops.gpfsGetSnapIdPair = (IntFnP)gpfs_enosys_op;
165  * (IntFnP *) & gpfs_ops.gpfsRemove = (IntFnP)gpfs_enosys_op;
166  * (IntFnP *) & gpfs_ops.gpfsRename = (IntFnP)gpfs_enosys_op;
167  * (IntFnP *) & gpfs_ops.gpfsRmdir = (IntFnP)gpfs_enosys_op;
168  * (IntFnP *) & gpfs_ops.gpfsSetattr = (IntFnP)gpfs_enosys_op;
169  * (IntFnP *) & gpfs_ops.gpfsSymlink = (IntFnP)gpfs_enosys_op;
170  * (IntFnP *) & gpfs_ops.gpfsFsyncRange = (IntFnP)gpfs_enosys_op;
171  * (IntFnP *) & gpfs_ops.gpfsClose = (IntFnP)gpfs_enosys_op;
172  * (IntFnP *) & gpfs_ops.gpfsUnmap = (IntFnP)gpfs_enosys_op;
173  * (IntFnP *) & gpfs_ops.gpfsFattr = (IntFnP)gpfs_enosys_op;
174  * (IntFnP *) & gpfs_ops.gpfsFsAttr = (IntFnP)gpfs_enosys_op;
175  * (IntFnP *) & gpfs_ops.gpfsFclear = (IntFnP)gpfs_enosys_op;
176  * (IntFnP *) & gpfs_ops.gpfsFtrunc = (IntFnP)gpfs_enosys_op;
177  * (IntFnP *) & gpfs_ops.gpfsRead = (IntFnP)gpfs_enosys_op;
178  * (IntFnP *) & gpfs_ops.gpfsWrite = (IntFnP)gpfs_enosys_op;
179  * (IntFnP *) & gpfs_ops.gpfsGetattr = (IntFnP)gpfs_enosys_op;
180  * (IntFnP *) & gpfs_ops.gpfsAccess = (IntFnP)gpfs_enosys_op;
181  * (IntFnP *) & gpfs_ops.gpfsReaddir = (IntFnP)gpfs_enosys_op;
182  * (IntFnP *) & gpfs_ops.gpfsReadlink = (IntFnP)gpfs_enosys_op;
183  * (IntFnP *) & gpfs_ops.gpfsCreate = (IntFnP)gpfs_enosys_op;
184  * (IntFnP *) & gpfs_ops.gpfsMknod = (IntFnP)gpfs_enosys_op;
185  * (IntFnP *) & gpfs_ops.gpfsRele = (IntFnP)gpfs_enosys_op;
186  * (IntFnP *) & gpfs_ops.gpfsLookup = (IntFnP)gpfs_enosys_op;
187  * (IntFnP *) & gpfs_ops.gpfsFcntl = (IntFnP)gpfs_enosys_op;
188  * (IntFnP *) & gpfs_ops.gpfsUncache = (IntFnP)gpfs_enosys_op;
189  * (IntFnP *) & gpfs_ops.gpfsUnmount = (IntFnP)gpfs_enosys_op;
190  * (VoidFnP*) & gpfs_ops.gpfsFinishUnmount = (VoidFnP)gpfs_void_op;
191#ifdef NFS4_CLUSTER
192  * (IntFnP*) & gpfs_ops.gpfsFsLocations = (IntFnP)gpfs_enosys_op;
193#endif
194  * (IntFnP *) & gpfs_ops.gpfsFcntlReset = (IntFnP)gpfs_enosys_op;
195  * (IntFnP *) & gpfs_ops.gpfsGetAcl = (IntFnP)gpfs_enosys_op;
196  * (IntFnP *) & gpfs_ops.gpfsPutAcl = (IntFnP)gpfs_enosys_op;
197  * (IntFnP *) & gpfs_ops.gpfsGetNFS = (IntFnP)gpfs_enosys_op;
198  * (IntFnP *) & gpfs_ops.gpfsReleaseNFS = (IntFnP)gpfs_enosys_op;
199  * (IntFnP *) & gpfs_ops.gpfsReady = (IntFnP)gpfs_enosys_op;
200  * (IntFnP *) & gpfs_ops.gpfsMmap = (IntFnP)gpfs_enosys_op;
201#ifdef SMB_LOCKS
202  * (IntFnP *) & gpfs_ops.SMBOpenLockControl = (IntFnP)gpfs_enosys_op;
203  * (IntFnP *) & gpfs_ops.SMBGetOplockState = (IntFnP)gpfs_enosys_op;
204  * (IntFnP *) & gpfs_ops.SMBGetOplockStateV = (IntFnP)gpfs_enosys_op;
205  * (IntFnP *) & gpfs_ops.gpfsSetSMBOplock = (IntFnP)gpfs_enosys_op;
206  * (IntFnP *) & gpfs_ops.gpfsReserveShare = (IntFnP)gpfs_enosys_op;
207  * (IntFnP *) & gpfs_ops.gpfsReserveDelegation = (IntFnP)gpfs_enosys_op;
208#endif
209  * (IntFnP *) & gpfs_ops.gpfsDaemonToDie = (IntFnP)gpfs_enosys_op;
210  * (IntFnP *) & gpfs_ops.gpfsCleanup = (IntFnP)gpfs_enosys_op;
211#ifdef UIDREMAP
212  * (IntFnP *) & gpfs_ops.UIDremapOn = (IntFnP)gpfs_enosys_op;
213#endif
214  * (VoidFnP*) & gpfs_ops.gpfsSwapdEnqueue = (VoidFnP)gpfs_enosys_op;
215  * (VoidFnP*) & gpfs_ops.gpfsQueueBufs = (VoidFnP)gpfs_enosys_op;
216  * (VoidFnP*) & gpfs_ops.gpfsMmapFlushLock = (VoidFnP)gpfs_enosys_op;
217  * (VoidFnP*) & gpfs_ops.gpfsMmapFlushUnlock = (VoidFnP)gpfs_enosys_op;
218#ifdef DMAPI
219  * (VoidFnP*) & gpfs_ops.gpfsDmUnmountEvent = (VoidFnP)gpfs_enosys_op;
220#endif
221  * (VoidFnP*) & gpfs_ops.gpfsNFSIget = (VoidFnP)gpfs_enosys_op;
222  * (IntFnP *) & gpfs_ops.gpfsOpenNFS = (IntFnP)gpfs_enosys_op;
223  * (VoidFnP*) & gpfs_ops.gpfsGrace = (VoidFnP)gpfs_enosys_op;
224#ifdef P_NFS4
225  * (IntFnP *) & gpfs_ops.gpfsGetDeviceList = (IntFnP)gpfs_enosys_op;
226  * (IntFnP *) & gpfs_ops.gpfsGetLayout = (IntFnP)gpfs_enosys_op;
227  * (IntFnP *) & gpfs_ops.gpfsGetOpenState = (IntFnP)gpfs_enosys_op;
228  * (IntFnP *) & gpfs_ops.gpfsLayoutRetrun = (IntFnP)gpfs_enosys_op;
229  * (IntFnP *) & gpfs_ops.gpfsGetDeviceInfo = (IntFnP)gpfs_enosys_op;
230  * (IntFnP *) & gpfs_ops.gpfsGetMyDevID = (IntFnP)gpfs_enosys_op;
231  * (VoidFnP *) & gpfs_ops.gpfsGetVerifier = (IntFnP)gpfs_enosys_op;
232#endif
233#ifdef GPFS_QUOTACTL
234 * (IntFnP *) & gpfs_ops.gpfsQuotactl = (IntFnP)gpfs_enosys_op;
235#endif
236};
237
238void 
239gpfs_clean()
240{
241  kill_mmfsd();
242  if (gpfs_ops.mmfs)
243  {
244    gpfs_ops.mmfs(CFG_TERM);
245  }
246  gpfs_unreg_fs();
247
248#if LINUX_KERNEL_VERSION < 2050000
249  /* GPFS on Linux 2.5 uses an anonymous mount */
250  gpfs_block_clean();
251#endif
252}
253
254int 
255gpfs_init()
256{
257  if (strlen(prog_path) > CXI_MAXPATHLEN)
258  {
259    TRACE2(TRACE_SHARED, 0, TRCID_GPFSINIT_000,
260         "gpfs_init: prog_path %s length %d too long\n",
261         prog_path, strlen(prog_path));
262    return -1;
263  }
264
265#if LINUX_KERNEL_VERSION < 2050000
266  /* GPFS on Linux 2.5 uses an anonymous mount */
267  if (gpfs_block_init())
268    return -1;
269
270  if (gpfs_reg_fs())
271  {
272    gpfs_block_clean();
273    return -1;
274  }
275#else
276  if (gpfs_reg_fs())
277    return -1;
278#endif
279 
280  if (gpfs_ops.mmfs)
281  {
282    if (gpfs_ops.mmfs(CFG_INIT))
283    {
284      gpfs_clean();
285      return -1;
286    }
287  }
288  else
289    return -1;
290
291  strcpy(bin_path, prog_path);
292  return 0;
293}
294
295int cxiCheckProductVersion(const char* mmfsProductVersion)
296{
297  if (cxiStrcmp(mmfsProductVersion, PRODUCT_VERSION) != 0)
298  {
299    TRACE2(TRACE_VNODE, 0, TRCID_PRODVER_MISMATCH,
300           "mmfslinux product version %s does not match mmfs version %s",
301           PRODUCT_VERSION, mmfsProductVersion);
302
303    /* Since getting a trace of an early startup failure is awkward,
304       we should make the issue more obvious. */
305    printk("GPFS mmfslinux product version %s does not match mmfs version %s",
306           PRODUCT_VERSION, mmfsProductVersion);
307
308    return EINVAL;
309  }
310
311  return 0;
312}
313
314int cxiCheckSiteMcrVersion(const char* siteMcrVersion)
315{
316  if (cxiStrcmp(siteMcrVersion, SITEMCRREV) != 0)
317  {
318    TRACE2(TRACE_VNODE, 0, TRCID_STEMCRVER_MISMATCH,
319           "mmfslinux was built with site.mcr rev %s which does not match "
320           "the site.mcr version %s used to build mmfs",
321           SITEMCRREV, siteMcrVersion);
322                                                                               
323    /* Since getting a trace of an early startup failure is awkward,
324       we should make the issue more obvious. */
325    printk("mmfslinux was built with site.mcr rev %s which does not match "
326           "the site.mcr version %s used to build mmfs",
327           SITEMCRREV, siteMcrVersion);
328
329    return EINVAL;
330  }
331                                                                               
332  return 0;
333}
334
335/* Module initialization */
336MY_INIT_FUNCTION()
337{
338  int i;
339
340#ifdef KSTACK_CHECK
341  shInit();
342#endif
343
344#ifdef MALLOC_DEBUG
345  MallocDebugStart();
346#endif
347
348  for (i=0 ; i<MAX_TRACE_CLASSES ; i++)
349     TraceFlagsP[i] = 9;
350
351#ifdef INSTRUMENT_LOCKS
352  InitBlockingMutexStats();
353#endif
354
355  InitSharedMemory();
356
357  reset_gpfs_operations();
358
359  TRACE1(TRACE_SHARED, 0, TRCID_PORTINIT_001,
360         "init_module: prog_path %s\n",
361         prog_path == NULL ? "NULL" : prog_path);
362
363  /* Ensure types are the correct size */
364  if (cxiCheckTypes())
365  {
366    CleanUpSharedMemory();
367    return -1;
368  }
369
370  if (ss_init())
371  {
372    CleanUpSharedMemory();
373    return -1;
374  }
375
376  gpfs_proc_export_init();
377
378  KibdModuleInit();
379   
380#ifdef API_32BIT
381  gpfs_reg_ioctl32();
382#endif
383
384  return 0;
385}
386
387/* Module unload */
388MY_EXIT_FUNCTION()
389{
390#ifdef API_32BIT
391  gpfs_unreg_ioctl32();
392#endif
393
394  gpfs_proc_export_term();
395
396  KibdModuleTerm();
397
398  TermSharedMemory();
399
400#ifdef MALLOC_DEBUG
401  MallocDebugEnd();
402#endif
403
404#ifdef KSTACK_CHECK
405  shTerm();
406#endif
407}
408
409DEFINE_MODULE_INIT();
410DEFINE_MODULE_EXIT();
411
Note: See TracBrowser for help on using the repository browser.