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.

440 lines
10 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
  1. #include <linux/fs.h>
  2. #include <linux/gfp.h>
  3. #include <linux/nfs.h>
  4. #include <linux/nfs3.h>
  5. #include <linux/nfs_fs.h>
  6. #include <linux/posix_acl_xattr.h>
  7. #include <linux/nfsacl.h>
  8. #include "internal.h"
  9. #define NFSDBG_FACILITY NFSDBG_PROC
  10. ssize_t nfs3_listxattr(struct dentry *dentry, char *buffer, size_t size)
  11. {
  12. struct inode *inode = dentry->d_inode;
  13. struct posix_acl *acl;
  14. int pos=0, len=0;
  15. # define output(s) do { \
  16. if (pos + sizeof(s) <= size) { \
  17. memcpy(buffer + pos, s, sizeof(s)); \
  18. pos += sizeof(s); \
  19. } \
  20. len += sizeof(s); \
  21. } while(0)
  22. acl = nfs3_proc_getacl(inode, ACL_TYPE_ACCESS);
  23. if (IS_ERR(acl))
  24. return PTR_ERR(acl);
  25. if (acl) {
  26. output("system.posix_acl_access");
  27. posix_acl_release(acl);
  28. }
  29. if (S_ISDIR(inode->i_mode)) {
  30. acl = nfs3_proc_getacl(inode, ACL_TYPE_DEFAULT);
  31. if (IS_ERR(acl))
  32. return PTR_ERR(acl);
  33. if (acl) {
  34. output("system.posix_acl_default");
  35. posix_acl_release(acl);
  36. }
  37. }
  38. # undef output
  39. if (!buffer || len <= size)
  40. return len;
  41. return -ERANGE;
  42. }
  43. ssize_t nfs3_getxattr(struct dentry *dentry, const char *name,
  44. void *buffer, size_t size)
  45. {
  46. struct inode *inode = dentry->d_inode;
  47. struct posix_acl *acl;
  48. int type, error = 0;
  49. if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
  50. type = ACL_TYPE_ACCESS;
  51. else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
  52. type = ACL_TYPE_DEFAULT;
  53. else
  54. return -EOPNOTSUPP;
  55. acl = nfs3_proc_getacl(inode, type);
  56. if (IS_ERR(acl))
  57. return PTR_ERR(acl);
  58. else if (acl) {
  59. if (type == ACL_TYPE_ACCESS && acl->a_count == 0)
  60. error = -ENODATA;
  61. else
  62. error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
  63. posix_acl_release(acl);
  64. } else
  65. error = -ENODATA;
  66. return error;
  67. }
  68. int nfs3_setxattr(struct dentry *dentry, const char *name,
  69. const void *value, size_t size, int flags)
  70. {
  71. struct inode *inode = dentry->d_inode;
  72. struct posix_acl *acl;
  73. int type, error;
  74. if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
  75. type = ACL_TYPE_ACCESS;
  76. else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
  77. type = ACL_TYPE_DEFAULT;
  78. else
  79. return -EOPNOTSUPP;
  80. acl = posix_acl_from_xattr(&init_user_ns, value, size);
  81. if (IS_ERR(acl))
  82. return PTR_ERR(acl);
  83. error = nfs3_proc_setacl(inode, type, acl);
  84. posix_acl_release(acl);
  85. return error;
  86. }
  87. int nfs3_removexattr(struct dentry *dentry, const char *name)
  88. {
  89. struct inode *inode = dentry->d_inode;
  90. int type;
  91. if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
  92. type = ACL_TYPE_ACCESS;
  93. else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
  94. type = ACL_TYPE_DEFAULT;
  95. else
  96. return -EOPNOTSUPP;
  97. return nfs3_proc_setacl(inode, type, NULL);
  98. }
  99. static void __nfs3_forget_cached_acls(struct nfs_inode *nfsi)
  100. {
  101. if (!IS_ERR(nfsi->acl_access)) {
  102. posix_acl_release(nfsi->acl_access);
  103. nfsi->acl_access = ERR_PTR(-EAGAIN);
  104. }
  105. if (!IS_ERR(nfsi->acl_default)) {
  106. posix_acl_release(nfsi->acl_default);
  107. nfsi->acl_default = ERR_PTR(-EAGAIN);
  108. }
  109. }
  110. void nfs3_forget_cached_acls(struct inode *inode)
  111. {
  112. dprintk("NFS: nfs3_forget_cached_acls(%s/%ld)\n", inode->i_sb->s_id,
  113. inode->i_ino);
  114. spin_lock(&inode->i_lock);
  115. __nfs3_forget_cached_acls(NFS_I(inode));
  116. spin_unlock(&inode->i_lock);
  117. }
  118. static struct posix_acl *nfs3_get_cached_acl(struct inode *inode, int type)
  119. {
  120. struct nfs_inode *nfsi = NFS_I(inode);
  121. struct posix_acl *acl = ERR_PTR(-EINVAL);
  122. spin_lock(&inode->i_lock);
  123. switch(type) {
  124. case ACL_TYPE_ACCESS:
  125. acl = nfsi->acl_access;
  126. break;
  127. case ACL_TYPE_DEFAULT:
  128. acl = nfsi->acl_default;
  129. break;
  130. default:
  131. goto out;
  132. }
  133. if (IS_ERR(acl))
  134. acl = ERR_PTR(-EAGAIN);
  135. else
  136. acl = posix_acl_dup(acl);
  137. out:
  138. spin_unlock(&inode->i_lock);
  139. dprintk("NFS: nfs3_get_cached_acl(%s/%ld, %d) = %p\n", inode->i_sb->s_id,
  140. inode->i_ino, type, acl);
  141. return acl;
  142. }
  143. static void nfs3_cache_acls(struct inode *inode, struct posix_acl *acl,
  144. struct posix_acl *dfacl)
  145. {
  146. struct nfs_inode *nfsi = NFS_I(inode);
  147. dprintk("nfs3_cache_acls(%s/%ld, %p, %p)\n", inode->i_sb->s_id,
  148. inode->i_ino, acl, dfacl);
  149. spin_lock(&inode->i_lock);
  150. __nfs3_forget_cached_acls(NFS_I(inode));
  151. if (!IS_ERR(acl))
  152. nfsi->acl_access = posix_acl_dup(acl);
  153. if (!IS_ERR(dfacl))
  154. nfsi->acl_default = posix_acl_dup(dfacl);
  155. spin_unlock(&inode->i_lock);
  156. }
  157. struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
  158. {
  159. struct nfs_server *server = NFS_SERVER(inode);
  160. struct page *pages[NFSACL_MAXPAGES] = { };
  161. struct nfs3_getaclargs args = {
  162. .fh = NFS_FH(inode),
  163. /* The xdr layer may allocate pages here. */
  164. .pages = pages,
  165. };
  166. struct nfs3_getaclres res = {
  167. NULL,
  168. };
  169. struct rpc_message msg = {
  170. .rpc_argp = &args,
  171. .rpc_resp = &res,
  172. };
  173. struct posix_acl *acl;
  174. int status, count;
  175. if (!nfs_server_capable(inode, NFS_CAP_ACLS))
  176. return ERR_PTR(-EOPNOTSUPP);
  177. status = nfs_revalidate_inode(server, inode);
  178. if (status < 0)
  179. return ERR_PTR(status);
  180. acl = nfs3_get_cached_acl(inode, type);
  181. if (acl != ERR_PTR(-EAGAIN))
  182. return acl;
  183. acl = NULL;
  184. /*
  185. * Only get the access acl when explicitly requested: We don't
  186. * need it for access decisions, and only some applications use
  187. * it. Applications which request the access acl first are not
  188. * penalized from this optimization.
  189. */
  190. if (type == ACL_TYPE_ACCESS)
  191. args.mask |= NFS_ACLCNT|NFS_ACL;
  192. if (S_ISDIR(inode->i_mode))
  193. args.mask |= NFS_DFACLCNT|NFS_DFACL;
  194. if (args.mask == 0)
  195. return NULL;
  196. dprintk("NFS call getacl\n");
  197. msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_GETACL];
  198. res.fattr = nfs_alloc_fattr();
  199. if (res.fattr == NULL)
  200. return ERR_PTR(-ENOMEM);
  201. status = rpc_call_sync(server->client_acl, &msg, 0);
  202. dprintk("NFS reply getacl: %d\n", status);
  203. /* pages may have been allocated at the xdr layer. */
  204. for (count = 0; count < NFSACL_MAXPAGES && args.pages[count]; count++)
  205. __free_page(args.pages[count]);
  206. switch (status) {
  207. case 0:
  208. status = nfs_refresh_inode(inode, res.fattr);
  209. break;
  210. case -EPFNOSUPPORT:
  211. case -EPROTONOSUPPORT:
  212. dprintk("NFS_V3_ACL extension not supported; disabling\n");
  213. server->caps &= ~NFS_CAP_ACLS;
  214. case -ENOTSUPP:
  215. status = -EOPNOTSUPP;
  216. default:
  217. goto getout;
  218. }
  219. if ((args.mask & res.mask) != args.mask) {
  220. status = -EIO;
  221. goto getout;
  222. }
  223. if (res.acl_access != NULL) {
  224. if (posix_acl_equiv_mode(res.acl_access, NULL) == 0) {
  225. posix_acl_release(res.acl_access);
  226. res.acl_access = NULL;
  227. }
  228. }
  229. nfs3_cache_acls(inode,
  230. (res.mask & NFS_ACL) ? res.acl_access : ERR_PTR(-EINVAL),
  231. (res.mask & NFS_DFACL) ? res.acl_default : ERR_PTR(-EINVAL));
  232. switch(type) {
  233. case ACL_TYPE_ACCESS:
  234. acl = res.acl_access;
  235. res.acl_access = NULL;
  236. break;
  237. case ACL_TYPE_DEFAULT:
  238. acl = res.acl_default;
  239. res.acl_default = NULL;
  240. }
  241. getout:
  242. posix_acl_release(res.acl_access);
  243. posix_acl_release(res.acl_default);
  244. nfs_free_fattr(res.fattr);
  245. if (status != 0) {
  246. posix_acl_release(acl);
  247. acl = ERR_PTR(status);
  248. }
  249. return acl;
  250. }
  251. static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
  252. struct posix_acl *dfacl)
  253. {
  254. struct nfs_server *server = NFS_SERVER(inode);
  255. struct nfs_fattr *fattr;
  256. struct page *pages[NFSACL_MAXPAGES];
  257. struct nfs3_setaclargs args = {
  258. .inode = inode,
  259. .mask = NFS_ACL,
  260. .acl_access = acl,
  261. .pages = pages,
  262. };
  263. struct rpc_message msg = {
  264. .rpc_argp = &args,
  265. .rpc_resp = &fattr,
  266. };
  267. int status;
  268. status = -EOPNOTSUPP;
  269. if (!nfs_server_capable(inode, NFS_CAP_ACLS))
  270. goto out;
  271. /* We are doing this here because XDR marshalling does not
  272. * return any results, it BUGs. */
  273. status = -ENOSPC;
  274. if (acl != NULL && acl->a_count > NFS_ACL_MAX_ENTRIES)
  275. goto out;
  276. if (dfacl != NULL && dfacl->a_count > NFS_ACL_MAX_ENTRIES)
  277. goto out;
  278. if (S_ISDIR(inode->i_mode)) {
  279. args.mask |= NFS_DFACL;
  280. args.acl_default = dfacl;
  281. args.len = nfsacl_size(acl, dfacl);
  282. } else
  283. args.len = nfsacl_size(acl, NULL);
  284. if (args.len > NFS_ACL_INLINE_BUFSIZE) {
  285. unsigned int npages = 1 + ((args.len - 1) >> PAGE_SHIFT);
  286. status = -ENOMEM;
  287. do {
  288. args.pages[args.npages] = alloc_page(GFP_KERNEL);
  289. if (args.pages[args.npages] == NULL)
  290. goto out_freepages;
  291. args.npages++;
  292. } while (args.npages < npages);
  293. }
  294. dprintk("NFS call setacl\n");
  295. status = -ENOMEM;
  296. fattr = nfs_alloc_fattr();
  297. if (fattr == NULL)
  298. goto out_freepages;
  299. msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL];
  300. msg.rpc_resp = fattr;
  301. status = rpc_call_sync(server->client_acl, &msg, 0);
  302. nfs_access_zap_cache(inode);
  303. nfs_zap_acl_cache(inode);
  304. dprintk("NFS reply setacl: %d\n", status);
  305. switch (status) {
  306. case 0:
  307. status = nfs_refresh_inode(inode, fattr);
  308. nfs3_cache_acls(inode, acl, dfacl);
  309. break;
  310. case -EPFNOSUPPORT:
  311. case -EPROTONOSUPPORT:
  312. dprintk("NFS_V3_ACL SETACL RPC not supported"
  313. "(will not retry)\n");
  314. server->caps &= ~NFS_CAP_ACLS;
  315. case -ENOTSUPP:
  316. status = -EOPNOTSUPP;
  317. }
  318. nfs_free_fattr(fattr);
  319. out_freepages:
  320. while (args.npages != 0) {
  321. args.npages--;
  322. __free_page(args.pages[args.npages]);
  323. }
  324. out:
  325. return status;
  326. }
  327. int nfs3_proc_setacl(struct inode *inode, int type, struct posix_acl *acl)
  328. {
  329. struct posix_acl *alloc = NULL, *dfacl = NULL;
  330. int status;
  331. if (S_ISDIR(inode->i_mode)) {
  332. switch(type) {
  333. case ACL_TYPE_ACCESS:
  334. alloc = dfacl = nfs3_proc_getacl(inode,
  335. ACL_TYPE_DEFAULT);
  336. if (IS_ERR(alloc))
  337. goto fail;
  338. break;
  339. case ACL_TYPE_DEFAULT:
  340. dfacl = acl;
  341. alloc = acl = nfs3_proc_getacl(inode,
  342. ACL_TYPE_ACCESS);
  343. if (IS_ERR(alloc))
  344. goto fail;
  345. break;
  346. default:
  347. return -EINVAL;
  348. }
  349. } else if (type != ACL_TYPE_ACCESS)
  350. return -EINVAL;
  351. if (acl == NULL) {
  352. alloc = acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
  353. if (IS_ERR(alloc))
  354. goto fail;
  355. }
  356. status = nfs3_proc_setacls(inode, acl, dfacl);
  357. posix_acl_release(alloc);
  358. return status;
  359. fail:
  360. return PTR_ERR(alloc);
  361. }
  362. int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode,
  363. umode_t mode)
  364. {
  365. struct posix_acl *dfacl, *acl;
  366. int error = 0;
  367. dfacl = nfs3_proc_getacl(dir, ACL_TYPE_DEFAULT);
  368. if (IS_ERR(dfacl)) {
  369. error = PTR_ERR(dfacl);
  370. return (error == -EOPNOTSUPP) ? 0 : error;
  371. }
  372. if (!dfacl)
  373. return 0;
  374. acl = posix_acl_dup(dfacl);
  375. error = posix_acl_create(&acl, GFP_KERNEL, &mode);
  376. if (error < 0)
  377. goto out_release_dfacl;
  378. error = nfs3_proc_setacls(inode, acl, S_ISDIR(inode->i_mode) ?
  379. dfacl : NULL);
  380. posix_acl_release(acl);
  381. out_release_dfacl:
  382. posix_acl_release(dfacl);
  383. return error;
  384. }