mmap.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * mmap.c
  5. *
  6. * Code to deal with the mess that is clustered mmap.
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/fs.h>
  26. #include <linux/types.h>
  27. #include <linux/slab.h>
  28. #include <linux/highmem.h>
  29. #include <linux/pagemap.h>
  30. #include <linux/uio.h>
  31. #include <linux/signal.h>
  32. #include <linux/rbtree.h>
  33. #define MLOG_MASK_PREFIX ML_FILE_IO
  34. #include <cluster/masklog.h>
  35. #include "ocfs2.h"
  36. #include "dlmglue.h"
  37. #include "file.h"
  38. #include "inode.h"
  39. #include "mmap.h"
  40. static struct page *ocfs2_nopage(struct vm_area_struct * area,
  41. unsigned long address,
  42. int *type)
  43. {
  44. struct page *page = NOPAGE_SIGBUS;
  45. sigset_t blocked, oldset;
  46. int ret;
  47. mlog_entry("(area=%p, address=%lu, type=%p)\n", area, address,
  48. type);
  49. /* The best way to deal with signals in this path is
  50. * to block them upfront, rather than allowing the
  51. * locking paths to return -ERESTARTSYS. */
  52. sigfillset(&blocked);
  53. /* We should technically never get a bad ret return
  54. * from sigprocmask */
  55. ret = sigprocmask(SIG_BLOCK, &blocked, &oldset);
  56. if (ret < 0) {
  57. mlog_errno(ret);
  58. goto out;
  59. }
  60. page = filemap_nopage(area, address, type);
  61. ret = sigprocmask(SIG_SETMASK, &oldset, NULL);
  62. if (ret < 0)
  63. mlog_errno(ret);
  64. out:
  65. mlog_exit_ptr(page);
  66. return page;
  67. }
  68. static struct vm_operations_struct ocfs2_file_vm_ops = {
  69. .nopage = ocfs2_nopage,
  70. };
  71. int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
  72. {
  73. int ret = 0, lock_level = 0;
  74. struct ocfs2_super *osb = OCFS2_SB(file->f_dentry->d_inode->i_sb);
  75. /*
  76. * Only support shared writeable mmap for local mounts which
  77. * don't know about holes.
  78. */
  79. if ((!ocfs2_mount_local(osb) || ocfs2_sparse_alloc(osb)) &&
  80. ((vma->vm_flags & VM_SHARED) || (vma->vm_flags & VM_MAYSHARE)) &&
  81. ((vma->vm_flags & VM_WRITE) || (vma->vm_flags & VM_MAYWRITE))) {
  82. mlog(0, "disallow shared writable mmaps %lx\n", vma->vm_flags);
  83. /* This is -EINVAL because generic_file_readonly_mmap
  84. * returns it in a similar situation. */
  85. return -EINVAL;
  86. }
  87. ret = ocfs2_meta_lock_atime(file->f_dentry->d_inode,
  88. file->f_vfsmnt, &lock_level);
  89. if (ret < 0) {
  90. mlog_errno(ret);
  91. goto out;
  92. }
  93. ocfs2_meta_unlock(file->f_dentry->d_inode, lock_level);
  94. out:
  95. vma->vm_ops = &ocfs2_file_vm_ops;
  96. return 0;
  97. }