2009-06-10 23:07:47 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008, Christoph Hellwig
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it would be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
#include "xfs.h"
|
2013-10-23 07:51:50 +08:00
|
|
|
#include "xfs_format.h"
|
2013-08-12 18:49:23 +08:00
|
|
|
#include "xfs_log_format.h"
|
2013-08-12 18:49:32 +08:00
|
|
|
#include "xfs_trans_resv.h"
|
2013-08-12 18:49:55 +08:00
|
|
|
#include "xfs_ag.h"
|
2013-06-05 10:09:10 +08:00
|
|
|
#include "xfs_sb.h"
|
|
|
|
#include "xfs_mount.h"
|
2013-10-23 07:51:50 +08:00
|
|
|
#include "xfs_inode.h"
|
|
|
|
#include "xfs_acl.h"
|
|
|
|
#include "xfs_attr.h"
|
2009-12-15 07:14:59 +08:00
|
|
|
#include "xfs_trace.h"
|
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>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-06-10 23:07:47 +08:00
|
|
|
#include <linux/xattr.h>
|
|
|
|
#include <linux/posix_acl_xattr.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Locking scheme:
|
|
|
|
* - all ACL updates are protected by inode->i_mutex, which is taken before
|
|
|
|
* calling into this file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
STATIC struct posix_acl *
|
2013-06-05 10:09:10 +08:00
|
|
|
xfs_acl_from_disk(
|
|
|
|
struct xfs_acl *aclp,
|
|
|
|
int max_entries)
|
2009-06-10 23:07:47 +08:00
|
|
|
{
|
|
|
|
struct posix_acl_entry *acl_e;
|
|
|
|
struct posix_acl *acl;
|
|
|
|
struct xfs_acl_entry *ace;
|
2011-12-13 05:55:52 +08:00
|
|
|
unsigned int count, i;
|
2009-06-10 23:07:47 +08:00
|
|
|
|
|
|
|
count = be32_to_cpu(aclp->acl_cnt);
|
2013-06-05 10:09:10 +08:00
|
|
|
if (count > max_entries)
|
2011-11-20 23:35:32 +08:00
|
|
|
return ERR_PTR(-EFSCORRUPTED);
|
2009-06-10 23:07:47 +08:00
|
|
|
|
|
|
|
acl = posix_acl_alloc(count, GFP_KERNEL);
|
|
|
|
if (!acl)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
acl_e = &acl->a_entries[i];
|
|
|
|
ace = &aclp->acl_entry[i];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The tag is 32 bits on disk and 16 bits in core.
|
|
|
|
*
|
|
|
|
* Because every access to it goes through the core
|
|
|
|
* format first this is not a problem.
|
|
|
|
*/
|
|
|
|
acl_e->e_tag = be32_to_cpu(ace->ae_tag);
|
|
|
|
acl_e->e_perm = be16_to_cpu(ace->ae_perm);
|
|
|
|
|
|
|
|
switch (acl_e->e_tag) {
|
|
|
|
case ACL_USER:
|
2013-08-16 02:07:59 +08:00
|
|
|
acl_e->e_uid = xfs_uid_to_kuid(be32_to_cpu(ace->ae_id));
|
|
|
|
break;
|
2009-06-10 23:07:47 +08:00
|
|
|
case ACL_GROUP:
|
2013-08-16 02:07:59 +08:00
|
|
|
acl_e->e_gid = xfs_gid_to_kgid(be32_to_cpu(ace->ae_id));
|
2009-06-10 23:07:47 +08:00
|
|
|
break;
|
|
|
|
case ACL_USER_OBJ:
|
|
|
|
case ACL_GROUP_OBJ:
|
|
|
|
case ACL_MASK:
|
|
|
|
case ACL_OTHER:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return acl;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
posix_acl_release(acl);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC void
|
|
|
|
xfs_acl_to_disk(struct xfs_acl *aclp, const struct posix_acl *acl)
|
|
|
|
{
|
|
|
|
const struct posix_acl_entry *acl_e;
|
|
|
|
struct xfs_acl_entry *ace;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
aclp->acl_cnt = cpu_to_be32(acl->a_count);
|
|
|
|
for (i = 0; i < acl->a_count; i++) {
|
|
|
|
ace = &aclp->acl_entry[i];
|
|
|
|
acl_e = &acl->a_entries[i];
|
|
|
|
|
|
|
|
ace->ae_tag = cpu_to_be32(acl_e->e_tag);
|
2013-08-16 02:07:59 +08:00
|
|
|
switch (acl_e->e_tag) {
|
|
|
|
case ACL_USER:
|
|
|
|
ace->ae_id = cpu_to_be32(xfs_kuid_to_uid(acl_e->e_uid));
|
|
|
|
break;
|
|
|
|
case ACL_GROUP:
|
|
|
|
ace->ae_id = cpu_to_be32(xfs_kgid_to_gid(acl_e->e_gid));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ace->ae_id = cpu_to_be32(ACL_UNDEFINED_ID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-10 23:07:47 +08:00
|
|
|
ace->ae_perm = cpu_to_be16(acl_e->e_perm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct posix_acl *
|
|
|
|
xfs_get_acl(struct inode *inode, int type)
|
|
|
|
{
|
|
|
|
struct xfs_inode *ip = XFS_I(inode);
|
2013-12-20 21:16:50 +08:00
|
|
|
struct posix_acl *acl = NULL;
|
2009-06-10 23:07:47 +08:00
|
|
|
struct xfs_acl *xfs_acl;
|
2010-01-20 07:47:48 +08:00
|
|
|
unsigned char *ea_name;
|
2009-06-10 23:07:47 +08:00
|
|
|
int error;
|
2013-06-05 10:09:10 +08:00
|
|
|
int len;
|
2009-06-10 23:07:47 +08:00
|
|
|
|
2011-07-23 23:37:31 +08:00
|
|
|
trace_xfs_get_acl(ip);
|
|
|
|
|
2009-06-10 23:07:47 +08:00
|
|
|
switch (type) {
|
|
|
|
case ACL_TYPE_ACCESS:
|
|
|
|
ea_name = SGI_ACL_FILE;
|
|
|
|
break;
|
|
|
|
case ACL_TYPE_DEFAULT:
|
|
|
|
ea_name = SGI_ACL_DEFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
2009-06-10 01:29:39 +08:00
|
|
|
BUG();
|
2009-06-10 23:07:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a cached ACLs value just return it, not need to
|
|
|
|
* go out to the disk.
|
|
|
|
*/
|
2013-06-05 10:09:10 +08:00
|
|
|
len = XFS_ACL_MAX_SIZE(ip->i_mount);
|
2013-09-02 18:53:00 +08:00
|
|
|
xfs_acl = kmem_zalloc_large(len, KM_SLEEP);
|
|
|
|
if (!xfs_acl)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2009-06-10 23:07:47 +08:00
|
|
|
|
2010-01-20 07:47:48 +08:00
|
|
|
error = -xfs_attr_get(ip, ea_name, (unsigned char *)xfs_acl,
|
|
|
|
&len, ATTR_ROOT);
|
2009-06-10 23:07:47 +08:00
|
|
|
if (error) {
|
|
|
|
/*
|
|
|
|
* If the attribute doesn't exist make sure we have a negative
|
|
|
|
* cache entry, for any other error assume it is transient and
|
2009-06-10 01:29:39 +08:00
|
|
|
* leave the cache entry as ACL_NOT_CACHED.
|
2009-06-10 23:07:47 +08:00
|
|
|
*/
|
2013-12-20 21:16:50 +08:00
|
|
|
if (error == -ENOATTR)
|
2009-06-10 23:07:47 +08:00
|
|
|
goto out_update_cache;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-06-05 10:09:10 +08:00
|
|
|
acl = xfs_acl_from_disk(xfs_acl, XFS_ACL_MAX_ENTRIES(ip->i_mount));
|
2009-06-10 23:07:47 +08:00
|
|
|
if (IS_ERR(acl))
|
|
|
|
goto out;
|
|
|
|
|
2013-09-02 18:52:59 +08:00
|
|
|
out_update_cache:
|
2009-06-10 01:29:39 +08:00
|
|
|
set_cached_acl(inode, type, acl);
|
2013-09-02 18:52:59 +08:00
|
|
|
out:
|
2013-09-02 18:53:00 +08:00
|
|
|
kmem_free(xfs_acl);
|
2009-06-10 23:07:47 +08:00
|
|
|
return acl;
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC int
|
2013-12-20 21:16:50 +08:00
|
|
|
__xfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
|
2009-06-10 23:07:47 +08:00
|
|
|
{
|
|
|
|
struct xfs_inode *ip = XFS_I(inode);
|
2010-01-20 07:47:48 +08:00
|
|
|
unsigned char *ea_name;
|
2009-06-10 23:07:47 +08:00
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ACL_TYPE_ACCESS:
|
|
|
|
ea_name = SGI_ACL_FILE;
|
|
|
|
break;
|
|
|
|
case ACL_TYPE_DEFAULT:
|
|
|
|
if (!S_ISDIR(inode->i_mode))
|
|
|
|
return acl ? -EACCES : 0;
|
|
|
|
ea_name = SGI_ACL_DEFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acl) {
|
|
|
|
struct xfs_acl *xfs_acl;
|
2013-06-05 10:09:10 +08:00
|
|
|
int len = XFS_ACL_MAX_SIZE(ip->i_mount);
|
2009-06-10 23:07:47 +08:00
|
|
|
|
2013-09-02 18:53:00 +08:00
|
|
|
xfs_acl = kmem_zalloc_large(len, KM_SLEEP);
|
|
|
|
if (!xfs_acl)
|
|
|
|
return -ENOMEM;
|
2009-06-10 23:07:47 +08:00
|
|
|
|
|
|
|
xfs_acl_to_disk(xfs_acl, acl);
|
2013-06-05 10:09:10 +08:00
|
|
|
|
|
|
|
/* subtract away the unused acl entries */
|
|
|
|
len -= sizeof(struct xfs_acl_entry) *
|
|
|
|
(XFS_ACL_MAX_ENTRIES(ip->i_mount) - acl->a_count);
|
2009-06-10 23:07:47 +08:00
|
|
|
|
2010-01-20 07:47:48 +08:00
|
|
|
error = -xfs_attr_set(ip, ea_name, (unsigned char *)xfs_acl,
|
2009-06-10 23:07:47 +08:00
|
|
|
len, ATTR_ROOT);
|
|
|
|
|
2013-09-02 18:53:00 +08:00
|
|
|
kmem_free(xfs_acl);
|
2009-06-10 23:07:47 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* A NULL ACL argument means we want to remove the ACL.
|
|
|
|
*/
|
|
|
|
error = -xfs_attr_remove(ip, ea_name, ATTR_ROOT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the attribute didn't exist to start with that's fine.
|
|
|
|
*/
|
|
|
|
if (error == -ENOATTR)
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!error)
|
2009-06-10 01:29:39 +08:00
|
|
|
set_cached_acl(inode, type, acl);
|
2009-06-10 23:07:47 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-07-24 06:37:50 +08:00
|
|
|
xfs_set_mode(struct inode *inode, umode_t mode)
|
2009-06-10 23:07:47 +08:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (mode != inode->i_mode) {
|
|
|
|
struct iattr iattr;
|
|
|
|
|
2009-12-24 00:09:13 +08:00
|
|
|
iattr.ia_valid = ATTR_MODE | ATTR_CTIME;
|
2009-06-10 23:07:47 +08:00
|
|
|
iattr.ia_mode = mode;
|
2009-12-24 00:09:13 +08:00
|
|
|
iattr.ia_ctime = current_fs_time(inode->i_sb);
|
2009-06-10 23:07:47 +08:00
|
|
|
|
2011-07-08 20:34:23 +08:00
|
|
|
error = -xfs_setattr_nonsize(XFS_I(inode), &iattr, XFS_ATTR_NOACL);
|
2009-06-10 23:07:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-01-20 07:47:48 +08:00
|
|
|
xfs_acl_exists(struct inode *inode, unsigned char *name)
|
2009-06-10 23:07:47 +08:00
|
|
|
{
|
2013-06-05 10:09:10 +08:00
|
|
|
int len = XFS_ACL_MAX_SIZE(XFS_M(inode->i_sb));
|
2009-06-10 23:07:47 +08:00
|
|
|
|
|
|
|
return (xfs_attr_get(XFS_I(inode), name, NULL, &len,
|
|
|
|
ATTR_ROOT|ATTR_KERNOVAL) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
posix_acl_access_exists(struct inode *inode)
|
|
|
|
{
|
|
|
|
return xfs_acl_exists(inode, SGI_ACL_FILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
posix_acl_default_exists(struct inode *inode)
|
|
|
|
{
|
|
|
|
if (!S_ISDIR(inode->i_mode))
|
|
|
|
return 0;
|
|
|
|
return xfs_acl_exists(inode, SGI_ACL_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-12-20 21:16:50 +08:00
|
|
|
xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
2009-06-10 23:07:47 +08:00
|
|
|
{
|
2009-11-13 17:52:56 +08:00
|
|
|
int error = 0;
|
2009-06-10 23:07:47 +08:00
|
|
|
|
2013-12-20 21:16:50 +08:00
|
|
|
if (!acl)
|
2009-06-10 23:07:47 +08:00
|
|
|
goto set_acl;
|
|
|
|
|
|
|
|
error = -EINVAL;
|
2013-06-05 10:09:10 +08:00
|
|
|
if (acl->a_count > XFS_ACL_MAX_ENTRIES(XFS_M(inode->i_sb)))
|
2013-12-20 21:16:50 +08:00
|
|
|
return error;
|
2009-06-10 23:07:47 +08:00
|
|
|
|
|
|
|
if (type == ACL_TYPE_ACCESS) {
|
2011-07-24 06:56:36 +08:00
|
|
|
umode_t mode = inode->i_mode;
|
2009-06-10 23:07:47 +08:00
|
|
|
error = posix_acl_equiv_mode(acl, &mode);
|
|
|
|
|
|
|
|
if (error <= 0) {
|
|
|
|
acl = NULL;
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = xfs_set_mode(inode, mode);
|
|
|
|
if (error)
|
2013-12-20 21:16:50 +08:00
|
|
|
return error;
|
2009-06-10 23:07:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set_acl:
|
2013-12-20 21:16:50 +08:00
|
|
|
return __xfs_set_acl(inode, type, acl);
|
2009-06-10 23:07:47 +08:00
|
|
|
}
|