diff options
Diffstat (limited to 'fs/ocfs2/dlmfs/dlmfs.c')
-rw-r--r-- | fs/ocfs2/dlmfs/dlmfs.c | 710 |
1 files changed, 710 insertions, 0 deletions
diff --git a/fs/ocfs2/dlmfs/dlmfs.c b/fs/ocfs2/dlmfs/dlmfs.c new file mode 100644 index 000000000000..e21ce0e5fc42 --- /dev/null +++ b/fs/ocfs2/dlmfs/dlmfs.c | |||
@@ -0,0 +1,710 @@ | |||
1 | /* -*- mode: c; c-basic-offset: 8; -*- | ||
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | ||
3 | * | ||
4 | * dlmfs.c | ||
5 | * | ||
6 | * Code which implements the kernel side of a minimal userspace | ||
7 | * interface to our DLM. This file handles the virtual file system | ||
8 | * used for communication with userspace. Credit should go to ramfs, | ||
9 | * which was a template for the fs side of this module. | ||
10 | * | ||
11 | * Copyright (C) 2003, 2004 Oracle. All rights reserved. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public | ||
15 | * License as published by the Free Software Foundation; either | ||
16 | * version 2 of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | * General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public | ||
24 | * License along with this program; if not, write to the | ||
25 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
26 | * Boston, MA 021110-1307, USA. | ||
27 | */ | ||
28 | |||
29 | /* Simple VFS hooks based on: */ | ||
30 | /* | ||
31 | * Resizable simple ram filesystem for Linux. | ||
32 | * | ||
33 | * Copyright (C) 2000 Linus Torvalds. | ||
34 | * 2000 Transmeta Corp. | ||
35 | */ | ||
36 | |||
37 | #include <linux/module.h> | ||
38 | #include <linux/fs.h> | ||
39 | #include <linux/pagemap.h> | ||
40 | #include <linux/types.h> | ||
41 | #include <linux/slab.h> | ||
42 | #include <linux/highmem.h> | ||
43 | #include <linux/init.h> | ||
44 | #include <linux/string.h> | ||
45 | #include <linux/backing-dev.h> | ||
46 | #include <linux/poll.h> | ||
47 | |||
48 | #include <asm/uaccess.h> | ||
49 | |||
50 | |||
51 | #include "cluster/nodemanager.h" | ||
52 | #include "cluster/heartbeat.h" | ||
53 | #include "cluster/tcp.h" | ||
54 | |||
55 | #include "dlm/dlmapi.h" | ||
56 | |||
57 | #include "userdlm.h" | ||
58 | |||
59 | #include "dlmfsver.h" | ||
60 | |||
61 | #define MLOG_MASK_PREFIX ML_DLMFS | ||
62 | #include "cluster/masklog.h" | ||
63 | |||
64 | #include "ocfs2_lockingver.h" | ||
65 | |||
66 | static const struct super_operations dlmfs_ops; | ||
67 | static const struct file_operations dlmfs_file_operations; | ||
68 | static const struct inode_operations dlmfs_dir_inode_operations; | ||
69 | static const struct inode_operations dlmfs_root_inode_operations; | ||
70 | static const struct inode_operations dlmfs_file_inode_operations; | ||
71 | static struct kmem_cache *dlmfs_inode_cache; | ||
72 | |||
73 | struct workqueue_struct *user_dlm_worker; | ||
74 | |||
75 | /* | ||
76 | * This is the userdlmfs locking protocol version. | ||
77 | * | ||
78 | * See fs/ocfs2/dlmglue.c for more details on locking versions. | ||
79 | */ | ||
80 | static const struct dlm_protocol_version user_locking_protocol = { | ||
81 | .pv_major = OCFS2_LOCKING_PROTOCOL_MAJOR, | ||
82 | .pv_minor = OCFS2_LOCKING_PROTOCOL_MINOR, | ||
83 | }; | ||
84 | |||
85 | |||
86 | /* | ||
87 | * These are the ABI capabilities of dlmfs. | ||
88 | * | ||
89 | * Over time, dlmfs has added some features that were not part of the | ||
90 | * initial ABI. Unfortunately, some of these features are not detectable | ||
91 | * via standard usage. For example, Linux's default poll always returns | ||
92 | * POLLIN, so there is no way for a caller of poll(2) to know when dlmfs | ||
93 | * added poll support. Instead, we provide this list of new capabilities. | ||
94 | * | ||
95 | * Capabilities is a read-only attribute. We do it as a module parameter | ||
96 | * so we can discover it whether dlmfs is built in, loaded, or even not | ||
97 | * loaded. | ||
98 | * | ||
99 | * The ABI features are local to this machine's dlmfs mount. This is | ||
100 | * distinct from the locking protocol, which is concerned with inter-node | ||
101 | * interaction. | ||
102 | * | ||
103 | * Capabilities: | ||
104 | * - bast : POLLIN against the file descriptor of a held lock | ||
105 | * signifies a bast fired on the lock. | ||
106 | */ | ||
107 | #define DLMFS_CAPABILITIES "bast" | ||
108 | extern int param_set_dlmfs_capabilities(const char *val, | ||
109 | struct kernel_param *kp) | ||
110 | { | ||
111 | printk(KERN_ERR "%s: readonly parameter\n", kp->name); | ||
112 | return -EINVAL; | ||
113 | } | ||
114 | static int param_get_dlmfs_capabilities(char *buffer, | ||
115 | struct kernel_param *kp) | ||
116 | { | ||
117 | return strlcpy(buffer, DLMFS_CAPABILITIES, | ||
118 | strlen(DLMFS_CAPABILITIES) + 1); | ||
119 | } | ||
120 | module_param_call(capabilities, param_set_dlmfs_capabilities, | ||
121 | param_get_dlmfs_capabilities, NULL, 0444); | ||
122 | MODULE_PARM_DESC(capabilities, DLMFS_CAPABILITIES); | ||
123 | |||
124 | |||
125 | /* | ||
126 | * decodes a set of open flags into a valid lock level and a set of flags. | ||
127 | * returns < 0 if we have invalid flags | ||
128 | * flags which mean something to us: | ||
129 | * O_RDONLY -> PRMODE level | ||
130 | * O_WRONLY -> EXMODE level | ||
131 | * | ||
132 | * O_NONBLOCK -> LKM_NOQUEUE | ||
133 | */ | ||
134 | static int dlmfs_decode_open_flags(int open_flags, | ||
135 | int *level, | ||
136 | int *flags) | ||
137 | { | ||
138 | if (open_flags & (O_WRONLY|O_RDWR)) | ||
139 | *level = LKM_EXMODE; | ||
140 | else | ||
141 | *level = LKM_PRMODE; | ||
142 | |||
143 | *flags = 0; | ||
144 | if (open_flags & O_NONBLOCK) | ||
145 | *flags |= LKM_NOQUEUE; | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | static int dlmfs_file_open(struct inode *inode, | ||
151 | struct file *file) | ||
152 | { | ||
153 | int status, level, flags; | ||
154 | struct dlmfs_filp_private *fp = NULL; | ||
155 | struct dlmfs_inode_private *ip; | ||
156 | |||
157 | if (S_ISDIR(inode->i_mode)) | ||
158 | BUG(); | ||
159 | |||
160 | mlog(0, "open called on inode %lu, flags 0x%x\n", inode->i_ino, | ||
161 | file->f_flags); | ||
162 | |||
163 | status = dlmfs_decode_open_flags(file->f_flags, &level, &flags); | ||
164 | if (status < 0) | ||
165 | goto bail; | ||
166 | |||
167 | /* We don't want to honor O_APPEND at read/write time as it | ||
168 | * doesn't make sense for LVB writes. */ | ||
169 | file->f_flags &= ~O_APPEND; | ||
170 | |||
171 | fp = kmalloc(sizeof(*fp), GFP_NOFS); | ||
172 | if (!fp) { | ||
173 | status = -ENOMEM; | ||
174 | goto bail; | ||
175 | } | ||
176 | fp->fp_lock_level = level; | ||
177 | |||
178 | ip = DLMFS_I(inode); | ||
179 | |||
180 | status = user_dlm_cluster_lock(&ip->ip_lockres, level, flags); | ||
181 | if (status < 0) { | ||
182 | /* this is a strange error to return here but I want | ||
183 | * to be able userspace to be able to distinguish a | ||
184 | * valid lock request from one that simply couldn't be | ||
185 | * granted. */ | ||
186 | if (flags & LKM_NOQUEUE && status == -EAGAIN) | ||
187 | status = -ETXTBSY; | ||
188 | kfree(fp); | ||
189 | goto bail; | ||
190 | } | ||
191 | |||
192 | file->private_data = fp; | ||
193 | bail: | ||
194 | return status; | ||
195 | } | ||
196 | |||
197 | static int dlmfs_file_release(struct inode *inode, | ||
198 | struct file *file) | ||
199 | { | ||
200 | int level, status; | ||
201 | struct dlmfs_inode_private *ip = DLMFS_I(inode); | ||
202 | struct dlmfs_filp_private *fp = | ||
203 | (struct dlmfs_filp_private *) file->private_data; | ||
204 | |||
205 | if (S_ISDIR(inode->i_mode)) | ||
206 | BUG(); | ||
207 | |||
208 | mlog(0, "close called on inode %lu\n", inode->i_ino); | ||
209 | |||
210 | status = 0; | ||
211 | if (fp) { | ||
212 | level = fp->fp_lock_level; | ||
213 | if (level != LKM_IVMODE) | ||
214 | user_dlm_cluster_unlock(&ip->ip_lockres, level); | ||
215 | |||
216 | kfree(fp); | ||
217 | file->private_data = NULL; | ||
218 | } | ||
219 | |||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | static unsigned int dlmfs_file_poll(struct file *file, poll_table *wait) | ||
224 | { | ||
225 | int event = 0; | ||
226 | struct inode *inode = file->f_path.dentry->d_inode; | ||
227 | struct dlmfs_inode_private *ip = DLMFS_I(inode); | ||
228 | |||
229 | poll_wait(file, &ip->ip_lockres.l_event, wait); | ||
230 | |||
231 | spin_lock(&ip->ip_lockres.l_lock); | ||
232 | if (ip->ip_lockres.l_flags & USER_LOCK_BLOCKED) | ||
233 | event = POLLIN | POLLRDNORM; | ||
234 | spin_unlock(&ip->ip_lockres.l_lock); | ||
235 | |||
236 | return event; | ||
237 | } | ||
238 | |||
239 | static ssize_t dlmfs_file_read(struct file *filp, | ||
240 | char __user *buf, | ||
241 | size_t count, | ||
242 | loff_t *ppos) | ||
243 | { | ||
244 | int bytes_left; | ||
245 | ssize_t readlen; | ||
246 | char *lvb_buf; | ||
247 | struct inode *inode = filp->f_path.dentry->d_inode; | ||
248 | |||
249 | mlog(0, "inode %lu, count = %zu, *ppos = %llu\n", | ||
250 | inode->i_ino, count, *ppos); | ||
251 | |||
252 | if (*ppos >= i_size_read(inode)) | ||
253 | return 0; | ||
254 | |||
255 | if (!count) | ||
256 | return 0; | ||
257 | |||
258 | if (!access_ok(VERIFY_WRITE, buf, count)) | ||
259 | return -EFAULT; | ||
260 | |||
261 | /* don't read past the lvb */ | ||
262 | if ((count + *ppos) > i_size_read(inode)) | ||
263 | readlen = i_size_read(inode) - *ppos; | ||
264 | else | ||
265 | readlen = count - *ppos; | ||
266 | |||
267 | lvb_buf = kmalloc(readlen, GFP_NOFS); | ||
268 | if (!lvb_buf) | ||
269 | return -ENOMEM; | ||
270 | |||
271 | user_dlm_read_lvb(inode, lvb_buf, readlen); | ||
272 | bytes_left = __copy_to_user(buf, lvb_buf, readlen); | ||
273 | readlen -= bytes_left; | ||
274 | |||
275 | kfree(lvb_buf); | ||
276 | |||
277 | *ppos = *ppos + readlen; | ||
278 | |||
279 | mlog(0, "read %zd bytes\n", readlen); | ||
280 | return readlen; | ||
281 | } | ||
282 | |||
283 | static ssize_t dlmfs_file_write(struct file *filp, | ||
284 | const char __user *buf, | ||
285 | size_t count, | ||
286 | loff_t *ppos) | ||
287 | { | ||
288 | int bytes_left; | ||
289 | ssize_t writelen; | ||
290 | char *lvb_buf; | ||
291 | struct inode *inode = filp->f_path.dentry->d_inode; | ||
292 | |||
293 | mlog(0, "inode %lu, count = %zu, *ppos = %llu\n", | ||
294 | inode->i_ino, count, *ppos); | ||
295 | |||
296 | if (*ppos >= i_size_read(inode)) | ||
297 | return -ENOSPC; | ||
298 | |||
299 | if (!count) | ||
300 | return 0; | ||
301 | |||
302 | if (!access_ok(VERIFY_READ, buf, count)) | ||
303 | return -EFAULT; | ||
304 | |||
305 | /* don't write past the lvb */ | ||
306 | if ((count + *ppos) > i_size_read(inode)) | ||
307 | writelen = i_size_read(inode) - *ppos; | ||
308 | else | ||
309 | writelen = count - *ppos; | ||
310 | |||
311 | lvb_buf = kmalloc(writelen, GFP_NOFS); | ||
312 | if (!lvb_buf) | ||
313 | return -ENOMEM; | ||
314 | |||
315 | bytes_left = copy_from_user(lvb_buf, buf, writelen); | ||
316 | writelen -= bytes_left; | ||
317 | if (writelen) | ||
318 | user_dlm_write_lvb(inode, lvb_buf, writelen); | ||
319 | |||
320 | kfree(lvb_buf); | ||
321 | |||
322 | *ppos = *ppos + writelen; | ||
323 | mlog(0, "wrote %zd bytes\n", writelen); | ||
324 | return writelen; | ||
325 | } | ||
326 | |||
327 | static void dlmfs_init_once(void *foo) | ||
328 | { | ||
329 | struct dlmfs_inode_private *ip = | ||
330 | (struct dlmfs_inode_private *) foo; | ||
331 | |||
332 | ip->ip_dlm = NULL; | ||
333 | ip->ip_parent = NULL; | ||
334 | |||
335 | inode_init_once(&ip->ip_vfs_inode); | ||
336 | } | ||
337 | |||
338 | static struct inode *dlmfs_alloc_inode(struct super_block *sb) | ||
339 | { | ||
340 | struct dlmfs_inode_private *ip; | ||
341 | |||
342 | ip = kmem_cache_alloc(dlmfs_inode_cache, GFP_NOFS); | ||
343 | if (!ip) | ||
344 | return NULL; | ||
345 | |||
346 | return &ip->ip_vfs_inode; | ||
347 | } | ||
348 | |||
349 | static void dlmfs_destroy_inode(struct inode *inode) | ||
350 | { | ||
351 | kmem_cache_free(dlmfs_inode_cache, DLMFS_I(inode)); | ||
352 | } | ||
353 | |||
354 | static void dlmfs_clear_inode(struct inode *inode) | ||
355 | { | ||
356 | int status; | ||
357 | struct dlmfs_inode_private *ip; | ||
358 | |||
359 | if (!inode) | ||
360 | return; | ||
361 | |||
362 | mlog(0, "inode %lu\n", inode->i_ino); | ||
363 | |||
364 | ip = DLMFS_I(inode); | ||
365 | |||
366 | if (S_ISREG(inode->i_mode)) { | ||
367 | status = user_dlm_destroy_lock(&ip->ip_lockres); | ||
368 | if (status < 0) | ||
369 | mlog_errno(status); | ||
370 | iput(ip->ip_parent); | ||
371 | goto clear_fields; | ||
372 | } | ||
373 | |||
374 | mlog(0, "we're a directory, ip->ip_dlm = 0x%p\n", ip->ip_dlm); | ||
375 | /* we must be a directory. If required, lets unregister the | ||
376 | * dlm context now. */ | ||
377 | if (ip->ip_dlm) | ||
378 | user_dlm_unregister_context(ip->ip_dlm); | ||
379 | clear_fields: | ||
380 | ip->ip_parent = NULL; | ||
381 | ip->ip_dlm = NULL; | ||
382 | } | ||
383 | |||
384 | static struct backing_dev_info dlmfs_backing_dev_info = { | ||
385 | .name = "ocfs2-dlmfs", | ||
386 | .ra_pages = 0, /* No readahead */ | ||
387 | .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, | ||
388 | }; | ||
389 | |||
390 | static struct inode *dlmfs_get_root_inode(struct super_block *sb) | ||
391 | { | ||
392 | struct inode *inode = new_inode(sb); | ||
393 | int mode = S_IFDIR | 0755; | ||
394 | struct dlmfs_inode_private *ip; | ||
395 | |||
396 | if (inode) { | ||
397 | ip = DLMFS_I(inode); | ||
398 | |||
399 | inode->i_mode = mode; | ||
400 | inode->i_uid = current_fsuid(); | ||
401 | inode->i_gid = current_fsgid(); | ||
402 | inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info; | ||
403 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; | ||
404 | inc_nlink(inode); | ||
405 | |||
406 | inode->i_fop = &simple_dir_operations; | ||
407 | inode->i_op = &dlmfs_root_inode_operations; | ||
408 | } | ||
409 | |||
410 | return inode; | ||
411 | } | ||
412 | |||
413 | static struct inode *dlmfs_get_inode(struct inode *parent, | ||
414 | struct dentry *dentry, | ||
415 | int mode) | ||
416 | { | ||
417 | struct super_block *sb = parent->i_sb; | ||
418 | struct inode * inode = new_inode(sb); | ||
419 | struct dlmfs_inode_private *ip; | ||
420 | |||
421 | if (!inode) | ||
422 | return NULL; | ||
423 | |||
424 | inode->i_mode = mode; | ||
425 | inode->i_uid = current_fsuid(); | ||
426 | inode->i_gid = current_fsgid(); | ||
427 | inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info; | ||
428 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; | ||
429 | |||
430 | ip = DLMFS_I(inode); | ||
431 | ip->ip_dlm = DLMFS_I(parent)->ip_dlm; | ||
432 | |||
433 | switch (mode & S_IFMT) { | ||
434 | default: | ||
435 | /* for now we don't support anything other than | ||
436 | * directories and regular files. */ | ||
437 | BUG(); | ||
438 | break; | ||
439 | case S_IFREG: | ||
440 | inode->i_op = &dlmfs_file_inode_operations; | ||
441 | inode->i_fop = &dlmfs_file_operations; | ||
442 | |||
443 | i_size_write(inode, DLM_LVB_LEN); | ||
444 | |||
445 | user_dlm_lock_res_init(&ip->ip_lockres, dentry); | ||
446 | |||
447 | /* released at clear_inode time, this insures that we | ||
448 | * get to drop the dlm reference on each lock *before* | ||
449 | * we call the unregister code for releasing parent | ||
450 | * directories. */ | ||
451 | ip->ip_parent = igrab(parent); | ||
452 | BUG_ON(!ip->ip_parent); | ||
453 | break; | ||
454 | case S_IFDIR: | ||
455 | inode->i_op = &dlmfs_dir_inode_operations; | ||
456 | inode->i_fop = &simple_dir_operations; | ||
457 | |||
458 | /* directory inodes start off with i_nlink == | ||
459 | * 2 (for "." entry) */ | ||
460 | inc_nlink(inode); | ||
461 | break; | ||
462 | } | ||
463 | |||
464 | if (parent->i_mode & S_ISGID) { | ||
465 | inode->i_gid = parent->i_gid; | ||
466 | if (S_ISDIR(mode)) | ||
467 | inode->i_mode |= S_ISGID; | ||
468 | } | ||
469 | |||
470 | return inode; | ||
471 | } | ||
472 | |||
473 | /* | ||
474 | * File creation. Allocate an inode, and we're done.. | ||
475 | */ | ||
476 | /* SMP-safe */ | ||
477 | static int dlmfs_mkdir(struct inode * dir, | ||
478 | struct dentry * dentry, | ||
479 | int mode) | ||
480 | { | ||
481 | int status; | ||
482 | struct inode *inode = NULL; | ||
483 | struct qstr *domain = &dentry->d_name; | ||
484 | struct dlmfs_inode_private *ip; | ||
485 | struct dlm_ctxt *dlm; | ||
486 | struct dlm_protocol_version proto = user_locking_protocol; | ||
487 | |||
488 | mlog(0, "mkdir %.*s\n", domain->len, domain->name); | ||
489 | |||
490 | /* verify that we have a proper domain */ | ||
491 | if (domain->len >= O2NM_MAX_NAME_LEN) { | ||
492 | status = -EINVAL; | ||
493 | mlog(ML_ERROR, "invalid domain name for directory.\n"); | ||
494 | goto bail; | ||
495 | } | ||
496 | |||
497 | inode = dlmfs_get_inode(dir, dentry, mode | S_IFDIR); | ||
498 | if (!inode) { | ||
499 | status = -ENOMEM; | ||
500 | mlog_errno(status); | ||
501 | goto bail; | ||
502 | } | ||
503 | |||
504 | ip = DLMFS_I(inode); | ||
505 | |||
506 | dlm = user_dlm_register_context(domain, &proto); | ||
507 | if (IS_ERR(dlm)) { | ||
508 | status = PTR_ERR(dlm); | ||
509 | mlog(ML_ERROR, "Error %d could not register domain \"%.*s\"\n", | ||
510 | status, domain->len, domain->name); | ||
511 | goto bail; | ||
512 | } | ||
513 | ip->ip_dlm = dlm; | ||
514 | |||
515 | inc_nlink(dir); | ||
516 | d_instantiate(dentry, inode); | ||
517 | dget(dentry); /* Extra count - pin the dentry in core */ | ||
518 | |||
519 | status = 0; | ||
520 | bail: | ||
521 | if (status < 0) | ||
522 | iput(inode); | ||
523 | return status; | ||
524 | } | ||
525 | |||
526 | static int dlmfs_create(struct inode *dir, | ||
527 | struct dentry *dentry, | ||
528 | int mode, | ||
529 | struct nameidata *nd) | ||
530 | { | ||
531 | int status = 0; | ||
532 | struct inode *inode; | ||
533 | struct qstr *name = &dentry->d_name; | ||
534 | |||
535 | mlog(0, "create %.*s\n", name->len, name->name); | ||
536 | |||
537 | /* verify name is valid and doesn't contain any dlm reserved | ||
538 | * characters */ | ||
539 | if (name->len >= USER_DLM_LOCK_ID_MAX_LEN || | ||
540 | name->name[0] == '$') { | ||
541 | status = -EINVAL; | ||
542 | mlog(ML_ERROR, "invalid lock name, %.*s\n", name->len, | ||
543 | name->name); | ||
544 | goto bail; | ||
545 | } | ||
546 | |||
547 | inode = dlmfs_get_inode(dir, dentry, mode | S_IFREG); | ||
548 | if (!inode) { | ||
549 | status = -ENOMEM; | ||
550 | mlog_errno(status); | ||
551 | goto bail; | ||
552 | } | ||
553 | |||
554 | d_instantiate(dentry, inode); | ||
555 | dget(dentry); /* Extra count - pin the dentry in core */ | ||
556 | bail: | ||
557 | return status; | ||
558 | } | ||
559 | |||
560 | static int dlmfs_unlink(struct inode *dir, | ||
561 | struct dentry *dentry) | ||
562 | { | ||
563 | int status; | ||
564 | struct inode *inode = dentry->d_inode; | ||
565 | |||
566 | mlog(0, "unlink inode %lu\n", inode->i_ino); | ||
567 | |||
568 | /* if there are no current holders, or none that are waiting | ||
569 | * to acquire a lock, this basically destroys our lockres. */ | ||
570 | status = user_dlm_destroy_lock(&DLMFS_I(inode)->ip_lockres); | ||
571 | if (status < 0) { | ||
572 | mlog(ML_ERROR, "unlink %.*s, error %d from destroy\n", | ||
573 | dentry->d_name.len, dentry->d_name.name, status); | ||
574 | goto bail; | ||
575 | } | ||
576 | status = simple_unlink(dir, dentry); | ||
577 | bail: | ||
578 | return status; | ||
579 | } | ||
580 | |||
581 | static int dlmfs_fill_super(struct super_block * sb, | ||
582 | void * data, | ||
583 | int silent) | ||
584 | { | ||
585 | struct inode * inode; | ||
586 | struct dentry * root; | ||
587 | |||
588 | sb->s_maxbytes = MAX_LFS_FILESIZE; | ||
589 | sb->s_blocksize = PAGE_CACHE_SIZE; | ||
590 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; | ||
591 | sb->s_magic = DLMFS_MAGIC; | ||
592 | sb->s_op = &dlmfs_ops; | ||
593 | inode = dlmfs_get_root_inode(sb); | ||
594 | if (!inode) | ||
595 | return -ENOMEM; | ||
596 | |||
597 | root = d_alloc_root(inode); | ||
598 | if (!root) { | ||
599 | iput(inode); | ||
600 | return -ENOMEM; | ||
601 | } | ||
602 | sb->s_root = root; | ||
603 | return 0; | ||
604 | } | ||
605 | |||
606 | static const struct file_operations dlmfs_file_operations = { | ||
607 | .open = dlmfs_file_open, | ||
608 | .release = dlmfs_file_release, | ||
609 | .poll = dlmfs_file_poll, | ||
610 | .read = dlmfs_file_read, | ||
611 | .write = dlmfs_file_write, | ||
612 | }; | ||
613 | |||
614 | static const struct inode_operations dlmfs_dir_inode_operations = { | ||
615 | .create = dlmfs_create, | ||
616 | .lookup = simple_lookup, | ||
617 | .unlink = dlmfs_unlink, | ||
618 | }; | ||
619 | |||
620 | /* this way we can restrict mkdir to only the toplevel of the fs. */ | ||
621 | static const struct inode_operations dlmfs_root_inode_operations = { | ||
622 | .lookup = simple_lookup, | ||
623 | .mkdir = dlmfs_mkdir, | ||
624 | .rmdir = simple_rmdir, | ||
625 | }; | ||
626 | |||
627 | static const struct super_operations dlmfs_ops = { | ||
628 | .statfs = simple_statfs, | ||
629 | .alloc_inode = dlmfs_alloc_inode, | ||
630 | .destroy_inode = dlmfs_destroy_inode, | ||
631 | .clear_inode = dlmfs_clear_inode, | ||
632 | .drop_inode = generic_delete_inode, | ||
633 | }; | ||
634 | |||
635 | static const struct inode_operations dlmfs_file_inode_operations = { | ||
636 | .getattr = simple_getattr, | ||
637 | }; | ||
638 | |||
639 | static int dlmfs_get_sb(struct file_system_type *fs_type, | ||
640 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) | ||
641 | { | ||
642 | return get_sb_nodev(fs_type, flags, data, dlmfs_fill_super, mnt); | ||
643 | } | ||
644 | |||
645 | static struct file_system_type dlmfs_fs_type = { | ||
646 | .owner = THIS_MODULE, | ||
647 | .name = "ocfs2_dlmfs", | ||
648 | .get_sb = dlmfs_get_sb, | ||
649 | .kill_sb = kill_litter_super, | ||
650 | }; | ||
651 | |||
652 | static int __init init_dlmfs_fs(void) | ||
653 | { | ||
654 | int status; | ||
655 | int cleanup_inode = 0, cleanup_worker = 0; | ||
656 | |||
657 | dlmfs_print_version(); | ||
658 | |||
659 | status = bdi_init(&dlmfs_backing_dev_info); | ||
660 | if (status) | ||
661 | return status; | ||
662 | |||
663 | dlmfs_inode_cache = kmem_cache_create("dlmfs_inode_cache", | ||
664 | sizeof(struct dlmfs_inode_private), | ||
665 | 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| | ||
666 | SLAB_MEM_SPREAD), | ||
667 | dlmfs_init_once); | ||
668 | if (!dlmfs_inode_cache) { | ||
669 | status = -ENOMEM; | ||
670 | goto bail; | ||
671 | } | ||
672 | cleanup_inode = 1; | ||
673 | |||
674 | user_dlm_worker = create_singlethread_workqueue("user_dlm"); | ||
675 | if (!user_dlm_worker) { | ||
676 | status = -ENOMEM; | ||
677 | goto bail; | ||
678 | } | ||
679 | cleanup_worker = 1; | ||
680 | |||
681 | status = register_filesystem(&dlmfs_fs_type); | ||
682 | bail: | ||
683 | if (status) { | ||
684 | if (cleanup_inode) | ||
685 | kmem_cache_destroy(dlmfs_inode_cache); | ||
686 | if (cleanup_worker) | ||
687 | destroy_workqueue(user_dlm_worker); | ||
688 | bdi_destroy(&dlmfs_backing_dev_info); | ||
689 | } else | ||
690 | printk("OCFS2 User DLM kernel interface loaded\n"); | ||
691 | return status; | ||
692 | } | ||
693 | |||
694 | static void __exit exit_dlmfs_fs(void) | ||
695 | { | ||
696 | unregister_filesystem(&dlmfs_fs_type); | ||
697 | |||
698 | flush_workqueue(user_dlm_worker); | ||
699 | destroy_workqueue(user_dlm_worker); | ||
700 | |||
701 | kmem_cache_destroy(dlmfs_inode_cache); | ||
702 | |||
703 | bdi_destroy(&dlmfs_backing_dev_info); | ||
704 | } | ||
705 | |||
706 | MODULE_AUTHOR("Oracle"); | ||
707 | MODULE_LICENSE("GPL"); | ||
708 | |||
709 | module_init(init_dlmfs_fs) | ||
710 | module_exit(exit_dlmfs_fs) | ||