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.

504 lines
12 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
[PATCH] getting rid of all casts of k[cmz]alloc() calls Run this: #!/bin/sh for f in $(grep -Erl "\([^\)]*\) *k[cmz]alloc" *) ; do echo "De-casting $f..." perl -pi -e "s/ ?= ?\([^\)]*\) *(k[cmz]alloc) *\(/ = \1\(/" $f done And then go through and reinstate those cases where code is casting pointers to non-pointers. And then drop a few hunks which conflicted with outstanding work. Cc: Russell King <rmk@arm.linux.org.uk>, Ian Molton <spyro@f2s.com> Cc: Mikael Starvik <starvik@axis.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Roman Zippel <zippel@linux-m68k.org> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Kyle McMartin <kyle@mcmartin.ca> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Jeff Dike <jdike@addtoit.com> Cc: Greg KH <greg@kroah.com> Cc: Jens Axboe <jens.axboe@oracle.com> Cc: Paul Fulghum <paulkf@microgate.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: Karsten Keil <kkeil@suse.de> Cc: Mauro Carvalho Chehab <mchehab@infradead.org> Cc: Jeff Garzik <jeff@garzik.org> Cc: James Bottomley <James.Bottomley@steeleye.com> Cc: Ian Kent <raven@themaw.net> Cc: Steven French <sfrench@us.ibm.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Neil Brown <neilb@cse.unsw.edu.au> Cc: Jaroslav Kysela <perex@suse.cz> Cc: Takashi Iwai <tiwai@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
15 years ago
  1. #include <linux/capability.h>
  2. #include <linux/fs.h>
  3. #include <linux/posix_acl.h>
  4. #include "reiserfs.h"
  5. #include <linux/errno.h>
  6. #include <linux/pagemap.h>
  7. #include <linux/xattr.h>
  8. #include <linux/slab.h>
  9. #include <linux/posix_acl_xattr.h>
  10. #include "xattr.h"
  11. #include "acl.h"
  12. #include <asm/uaccess.h>
  13. static int reiserfs_set_acl(struct reiserfs_transaction_handle *th,
  14. struct inode *inode, int type,
  15. struct posix_acl *acl);
  16. static int
  17. posix_acl_set(struct dentry *dentry, const char *name, const void *value,
  18. size_t size, int flags, int type)
  19. {
  20. struct inode *inode = dentry->d_inode;
  21. struct posix_acl *acl;
  22. int error, error2;
  23. struct reiserfs_transaction_handle th;
  24. size_t jcreate_blocks;
  25. if (!reiserfs_posixacl(inode->i_sb))
  26. return -EOPNOTSUPP;
  27. if (!inode_owner_or_capable(inode))
  28. return -EPERM;
  29. if (value) {
  30. acl = posix_acl_from_xattr(&init_user_ns, value, size);
  31. if (IS_ERR(acl)) {
  32. return PTR_ERR(acl);
  33. } else if (acl) {
  34. error = posix_acl_valid(acl);
  35. if (error)
  36. goto release_and_out;
  37. }
  38. } else
  39. acl = NULL;
  40. /* Pessimism: We can't assume that anything from the xattr root up
  41. * has been created. */
  42. jcreate_blocks = reiserfs_xattr_jcreate_nblocks(inode) +
  43. reiserfs_xattr_nblocks(inode, size) * 2;
  44. reiserfs_write_lock(inode->i_sb);
  45. error = journal_begin(&th, inode->i_sb, jcreate_blocks);
  46. if (error == 0) {
  47. error = reiserfs_set_acl(&th, inode, type, acl);
  48. error2 = journal_end(&th, inode->i_sb, jcreate_blocks);
  49. if (error2)
  50. error = error2;
  51. }
  52. reiserfs_write_unlock(inode->i_sb);
  53. release_and_out:
  54. posix_acl_release(acl);
  55. return error;
  56. }
  57. static int
  58. posix_acl_get(struct dentry *dentry, const char *name, void *buffer,
  59. size_t size, int type)
  60. {
  61. struct posix_acl *acl;
  62. int error;
  63. if (!reiserfs_posixacl(dentry->d_sb))
  64. return -EOPNOTSUPP;
  65. acl = reiserfs_get_acl(dentry->d_inode, type);
  66. if (IS_ERR(acl))
  67. return PTR_ERR(acl);
  68. if (acl == NULL)
  69. return -ENODATA;
  70. error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
  71. posix_acl_release(acl);
  72. return error;
  73. }
  74. /*
  75. * Convert from filesystem to in-memory representation.
  76. */
  77. static struct posix_acl *posix_acl_from_disk(const void *value, size_t size)
  78. {
  79. const char *end = (char *)value + size;
  80. int n, count;
  81. struct posix_acl *acl;
  82. if (!value)
  83. return NULL;
  84. if (size < sizeof(reiserfs_acl_header))
  85. return ERR_PTR(-EINVAL);
  86. if (((reiserfs_acl_header *) value)->a_version !=
  87. cpu_to_le32(REISERFS_ACL_VERSION))
  88. return ERR_PTR(-EINVAL);
  89. value = (char *)value + sizeof(reiserfs_acl_header);
  90. count = reiserfs_acl_count(size);
  91. if (count < 0)
  92. return ERR_PTR(-EINVAL);
  93. if (count == 0)
  94. return NULL;
  95. acl = posix_acl_alloc(count, GFP_NOFS);
  96. if (!acl)
  97. return ERR_PTR(-ENOMEM);
  98. for (n = 0; n < count; n++) {
  99. reiserfs_acl_entry *entry = (reiserfs_acl_entry *) value;
  100. if ((char *)value + sizeof(reiserfs_acl_entry_short) > end)
  101. goto fail;
  102. acl->a_entries[n].e_tag = le16_to_cpu(entry->e_tag);
  103. acl->a_entries[n].e_perm = le16_to_cpu(entry->e_perm);
  104. switch (acl->a_entries[n].e_tag) {
  105. case ACL_USER_OBJ:
  106. case ACL_GROUP_OBJ:
  107. case ACL_MASK:
  108. case ACL_OTHER:
  109. value = (char *)value +
  110. sizeof(reiserfs_acl_entry_short);
  111. acl->a_entries[n].e_id = ACL_UNDEFINED_ID;
  112. break;
  113. case ACL_USER:
  114. case ACL_GROUP:
  115. value = (char *)value + sizeof(reiserfs_acl_entry);
  116. if ((char *)value > end)
  117. goto fail;
  118. acl->a_entries[n].e_id = le32_to_cpu(entry->e_id);
  119. break;
  120. default:
  121. goto fail;
  122. }
  123. }
  124. if (value != end)
  125. goto fail;
  126. return acl;
  127. fail:
  128. posix_acl_release(acl);
  129. return ERR_PTR(-EINVAL);
  130. }
  131. /*
  132. * Convert from in-memory to filesystem representation.
  133. */
  134. static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
  135. {
  136. reiserfs_acl_header *ext_acl;
  137. char *e;
  138. int n;
  139. *size = reiserfs_acl_size(acl->a_count);
  140. ext_acl = kmalloc(sizeof(reiserfs_acl_header) +
  141. acl->a_count *
  142. sizeof(reiserfs_acl_entry),
  143. GFP_NOFS);
  144. if (!ext_acl)
  145. return ERR_PTR(-ENOMEM);
  146. ext_acl->a_version = cpu_to_le32(REISERFS_ACL_VERSION);
  147. e = (char *)ext_acl + sizeof(reiserfs_acl_header);
  148. for (n = 0; n < acl->a_count; n++) {
  149. reiserfs_acl_entry *entry = (reiserfs_acl_entry *) e;
  150. entry->e_tag = cpu_to_le16(acl->a_entries[n].e_tag);
  151. entry->e_perm = cpu_to_le16(acl->a_entries[n].e_perm);
  152. switch (acl->a_entries[n].e_tag) {
  153. case ACL_USER:
  154. case ACL_GROUP:
  155. entry->e_id = cpu_to_le32(acl->a_entries[n].e_id);
  156. e += sizeof(reiserfs_acl_entry);
  157. break;
  158. case ACL_USER_OBJ:
  159. case ACL_GROUP_OBJ:
  160. case ACL_MASK:
  161. case ACL_OTHER:
  162. e += sizeof(reiserfs_acl_entry_short);
  163. break;
  164. default:
  165. goto fail;
  166. }
  167. }
  168. return (char *)ext_acl;
  169. fail:
  170. kfree(ext_acl);
  171. return ERR_PTR(-EINVAL);
  172. }
  173. /*
  174. * Inode operation get_posix_acl().
  175. *
  176. * inode->i_mutex: down
  177. * BKL held [before 2.5.x]
  178. */
  179. struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
  180. {
  181. char *name, *value;
  182. struct posix_acl *acl;
  183. int size;
  184. int retval;
  185. acl = get_cached_acl(inode, type);
  186. if (acl != ACL_NOT_CACHED)
  187. return acl;
  188. switch (type) {
  189. case ACL_TYPE_ACCESS:
  190. name = POSIX_ACL_XATTR_ACCESS;
  191. break;
  192. case ACL_TYPE_DEFAULT:
  193. name = POSIX_ACL_XATTR_DEFAULT;
  194. break;
  195. default:
  196. BUG();
  197. }
  198. size = reiserfs_xattr_get(inode, name, NULL, 0);
  199. if (size < 0) {
  200. if (size == -ENODATA || size == -ENOSYS) {
  201. set_cached_acl(inode, type, NULL);
  202. return NULL;
  203. }
  204. return ERR_PTR(size);
  205. }
  206. value = kmalloc(size, GFP_NOFS);
  207. if (!value)
  208. return ERR_PTR(-ENOMEM);
  209. retval = reiserfs_xattr_get(inode, name, value, size);
  210. if (retval == -ENODATA || retval == -ENOSYS) {
  211. /* This shouldn't actually happen as it should have
  212. been caught above.. but just in case */
  213. acl = NULL;
  214. } else if (retval < 0) {
  215. acl = ERR_PTR(retval);
  216. } else {
  217. acl = posix_acl_from_disk(value, retval);
  218. }
  219. if (!IS_ERR(acl))
  220. set_cached_acl(inode, type, acl);
  221. kfree(value);
  222. return acl;
  223. }
  224. /*
  225. * Inode operation set_posix_acl().
  226. *
  227. * inode->i_mutex: down
  228. * BKL held [before 2.5.x]
  229. */
  230. static int
  231. reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
  232. int type, struct posix_acl *acl)
  233. {
  234. char *name;
  235. void *value = NULL;
  236. size_t size = 0;
  237. int error;
  238. if (S_ISLNK(inode->i_mode))
  239. return -EOPNOTSUPP;
  240. switch (type) {
  241. case ACL_TYPE_ACCESS:
  242. name = POSIX_ACL_XATTR_ACCESS;
  243. if (acl) {
  244. error = posix_acl_equiv_mode(acl, &inode->i_mode);
  245. if (error < 0)
  246. return error;
  247. else {
  248. if (error == 0)
  249. acl = NULL;
  250. }
  251. }
  252. break;
  253. case ACL_TYPE_DEFAULT:
  254. name = POSIX_ACL_XATTR_DEFAULT;
  255. if (!S_ISDIR(inode->i_mode))
  256. return acl ? -EACCES : 0;
  257. break;
  258. default:
  259. return -EINVAL;
  260. }
  261. if (acl) {
  262. value = posix_acl_to_disk(acl, &size);
  263. if (IS_ERR(value))
  264. return (int)PTR_ERR(value);
  265. }
  266. error = reiserfs_xattr_set_handle(th, inode, name, value, size, 0);
  267. /*
  268. * Ensure that the inode gets dirtied if we're only using
  269. * the mode bits and an old ACL didn't exist. We don't need
  270. * to check if the inode is hashed here since we won't get
  271. * called by reiserfs_inherit_default_acl().
  272. */
  273. if (error == -ENODATA) {
  274. error = 0;
  275. if (type == ACL_TYPE_ACCESS) {
  276. inode->i_ctime = CURRENT_TIME_SEC;
  277. mark_inode_dirty(inode);
  278. }
  279. }
  280. kfree(value);
  281. if (!error)
  282. set_cached_acl(inode, type, acl);
  283. return error;
  284. }
  285. /* dir->i_mutex: locked,
  286. * inode is new and not released into the wild yet */
  287. int
  288. reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
  289. struct inode *dir, struct dentry *dentry,
  290. struct inode *inode)
  291. {
  292. struct posix_acl *acl;
  293. int err = 0;
  294. /* ACLs only get applied to files and directories */
  295. if (S_ISLNK(inode->i_mode))
  296. return 0;
  297. /* ACLs can only be used on "new" objects, so if it's an old object
  298. * there is nothing to inherit from */
  299. if (get_inode_sd_version(dir) == STAT_DATA_V1)
  300. goto apply_umask;
  301. /* Don't apply ACLs to objects in the .reiserfs_priv tree.. This
  302. * would be useless since permissions are ignored, and a pain because
  303. * it introduces locking cycles */
  304. if (IS_PRIVATE(dir)) {
  305. inode->i_flags |= S_PRIVATE;
  306. goto apply_umask;
  307. }
  308. acl = reiserfs_get_acl(dir, ACL_TYPE_DEFAULT);
  309. if (IS_ERR(acl))
  310. return PTR_ERR(acl);
  311. if (acl) {
  312. /* Copy the default ACL to the default ACL of a new directory */
  313. if (S_ISDIR(inode->i_mode)) {
  314. err = reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
  315. acl);
  316. if (err)
  317. goto cleanup;
  318. }
  319. /* Now we reconcile the new ACL and the mode,
  320. potentially modifying both */
  321. err = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
  322. if (err < 0)
  323. return err;
  324. /* If we need an ACL.. */
  325. if (err > 0)
  326. err = reiserfs_set_acl(th, inode, ACL_TYPE_ACCESS, acl);
  327. cleanup:
  328. posix_acl_release(acl);
  329. } else {
  330. apply_umask:
  331. /* no ACL, apply umask */
  332. inode->i_mode &= ~current_umask();
  333. }
  334. return err;
  335. }
  336. /* This is used to cache the default acl before a new object is created.
  337. * The biggest reason for this is to get an idea of how many blocks will
  338. * actually be required for the create operation if we must inherit an ACL.
  339. * An ACL write can add up to 3 object creations and an additional file write
  340. * so we'd prefer not to reserve that many blocks in the journal if we can.
  341. * It also has the advantage of not loading the ACL with a transaction open,
  342. * this may seem silly, but if the owner of the directory is doing the
  343. * creation, the ACL may not be loaded since the permissions wouldn't require
  344. * it.
  345. * We return the number of blocks required for the transaction.
  346. */
  347. int reiserfs_cache_default_acl(struct inode *inode)
  348. {
  349. struct posix_acl *acl;
  350. int nblocks = 0;
  351. if (IS_PRIVATE(inode))
  352. return 0;
  353. acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
  354. if (acl && !IS_ERR(acl)) {
  355. int size = reiserfs_acl_size(acl->a_count);
  356. /* Other xattrs can be created during inode creation. We don't
  357. * want to claim too many blocks, so we check to see if we
  358. * we need to create the tree to the xattrs, and then we
  359. * just want two files. */
  360. nblocks = reiserfs_xattr_jcreate_nblocks(inode);
  361. nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
  362. REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
  363. /* We need to account for writes + bitmaps for two files */
  364. nblocks += reiserfs_xattr_nblocks(inode, size) * 4;
  365. posix_acl_release(acl);
  366. }
  367. return nblocks;
  368. }
  369. int reiserfs_acl_chmod(struct inode *inode)
  370. {
  371. struct reiserfs_transaction_handle th;
  372. struct posix_acl *acl;
  373. size_t size;
  374. int depth;
  375. int error;
  376. if (S_ISLNK(inode->i_mode))
  377. return -EOPNOTSUPP;
  378. if (get_inode_sd_version(inode) == STAT_DATA_V1 ||
  379. !reiserfs_posixacl(inode->i_sb)) {
  380. return 0;
  381. }
  382. reiserfs_write_unlock(inode->i_sb);
  383. acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
  384. reiserfs_write_lock(inode->i_sb);
  385. if (!acl)
  386. return 0;
  387. if (IS_ERR(acl))
  388. return PTR_ERR(acl);
  389. error = posix_acl_chmod(&acl, GFP_NOFS, inode->i_mode);
  390. if (error)
  391. return error;
  392. size = reiserfs_xattr_nblocks(inode, reiserfs_acl_size(acl->a_count));
  393. depth = reiserfs_write_lock_once(inode->i_sb);
  394. error = journal_begin(&th, inode->i_sb, size * 2);
  395. if (!error) {
  396. int error2;
  397. error = reiserfs_set_acl(&th, inode, ACL_TYPE_ACCESS, acl);
  398. error2 = journal_end(&th, inode->i_sb, size * 2);
  399. if (error2)
  400. error = error2;
  401. }
  402. reiserfs_write_unlock_once(inode->i_sb, depth);
  403. posix_acl_release(acl);
  404. return error;
  405. }
  406. static size_t posix_acl_access_list(struct dentry *dentry, char *list,
  407. size_t list_size, const char *name,
  408. size_t name_len, int type)
  409. {
  410. const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
  411. if (!reiserfs_posixacl(dentry->d_sb))
  412. return 0;
  413. if (list && size <= list_size)
  414. memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
  415. return size;
  416. }
  417. const struct xattr_handler reiserfs_posix_acl_access_handler = {
  418. .prefix = POSIX_ACL_XATTR_ACCESS,
  419. .flags = ACL_TYPE_ACCESS,
  420. .get = posix_acl_get,
  421. .set = posix_acl_set,
  422. .list = posix_acl_access_list,
  423. };
  424. static size_t posix_acl_default_list(struct dentry *dentry, char *list,
  425. size_t list_size, const char *name,
  426. size_t name_len, int type)
  427. {
  428. const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
  429. if (!reiserfs_posixacl(dentry->d_sb))
  430. return 0;
  431. if (list && size <= list_size)
  432. memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
  433. return size;
  434. }
  435. const struct xattr_handler reiserfs_posix_acl_default_handler = {
  436. .prefix = POSIX_ACL_XATTR_DEFAULT,
  437. .flags = ACL_TYPE_DEFAULT,
  438. .get = posix_acl_get,
  439. .set = posix_acl_set,
  440. .list = posix_acl_default_list,
  441. };