2 * hugetlbpage-backed filesystem. Based on ramfs.
6 * Copyright (C) 2002 Linus Torvalds.
9 #include <linux/module.h>
10 #include <linux/thread_info.h>
11 #include <asm/current.h>
12 #include <linux/sched.h> /* remove ASAP */
14 #include <linux/mount.h>
15 #include <linux/file.h>
16 #include <linux/writeback.h>
17 #include <linux/pagemap.h>
18 #include <linux/highmem.h>
19 #include <linux/init.h>
20 #include <linux/string.h>
21 #include <linux/capability.h>
22 #include <linux/backing-dev.h>
23 #include <linux/hugetlb.h>
24 #include <linux/pagevec.h>
25 #include <linux/quotaops.h>
26 #include <linux/slab.h>
27 #include <linux/dnotify.h>
28 #include <linux/statfs.h>
29 #include <linux/security.h>
31 #include <asm/uaccess.h>
33 /* some random number */
34 #define HUGETLBFS_MAGIC 0x958458f6
36 static struct super_operations hugetlbfs_ops
;
37 static struct address_space_operations hugetlbfs_aops
;
38 struct file_operations hugetlbfs_file_operations
;
39 static struct inode_operations hugetlbfs_dir_inode_operations
;
40 static struct inode_operations hugetlbfs_inode_operations
;
42 static struct backing_dev_info hugetlbfs_backing_dev_info
= {
43 .ra_pages
= 0, /* No readahead */
44 .capabilities
= BDI_CAP_NO_ACCT_DIRTY
| BDI_CAP_NO_WRITEBACK
,
47 int sysctl_hugetlb_shm_group
;
49 static void huge_pagevec_release(struct pagevec
*pvec
)
53 for (i
= 0; i
< pagevec_count(pvec
); ++i
)
54 put_page(pvec
->pages
[i
]);
60 * huge_pages_needed tries to determine the number of new huge pages that
61 * will be required to fully populate this VMA. This will be equal to
62 * the size of the VMA in huge pages minus the number of huge pages
63 * (covered by this VMA) that are found in the page cache.
65 * Result is in bytes to be compatible with is_hugepage_mem_enough()
68 huge_pages_needed(struct address_space
*mapping
, struct vm_area_struct
*vma
)
72 unsigned long start
= vma
->vm_start
;
73 unsigned long end
= vma
->vm_end
;
74 unsigned long hugepages
= (end
- start
) >> HPAGE_SHIFT
;
75 pgoff_t next
= vma
->vm_pgoff
>> (HPAGE_SHIFT
- PAGE_SHIFT
);
76 pgoff_t endpg
= next
+ hugepages
;
78 pagevec_init(&pvec
, 0);
79 while (next
< endpg
) {
80 if (!pagevec_lookup(&pvec
, mapping
, next
, PAGEVEC_SIZE
))
82 for (i
= 0; i
< pagevec_count(&pvec
); i
++) {
83 struct page
*page
= pvec
.pages
[i
];
84 if (page
->index
> next
)
86 if (page
->index
>= endpg
)
91 huge_pagevec_release(&pvec
);
93 return hugepages
<< HPAGE_SHIFT
;
96 static int hugetlbfs_file_mmap(struct file
*file
, struct vm_area_struct
*vma
)
98 struct inode
*inode
= file
->f_dentry
->d_inode
;
99 struct address_space
*mapping
= inode
->i_mapping
;
104 if (vma
->vm_pgoff
& (HPAGE_SIZE
/ PAGE_SIZE
- 1))
107 if (vma
->vm_start
& ~HPAGE_MASK
)
110 if (vma
->vm_end
& ~HPAGE_MASK
)
113 if (vma
->vm_end
- vma
->vm_start
< HPAGE_SIZE
)
116 bytes
= huge_pages_needed(mapping
, vma
);
117 if (!is_hugepage_mem_enough(bytes
))
120 vma_len
= (loff_t
)(vma
->vm_end
- vma
->vm_start
);
122 mutex_lock(&inode
->i_mutex
);
124 vma
->vm_flags
|= VM_HUGETLB
| VM_RESERVED
;
125 vma
->vm_ops
= &hugetlb_vm_ops
;
128 len
= vma_len
+ ((loff_t
)vma
->vm_pgoff
<< PAGE_SHIFT
);
129 if (!(vma
->vm_flags
& VM_WRITE
) && len
> inode
->i_size
)
133 hugetlb_prefault_arch_hook(vma
->vm_mm
);
134 if (inode
->i_size
< len
)
137 mutex_unlock(&inode
->i_mutex
);
143 * Called under down_write(mmap_sem).
146 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
147 unsigned long hugetlb_get_unmapped_area(struct file
*file
, unsigned long addr
,
148 unsigned long len
, unsigned long pgoff
, unsigned long flags
);
151 hugetlb_get_unmapped_area(struct file
*file
, unsigned long addr
,
152 unsigned long len
, unsigned long pgoff
, unsigned long flags
)
154 struct mm_struct
*mm
= current
->mm
;
155 struct vm_area_struct
*vma
;
156 unsigned long start_addr
;
158 if (len
& ~HPAGE_MASK
)
164 addr
= ALIGN(addr
, HPAGE_SIZE
);
165 vma
= find_vma(mm
, addr
);
166 if (TASK_SIZE
- len
>= addr
&&
167 (!vma
|| addr
+ len
<= vma
->vm_start
))
171 start_addr
= mm
->free_area_cache
;
173 if (len
<= mm
->cached_hole_size
)
174 start_addr
= TASK_UNMAPPED_BASE
;
177 addr
= ALIGN(start_addr
, HPAGE_SIZE
);
179 for (vma
= find_vma(mm
, addr
); ; vma
= vma
->vm_next
) {
180 /* At this point: (!vma || addr < vma->vm_end). */
181 if (TASK_SIZE
- len
< addr
) {
183 * Start a new search - just in case we missed
186 if (start_addr
!= TASK_UNMAPPED_BASE
) {
187 start_addr
= TASK_UNMAPPED_BASE
;
193 if (!vma
|| addr
+ len
<= vma
->vm_start
)
195 addr
= ALIGN(vma
->vm_end
, HPAGE_SIZE
);
201 * Read a page. Again trivial. If it didn't already exist
202 * in the page cache, it is zero-filled.
204 static int hugetlbfs_readpage(struct file
*file
, struct page
* page
)
210 static int hugetlbfs_prepare_write(struct file
*file
,
211 struct page
*page
, unsigned offset
, unsigned to
)
216 static int hugetlbfs_commit_write(struct file
*file
,
217 struct page
*page
, unsigned offset
, unsigned to
)
222 static void truncate_huge_page(struct page
*page
)
224 clear_page_dirty(page
);
225 ClearPageUptodate(page
);
226 remove_from_page_cache(page
);
230 static void truncate_hugepages(struct address_space
*mapping
, loff_t lstart
)
232 const pgoff_t start
= lstart
>> HPAGE_SHIFT
;
237 pagevec_init(&pvec
, 0);
240 if (!pagevec_lookup(&pvec
, mapping
, next
, PAGEVEC_SIZE
)) {
247 for (i
= 0; i
< pagevec_count(&pvec
); ++i
) {
248 struct page
*page
= pvec
.pages
[i
];
251 if (page
->index
> next
)
254 truncate_huge_page(page
);
256 hugetlb_put_quota(mapping
);
258 huge_pagevec_release(&pvec
);
260 BUG_ON(!lstart
&& mapping
->nrpages
);
263 static void hugetlbfs_delete_inode(struct inode
*inode
)
265 if (inode
->i_data
.nrpages
)
266 truncate_hugepages(&inode
->i_data
, 0);
270 static void hugetlbfs_forget_inode(struct inode
*inode
)
272 struct super_block
*sb
= inode
->i_sb
;
274 if (!hlist_unhashed(&inode
->i_hash
)) {
275 if (!(inode
->i_state
& (I_DIRTY
|I_LOCK
)))
276 list_move(&inode
->i_list
, &inode_unused
);
277 inodes_stat
.nr_unused
++;
278 if (!sb
|| (sb
->s_flags
& MS_ACTIVE
)) {
279 spin_unlock(&inode_lock
);
282 inode
->i_state
|= I_WILL_FREE
;
283 spin_unlock(&inode_lock
);
285 * write_inode_now is a noop as we set BDI_CAP_NO_WRITEBACK
286 * in our backing_dev_info.
288 write_inode_now(inode
, 1);
289 spin_lock(&inode_lock
);
290 inode
->i_state
&= ~I_WILL_FREE
;
291 inodes_stat
.nr_unused
--;
292 hlist_del_init(&inode
->i_hash
);
294 list_del_init(&inode
->i_list
);
295 list_del_init(&inode
->i_sb_list
);
296 inode
->i_state
|= I_FREEING
;
297 inodes_stat
.nr_inodes
--;
298 spin_unlock(&inode_lock
);
299 if (inode
->i_data
.nrpages
)
300 truncate_hugepages(&inode
->i_data
, 0);
302 destroy_inode(inode
);
305 static void hugetlbfs_drop_inode(struct inode
*inode
)
308 generic_delete_inode(inode
);
310 hugetlbfs_forget_inode(inode
);
314 hugetlb_vmtruncate_list(struct prio_tree_root
*root
, pgoff_t pgoff
)
316 struct vm_area_struct
*vma
;
317 struct prio_tree_iter iter
;
319 vma_prio_tree_foreach(vma
, &iter
, root
, pgoff
, ULONG_MAX
) {
320 unsigned long v_offset
;
323 * Can the expression below overflow on 32-bit arches?
324 * No, because the prio_tree returns us only those vmas
325 * which overlap the truncated area starting at pgoff,
326 * and no vma on a 32-bit arch can span beyond the 4GB.
328 if (vma
->vm_pgoff
< pgoff
)
329 v_offset
= (pgoff
- vma
->vm_pgoff
) << PAGE_SHIFT
;
333 unmap_hugepage_range(vma
,
334 vma
->vm_start
+ v_offset
, vma
->vm_end
);
339 * Expanding truncates are not allowed.
341 static int hugetlb_vmtruncate(struct inode
*inode
, loff_t offset
)
344 struct address_space
*mapping
= inode
->i_mapping
;
346 if (offset
> inode
->i_size
)
349 BUG_ON(offset
& ~HPAGE_MASK
);
350 pgoff
= offset
>> PAGE_SHIFT
;
352 inode
->i_size
= offset
;
353 spin_lock(&mapping
->i_mmap_lock
);
354 if (!prio_tree_empty(&mapping
->i_mmap
))
355 hugetlb_vmtruncate_list(&mapping
->i_mmap
, pgoff
);
356 spin_unlock(&mapping
->i_mmap_lock
);
357 truncate_hugepages(mapping
, offset
);
361 static int hugetlbfs_setattr(struct dentry
*dentry
, struct iattr
*attr
)
363 struct inode
*inode
= dentry
->d_inode
;
365 unsigned int ia_valid
= attr
->ia_valid
;
369 error
= inode_change_ok(inode
, attr
);
373 if (ia_valid
& ATTR_SIZE
) {
375 if (!(attr
->ia_size
& ~HPAGE_MASK
))
376 error
= hugetlb_vmtruncate(inode
, attr
->ia_size
);
379 attr
->ia_valid
&= ~ATTR_SIZE
;
381 error
= inode_setattr(inode
, attr
);
386 static struct inode
*hugetlbfs_get_inode(struct super_block
*sb
, uid_t uid
,
387 gid_t gid
, int mode
, dev_t dev
)
391 inode
= new_inode(sb
);
393 struct hugetlbfs_inode_info
*info
;
394 inode
->i_mode
= mode
;
397 inode
->i_blksize
= HPAGE_SIZE
;
399 inode
->i_mapping
->a_ops
= &hugetlbfs_aops
;
400 inode
->i_mapping
->backing_dev_info
=&hugetlbfs_backing_dev_info
;
401 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
402 info
= HUGETLBFS_I(inode
);
403 mpol_shared_policy_init(&info
->policy
, MPOL_DEFAULT
, NULL
);
404 switch (mode
& S_IFMT
) {
406 init_special_inode(inode
, mode
, dev
);
409 inode
->i_op
= &hugetlbfs_inode_operations
;
410 inode
->i_fop
= &hugetlbfs_file_operations
;
413 inode
->i_op
= &hugetlbfs_dir_inode_operations
;
414 inode
->i_fop
= &simple_dir_operations
;
416 /* directory inodes start off with i_nlink == 2 (for "." entry) */
420 inode
->i_op
= &page_symlink_inode_operations
;
428 * File creation. Allocate an inode, and we're done..
430 static int hugetlbfs_mknod(struct inode
*dir
,
431 struct dentry
*dentry
, int mode
, dev_t dev
)
437 if (dir
->i_mode
& S_ISGID
) {
442 gid
= current
->fsgid
;
444 inode
= hugetlbfs_get_inode(dir
->i_sb
, current
->fsuid
, gid
, mode
, dev
);
446 dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME
;
447 d_instantiate(dentry
, inode
);
448 dget(dentry
); /* Extra count - pin the dentry in core */
454 static int hugetlbfs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
456 int retval
= hugetlbfs_mknod(dir
, dentry
, mode
| S_IFDIR
, 0);
462 static int hugetlbfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
, struct nameidata
*nd
)
464 return hugetlbfs_mknod(dir
, dentry
, mode
| S_IFREG
, 0);
467 static int hugetlbfs_symlink(struct inode
*dir
,
468 struct dentry
*dentry
, const char *symname
)
474 if (dir
->i_mode
& S_ISGID
)
477 gid
= current
->fsgid
;
479 inode
= hugetlbfs_get_inode(dir
->i_sb
, current
->fsuid
,
480 gid
, S_IFLNK
|S_IRWXUGO
, 0);
482 int l
= strlen(symname
)+1;
483 error
= page_symlink(inode
, symname
, l
);
485 d_instantiate(dentry
, inode
);
490 dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME
;
496 * For direct-IO reads into hugetlb pages
498 static int hugetlbfs_set_page_dirty(struct page
*page
)
503 static int hugetlbfs_statfs(struct super_block
*sb
, struct kstatfs
*buf
)
505 struct hugetlbfs_sb_info
*sbinfo
= HUGETLBFS_SB(sb
);
507 buf
->f_type
= HUGETLBFS_MAGIC
;
508 buf
->f_bsize
= HPAGE_SIZE
;
510 spin_lock(&sbinfo
->stat_lock
);
511 /* If no limits set, just report 0 for max/free/used
512 * blocks, like simple_statfs() */
513 if (sbinfo
->max_blocks
>= 0) {
514 buf
->f_blocks
= sbinfo
->max_blocks
;
515 buf
->f_bavail
= buf
->f_bfree
= sbinfo
->free_blocks
;
516 buf
->f_files
= sbinfo
->max_inodes
;
517 buf
->f_ffree
= sbinfo
->free_inodes
;
519 spin_unlock(&sbinfo
->stat_lock
);
521 buf
->f_namelen
= NAME_MAX
;
525 static void hugetlbfs_put_super(struct super_block
*sb
)
527 struct hugetlbfs_sb_info
*sbi
= HUGETLBFS_SB(sb
);
530 sb
->s_fs_info
= NULL
;
535 static inline int hugetlbfs_dec_free_inodes(struct hugetlbfs_sb_info
*sbinfo
)
537 if (sbinfo
->free_inodes
>= 0) {
538 spin_lock(&sbinfo
->stat_lock
);
539 if (unlikely(!sbinfo
->free_inodes
)) {
540 spin_unlock(&sbinfo
->stat_lock
);
543 sbinfo
->free_inodes
--;
544 spin_unlock(&sbinfo
->stat_lock
);
550 static void hugetlbfs_inc_free_inodes(struct hugetlbfs_sb_info
*sbinfo
)
552 if (sbinfo
->free_inodes
>= 0) {
553 spin_lock(&sbinfo
->stat_lock
);
554 sbinfo
->free_inodes
++;
555 spin_unlock(&sbinfo
->stat_lock
);
560 static kmem_cache_t
*hugetlbfs_inode_cachep
;
562 static struct inode
*hugetlbfs_alloc_inode(struct super_block
*sb
)
564 struct hugetlbfs_sb_info
*sbinfo
= HUGETLBFS_SB(sb
);
565 struct hugetlbfs_inode_info
*p
;
567 if (unlikely(!hugetlbfs_dec_free_inodes(sbinfo
)))
569 p
= kmem_cache_alloc(hugetlbfs_inode_cachep
, SLAB_KERNEL
);
571 hugetlbfs_inc_free_inodes(sbinfo
);
574 return &p
->vfs_inode
;
577 static void hugetlbfs_destroy_inode(struct inode
*inode
)
579 hugetlbfs_inc_free_inodes(HUGETLBFS_SB(inode
->i_sb
));
580 mpol_free_shared_policy(&HUGETLBFS_I(inode
)->policy
);
581 kmem_cache_free(hugetlbfs_inode_cachep
, HUGETLBFS_I(inode
));
584 static struct address_space_operations hugetlbfs_aops
= {
585 .readpage
= hugetlbfs_readpage
,
586 .prepare_write
= hugetlbfs_prepare_write
,
587 .commit_write
= hugetlbfs_commit_write
,
588 .set_page_dirty
= hugetlbfs_set_page_dirty
,
592 static void init_once(void *foo
, kmem_cache_t
*cachep
, unsigned long flags
)
594 struct hugetlbfs_inode_info
*ei
= (struct hugetlbfs_inode_info
*)foo
;
596 if ((flags
& (SLAB_CTOR_VERIFY
|SLAB_CTOR_CONSTRUCTOR
)) ==
597 SLAB_CTOR_CONSTRUCTOR
)
598 inode_init_once(&ei
->vfs_inode
);
601 struct file_operations hugetlbfs_file_operations
= {
602 .mmap
= hugetlbfs_file_mmap
,
603 .fsync
= simple_sync_file
,
604 .get_unmapped_area
= hugetlb_get_unmapped_area
,
607 static struct inode_operations hugetlbfs_dir_inode_operations
= {
608 .create
= hugetlbfs_create
,
609 .lookup
= simple_lookup
,
611 .unlink
= simple_unlink
,
612 .symlink
= hugetlbfs_symlink
,
613 .mkdir
= hugetlbfs_mkdir
,
614 .rmdir
= simple_rmdir
,
615 .mknod
= hugetlbfs_mknod
,
616 .rename
= simple_rename
,
617 .setattr
= hugetlbfs_setattr
,
620 static struct inode_operations hugetlbfs_inode_operations
= {
621 .setattr
= hugetlbfs_setattr
,
624 static struct super_operations hugetlbfs_ops
= {
625 .alloc_inode
= hugetlbfs_alloc_inode
,
626 .destroy_inode
= hugetlbfs_destroy_inode
,
627 .statfs
= hugetlbfs_statfs
,
628 .delete_inode
= hugetlbfs_delete_inode
,
629 .drop_inode
= hugetlbfs_drop_inode
,
630 .put_super
= hugetlbfs_put_super
,
634 hugetlbfs_parse_options(char *options
, struct hugetlbfs_config
*pconfig
)
636 char *opt
, *value
, *rest
;
640 while ((opt
= strsep(&options
, ",")) != NULL
) {
644 value
= strchr(opt
, '=');
645 if (!value
|| !*value
)
650 if (!strcmp(opt
, "uid"))
651 pconfig
->uid
= simple_strtoul(value
, &value
, 0);
652 else if (!strcmp(opt
, "gid"))
653 pconfig
->gid
= simple_strtoul(value
, &value
, 0);
654 else if (!strcmp(opt
, "mode"))
655 pconfig
->mode
= simple_strtoul(value
,&value
,0) & 0777U;
656 else if (!strcmp(opt
, "size")) {
657 unsigned long long size
= memparse(value
, &rest
);
659 size
<<= HPAGE_SHIFT
;
660 size
*= max_huge_pages
;
664 pconfig
->nr_blocks
= (size
>> HPAGE_SHIFT
);
666 } else if (!strcmp(opt
,"nr_inodes")) {
667 pconfig
->nr_inodes
= memparse(value
, &rest
);
679 hugetlbfs_fill_super(struct super_block
*sb
, void *data
, int silent
)
681 struct inode
* inode
;
682 struct dentry
* root
;
684 struct hugetlbfs_config config
;
685 struct hugetlbfs_sb_info
*sbinfo
;
687 config
.nr_blocks
= -1; /* No limit on size by default */
688 config
.nr_inodes
= -1; /* No limit on number of inodes by default */
689 config
.uid
= current
->fsuid
;
690 config
.gid
= current
->fsgid
;
692 ret
= hugetlbfs_parse_options(data
, &config
);
697 sbinfo
= kmalloc(sizeof(struct hugetlbfs_sb_info
), GFP_KERNEL
);
700 sb
->s_fs_info
= sbinfo
;
701 spin_lock_init(&sbinfo
->stat_lock
);
702 sbinfo
->max_blocks
= config
.nr_blocks
;
703 sbinfo
->free_blocks
= config
.nr_blocks
;
704 sbinfo
->max_inodes
= config
.nr_inodes
;
705 sbinfo
->free_inodes
= config
.nr_inodes
;
706 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
707 sb
->s_blocksize
= HPAGE_SIZE
;
708 sb
->s_blocksize_bits
= HPAGE_SHIFT
;
709 sb
->s_magic
= HUGETLBFS_MAGIC
;
710 sb
->s_op
= &hugetlbfs_ops
;
712 inode
= hugetlbfs_get_inode(sb
, config
.uid
, config
.gid
,
713 S_IFDIR
| config
.mode
, 0);
717 root
= d_alloc_root(inode
);
729 int hugetlb_get_quota(struct address_space
*mapping
)
732 struct hugetlbfs_sb_info
*sbinfo
= HUGETLBFS_SB(mapping
->host
->i_sb
);
734 if (sbinfo
->free_blocks
> -1) {
735 spin_lock(&sbinfo
->stat_lock
);
736 if (sbinfo
->free_blocks
> 0)
737 sbinfo
->free_blocks
--;
740 spin_unlock(&sbinfo
->stat_lock
);
746 void hugetlb_put_quota(struct address_space
*mapping
)
748 struct hugetlbfs_sb_info
*sbinfo
= HUGETLBFS_SB(mapping
->host
->i_sb
);
750 if (sbinfo
->free_blocks
> -1) {
751 spin_lock(&sbinfo
->stat_lock
);
752 sbinfo
->free_blocks
++;
753 spin_unlock(&sbinfo
->stat_lock
);
757 static struct super_block
*hugetlbfs_get_sb(struct file_system_type
*fs_type
,
758 int flags
, const char *dev_name
, void *data
)
760 return get_sb_nodev(fs_type
, flags
, data
, hugetlbfs_fill_super
);
763 static struct file_system_type hugetlbfs_fs_type
= {
765 .get_sb
= hugetlbfs_get_sb
,
766 .kill_sb
= kill_litter_super
,
769 static struct vfsmount
*hugetlbfs_vfsmount
;
772 * Return the next identifier for a shm file
774 static unsigned long hugetlbfs_counter(void)
776 static DEFINE_SPINLOCK(lock
);
777 static unsigned long counter
;
786 static int can_do_hugetlb_shm(void)
788 return likely(capable(CAP_IPC_LOCK
) ||
789 in_group_p(sysctl_hugetlb_shm_group
) ||
793 struct file
*hugetlb_zero_setup(size_t size
)
798 struct dentry
*dentry
, *root
;
799 struct qstr quick_string
;
802 if (!can_do_hugetlb_shm())
803 return ERR_PTR(-EPERM
);
805 if (!is_hugepage_mem_enough(size
))
806 return ERR_PTR(-ENOMEM
);
808 if (!user_shm_lock(size
, current
->user
))
809 return ERR_PTR(-ENOMEM
);
811 root
= hugetlbfs_vfsmount
->mnt_root
;
812 snprintf(buf
, 16, "%lu", hugetlbfs_counter());
813 quick_string
.name
= buf
;
814 quick_string
.len
= strlen(quick_string
.name
);
815 quick_string
.hash
= 0;
816 dentry
= d_alloc(root
, &quick_string
);
821 file
= get_empty_filp();
826 inode
= hugetlbfs_get_inode(root
->d_sb
, current
->fsuid
,
827 current
->fsgid
, S_IFREG
| S_IRWXUGO
, 0);
831 d_instantiate(dentry
, inode
);
832 inode
->i_size
= size
;
834 file
->f_vfsmnt
= mntget(hugetlbfs_vfsmount
);
835 file
->f_dentry
= dentry
;
836 file
->f_mapping
= inode
->i_mapping
;
837 file
->f_op
= &hugetlbfs_file_operations
;
838 file
->f_mode
= FMODE_WRITE
| FMODE_READ
;
846 user_shm_unlock(size
, current
->user
);
847 return ERR_PTR(error
);
850 static int __init
init_hugetlbfs_fs(void)
853 struct vfsmount
*vfsmount
;
855 hugetlbfs_inode_cachep
= kmem_cache_create("hugetlbfs_inode_cache",
856 sizeof(struct hugetlbfs_inode_info
),
857 0, 0, init_once
, NULL
);
858 if (hugetlbfs_inode_cachep
== NULL
)
861 error
= register_filesystem(&hugetlbfs_fs_type
);
865 vfsmount
= kern_mount(&hugetlbfs_fs_type
);
867 if (!IS_ERR(vfsmount
)) {
868 hugetlbfs_vfsmount
= vfsmount
;
872 error
= PTR_ERR(vfsmount
);
876 kmem_cache_destroy(hugetlbfs_inode_cachep
);
880 static void __exit
exit_hugetlbfs_fs(void)
882 kmem_cache_destroy(hugetlbfs_inode_cachep
);
883 unregister_filesystem(&hugetlbfs_fs_type
);
886 module_init(init_hugetlbfs_fs
)
887 module_exit(exit_hugetlbfs_fs
)
889 MODULE_LICENSE("GPL");