[XFS] use generic_permission

Now that all direct caller of xfs_iaccess are gone we can kill xfs_iaccess
and xfs_access and just use generic_permission with a check_acl callback.
This is required for the per-mount read-only patchset in -mm to work
properly with XFS.

SGI-PV: 971186
SGI-Modid: xfs-linux-melb:xfs-kern:30370a

Signed-off-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>

authored by Christoph Hellwig and committed by Lachlan McIlroy 4576758d f6aa7f21

+26 -121
+24 -5
fs/xfs/linux-2.6/xfs_iops.c
··· 559 560 #ifdef CONFIG_XFS_POSIX_ACL 561 STATIC int 562 - xfs_vn_permission( 563 - struct inode *inode, 564 - int mode, 565 - struct nameidata *nd) 566 { 567 - return -xfs_access(XFS_I(inode), mode << 6, NULL); 568 } 569 #else 570 #define xfs_vn_permission NULL
··· 559 560 #ifdef CONFIG_XFS_POSIX_ACL 561 STATIC int 562 + xfs_check_acl( 563 + struct inode *inode, 564 + int mask) 565 { 566 + struct xfs_inode *ip = XFS_I(inode); 567 + int error; 568 + 569 + xfs_itrace_entry(ip); 570 + 571 + if (XFS_IFORK_Q(ip)) { 572 + error = xfs_acl_iaccess(ip, mask, NULL); 573 + if (error != -1) 574 + return -error; 575 + } 576 + 577 + return -EAGAIN; 578 + } 579 + 580 + STATIC int 581 + xfs_vn_permission( 582 + struct inode *inode, 583 + int mask, 584 + struct nameidata *nd) 585 + { 586 + return generic_permission(inode, mask, xfs_check_acl); 587 } 588 #else 589 #define xfs_vn_permission NULL
+2 -28
fs/xfs/xfs_acl.c
··· 392 } 393 394 /* 395 - * The access control process to determine the access permission: 396 - * if uid == file owner id, use the file owner bits. 397 - * if gid == file owner group id, use the file group bits. 398 - * scan ACL for a matching user or group, and use matched entry 399 - * permission. Use total permissions of all matching group entries, 400 - * until all acl entries are exhausted. The final permission produced 401 - * by matching acl entry or entries needs to be & with group permission. 402 - * if not owner, owning group, or matching entry in ACL, use file 403 - * other bits. 404 - */ 405 - STATIC int 406 - xfs_acl_capability_check( 407 - mode_t mode, 408 - cred_t *cr) 409 - { 410 - if ((mode & ACL_READ) && !capable_cred(cr, CAP_DAC_READ_SEARCH)) 411 - return EACCES; 412 - if ((mode & ACL_WRITE) && !capable_cred(cr, CAP_DAC_OVERRIDE)) 413 - return EACCES; 414 - if ((mode & ACL_EXECUTE) && !capable_cred(cr, CAP_DAC_OVERRIDE)) 415 - return EACCES; 416 - 417 - return 0; 418 - } 419 - 420 - /* 421 * Note: cr is only used here for the capability check if the ACL test fails. 422 * It is not used to find out the credentials uid or groups etc, as was 423 * done in IRIX. It is assumed that the uid and groups for the current ··· 412 413 matched.ae_tag = 0; /* Invalid type */ 414 matched.ae_perm = 0; 415 - md >>= 6; /* Normalize the bits for comparison */ 416 417 for (i = 0; i < fap->acl_cnt; i++) { 418 /* ··· 493 break; 494 } 495 496 - return xfs_acl_capability_check(md, cr); 497 } 498 499 /*
··· 392 } 393 394 /* 395 * Note: cr is only used here for the capability check if the ACL test fails. 396 * It is not used to find out the credentials uid or groups etc, as was 397 * done in IRIX. It is assumed that the uid and groups for the current ··· 438 439 matched.ae_tag = 0; /* Invalid type */ 440 matched.ae_perm = 0; 441 442 for (i = 0; i < fap->acl_cnt; i++) { 443 /* ··· 520 break; 521 } 522 523 + /* EACCES tells generic_permission to check for capability overrides */ 524 + return EACCES; 525 } 526 527 /*
-2
fs/xfs/xfs_acl.h
··· 75 #define _ACL_GET_DEFAULT(pv,pd) (xfs_acl_vtoacl(pv,NULL,pd) == 0) 76 #define _ACL_ACCESS_EXISTS xfs_acl_vhasacl_access 77 #define _ACL_DEFAULT_EXISTS xfs_acl_vhasacl_default 78 - #define _ACL_XFS_IACCESS(i,m,c) (XFS_IFORK_Q(i) ? xfs_acl_iaccess(i,m,c) : -1) 79 80 #define _ACL_ALLOC(a) ((a) = kmem_zone_alloc(xfs_acl_zone, KM_SLEEP)) 81 #define _ACL_FREE(a) ((a)? kmem_zone_free(xfs_acl_zone, (a)):(void)0) ··· 94 #define _ACL_GET_DEFAULT(pv,pd) (0) 95 #define _ACL_ACCESS_EXISTS (NULL) 96 #define _ACL_DEFAULT_EXISTS (NULL) 97 - #define _ACL_XFS_IACCESS(i,m,c) (-1) 98 #endif 99 100 #endif /* __XFS_ACL_H__ */
··· 75 #define _ACL_GET_DEFAULT(pv,pd) (xfs_acl_vtoacl(pv,NULL,pd) == 0) 76 #define _ACL_ACCESS_EXISTS xfs_acl_vhasacl_access 77 #define _ACL_DEFAULT_EXISTS xfs_acl_vhasacl_default 78 79 #define _ACL_ALLOC(a) ((a) = kmem_zone_alloc(xfs_acl_zone, KM_SLEEP)) 80 #define _ACL_FREE(a) ((a)? kmem_zone_free(xfs_acl_zone, (a)):(void)0) ··· 95 #define _ACL_GET_DEFAULT(pv,pd) (0) 96 #define _ACL_ACCESS_EXISTS (NULL) 97 #define _ACL_DEFAULT_EXISTS (NULL) 98 #endif 99 100 #endif /* __XFS_ACL_H__ */
-63
fs/xfs/xfs_inode.c
··· 3583 XFS_MOUNT_IUNLOCK(mp); 3584 } 3585 3586 - /* 3587 - * xfs_iaccess: check accessibility of inode for mode. 3588 - */ 3589 - int 3590 - xfs_iaccess( 3591 - xfs_inode_t *ip, 3592 - mode_t mode, 3593 - cred_t *cr) 3594 - { 3595 - int error; 3596 - mode_t orgmode = mode; 3597 - struct inode *inode = vn_to_inode(XFS_ITOV(ip)); 3598 - 3599 - if (mode & S_IWUSR) { 3600 - umode_t imode = inode->i_mode; 3601 - 3602 - if (IS_RDONLY(inode) && 3603 - (S_ISREG(imode) || S_ISDIR(imode) || S_ISLNK(imode))) 3604 - return XFS_ERROR(EROFS); 3605 - 3606 - if (IS_IMMUTABLE(inode)) 3607 - return XFS_ERROR(EACCES); 3608 - } 3609 - 3610 - /* 3611 - * If there's an Access Control List it's used instead of 3612 - * the mode bits. 3613 - */ 3614 - if ((error = _ACL_XFS_IACCESS(ip, mode, cr)) != -1) 3615 - return error ? XFS_ERROR(error) : 0; 3616 - 3617 - if (current_fsuid(cr) != ip->i_d.di_uid) { 3618 - mode >>= 3; 3619 - if (!in_group_p((gid_t)ip->i_d.di_gid)) 3620 - mode >>= 3; 3621 - } 3622 - 3623 - /* 3624 - * If the DACs are ok we don't need any capability check. 3625 - */ 3626 - if ((ip->i_d.di_mode & mode) == mode) 3627 - return 0; 3628 - /* 3629 - * Read/write DACs are always overridable. 3630 - * Executable DACs are overridable if at least one exec bit is set. 3631 - */ 3632 - if (!(orgmode & S_IXUSR) || 3633 - (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode)) 3634 - if (capable_cred(cr, CAP_DAC_OVERRIDE)) 3635 - return 0; 3636 - 3637 - if ((orgmode == S_IRUSR) || 3638 - (S_ISDIR(inode->i_mode) && (!(orgmode & S_IWUSR)))) { 3639 - if (capable_cred(cr, CAP_DAC_READ_SEARCH)) 3640 - return 0; 3641 - #ifdef NOISE 3642 - cmn_err(CE_NOTE, "Ick: mode=%o, orgmode=%o", mode, orgmode); 3643 - #endif /* NOISE */ 3644 - return XFS_ERROR(EACCES); 3645 - } 3646 - return XFS_ERROR(EACCES); 3647 - } 3648 - 3649 #ifdef XFS_ILOCK_TRACE 3650 ktrace_t *xfs_ilock_trace_buf; 3651
··· 3583 XFS_MOUNT_IUNLOCK(mp); 3584 } 3585 3586 #ifdef XFS_ILOCK_TRACE 3587 ktrace_t *xfs_ilock_trace_buf; 3588
-1
fs/xfs/xfs_inode.h
··· 550 int xfs_iextents_copy(xfs_inode_t *, xfs_bmbt_rec_t *, int); 551 int xfs_iflush(xfs_inode_t *, uint); 552 void xfs_iflush_all(struct xfs_mount *); 553 - int xfs_iaccess(xfs_inode_t *, mode_t, cred_t *); 554 void xfs_ichgtime(xfs_inode_t *, int); 555 xfs_fsize_t xfs_file_last_byte(xfs_inode_t *); 556 void xfs_lock_inodes(xfs_inode_t **, int, int, uint);
··· 550 int xfs_iextents_copy(xfs_inode_t *, xfs_bmbt_rec_t *, int); 551 int xfs_iflush(xfs_inode_t *, uint); 552 void xfs_iflush_all(struct xfs_mount *); 553 void xfs_ichgtime(xfs_inode_t *, int); 554 xfs_fsize_t xfs_file_last_byte(xfs_inode_t *); 555 void xfs_lock_inodes(xfs_inode_t **, int, int, uint);
-21
fs/xfs/xfs_vnodeops.c
··· 898 return code; 899 } 900 901 - 902 - /* 903 - * xfs_access 904 - * Null conversion from vnode mode bits to inode mode bits, as in efs. 905 - */ 906 - int 907 - xfs_access( 908 - xfs_inode_t *ip, 909 - int mode, 910 - cred_t *credp) 911 - { 912 - int error; 913 - 914 - xfs_itrace_entry(ip); 915 - xfs_ilock(ip, XFS_ILOCK_SHARED); 916 - error = xfs_iaccess(ip, mode, credp); 917 - xfs_iunlock(ip, XFS_ILOCK_SHARED); 918 - return error; 919 - } 920 - 921 - 922 /* 923 * The maximum pathlen is 1024 bytes. Since the minimum file system 924 * blocksize is 512 bytes, we can get a max of 2 extents back from
··· 898 return code; 899 } 900 901 /* 902 * The maximum pathlen is 1024 bytes. Since the minimum file system 903 * blocksize is 512 bytes, we can get a max of 2 extents back from
-1
fs/xfs/xfs_vnodeops.h
··· 18 int xfs_getattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags); 19 int xfs_setattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags, 20 struct cred *credp); 21 - int xfs_access(struct xfs_inode *ip, int mode, struct cred *credp); 22 int xfs_readlink(struct xfs_inode *ip, char *link); 23 int xfs_fsync(struct xfs_inode *ip, int flag, xfs_off_t start, 24 xfs_off_t stop);
··· 18 int xfs_getattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags); 19 int xfs_setattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags, 20 struct cred *credp); 21 int xfs_readlink(struct xfs_inode *ip, char *link); 22 int xfs_fsync(struct xfs_inode *ip, int flag, xfs_off_t start, 23 xfs_off_t stop);