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.

422 lines
8.7 KiB

xfs: event tracing support Convert the old xfs tracing support that could only be used with the out of tree kdb and xfsidbg patches to use the generic event tracer. To use it make sure CONFIG_EVENT_TRACING is enabled and then enable all xfs trace channels by: echo 1 > /sys/kernel/debug/tracing/events/xfs/enable or alternatively enable single events by just doing the same in one event subdirectory, e.g. echo 1 > /sys/kernel/debug/tracing/events/xfs/xfs_ihold/enable or set more complex filters, etc. In Documentation/trace/events.txt all this is desctribed in more detail. To reads the events do a cat /sys/kernel/debug/tracing/trace Compared to the last posting this patch converts the tracing mostly to the one tracepoint per callsite model that other users of the new tracing facility also employ. This allows a very fine-grained control of the tracing, a cleaner output of the traces and also enables the perf tool to use each tracepoint as a virtual performance counter, allowing us to e.g. count how often certain workloads git various spots in XFS. Take a look at http://lwn.net/Articles/346470/ for some examples. Also the btree tracing isn't included at all yet, as it will require additional core tracing features not in mainline yet, I plan to deliver it later. And the really nice thing about this patch is that it actually removes many lines of code while adding this nice functionality: fs/xfs/Makefile | 8 fs/xfs/linux-2.6/xfs_acl.c | 1 fs/xfs/linux-2.6/xfs_aops.c | 52 - fs/xfs/linux-2.6/xfs_aops.h | 2 fs/xfs/linux-2.6/xfs_buf.c | 117 +-- fs/xfs/linux-2.6/xfs_buf.h | 33 fs/xfs/linux-2.6/xfs_fs_subr.c | 3 fs/xfs/linux-2.6/xfs_ioctl.c | 1 fs/xfs/linux-2.6/xfs_ioctl32.c | 1 fs/xfs/linux-2.6/xfs_iops.c | 1 fs/xfs/linux-2.6/xfs_linux.h | 1 fs/xfs/linux-2.6/xfs_lrw.c | 87 -- fs/xfs/linux-2.6/xfs_lrw.h | 45 - fs/xfs/linux-2.6/xfs_super.c | 104 --- fs/xfs/linux-2.6/xfs_super.h | 7 fs/xfs/linux-2.6/xfs_sync.c | 1 fs/xfs/linux-2.6/xfs_trace.c | 75 ++ fs/xfs/linux-2.6/xfs_trace.h | 1369 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/linux-2.6/xfs_vnode.h | 4 fs/xfs/quota/xfs_dquot.c | 110 --- fs/xfs/quota/xfs_dquot.h | 21 fs/xfs/quota/xfs_qm.c | 40 - fs/xfs/quota/xfs_qm_syscalls.c | 4 fs/xfs/support/ktrace.c | 323 --------- fs/xfs/support/ktrace.h | 85 -- fs/xfs/xfs.h | 16 fs/xfs/xfs_ag.h | 14 fs/xfs/xfs_alloc.c | 230 +----- fs/xfs/xfs_alloc.h | 27 fs/xfs/xfs_alloc_btree.c | 1 fs/xfs/xfs_attr.c | 107 --- fs/xfs/xfs_attr.h | 10 fs/xfs/xfs_attr_leaf.c | 14 fs/xfs/xfs_attr_sf.h | 40 - fs/xfs/xfs_bmap.c | 507 +++------------ fs/xfs/xfs_bmap.h | 49 - fs/xfs/xfs_bmap_btree.c | 6 fs/xfs/xfs_btree.c | 5 fs/xfs/xfs_btree_trace.h | 17 fs/xfs/xfs_buf_item.c | 87 -- fs/xfs/xfs_buf_item.h | 20 fs/xfs/xfs_da_btree.c | 3 fs/xfs/xfs_da_btree.h | 7 fs/xfs/xfs_dfrag.c | 2 fs/xfs/xfs_dir2.c | 8 fs/xfs/xfs_dir2_block.c | 20 fs/xfs/xfs_dir2_leaf.c | 21 fs/xfs/xfs_dir2_node.c | 27 fs/xfs/xfs_dir2_sf.c | 26 fs/xfs/xfs_dir2_trace.c | 216 ------ fs/xfs/xfs_dir2_trace.h | 72 -- fs/xfs/xfs_filestream.c | 8 fs/xfs/xfs_fsops.c | 2 fs/xfs/xfs_iget.c | 111 --- fs/xfs/xfs_inode.c | 67 -- fs/xfs/xfs_inode.h | 76 -- fs/xfs/xfs_inode_item.c | 5 fs/xfs/xfs_iomap.c | 85 -- fs/xfs/xfs_iomap.h | 8 fs/xfs/xfs_log.c | 181 +---- fs/xfs/xfs_log_priv.h | 20 fs/xfs/xfs_log_recover.c | 1 fs/xfs/xfs_mount.c | 2 fs/xfs/xfs_quota.h | 8 fs/xfs/xfs_rename.c | 1 fs/xfs/xfs_rtalloc.c | 1 fs/xfs/xfs_rw.c | 3 fs/xfs/xfs_trans.h | 47 + fs/xfs/xfs_trans_buf.c | 62 - fs/xfs/xfs_vnodeops.c | 8 70 files changed, 2151 insertions(+), 2592 deletions(-) Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Alex Elder <aelder@sgi.com>
12 years ago
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
  1. /*
  2. * Copyright (c) 2008, Christoph Hellwig
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_acl.h"
  20. #include "xfs_attr.h"
  21. #include "xfs_bmap_btree.h"
  22. #include "xfs_inode.h"
  23. #include "xfs_vnodeops.h"
  24. #include "xfs_trace.h"
  25. #include <linux/slab.h>
  26. #include <linux/xattr.h>
  27. #include <linux/posix_acl_xattr.h>
  28. /*
  29. * Locking scheme:
  30. * - all ACL updates are protected by inode->i_mutex, which is taken before
  31. * calling into this file.
  32. */
  33. STATIC struct posix_acl *
  34. xfs_acl_from_disk(struct xfs_acl *aclp)
  35. {
  36. struct posix_acl_entry *acl_e;
  37. struct posix_acl *acl;
  38. struct xfs_acl_entry *ace;
  39. unsigned int count, i;
  40. count = be32_to_cpu(aclp->acl_cnt);
  41. if (count > XFS_ACL_MAX_ENTRIES)
  42. return ERR_PTR(-EFSCORRUPTED);
  43. acl = posix_acl_alloc(count, GFP_KERNEL);
  44. if (!acl)
  45. return ERR_PTR(-ENOMEM);
  46. for (i = 0; i < count; i++) {
  47. acl_e = &acl->a_entries[i];
  48. ace = &aclp->acl_entry[i];
  49. /*
  50. * The tag is 32 bits on disk and 16 bits in core.
  51. *
  52. * Because every access to it goes through the core
  53. * format first this is not a problem.
  54. */
  55. acl_e->e_tag = be32_to_cpu(ace->ae_tag);
  56. acl_e->e_perm = be16_to_cpu(ace->ae_perm);
  57. switch (acl_e->e_tag) {
  58. case ACL_USER:
  59. case ACL_GROUP:
  60. acl_e->e_id = be32_to_cpu(ace->ae_id);
  61. break;
  62. case ACL_USER_OBJ:
  63. case ACL_GROUP_OBJ:
  64. case ACL_MASK:
  65. case ACL_OTHER:
  66. acl_e->e_id = ACL_UNDEFINED_ID;
  67. break;
  68. default:
  69. goto fail;
  70. }
  71. }
  72. return acl;
  73. fail:
  74. posix_acl_release(acl);
  75. return ERR_PTR(-EINVAL);
  76. }
  77. STATIC void
  78. xfs_acl_to_disk(struct xfs_acl *aclp, const struct posix_acl *acl)
  79. {
  80. const struct posix_acl_entry *acl_e;
  81. struct xfs_acl_entry *ace;
  82. int i;
  83. aclp->acl_cnt = cpu_to_be32(acl->a_count);
  84. for (i = 0; i < acl->a_count; i++) {
  85. ace = &aclp->acl_entry[i];
  86. acl_e = &acl->a_entries[i];
  87. ace->ae_tag = cpu_to_be32(acl_e->e_tag);
  88. ace->ae_id = cpu_to_be32(acl_e->e_id);
  89. ace->ae_perm = cpu_to_be16(acl_e->e_perm);
  90. }
  91. }
  92. struct posix_acl *
  93. xfs_get_acl(struct inode *inode, int type)
  94. {
  95. struct xfs_inode *ip = XFS_I(inode);
  96. struct posix_acl *acl;
  97. struct xfs_acl *xfs_acl;
  98. int len = sizeof(struct xfs_acl);
  99. unsigned char *ea_name;
  100. int error;
  101. acl = get_cached_acl(inode, type);
  102. if (acl != ACL_NOT_CACHED)
  103. return acl;
  104. trace_xfs_get_acl(ip);
  105. switch (type) {
  106. case ACL_TYPE_ACCESS:
  107. ea_name = SGI_ACL_FILE;
  108. break;
  109. case ACL_TYPE_DEFAULT:
  110. ea_name = SGI_ACL_DEFAULT;
  111. break;
  112. default:
  113. BUG();
  114. }
  115. /*
  116. * If we have a cached ACLs value just return it, not need to
  117. * go out to the disk.
  118. */
  119. xfs_acl = kzalloc(sizeof(struct xfs_acl), GFP_KERNEL);
  120. if (!xfs_acl)
  121. return ERR_PTR(-ENOMEM);
  122. error = -xfs_attr_get(ip, ea_name, (unsigned char *)xfs_acl,
  123. &len, ATTR_ROOT);
  124. if (error) {
  125. /*
  126. * If the attribute doesn't exist make sure we have a negative
  127. * cache entry, for any other error assume it is transient and
  128. * leave the cache entry as ACL_NOT_CACHED.
  129. */
  130. if (error == -ENOATTR) {
  131. acl = NULL;
  132. goto out_update_cache;
  133. }
  134. goto out;
  135. }
  136. acl = xfs_acl_from_disk(xfs_acl);
  137. if (IS_ERR(acl))
  138. goto out;
  139. out_update_cache:
  140. set_cached_acl(inode, type, acl);
  141. out:
  142. kfree(xfs_acl);
  143. return acl;
  144. }
  145. STATIC int
  146. xfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
  147. {
  148. struct xfs_inode *ip = XFS_I(inode);
  149. unsigned char *ea_name;
  150. int error;
  151. if (S_ISLNK(inode->i_mode))
  152. return -EOPNOTSUPP;
  153. switch (type) {
  154. case ACL_TYPE_ACCESS:
  155. ea_name = SGI_ACL_FILE;
  156. break;
  157. case ACL_TYPE_DEFAULT:
  158. if (!S_ISDIR(inode->i_mode))
  159. return acl ? -EACCES : 0;
  160. ea_name = SGI_ACL_DEFAULT;
  161. break;
  162. default:
  163. return -EINVAL;
  164. }
  165. if (acl) {
  166. struct xfs_acl *xfs_acl;
  167. int len;
  168. xfs_acl = kzalloc(sizeof(struct xfs_acl), GFP_KERNEL);
  169. if (!xfs_acl)
  170. return -ENOMEM;
  171. xfs_acl_to_disk(xfs_acl, acl);
  172. len = sizeof(struct xfs_acl) -
  173. (sizeof(struct xfs_acl_entry) *
  174. (XFS_ACL_MAX_ENTRIES - acl->a_count));
  175. error = -xfs_attr_set(ip, ea_name, (unsigned char *)xfs_acl,
  176. len, ATTR_ROOT);
  177. kfree(xfs_acl);
  178. } else {
  179. /*
  180. * A NULL ACL argument means we want to remove the ACL.
  181. */
  182. error = -xfs_attr_remove(ip, ea_name, ATTR_ROOT);
  183. /*
  184. * If the attribute didn't exist to start with that's fine.
  185. */
  186. if (error == -ENOATTR)
  187. error = 0;
  188. }
  189. if (!error)
  190. set_cached_acl(inode, type, acl);
  191. return error;
  192. }
  193. static int
  194. xfs_set_mode(struct inode *inode, umode_t mode)
  195. {
  196. int error = 0;
  197. if (mode != inode->i_mode) {
  198. struct iattr iattr;
  199. iattr.ia_valid = ATTR_MODE | ATTR_CTIME;
  200. iattr.ia_mode = mode;
  201. iattr.ia_ctime = current_fs_time(inode->i_sb);
  202. error = -xfs_setattr_nonsize(XFS_I(inode), &iattr, XFS_ATTR_NOACL);
  203. }
  204. return error;
  205. }
  206. static int
  207. xfs_acl_exists(struct inode *inode, unsigned char *name)
  208. {
  209. int len = sizeof(struct xfs_acl);
  210. return (xfs_attr_get(XFS_I(inode), name, NULL, &len,
  211. ATTR_ROOT|ATTR_KERNOVAL) == 0);
  212. }
  213. int
  214. posix_acl_access_exists(struct inode *inode)
  215. {
  216. return xfs_acl_exists(inode, SGI_ACL_FILE);
  217. }
  218. int
  219. posix_acl_default_exists(struct inode *inode)
  220. {
  221. if (!S_ISDIR(inode->i_mode))
  222. return 0;
  223. return xfs_acl_exists(inode, SGI_ACL_DEFAULT);
  224. }
  225. /*
  226. * No need for i_mutex because the inode is not yet exposed to the VFS.
  227. */
  228. int
  229. xfs_inherit_acl(struct inode *inode, struct posix_acl *acl)
  230. {
  231. umode_t mode = inode->i_mode;
  232. int error = 0, inherit = 0;
  233. if (S_ISDIR(inode->i_mode)) {
  234. error = xfs_set_acl(inode, ACL_TYPE_DEFAULT, acl);
  235. if (error)
  236. goto out;
  237. }
  238. error = posix_acl_create(&acl, GFP_KERNEL, &mode);
  239. if (error < 0)
  240. return error;
  241. /*
  242. * If posix_acl_create returns a positive value we need to
  243. * inherit a permission that can't be represented using the Unix
  244. * mode bits and we actually need to set an ACL.
  245. */
  246. if (error > 0)
  247. inherit = 1;
  248. error = xfs_set_mode(inode, mode);
  249. if (error)
  250. goto out;
  251. if (inherit)
  252. error = xfs_set_acl(inode, ACL_TYPE_ACCESS, acl);
  253. out:
  254. posix_acl_release(acl);
  255. return error;
  256. }
  257. int
  258. xfs_acl_chmod(struct inode *inode)
  259. {
  260. struct posix_acl *acl;
  261. int error;
  262. if (S_ISLNK(inode->i_mode))
  263. return -EOPNOTSUPP;
  264. acl = xfs_get_acl(inode, ACL_TYPE_ACCESS);
  265. if (IS_ERR(acl) || !acl)
  266. return PTR_ERR(acl);
  267. error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
  268. if (error)
  269. return error;
  270. error = xfs_set_acl(inode, ACL_TYPE_ACCESS, acl);
  271. posix_acl_release(acl);
  272. return error;
  273. }
  274. static int
  275. xfs_xattr_acl_get(struct dentry *dentry, const char *name,
  276. void *value, size_t size, int type)
  277. {
  278. struct posix_acl *acl;
  279. int error;
  280. acl = xfs_get_acl(dentry->d_inode, type);
  281. if (IS_ERR(acl))
  282. return PTR_ERR(acl);
  283. if (acl == NULL)
  284. return -ENODATA;
  285. error = posix_acl_to_xattr(&init_user_ns, acl, value, size);
  286. posix_acl_release(acl);
  287. return error;
  288. }
  289. static int
  290. xfs_xattr_acl_set(struct dentry *dentry, const char *name,
  291. const void *value, size_t size, int flags, int type)
  292. {
  293. struct inode *inode = dentry->d_inode;
  294. struct posix_acl *acl = NULL;
  295. int error = 0;
  296. if (flags & XATTR_CREATE)
  297. return -EINVAL;
  298. if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
  299. return value ? -EACCES : 0;
  300. if ((current_fsuid() != inode->i_uid) && !capable(CAP_FOWNER))
  301. return -EPERM;
  302. if (!value)
  303. goto set_acl;
  304. acl = posix_acl_from_xattr(&init_user_ns, value, size);
  305. if (!acl) {
  306. /*
  307. * acl_set_file(3) may request that we set default ACLs with
  308. * zero length -- defend (gracefully) against that here.
  309. */
  310. goto out;
  311. }
  312. if (IS_ERR(acl)) {
  313. error = PTR_ERR(acl);
  314. goto out;
  315. }
  316. error = posix_acl_valid(acl);
  317. if (error)
  318. goto out_release;
  319. error = -EINVAL;
  320. if (acl->a_count > XFS_ACL_MAX_ENTRIES)
  321. goto out_release;
  322. if (type == ACL_TYPE_ACCESS) {
  323. umode_t mode = inode->i_mode;
  324. error = posix_acl_equiv_mode(acl, &mode);
  325. if (error <= 0) {
  326. posix_acl_release(acl);
  327. acl = NULL;
  328. if (error < 0)
  329. return error;
  330. }
  331. error = xfs_set_mode(inode, mode);
  332. if (error)
  333. goto out_release;
  334. }
  335. set_acl:
  336. error = xfs_set_acl(inode, type, acl);
  337. out_release:
  338. posix_acl_release(acl);
  339. out:
  340. return error;
  341. }
  342. const struct xattr_handler xfs_xattr_acl_access_handler = {
  343. .prefix = POSIX_ACL_XATTR_ACCESS,
  344. .flags = ACL_TYPE_ACCESS,
  345. .get = xfs_xattr_acl_get,
  346. .set = xfs_xattr_acl_set,
  347. };
  348. const struct xattr_handler xfs_xattr_acl_default_handler = {
  349. .prefix = POSIX_ACL_XATTR_DEFAULT,
  350. .flags = ACL_TYPE_DEFAULT,
  351. .get = xfs_xattr_acl_get,
  352. .set = xfs_xattr_acl_set,
  353. };