]>
Commit | Line | Data |
---|---|---|
274dcf55 MM |
1 | /* |
2 | * (C) 2001 Clemson University and The University of Chicago | |
3 | * | |
4 | * See COPYING in top-level directory. | |
5 | */ | |
6 | ||
7 | #include "protocol.h" | |
8 | #include "pvfs2-kernel.h" | |
9 | ||
10 | /* tags assigned to kernel upcall operations */ | |
11 | static __u64 next_tag_value; | |
12 | static DEFINE_SPINLOCK(next_tag_value_lock); | |
13 | ||
14 | /* the pvfs2 memory caches */ | |
15 | ||
16 | /* a cache for pvfs2 upcall/downcall operations */ | |
17 | static struct kmem_cache *op_cache; | |
18 | ||
19 | /* a cache for device (/dev/pvfs2-req) communication */ | |
20 | static struct kmem_cache *dev_req_cache; | |
21 | ||
22 | /* a cache for pvfs2_kiocb objects (i.e pvfs2 iocb structures ) */ | |
23 | static struct kmem_cache *pvfs2_kiocb_cache; | |
24 | ||
25 | int op_cache_initialize(void) | |
26 | { | |
27 | op_cache = kmem_cache_create("pvfs2_op_cache", | |
28 | sizeof(struct pvfs2_kernel_op_s), | |
29 | 0, | |
30 | PVFS2_CACHE_CREATE_FLAGS, | |
31 | NULL); | |
32 | ||
33 | if (!op_cache) { | |
34 | gossip_err("Cannot create pvfs2_op_cache\n"); | |
35 | return -ENOMEM; | |
36 | } | |
37 | ||
38 | /* initialize our atomic tag counter */ | |
39 | spin_lock(&next_tag_value_lock); | |
40 | next_tag_value = 100; | |
41 | spin_unlock(&next_tag_value_lock); | |
42 | return 0; | |
43 | } | |
44 | ||
45 | int op_cache_finalize(void) | |
46 | { | |
47 | kmem_cache_destroy(op_cache); | |
48 | return 0; | |
49 | } | |
50 | ||
51 | char *get_opname_string(struct pvfs2_kernel_op_s *new_op) | |
52 | { | |
53 | if (new_op) { | |
54 | __s32 type = new_op->upcall.type; | |
55 | ||
56 | if (type == PVFS2_VFS_OP_FILE_IO) | |
57 | return "OP_FILE_IO"; | |
58 | else if (type == PVFS2_VFS_OP_LOOKUP) | |
59 | return "OP_LOOKUP"; | |
60 | else if (type == PVFS2_VFS_OP_CREATE) | |
61 | return "OP_CREATE"; | |
62 | else if (type == PVFS2_VFS_OP_GETATTR) | |
63 | return "OP_GETATTR"; | |
64 | else if (type == PVFS2_VFS_OP_REMOVE) | |
65 | return "OP_REMOVE"; | |
66 | else if (type == PVFS2_VFS_OP_MKDIR) | |
67 | return "OP_MKDIR"; | |
68 | else if (type == PVFS2_VFS_OP_READDIR) | |
69 | return "OP_READDIR"; | |
70 | else if (type == PVFS2_VFS_OP_READDIRPLUS) | |
71 | return "OP_READDIRPLUS"; | |
72 | else if (type == PVFS2_VFS_OP_SETATTR) | |
73 | return "OP_SETATTR"; | |
74 | else if (type == PVFS2_VFS_OP_SYMLINK) | |
75 | return "OP_SYMLINK"; | |
76 | else if (type == PVFS2_VFS_OP_RENAME) | |
77 | return "OP_RENAME"; | |
78 | else if (type == PVFS2_VFS_OP_STATFS) | |
79 | return "OP_STATFS"; | |
80 | else if (type == PVFS2_VFS_OP_TRUNCATE) | |
81 | return "OP_TRUNCATE"; | |
82 | else if (type == PVFS2_VFS_OP_MMAP_RA_FLUSH) | |
83 | return "OP_MMAP_RA_FLUSH"; | |
84 | else if (type == PVFS2_VFS_OP_FS_MOUNT) | |
85 | return "OP_FS_MOUNT"; | |
86 | else if (type == PVFS2_VFS_OP_FS_UMOUNT) | |
87 | return "OP_FS_UMOUNT"; | |
88 | else if (type == PVFS2_VFS_OP_GETXATTR) | |
89 | return "OP_GETXATTR"; | |
90 | else if (type == PVFS2_VFS_OP_SETXATTR) | |
91 | return "OP_SETXATTR"; | |
92 | else if (type == PVFS2_VFS_OP_LISTXATTR) | |
93 | return "OP_LISTXATTR"; | |
94 | else if (type == PVFS2_VFS_OP_REMOVEXATTR) | |
95 | return "OP_REMOVEXATTR"; | |
96 | else if (type == PVFS2_VFS_OP_PARAM) | |
97 | return "OP_PARAM"; | |
98 | else if (type == PVFS2_VFS_OP_PERF_COUNT) | |
99 | return "OP_PERF_COUNT"; | |
100 | else if (type == PVFS2_VFS_OP_CANCEL) | |
101 | return "OP_CANCEL"; | |
102 | else if (type == PVFS2_VFS_OP_FSYNC) | |
103 | return "OP_FSYNC"; | |
104 | else if (type == PVFS2_VFS_OP_FSKEY) | |
105 | return "OP_FSKEY"; | |
106 | else if (type == PVFS2_VFS_OP_FILE_IOX) | |
107 | return "OP_FILE_IOX"; | |
108 | } | |
109 | return "OP_UNKNOWN?"; | |
110 | } | |
111 | ||
112 | static struct pvfs2_kernel_op_s *op_alloc_common(__s32 op_linger, __s32 type) | |
113 | { | |
114 | struct pvfs2_kernel_op_s *new_op = NULL; | |
115 | ||
116 | new_op = kmem_cache_alloc(op_cache, PVFS2_CACHE_ALLOC_FLAGS); | |
117 | if (new_op) { | |
118 | memset(new_op, 0, sizeof(struct pvfs2_kernel_op_s)); | |
119 | ||
120 | INIT_LIST_HEAD(&new_op->list); | |
121 | spin_lock_init(&new_op->lock); | |
122 | init_waitqueue_head(&new_op->waitq); | |
123 | ||
124 | init_waitqueue_head(&new_op->io_completion_waitq); | |
125 | atomic_set(&new_op->aio_ref_count, 0); | |
126 | ||
127 | pvfs2_op_initialize(new_op); | |
128 | ||
129 | /* initialize the op specific tag and upcall credentials */ | |
130 | spin_lock(&next_tag_value_lock); | |
131 | new_op->tag = next_tag_value++; | |
132 | if (next_tag_value == 0) | |
133 | next_tag_value = 100; | |
134 | spin_unlock(&next_tag_value_lock); | |
135 | new_op->upcall.type = type; | |
136 | new_op->attempts = 0; | |
137 | gossip_debug(GOSSIP_CACHE_DEBUG, | |
138 | "Alloced OP (%p: %llu %s)\n", | |
139 | new_op, | |
140 | llu(new_op->tag), | |
141 | get_opname_string(new_op)); | |
142 | ||
143 | new_op->upcall.uid = from_kuid(current_user_ns(), | |
144 | current_fsuid()); | |
145 | ||
146 | new_op->upcall.gid = from_kgid(current_user_ns(), | |
147 | current_fsgid()); | |
148 | ||
149 | new_op->op_linger = new_op->op_linger_tmp = op_linger; | |
150 | } else { | |
151 | gossip_err("op_alloc: kmem_cache_alloc failed!\n"); | |
152 | } | |
153 | return new_op; | |
154 | } | |
155 | ||
156 | struct pvfs2_kernel_op_s *op_alloc(__s32 type) | |
157 | { | |
158 | return op_alloc_common(1, type); | |
159 | } | |
160 | ||
161 | struct pvfs2_kernel_op_s *op_alloc_trailer(__s32 type) | |
162 | { | |
163 | return op_alloc_common(2, type); | |
164 | } | |
165 | ||
166 | void op_release(struct pvfs2_kernel_op_s *pvfs2_op) | |
167 | { | |
168 | if (pvfs2_op) { | |
169 | gossip_debug(GOSSIP_CACHE_DEBUG, | |
170 | "Releasing OP (%p: %llu)\n", | |
171 | pvfs2_op, | |
172 | llu(pvfs2_op->tag)); | |
173 | pvfs2_op_initialize(pvfs2_op); | |
174 | kmem_cache_free(op_cache, pvfs2_op); | |
175 | } else { | |
176 | gossip_err("NULL pointer in op_release\n"); | |
177 | } | |
178 | } | |
179 | ||
180 | int dev_req_cache_initialize(void) | |
181 | { | |
182 | dev_req_cache = kmem_cache_create("pvfs2_devreqcache", | |
183 | MAX_ALIGNED_DEV_REQ_DOWNSIZE, | |
184 | 0, | |
185 | PVFS2_CACHE_CREATE_FLAGS, | |
186 | NULL); | |
187 | ||
188 | if (!dev_req_cache) { | |
189 | gossip_err("Cannot create pvfs2_dev_req_cache\n"); | |
190 | return -ENOMEM; | |
191 | } | |
192 | return 0; | |
193 | } | |
194 | ||
195 | int dev_req_cache_finalize(void) | |
196 | { | |
197 | kmem_cache_destroy(dev_req_cache); | |
198 | return 0; | |
199 | } | |
200 | ||
201 | void *dev_req_alloc(void) | |
202 | { | |
203 | void *buffer; | |
204 | ||
205 | buffer = kmem_cache_alloc(dev_req_cache, PVFS2_CACHE_ALLOC_FLAGS); | |
206 | if (buffer == NULL) | |
207 | gossip_err("Failed to allocate from dev_req_cache\n"); | |
208 | else | |
209 | memset(buffer, 0, sizeof(MAX_ALIGNED_DEV_REQ_DOWNSIZE)); | |
210 | return buffer; | |
211 | } | |
212 | ||
213 | void dev_req_release(void *buffer) | |
214 | { | |
215 | if (buffer) | |
216 | kmem_cache_free(dev_req_cache, buffer); | |
217 | else | |
218 | gossip_err("NULL pointer passed to dev_req_release\n"); | |
219 | } | |
220 | ||
221 | int kiocb_cache_initialize(void) | |
222 | { | |
223 | pvfs2_kiocb_cache = kmem_cache_create("pvfs2_kiocbcache", | |
224 | sizeof(struct pvfs2_kiocb_s), | |
225 | 0, | |
226 | PVFS2_CACHE_CREATE_FLAGS, | |
227 | NULL); | |
228 | ||
229 | if (!pvfs2_kiocb_cache) { | |
230 | gossip_err("Cannot create pvfs2_kiocb_cache!\n"); | |
231 | return -ENOMEM; | |
232 | } | |
233 | return 0; | |
234 | } | |
235 | ||
236 | int kiocb_cache_finalize(void) | |
237 | { | |
238 | kmem_cache_destroy(pvfs2_kiocb_cache); | |
239 | return 0; | |
240 | } | |
241 | ||
242 | struct pvfs2_kiocb_s *kiocb_alloc(void) | |
243 | { | |
244 | struct pvfs2_kiocb_s *x = NULL; | |
245 | ||
246 | x = kmem_cache_alloc(pvfs2_kiocb_cache, PVFS2_CACHE_ALLOC_FLAGS); | |
247 | if (x == NULL) | |
248 | gossip_err("kiocb_alloc: kmem_cache_alloc failed!\n"); | |
249 | else | |
250 | memset(x, 0, sizeof(struct pvfs2_kiocb_s)); | |
251 | return x; | |
252 | } | |
253 | ||
254 | void kiocb_release(struct pvfs2_kiocb_s *x) | |
255 | { | |
256 | if (x) | |
257 | kmem_cache_free(pvfs2_kiocb_cache, x); | |
258 | else | |
259 | gossip_err("kiocb_release: kmem_cache_free NULL pointer!\n"); | |
260 | } |