File: module.c

package info (click to toggle)
open-vm-tools 1%3A8.4.2-261024-1%2Bbuild1
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze-lts
  • size: 20,376 kB
  • ctags: 30,043
  • sloc: ansic: 164,785; sh: 10,713; cpp: 6,525; makefile: 3,386
file content (168 lines) | stat: -rw-r--r-- 4,010 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*********************************************************
 * Copyright (C) 2006 VMware, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Common
 * Development and Distribution License (the "License") version 1.0
 * and no later version.  You may not use this file except in
 * compliance with the License.
 *
 * You can obtain a copy of the License at
 *         http://www.opensource.org/licenses/cddl1.php
 *
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 *********************************************************/


/*
 * module.c --
 *
 *      Main loading and unloading of kernel module.
 */

#include <sys/errno.h>

#include "module.h"
#include "block.h"

static vfsdef_t VMBlockVfsDef = {
   VFSDEF_VERSION,         /* Structure version: defined in <sys/vfs.h> */
   VMBLOCK_FS_NAME,        /* Name of file system */
   VMBlockInit,            /* File system initialization routine */
   VMBLOCK_VFSSW_FLAGS,    /* File system flags */
   NULL                    /* No mount options */
};

/* Filesystem module structure */
static struct modlfs VMBlockModlfs = {
   &mod_fsops,             /* Module operation structure: for
                            * auto loading/unloading */
   "VMBlock File system",  /* Name */
   &VMBlockVfsDef          /* Filesystem type definition record */
};

static struct modlinkage VMBlockModlinkage = {
   MODREV_1,            /* Module revision: must be MODREV_1 */
   {
      &VMBlockModlfs,   /* FS module structure */
      NULL,
   }
};

#ifdef VMX86_DEBUG
/* XXX: Figure out how to pass this in at module load time. */
int LOGLEVEL = 4;
#else
int LOGLEVEL = 0;
#endif

int vmblockType;
vnodeops_t *vmblockVnodeOps;




/*
 * Module loading/unloading/info functions.
 */


/*
 *----------------------------------------------------------------------------
 *
 * _init --
 *    Invoked when module is being loaded into kernel, and is called before
 *    any function in the module.  Any state that spans all instances of the
 *    driver should be allocated and initialized here.
 *
 * Results:
 *    Returns the result of mod_install(9F), which is zero on success and a
 *    non-zero value on failure.
 *
 * Side effects:
 *    None.
 *
 *----------------------------------------------------------------------------
 */

int
_init(void)
{
   int error;

   error = mod_install(&VMBlockModlinkage);
   if (error) {
      Warning("Could not install vmblock module.\n");
      return error;
   }

   error = BlockInit();
   if (error) {
      Warning("Could not initialize blocking.\n");
      mod_remove(&VMBlockModlinkage);
      return error;
   }

   return 0;
}


/*
 *----------------------------------------------------------------------------
 *
 * _fini --
 *    Invoked when a module is being removed from the kernel.
 *
 * Results:
 *    Returns the result of mod_remove(9F), which is zero on success, and a
 *    non-zero value on failure.
 *
 * Side effects:
 *    The module will be removed from the kernel.
 *
 *----------------------------------------------------------------------------
 */

int
_fini(void)
{
   int error;

   error = mod_remove(&VMBlockModlinkage);
   if (error) {
      Warning("Could not remove vmblock module.\n");
      return error;
   }

   BlockCleanup();
   vfs_freevfsops_by_type(vmblockType);
   vn_freevnodeops(vmblockVnodeOps);

   return 0;
}


/*
 *----------------------------------------------------------------------------
 *
 * _info --
 *
 *    Invoked when the modinfo(1M) command is executed.  mod_info(9F) handles
 *    this for us.
 *
 * Results:
 *    Returns mod_info(9F)'s results, which are a non-zero value on success, and
 *    zero on failure.
 *
 * Side effects:
 *    None.
 *
 *----------------------------------------------------------------------------
 */

int
_info(struct modinfo *modinfop) // OUT: Filled in with module's information
{
   return mod_info(&VMBlockModlinkage, modinfop);
}