original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

510 lines
11 KiB

include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
12 years ago
Fix the nested PR lock calling issue in ACL Hi, Thanks a lot for all the review and comments so far;) I'd like to send the improved (V4) version of this patch. This patch fixes a deadlock in OCFS2 ACL. We found this bug in OCFS2 and Samba integration using scenario, the symptom is several smbd processes will be hung under heavy workload. Finally we found out it is the nested PR lock calling that leads to this deadlock: node1 node2 gr PR | V PR(EX)---> BAST:OCFS2_LOCK_BLOCKED | V rq PR | V wait=1 After requesting the 2nd PR lock, the process "smbd" went into D state. It can only be woken up when the 1st PR lock's RO holder equals zero. There should be an ocfs2_inode_unlock in the calling path later on, which can decrement the RO holder. But since it has been in uninterruptible sleep, the unlock function has no chance to be called. The related stack trace is: smbd D ffff8800013d0600 0 9522 5608 0x00000000 ffff88002ca7fb18 0000000000000282 ffff88002f964500 ffff88002ca7fa98 ffff8800013d0600 ffff88002ca7fae0 ffff88002f964340 ffff88002f964340 ffff88002ca7ffd8 ffff88002ca7ffd8 ffff88002f964340 ffff88002f964340 Call Trace: [<ffffffff80350425>] schedule_timeout+0x175/0x210 [<ffffffff8034f580>] wait_for_common+0xf0/0x210 [<ffffffffa03e12b9>] __ocfs2_cluster_lock+0x3b9/0xa90 [ocfs2] [<ffffffffa03e7665>] ocfs2_inode_lock_full_nested+0x255/0xdb0 [ocfs2] [<ffffffffa0446019>] ocfs2_get_acl+0x69/0x120 [ocfs2] [<ffffffffa0446368>] ocfs2_check_acl+0x28/0x80 [ocfs2] [<ffffffff800e3507>] acl_permission_check+0x57/0xb0 [<ffffffff800e357d>] generic_permission+0x1d/0xc0 [<ffffffffa03eecea>] ocfs2_permission+0x10a/0x1d0 [ocfs2] [<ffffffff800e3f65>] inode_permission+0x45/0x100 [<ffffffff800d86b3>] sys_chdir+0x53/0x90 [<ffffffff80007458>] system_call_fastpath+0x16/0x1b [<00007f34a4ef6927>] 0x7f34a4ef6927 For details, please see: https://bugzilla.novell.com/show_bug.cgi?id=614332 and http://oss.oracle.com/bugzilla/show_bug.cgi?id=1278 Signed-off-by: Jiaju Zhang <jjzhang@suse.de> Acked-by: Mark Fasheh <mfasheh@suse.com> Cc: stable@kernel.org Signed-off-by: Joel Becker <joel.becker@oracle.com>
11 years ago
Fix the nested PR lock calling issue in ACL Hi, Thanks a lot for all the review and comments so far;) I'd like to send the improved (V4) version of this patch. This patch fixes a deadlock in OCFS2 ACL. We found this bug in OCFS2 and Samba integration using scenario, the symptom is several smbd processes will be hung under heavy workload. Finally we found out it is the nested PR lock calling that leads to this deadlock: node1 node2 gr PR | V PR(EX)---> BAST:OCFS2_LOCK_BLOCKED | V rq PR | V wait=1 After requesting the 2nd PR lock, the process "smbd" went into D state. It can only be woken up when the 1st PR lock's RO holder equals zero. There should be an ocfs2_inode_unlock in the calling path later on, which can decrement the RO holder. But since it has been in uninterruptible sleep, the unlock function has no chance to be called. The related stack trace is: smbd D ffff8800013d0600 0 9522 5608 0x00000000 ffff88002ca7fb18 0000000000000282 ffff88002f964500 ffff88002ca7fa98 ffff8800013d0600 ffff88002ca7fae0 ffff88002f964340 ffff88002f964340 ffff88002ca7ffd8 ffff88002ca7ffd8 ffff88002f964340 ffff88002f964340 Call Trace: [<ffffffff80350425>] schedule_timeout+0x175/0x210 [<ffffffff8034f580>] wait_for_common+0xf0/0x210 [<ffffffffa03e12b9>] __ocfs2_cluster_lock+0x3b9/0xa90 [ocfs2] [<ffffffffa03e7665>] ocfs2_inode_lock_full_nested+0x255/0xdb0 [ocfs2] [<ffffffffa0446019>] ocfs2_get_acl+0x69/0x120 [ocfs2] [<ffffffffa0446368>] ocfs2_check_acl+0x28/0x80 [ocfs2] [<ffffffff800e3507>] acl_permission_check+0x57/0xb0 [<ffffffff800e357d>] generic_permission+0x1d/0xc0 [<ffffffffa03eecea>] ocfs2_permission+0x10a/0x1d0 [ocfs2] [<ffffffff800e3f65>] inode_permission+0x45/0x100 [<ffffffff800d86b3>] sys_chdir+0x53/0x90 [<ffffffff80007458>] system_call_fastpath+0x16/0x1b [<00007f34a4ef6927>] 0x7f34a4ef6927 For details, please see: https://bugzilla.novell.com/show_bug.cgi?id=614332 and http://oss.oracle.com/bugzilla/show_bug.cgi?id=1278 Signed-off-by: Jiaju Zhang <jjzhang@suse.de> Acked-by: Mark Fasheh <mfasheh@suse.com> Cc: stable@kernel.org Signed-off-by: Joel Becker <joel.becker@oracle.com>
11 years ago
Fix the nested PR lock calling issue in ACL Hi, Thanks a lot for all the review and comments so far;) I'd like to send the improved (V4) version of this patch. This patch fixes a deadlock in OCFS2 ACL. We found this bug in OCFS2 and Samba integration using scenario, the symptom is several smbd processes will be hung under heavy workload. Finally we found out it is the nested PR lock calling that leads to this deadlock: node1 node2 gr PR | V PR(EX)---> BAST:OCFS2_LOCK_BLOCKED | V rq PR | V wait=1 After requesting the 2nd PR lock, the process "smbd" went into D state. It can only be woken up when the 1st PR lock's RO holder equals zero. There should be an ocfs2_inode_unlock in the calling path later on, which can decrement the RO holder. But since it has been in uninterruptible sleep, the unlock function has no chance to be called. The related stack trace is: smbd D ffff8800013d0600 0 9522 5608 0x00000000 ffff88002ca7fb18 0000000000000282 ffff88002f964500 ffff88002ca7fa98 ffff8800013d0600 ffff88002ca7fae0 ffff88002f964340 ffff88002f964340 ffff88002ca7ffd8 ffff88002ca7ffd8 ffff88002f964340 ffff88002f964340 Call Trace: [<ffffffff80350425>] schedule_timeout+0x175/0x210 [<ffffffff8034f580>] wait_for_common+0xf0/0x210 [<ffffffffa03e12b9>] __ocfs2_cluster_lock+0x3b9/0xa90 [ocfs2] [<ffffffffa03e7665>] ocfs2_inode_lock_full_nested+0x255/0xdb0 [ocfs2] [<ffffffffa0446019>] ocfs2_get_acl+0x69/0x120 [ocfs2] [<ffffffffa0446368>] ocfs2_check_acl+0x28/0x80 [ocfs2] [<ffffffff800e3507>] acl_permission_check+0x57/0xb0 [<ffffffff800e357d>] generic_permission+0x1d/0xc0 [<ffffffffa03eecea>] ocfs2_permission+0x10a/0x1d0 [ocfs2] [<ffffffff800e3f65>] inode_permission+0x45/0x100 [<ffffffff800d86b3>] sys_chdir+0x53/0x90 [<ffffffff80007458>] system_call_fastpath+0x16/0x1b [<00007f34a4ef6927>] 0x7f34a4ef6927 For details, please see: https://bugzilla.novell.com/show_bug.cgi?id=614332 and http://oss.oracle.com/bugzilla/show_bug.cgi?id=1278 Signed-off-by: Jiaju Zhang <jjzhang@suse.de> Acked-by: Mark Fasheh <mfasheh@suse.com> Cc: stable@kernel.org Signed-off-by: Joel Becker <joel.becker@oracle.com>
11 years ago
Fix the nested PR lock calling issue in ACL Hi, Thanks a lot for all the review and comments so far;) I'd like to send the improved (V4) version of this patch. This patch fixes a deadlock in OCFS2 ACL. We found this bug in OCFS2 and Samba integration using scenario, the symptom is several smbd processes will be hung under heavy workload. Finally we found out it is the nested PR lock calling that leads to this deadlock: node1 node2 gr PR | V PR(EX)---> BAST:OCFS2_LOCK_BLOCKED | V rq PR | V wait=1 After requesting the 2nd PR lock, the process "smbd" went into D state. It can only be woken up when the 1st PR lock's RO holder equals zero. There should be an ocfs2_inode_unlock in the calling path later on, which can decrement the RO holder. But since it has been in uninterruptible sleep, the unlock function has no chance to be called. The related stack trace is: smbd D ffff8800013d0600 0 9522 5608 0x00000000 ffff88002ca7fb18 0000000000000282 ffff88002f964500 ffff88002ca7fa98 ffff8800013d0600 ffff88002ca7fae0 ffff88002f964340 ffff88002f964340 ffff88002ca7ffd8 ffff88002ca7ffd8 ffff88002f964340 ffff88002f964340 Call Trace: [<ffffffff80350425>] schedule_timeout+0x175/0x210 [<ffffffff8034f580>] wait_for_common+0xf0/0x210 [<ffffffffa03e12b9>] __ocfs2_cluster_lock+0x3b9/0xa90 [ocfs2] [<ffffffffa03e7665>] ocfs2_inode_lock_full_nested+0x255/0xdb0 [ocfs2] [<ffffffffa0446019>] ocfs2_get_acl+0x69/0x120 [ocfs2] [<ffffffffa0446368>] ocfs2_check_acl+0x28/0x80 [ocfs2] [<ffffffff800e3507>] acl_permission_check+0x57/0xb0 [<ffffffff800e357d>] generic_permission+0x1d/0xc0 [<ffffffffa03eecea>] ocfs2_permission+0x10a/0x1d0 [ocfs2] [<ffffffff800e3f65>] inode_permission+0x45/0x100 [<ffffffff800d86b3>] sys_chdir+0x53/0x90 [<ffffffff80007458>] system_call_fastpath+0x16/0x1b [<00007f34a4ef6927>] 0x7f34a4ef6927 For details, please see: https://bugzilla.novell.com/show_bug.cgi?id=614332 and http://oss.oracle.com/bugzilla/show_bug.cgi?id=1278 Signed-off-by: Jiaju Zhang <jjzhang@suse.de> Acked-by: Mark Fasheh <mfasheh@suse.com> Cc: stable@kernel.org Signed-off-by: Joel Becker <joel.becker@oracle.com>
11 years ago
Fix the nested PR lock calling issue in ACL Hi, Thanks a lot for all the review and comments so far;) I'd like to send the improved (V4) version of this patch. This patch fixes a deadlock in OCFS2 ACL. We found this bug in OCFS2 and Samba integration using scenario, the symptom is several smbd processes will be hung under heavy workload. Finally we found out it is the nested PR lock calling that leads to this deadlock: node1 node2 gr PR | V PR(EX)---> BAST:OCFS2_LOCK_BLOCKED | V rq PR | V wait=1 After requesting the 2nd PR lock, the process "smbd" went into D state. It can only be woken up when the 1st PR lock's RO holder equals zero. There should be an ocfs2_inode_unlock in the calling path later on, which can decrement the RO holder. But since it has been in uninterruptible sleep, the unlock function has no chance to be called. The related stack trace is: smbd D ffff8800013d0600 0 9522 5608 0x00000000 ffff88002ca7fb18 0000000000000282 ffff88002f964500 ffff88002ca7fa98 ffff8800013d0600 ffff88002ca7fae0 ffff88002f964340 ffff88002f964340 ffff88002ca7ffd8 ffff88002ca7ffd8 ffff88002f964340 ffff88002f964340 Call Trace: [<ffffffff80350425>] schedule_timeout+0x175/0x210 [<ffffffff8034f580>] wait_for_common+0xf0/0x210 [<ffffffffa03e12b9>] __ocfs2_cluster_lock+0x3b9/0xa90 [ocfs2] [<ffffffffa03e7665>] ocfs2_inode_lock_full_nested+0x255/0xdb0 [ocfs2] [<ffffffffa0446019>] ocfs2_get_acl+0x69/0x120 [ocfs2] [<ffffffffa0446368>] ocfs2_check_acl+0x28/0x80 [ocfs2] [<ffffffff800e3507>] acl_permission_check+0x57/0xb0 [<ffffffff800e357d>] generic_permission+0x1d/0xc0 [<ffffffffa03eecea>] ocfs2_permission+0x10a/0x1d0 [ocfs2] [<ffffffff800e3f65>] inode_permission+0x45/0x100 [<ffffffff800d86b3>] sys_chdir+0x53/0x90 [<ffffffff80007458>] system_call_fastpath+0x16/0x1b [<00007f34a4ef6927>] 0x7f34a4ef6927 For details, please see: https://bugzilla.novell.com/show_bug.cgi?id=614332 and http://oss.oracle.com/bugzilla/show_bug.cgi?id=1278 Signed-off-by: Jiaju Zhang <jjzhang@suse.de> Acked-by: Mark Fasheh <mfasheh@suse.com> Cc: stable@kernel.org Signed-off-by: Joel Becker <joel.becker@oracle.com>
11 years ago
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * acl.c
  5. *
  6. * Copyright (C) 2004, 2008 Oracle. All rights reserved.
  7. *
  8. * CREDITS:
  9. * Lots of code in this file is copy from linux/fs/ext3/acl.c.
  10. * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public
  14. * License version 2 as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. */
  21. #include <linux/init.h>
  22. #include <linux/module.h>
  23. #include <linux/slab.h>
  24. #include <linux/string.h>
  25. #include <cluster/masklog.h>
  26. #include "ocfs2.h"
  27. #include "alloc.h"
  28. #include "dlmglue.h"
  29. #include "file.h"
  30. #include "inode.h"
  31. #include "journal.h"
  32. #include "ocfs2_fs.h"
  33. #include "xattr.h"
  34. #include "acl.h"
  35. /*
  36. * Convert from xattr value to acl struct.
  37. */
  38. static struct posix_acl *ocfs2_acl_from_xattr(const void *value, size_t size)
  39. {
  40. int n, count;
  41. struct posix_acl *acl;
  42. if (!value)
  43. return NULL;
  44. if (size < sizeof(struct posix_acl_entry))
  45. return ERR_PTR(-EINVAL);
  46. count = size / sizeof(struct posix_acl_entry);
  47. if (count < 0)
  48. return ERR_PTR(-EINVAL);
  49. if (count == 0)
  50. return NULL;
  51. acl = posix_acl_alloc(count, GFP_NOFS);
  52. if (!acl)
  53. return ERR_PTR(-ENOMEM);
  54. for (n = 0; n < count; n++) {
  55. struct ocfs2_acl_entry *entry =
  56. (struct ocfs2_acl_entry *)value;
  57. acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
  58. acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
  59. acl->a_entries[n].e_id = le32_to_cpu(entry->e_id);
  60. value += sizeof(struct posix_acl_entry);
  61. }
  62. return acl;
  63. }
  64. /*
  65. * Convert acl struct to xattr value.
  66. */
  67. static void *ocfs2_acl_to_xattr(const struct posix_acl *acl, size_t *size)
  68. {
  69. struct ocfs2_acl_entry *entry = NULL;
  70. char *ocfs2_acl;
  71. size_t n;
  72. *size = acl->a_count * sizeof(struct posix_acl_entry);
  73. ocfs2_acl = kmalloc(*size, GFP_NOFS);
  74. if (!ocfs2_acl)
  75. return ERR_PTR(-ENOMEM);
  76. entry = (struct ocfs2_acl_entry *)ocfs2_acl;
  77. for (n = 0; n < acl->a_count; n++, entry++) {
  78. entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
  79. entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
  80. entry->e_id = cpu_to_le32(acl->a_entries[n].e_id);
  81. }
  82. return ocfs2_acl;
  83. }
  84. static struct posix_acl *ocfs2_get_acl_nolock(struct inode *inode,
  85. int type,
  86. struct buffer_head *di_bh)
  87. {
  88. int name_index;
  89. char *value = NULL;
  90. struct posix_acl *acl;
  91. int retval;
  92. switch (type) {
  93. case ACL_TYPE_ACCESS:
  94. name_index = OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS;
  95. break;
  96. case ACL_TYPE_DEFAULT:
  97. name_index = OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT;
  98. break;
  99. default:
  100. return ERR_PTR(-EINVAL);
  101. }
  102. retval = ocfs2_xattr_get_nolock(inode, di_bh, name_index, "", NULL, 0);
  103. if (retval > 0) {
  104. value = kmalloc(retval, GFP_NOFS);
  105. if (!value)
  106. return ERR_PTR(-ENOMEM);
  107. retval = ocfs2_xattr_get_nolock(inode, di_bh, name_index,
  108. "", value, retval);
  109. }
  110. if (retval > 0)
  111. acl = ocfs2_acl_from_xattr(value, retval);
  112. else if (retval == -ENODATA || retval == 0)
  113. acl = NULL;
  114. else
  115. acl = ERR_PTR(retval);
  116. kfree(value);
  117. return acl;
  118. }
  119. /*
  120. * Get posix acl.
  121. */
  122. static struct posix_acl *ocfs2_get_acl(struct inode *inode, int type)
  123. {
  124. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  125. struct buffer_head *di_bh = NULL;
  126. struct posix_acl *acl;
  127. int ret;
  128. if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
  129. return NULL;
  130. ret = ocfs2_inode_lock(inode, &di_bh, 0);
  131. if (ret < 0) {
  132. mlog_errno(ret);
  133. acl = ERR_PTR(ret);
  134. return acl;
  135. }
  136. acl = ocfs2_get_acl_nolock(inode, type, di_bh);
  137. ocfs2_inode_unlock(inode, 0);
  138. brelse(di_bh);
  139. return acl;
  140. }
  141. /*
  142. * Helper function to set i_mode in memory and disk. Some call paths
  143. * will not have di_bh or a journal handle to pass, in which case it
  144. * will create it's own.
  145. */
  146. static int ocfs2_acl_set_mode(struct inode *inode, struct buffer_head *di_bh,
  147. handle_t *handle, umode_t new_mode)
  148. {
  149. int ret, commit_handle = 0;
  150. struct ocfs2_dinode *di;
  151. if (di_bh == NULL) {
  152. ret = ocfs2_read_inode_block(inode, &di_bh);
  153. if (ret) {
  154. mlog_errno(ret);
  155. goto out;
  156. }
  157. } else
  158. get_bh(di_bh);
  159. if (handle == NULL) {
  160. handle = ocfs2_start_trans(OCFS2_SB(inode->i_sb),
  161. OCFS2_INODE_UPDATE_CREDITS);
  162. if (IS_ERR(handle)) {
  163. ret = PTR_ERR(handle);
  164. mlog_errno(ret);
  165. goto out_brelse;
  166. }
  167. commit_handle = 1;
  168. }
  169. di = (struct ocfs2_dinode *)di_bh->b_data;
  170. ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
  171. OCFS2_JOURNAL_ACCESS_WRITE);
  172. if (ret) {
  173. mlog_errno(ret);
  174. goto out_commit;
  175. }
  176. inode->i_mode = new_mode;
  177. inode->i_ctime = CURRENT_TIME;
  178. di->i_mode = cpu_to_le16(inode->i_mode);
  179. di->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
  180. di->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
  181. ocfs2_journal_dirty(handle, di_bh);
  182. out_commit:
  183. if (commit_handle)
  184. ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
  185. out_brelse:
  186. brelse(di_bh);
  187. out:
  188. return ret;
  189. }
  190. /*
  191. * Set the access or default ACL of an inode.
  192. */
  193. static int ocfs2_set_acl(handle_t *handle,
  194. struct inode *inode,
  195. struct buffer_head *di_bh,
  196. int type,
  197. struct posix_acl *acl,
  198. struct ocfs2_alloc_context *meta_ac,
  199. struct ocfs2_alloc_context *data_ac)
  200. {
  201. int name_index;
  202. void *value = NULL;
  203. size_t size = 0;
  204. int ret;
  205. if (S_ISLNK(inode->i_mode))
  206. return -EOPNOTSUPP;
  207. switch (type) {
  208. case ACL_TYPE_ACCESS:
  209. name_index = OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS;
  210. if (acl) {
  211. umode_t mode = inode->i_mode;
  212. ret = posix_acl_equiv_mode(acl, &mode);
  213. if (ret < 0)
  214. return ret;
  215. else {
  216. if (ret == 0)
  217. acl = NULL;
  218. ret = ocfs2_acl_set_mode(inode, di_bh,
  219. handle, mode);
  220. if (ret)
  221. return ret;
  222. }
  223. }
  224. break;
  225. case ACL_TYPE_DEFAULT:
  226. name_index = OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT;
  227. if (!S_ISDIR(inode->i_mode))
  228. return acl ? -EACCES : 0;
  229. break;
  230. default:
  231. return -EINVAL;
  232. }
  233. if (acl) {
  234. value = ocfs2_acl_to_xattr(acl, &size);
  235. if (IS_ERR(value))
  236. return (int)PTR_ERR(value);
  237. }
  238. if (handle)
  239. ret = ocfs2_xattr_set_handle(handle, inode, di_bh, name_index,
  240. "", value, size, 0,
  241. meta_ac, data_ac);
  242. else
  243. ret = ocfs2_xattr_set(inode, name_index, "", value, size, 0);
  244. kfree(value);
  245. return ret;
  246. }
  247. struct posix_acl *ocfs2_iop_get_acl(struct inode *inode, int type)
  248. {
  249. struct ocfs2_super *osb;
  250. struct buffer_head *di_bh = NULL;
  251. struct posix_acl *acl;
  252. int ret = -EAGAIN;
  253. osb = OCFS2_SB(inode->i_sb);
  254. if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
  255. return NULL;
  256. ret = ocfs2_read_inode_block(inode, &di_bh);
  257. if (ret < 0)
  258. return ERR_PTR(ret);
  259. acl = ocfs2_get_acl_nolock(inode, type, di_bh);
  260. brelse(di_bh);
  261. return acl;
  262. }
  263. int ocfs2_acl_chmod(struct inode *inode)
  264. {
  265. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  266. struct posix_acl *acl;
  267. int ret;
  268. if (S_ISLNK(inode->i_mode))
  269. return -EOPNOTSUPP;
  270. if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
  271. return 0;
  272. acl = ocfs2_get_acl(inode, ACL_TYPE_ACCESS);
  273. if (IS_ERR(acl) || !acl)
  274. return PTR_ERR(acl);
  275. ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
  276. if (ret)
  277. return ret;
  278. ret = ocfs2_set_acl(NULL, inode, NULL, ACL_TYPE_ACCESS,
  279. acl, NULL, NULL);
  280. posix_acl_release(acl);
  281. return ret;
  282. }
  283. /*
  284. * Initialize the ACLs of a new inode. If parent directory has default ACL,
  285. * then clone to new inode. Called from ocfs2_mknod.
  286. */
  287. int ocfs2_init_acl(handle_t *handle,
  288. struct inode *inode,
  289. struct inode *dir,
  290. struct buffer_head *di_bh,
  291. struct buffer_head *dir_bh,
  292. struct ocfs2_alloc_context *meta_ac,
  293. struct ocfs2_alloc_context *data_ac)
  294. {
  295. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  296. struct posix_acl *acl = NULL;
  297. int ret = 0, ret2;
  298. umode_t mode;
  299. if (!S_ISLNK(inode->i_mode)) {
  300. if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
  301. acl = ocfs2_get_acl_nolock(dir, ACL_TYPE_DEFAULT,
  302. dir_bh);
  303. if (IS_ERR(acl))
  304. return PTR_ERR(acl);
  305. }
  306. if (!acl) {
  307. mode = inode->i_mode & ~current_umask();
  308. ret = ocfs2_acl_set_mode(inode, di_bh, handle, mode);
  309. if (ret) {
  310. mlog_errno(ret);
  311. goto cleanup;
  312. }
  313. }
  314. }
  315. if ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) && acl) {
  316. if (S_ISDIR(inode->i_mode)) {
  317. ret = ocfs2_set_acl(handle, inode, di_bh,
  318. ACL_TYPE_DEFAULT, acl,
  319. meta_ac, data_ac);
  320. if (ret)
  321. goto cleanup;
  322. }
  323. mode = inode->i_mode;
  324. ret = posix_acl_create(&acl, GFP_NOFS, &mode);
  325. if (ret < 0)
  326. return ret;
  327. ret2 = ocfs2_acl_set_mode(inode, di_bh, handle, mode);
  328. if (ret2) {
  329. mlog_errno(ret2);
  330. ret = ret2;
  331. goto cleanup;
  332. }
  333. if (ret > 0) {
  334. ret = ocfs2_set_acl(handle, inode,
  335. di_bh, ACL_TYPE_ACCESS,
  336. acl, meta_ac, data_ac);
  337. }
  338. }
  339. cleanup:
  340. posix_acl_release(acl);
  341. return ret;
  342. }
  343. static size_t ocfs2_xattr_list_acl_access(struct dentry *dentry,
  344. char *list,
  345. size_t list_len,
  346. const char *name,
  347. size_t name_len,
  348. int type)
  349. {
  350. struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
  351. const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
  352. if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
  353. return 0;
  354. if (list && size <= list_len)
  355. memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
  356. return size;
  357. }
  358. static size_t ocfs2_xattr_list_acl_default(struct dentry *dentry,
  359. char *list,
  360. size_t list_len,
  361. const char *name,
  362. size_t name_len,
  363. int type)
  364. {
  365. struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
  366. const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
  367. if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
  368. return 0;
  369. if (list && size <= list_len)
  370. memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
  371. return size;
  372. }
  373. static int ocfs2_xattr_get_acl(struct dentry *dentry, const char *name,
  374. void *buffer, size_t size, int type)
  375. {
  376. struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
  377. struct posix_acl *acl;
  378. int ret;
  379. if (strcmp(name, "") != 0)
  380. return -EINVAL;
  381. if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
  382. return -EOPNOTSUPP;
  383. acl = ocfs2_get_acl(dentry->d_inode, type);
  384. if (IS_ERR(acl))
  385. return PTR_ERR(acl);
  386. if (acl == NULL)
  387. return -ENODATA;
  388. ret = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
  389. posix_acl_release(acl);
  390. return ret;
  391. }
  392. static int ocfs2_xattr_set_acl(struct dentry *dentry, const char *name,
  393. const void *value, size_t size, int flags, int type)
  394. {
  395. struct inode *inode = dentry->d_inode;
  396. struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
  397. struct posix_acl *acl;
  398. int ret = 0;
  399. if (strcmp(name, "") != 0)
  400. return -EINVAL;
  401. if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
  402. return -EOPNOTSUPP;
  403. if (!inode_owner_or_capable(inode))
  404. return -EPERM;
  405. if (value) {
  406. acl = posix_acl_from_xattr(&init_user_ns, value, size);
  407. if (IS_ERR(acl))
  408. return PTR_ERR(acl);
  409. else if (acl) {
  410. ret = posix_acl_valid(acl);
  411. if (ret)
  412. goto cleanup;
  413. }
  414. } else
  415. acl = NULL;
  416. ret = ocfs2_set_acl(NULL, inode, NULL, type, acl, NULL, NULL);
  417. cleanup:
  418. posix_acl_release(acl);
  419. return ret;
  420. }
  421. const struct xattr_handler ocfs2_xattr_acl_access_handler = {
  422. .prefix = POSIX_ACL_XATTR_ACCESS,
  423. .flags = ACL_TYPE_ACCESS,
  424. .list = ocfs2_xattr_list_acl_access,
  425. .get = ocfs2_xattr_get_acl,
  426. .set = ocfs2_xattr_set_acl,
  427. };
  428. const struct xattr_handler ocfs2_xattr_acl_default_handler = {
  429. .prefix = POSIX_ACL_XATTR_DEFAULT,
  430. .flags = ACL_TYPE_DEFAULT,
  431. .list = ocfs2_xattr_list_acl_default,
  432. .get = ocfs2_xattr_get_acl,
  433. .set = ocfs2_xattr_set_acl,
  434. };