2 * (C) 2001 Clemson University and The University of Chicago
4 * See COPYING in top-level directory.
8 #include "orangefs-kernel.h"
9 #include "orangefs-bufmap.h"
10 #include <linux/posix_acl_xattr.h>
11 #include <linux/fs_struct.h>
13 struct posix_acl
*orangefs_get_acl(struct inode
*inode
, int type
)
15 struct posix_acl
*acl
;
17 char *key
= NULL
, *value
= NULL
;
21 key
= XATTR_NAME_POSIX_ACL_ACCESS
;
23 case ACL_TYPE_DEFAULT
:
24 key
= XATTR_NAME_POSIX_ACL_DEFAULT
;
27 gossip_err("orangefs_get_acl: bogus value of type %d\n", type
);
28 return ERR_PTR(-EINVAL
);
31 * Rather than incurring a network call just to determine the exact
32 * length of the attribute, I just allocate a max length to save on
33 * the network call. Conceivably, we could pass NULL to
34 * orangefs_inode_getxattr() to probe the length of the value, but
35 * I don't do that for now.
37 value
= kmalloc(ORANGEFS_MAX_XATTR_VALUELEN
, GFP_KERNEL
);
39 return ERR_PTR(-ENOMEM
);
41 gossip_debug(GOSSIP_ACL_DEBUG
,
42 "inode %pU, key %s, type %d\n",
43 get_khandle_from_ino(inode
),
46 ret
= orangefs_inode_getxattr(inode
, key
, value
,
47 ORANGEFS_MAX_XATTR_VALUELEN
);
48 /* if the key exists, convert it to an in-memory rep */
50 acl
= posix_acl_from_xattr(&init_user_ns
, value
, ret
);
51 } else if (ret
== -ENODATA
|| ret
== -ENOSYS
) {
54 gossip_err("inode %pU retrieving acl's failed with error %d\n",
55 get_khandle_from_ino(inode
),
59 /* kfree(NULL) is safe, so don't worry if value ever got used */
64 int orangefs_set_acl(struct inode
*inode
, struct posix_acl
*acl
, int type
)
66 struct orangefs_inode_s
*orangefs_inode
= ORANGEFS_I(inode
);
70 const char *name
= NULL
;
74 name
= XATTR_NAME_POSIX_ACL_ACCESS
;
78 error
= posix_acl_update_mode(inode
, &mode
, &acl
);
80 gossip_err("%s: posix_acl_update_mode err: %d\n",
86 if (inode
->i_mode
!= mode
)
87 SetModeFlag(orangefs_inode
);
89 mark_inode_dirty_sync(inode
);
92 case ACL_TYPE_DEFAULT
:
93 name
= XATTR_NAME_POSIX_ACL_DEFAULT
;
96 gossip_err("%s: invalid type %d!\n", __func__
, type
);
100 gossip_debug(GOSSIP_ACL_DEBUG
,
101 "%s: inode %pU, key %s type %d\n",
102 __func__
, get_khandle_from_ino(inode
),
107 size
= posix_acl_xattr_size(acl
->a_count
);
108 value
= kmalloc(size
, GFP_KERNEL
);
112 error
= posix_acl_to_xattr(&init_user_ns
, acl
, value
, size
);
117 gossip_debug(GOSSIP_ACL_DEBUG
,
118 "%s: name %s, value %p, size %zd, acl %p\n",
119 __func__
, name
, value
, size
, acl
);
121 * Go ahead and set the extended attribute now. NOTE: Suppose acl
122 * was NULL, then value will be NULL and size will be 0 and that
123 * will xlate to a removexattr. However, we don't want removexattr
124 * complain if attributes does not exist.
126 error
= orangefs_inode_setxattr(inode
, name
, value
, size
, 0);
131 set_cached_acl(inode
, type
, acl
);
135 int orangefs_init_acl(struct inode
*inode
, struct inode
*dir
)
137 struct orangefs_inode_s
*orangefs_inode
= ORANGEFS_I(inode
);
138 struct posix_acl
*default_acl
, *acl
;
139 umode_t mode
= inode
->i_mode
;
142 ClearModeFlag(orangefs_inode
);
144 error
= posix_acl_create(dir
, &mode
, &default_acl
, &acl
);
149 error
= orangefs_set_acl(inode
, default_acl
, ACL_TYPE_DEFAULT
);
150 posix_acl_release(default_acl
);
155 error
= orangefs_set_acl(inode
, acl
, ACL_TYPE_ACCESS
);
156 posix_acl_release(acl
);
159 /* If mode of the inode was changed, then do a forcible ->setattr */
160 if (mode
!= inode
->i_mode
) {
161 SetModeFlag(orangefs_inode
);
162 inode
->i_mode
= mode
;
163 orangefs_flush_inode(inode
);