185ff872dSAneesh Kumar K.V /* 285ff872dSAneesh Kumar K.V * Copyright IBM Corporation, 2010 385ff872dSAneesh Kumar K.V * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> 485ff872dSAneesh Kumar K.V * 585ff872dSAneesh Kumar K.V * This program is free software; you can redistribute it and/or modify it 685ff872dSAneesh Kumar K.V * under the terms of version 2.1 of the GNU Lesser General Public License 785ff872dSAneesh Kumar K.V * as published by the Free Software Foundation. 885ff872dSAneesh Kumar K.V * 985ff872dSAneesh Kumar K.V * This program is distributed in the hope that it would be useful, but 1085ff872dSAneesh Kumar K.V * WITHOUT ANY WARRANTY; without even the implied warranty of 1185ff872dSAneesh Kumar K.V * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 1285ff872dSAneesh Kumar K.V * 1385ff872dSAneesh Kumar K.V */ 1485ff872dSAneesh Kumar K.V 1585ff872dSAneesh Kumar K.V #include <linux/module.h> 1685ff872dSAneesh Kumar K.V #include <linux/fs.h> 1785ff872dSAneesh Kumar K.V #include <net/9p/9p.h> 1885ff872dSAneesh Kumar K.V #include <net/9p/client.h> 1985ff872dSAneesh Kumar K.V #include <linux/slab.h> 2022d8dcdfSAneesh Kumar K.V #include <linux/sched.h> 2185ff872dSAneesh Kumar K.V #include <linux/posix_acl_xattr.h> 2285ff872dSAneesh Kumar K.V #include "xattr.h" 2385ff872dSAneesh Kumar K.V #include "acl.h" 2422d8dcdfSAneesh Kumar K.V #include "v9fs_vfs.h" 2576381a42SAneesh Kumar K.V #include "v9fs.h" 2685ff872dSAneesh Kumar K.V 2785ff872dSAneesh Kumar K.V static struct posix_acl *__v9fs_get_acl(struct p9_fid *fid, char *name) 2885ff872dSAneesh Kumar K.V { 2985ff872dSAneesh Kumar K.V ssize_t size; 3085ff872dSAneesh Kumar K.V void *value = NULL; 31009ca389SJoe Perches struct posix_acl *acl = NULL; 3285ff872dSAneesh Kumar K.V 3385ff872dSAneesh Kumar K.V size = v9fs_fid_xattr_get(fid, name, NULL, 0); 3485ff872dSAneesh Kumar K.V if (size > 0) { 3585ff872dSAneesh Kumar K.V value = kzalloc(size, GFP_NOFS); 3685ff872dSAneesh Kumar K.V if (!value) 3785ff872dSAneesh Kumar K.V return ERR_PTR(-ENOMEM); 3885ff872dSAneesh Kumar K.V size = v9fs_fid_xattr_get(fid, name, value, size); 3985ff872dSAneesh Kumar K.V if (size > 0) { 4085ff872dSAneesh Kumar K.V acl = posix_acl_from_xattr(value, size); 4185ff872dSAneesh Kumar K.V if (IS_ERR(acl)) 4285ff872dSAneesh Kumar K.V goto err_out; 4385ff872dSAneesh Kumar K.V } 4485ff872dSAneesh Kumar K.V } else if (size == -ENODATA || size == 0 || 4585ff872dSAneesh Kumar K.V size == -ENOSYS || size == -EOPNOTSUPP) { 4685ff872dSAneesh Kumar K.V acl = NULL; 4785ff872dSAneesh Kumar K.V } else 4885ff872dSAneesh Kumar K.V acl = ERR_PTR(-EIO); 4985ff872dSAneesh Kumar K.V 5085ff872dSAneesh Kumar K.V err_out: 5185ff872dSAneesh Kumar K.V kfree(value); 5285ff872dSAneesh Kumar K.V return acl; 5385ff872dSAneesh Kumar K.V } 5485ff872dSAneesh Kumar K.V 5585ff872dSAneesh Kumar K.V int v9fs_get_acl(struct inode *inode, struct p9_fid *fid) 5685ff872dSAneesh Kumar K.V { 5785ff872dSAneesh Kumar K.V int retval = 0; 5885ff872dSAneesh Kumar K.V struct posix_acl *pacl, *dacl; 5976381a42SAneesh Kumar K.V struct v9fs_session_info *v9ses; 6085ff872dSAneesh Kumar K.V 6176381a42SAneesh Kumar K.V v9ses = v9fs_inode2v9ses(inode); 6276381a42SAneesh Kumar K.V if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) { 6376381a42SAneesh Kumar K.V set_cached_acl(inode, ACL_TYPE_DEFAULT, NULL); 6476381a42SAneesh Kumar K.V set_cached_acl(inode, ACL_TYPE_ACCESS, NULL); 6576381a42SAneesh Kumar K.V return 0; 6676381a42SAneesh Kumar K.V } 6785ff872dSAneesh Kumar K.V /* get the default/access acl values and cache them */ 6885ff872dSAneesh Kumar K.V dacl = __v9fs_get_acl(fid, POSIX_ACL_XATTR_DEFAULT); 6985ff872dSAneesh Kumar K.V pacl = __v9fs_get_acl(fid, POSIX_ACL_XATTR_ACCESS); 7085ff872dSAneesh Kumar K.V 7185ff872dSAneesh Kumar K.V if (!IS_ERR(dacl) && !IS_ERR(pacl)) { 7285ff872dSAneesh Kumar K.V set_cached_acl(inode, ACL_TYPE_DEFAULT, dacl); 7385ff872dSAneesh Kumar K.V set_cached_acl(inode, ACL_TYPE_ACCESS, pacl); 7485ff872dSAneesh Kumar K.V posix_acl_release(dacl); 7585ff872dSAneesh Kumar K.V posix_acl_release(pacl); 7685ff872dSAneesh Kumar K.V } else 7785ff872dSAneesh Kumar K.V retval = -EIO; 7885ff872dSAneesh Kumar K.V 7985ff872dSAneesh Kumar K.V return retval; 8085ff872dSAneesh Kumar K.V } 8185ff872dSAneesh Kumar K.V 8285ff872dSAneesh Kumar K.V static struct posix_acl *v9fs_get_cached_acl(struct inode *inode, int type) 8385ff872dSAneesh Kumar K.V { 8485ff872dSAneesh Kumar K.V struct posix_acl *acl; 8585ff872dSAneesh Kumar K.V /* 8685ff872dSAneesh Kumar K.V * 9p Always cache the acl value when 8785ff872dSAneesh Kumar K.V * instantiating the inode (v9fs_inode_from_fid) 8885ff872dSAneesh Kumar K.V */ 8985ff872dSAneesh Kumar K.V acl = get_cached_acl(inode, type); 9085ff872dSAneesh Kumar K.V BUG_ON(acl == ACL_NOT_CACHED); 9185ff872dSAneesh Kumar K.V return acl; 9285ff872dSAneesh Kumar K.V } 9385ff872dSAneesh Kumar K.V 94b74c79e9SNick Piggin int v9fs_check_acl(struct inode *inode, int mask, unsigned int flags) 9585ff872dSAneesh Kumar K.V { 9676381a42SAneesh Kumar K.V struct posix_acl *acl; 9776381a42SAneesh Kumar K.V struct v9fs_session_info *v9ses; 9876381a42SAneesh Kumar K.V 99b74c79e9SNick Piggin if (flags & IPERM_FLAG_RCU) 100b74c79e9SNick Piggin return -ECHILD; 101b74c79e9SNick Piggin 10276381a42SAneesh Kumar K.V v9ses = v9fs_inode2v9ses(inode); 10376381a42SAneesh Kumar K.V if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) { 10476381a42SAneesh Kumar K.V /* 10576381a42SAneesh Kumar K.V * On access = client mode get the acl 10676381a42SAneesh Kumar K.V * values from the server 10776381a42SAneesh Kumar K.V */ 10876381a42SAneesh Kumar K.V return 0; 10976381a42SAneesh Kumar K.V } 11076381a42SAneesh Kumar K.V acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS); 11185ff872dSAneesh Kumar K.V 11285ff872dSAneesh Kumar K.V if (IS_ERR(acl)) 11385ff872dSAneesh Kumar K.V return PTR_ERR(acl); 11485ff872dSAneesh Kumar K.V if (acl) { 11585ff872dSAneesh Kumar K.V int error = posix_acl_permission(inode, acl, mask); 11685ff872dSAneesh Kumar K.V posix_acl_release(acl); 11785ff872dSAneesh Kumar K.V return error; 11885ff872dSAneesh Kumar K.V } 11985ff872dSAneesh Kumar K.V return -EAGAIN; 12085ff872dSAneesh Kumar K.V } 1217a4566b0SAneesh Kumar K.V 1226e8dc555SAneesh Kumar K.V static int v9fs_set_acl(struct dentry *dentry, int type, struct posix_acl *acl) 1236e8dc555SAneesh Kumar K.V { 1246e8dc555SAneesh Kumar K.V int retval; 1256e8dc555SAneesh Kumar K.V char *name; 1266e8dc555SAneesh Kumar K.V size_t size; 1276e8dc555SAneesh Kumar K.V void *buffer; 1286e8dc555SAneesh Kumar K.V struct inode *inode = dentry->d_inode; 1296e8dc555SAneesh Kumar K.V 1306e8dc555SAneesh Kumar K.V set_cached_acl(inode, type, acl); 1316e8dc555SAneesh Kumar K.V /* Set a setxattr request to server */ 1326e8dc555SAneesh Kumar K.V size = posix_acl_xattr_size(acl->a_count); 1336e8dc555SAneesh Kumar K.V buffer = kmalloc(size, GFP_KERNEL); 1346e8dc555SAneesh Kumar K.V if (!buffer) 1356e8dc555SAneesh Kumar K.V return -ENOMEM; 1366e8dc555SAneesh Kumar K.V retval = posix_acl_to_xattr(acl, buffer, size); 1376e8dc555SAneesh Kumar K.V if (retval < 0) 1386e8dc555SAneesh Kumar K.V goto err_free_out; 1396e8dc555SAneesh Kumar K.V switch (type) { 1406e8dc555SAneesh Kumar K.V case ACL_TYPE_ACCESS: 1416e8dc555SAneesh Kumar K.V name = POSIX_ACL_XATTR_ACCESS; 1426e8dc555SAneesh Kumar K.V break; 1436e8dc555SAneesh Kumar K.V case ACL_TYPE_DEFAULT: 1446e8dc555SAneesh Kumar K.V name = POSIX_ACL_XATTR_DEFAULT; 1456e8dc555SAneesh Kumar K.V break; 1466e8dc555SAneesh Kumar K.V default: 1476e8dc555SAneesh Kumar K.V BUG(); 1486e8dc555SAneesh Kumar K.V } 1496e8dc555SAneesh Kumar K.V retval = v9fs_xattr_set(dentry, name, buffer, size, 0); 1506e8dc555SAneesh Kumar K.V err_free_out: 1516e8dc555SAneesh Kumar K.V kfree(buffer); 1526e8dc555SAneesh Kumar K.V return retval; 1536e8dc555SAneesh Kumar K.V } 1546e8dc555SAneesh Kumar K.V 1556e8dc555SAneesh Kumar K.V int v9fs_acl_chmod(struct dentry *dentry) 1566e8dc555SAneesh Kumar K.V { 1576e8dc555SAneesh Kumar K.V int retval = 0; 1586e8dc555SAneesh Kumar K.V struct posix_acl *acl, *clone; 1596e8dc555SAneesh Kumar K.V struct inode *inode = dentry->d_inode; 1606e8dc555SAneesh Kumar K.V 1616e8dc555SAneesh Kumar K.V if (S_ISLNK(inode->i_mode)) 1626e8dc555SAneesh Kumar K.V return -EOPNOTSUPP; 1636e8dc555SAneesh Kumar K.V acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS); 1646e8dc555SAneesh Kumar K.V if (acl) { 1656e8dc555SAneesh Kumar K.V clone = posix_acl_clone(acl, GFP_KERNEL); 1666e8dc555SAneesh Kumar K.V posix_acl_release(acl); 1676e8dc555SAneesh Kumar K.V if (!clone) 1686e8dc555SAneesh Kumar K.V return -ENOMEM; 1696e8dc555SAneesh Kumar K.V retval = posix_acl_chmod_masq(clone, inode->i_mode); 1706e8dc555SAneesh Kumar K.V if (!retval) 1716e8dc555SAneesh Kumar K.V retval = v9fs_set_acl(dentry, ACL_TYPE_ACCESS, clone); 1726e8dc555SAneesh Kumar K.V posix_acl_release(clone); 1736e8dc555SAneesh Kumar K.V } 1746e8dc555SAneesh Kumar K.V return retval; 1756e8dc555SAneesh Kumar K.V } 1766e8dc555SAneesh Kumar K.V 177ad77dbceSAneesh Kumar K.V int v9fs_set_create_acl(struct dentry *dentry, 178ad77dbceSAneesh Kumar K.V struct posix_acl *dpacl, struct posix_acl *pacl) 179ad77dbceSAneesh Kumar K.V { 180ad77dbceSAneesh Kumar K.V if (dpacl) 181ad77dbceSAneesh Kumar K.V v9fs_set_acl(dentry, ACL_TYPE_DEFAULT, dpacl); 182ad77dbceSAneesh Kumar K.V if (pacl) 183ad77dbceSAneesh Kumar K.V v9fs_set_acl(dentry, ACL_TYPE_ACCESS, pacl); 184ad77dbceSAneesh Kumar K.V posix_acl_release(dpacl); 185ad77dbceSAneesh Kumar K.V posix_acl_release(pacl); 186ad77dbceSAneesh Kumar K.V return 0; 187ad77dbceSAneesh Kumar K.V } 188ad77dbceSAneesh Kumar K.V 189ad77dbceSAneesh Kumar K.V int v9fs_acl_mode(struct inode *dir, mode_t *modep, 190ad77dbceSAneesh Kumar K.V struct posix_acl **dpacl, struct posix_acl **pacl) 191ad77dbceSAneesh Kumar K.V { 192ad77dbceSAneesh Kumar K.V int retval = 0; 193ad77dbceSAneesh Kumar K.V mode_t mode = *modep; 194ad77dbceSAneesh Kumar K.V struct posix_acl *acl = NULL; 195ad77dbceSAneesh Kumar K.V 196ad77dbceSAneesh Kumar K.V if (!S_ISLNK(mode)) { 197ad77dbceSAneesh Kumar K.V acl = v9fs_get_cached_acl(dir, ACL_TYPE_DEFAULT); 198ad77dbceSAneesh Kumar K.V if (IS_ERR(acl)) 199ad77dbceSAneesh Kumar K.V return PTR_ERR(acl); 200ad77dbceSAneesh Kumar K.V if (!acl) 201ad77dbceSAneesh Kumar K.V mode &= ~current_umask(); 202ad77dbceSAneesh Kumar K.V } 203ad77dbceSAneesh Kumar K.V if (acl) { 204ad77dbceSAneesh Kumar K.V struct posix_acl *clone; 205ad77dbceSAneesh Kumar K.V 206ad77dbceSAneesh Kumar K.V if (S_ISDIR(mode)) 207ad77dbceSAneesh Kumar K.V *dpacl = acl; 208ad77dbceSAneesh Kumar K.V clone = posix_acl_clone(acl, GFP_NOFS); 209ad77dbceSAneesh Kumar K.V retval = -ENOMEM; 210ad77dbceSAneesh Kumar K.V if (!clone) 211ad77dbceSAneesh Kumar K.V goto cleanup; 212ad77dbceSAneesh Kumar K.V 213ad77dbceSAneesh Kumar K.V retval = posix_acl_create_masq(clone, &mode); 214ad77dbceSAneesh Kumar K.V if (retval < 0) { 215ad77dbceSAneesh Kumar K.V posix_acl_release(clone); 216ad77dbceSAneesh Kumar K.V goto cleanup; 217ad77dbceSAneesh Kumar K.V } 218ad77dbceSAneesh Kumar K.V if (retval > 0) 219ad77dbceSAneesh Kumar K.V *pacl = clone; 220ad77dbceSAneesh Kumar K.V } 221ad77dbceSAneesh Kumar K.V *modep = mode; 222ad77dbceSAneesh Kumar K.V return 0; 223ad77dbceSAneesh Kumar K.V cleanup: 224ad77dbceSAneesh Kumar K.V posix_acl_release(acl); 225ad77dbceSAneesh Kumar K.V return retval; 226ad77dbceSAneesh Kumar K.V 227ad77dbceSAneesh Kumar K.V } 228ad77dbceSAneesh Kumar K.V 22976381a42SAneesh Kumar K.V static int v9fs_remote_get_acl(struct dentry *dentry, const char *name, 23076381a42SAneesh Kumar K.V void *buffer, size_t size, int type) 23176381a42SAneesh Kumar K.V { 23276381a42SAneesh Kumar K.V char *full_name; 23376381a42SAneesh Kumar K.V 23476381a42SAneesh Kumar K.V switch (type) { 23576381a42SAneesh Kumar K.V case ACL_TYPE_ACCESS: 23676381a42SAneesh Kumar K.V full_name = POSIX_ACL_XATTR_ACCESS; 23776381a42SAneesh Kumar K.V break; 23876381a42SAneesh Kumar K.V case ACL_TYPE_DEFAULT: 23976381a42SAneesh Kumar K.V full_name = POSIX_ACL_XATTR_DEFAULT; 24076381a42SAneesh Kumar K.V break; 24176381a42SAneesh Kumar K.V default: 24276381a42SAneesh Kumar K.V BUG(); 24376381a42SAneesh Kumar K.V } 24476381a42SAneesh Kumar K.V return v9fs_xattr_get(dentry, full_name, buffer, size); 24576381a42SAneesh Kumar K.V } 24676381a42SAneesh Kumar K.V 2477a4566b0SAneesh Kumar K.V static int v9fs_xattr_get_acl(struct dentry *dentry, const char *name, 2487a4566b0SAneesh Kumar K.V void *buffer, size_t size, int type) 2497a4566b0SAneesh Kumar K.V { 25076381a42SAneesh Kumar K.V struct v9fs_session_info *v9ses; 2517a4566b0SAneesh Kumar K.V struct posix_acl *acl; 2527a4566b0SAneesh Kumar K.V int error; 2537a4566b0SAneesh Kumar K.V 2547a4566b0SAneesh Kumar K.V if (strcmp(name, "") != 0) 2557a4566b0SAneesh Kumar K.V return -EINVAL; 2567a4566b0SAneesh Kumar K.V 25776381a42SAneesh Kumar K.V v9ses = v9fs_inode2v9ses(dentry->d_inode); 25876381a42SAneesh Kumar K.V /* 25976381a42SAneesh Kumar K.V * We allow set/get/list of acl when access=client is not specified 26076381a42SAneesh Kumar K.V */ 26176381a42SAneesh Kumar K.V if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) 26276381a42SAneesh Kumar K.V return v9fs_remote_get_acl(dentry, name, buffer, size, type); 26376381a42SAneesh Kumar K.V 2647a4566b0SAneesh Kumar K.V acl = v9fs_get_cached_acl(dentry->d_inode, type); 2657a4566b0SAneesh Kumar K.V if (IS_ERR(acl)) 2667a4566b0SAneesh Kumar K.V return PTR_ERR(acl); 2677a4566b0SAneesh Kumar K.V if (acl == NULL) 2687a4566b0SAneesh Kumar K.V return -ENODATA; 2697a4566b0SAneesh Kumar K.V error = posix_acl_to_xattr(acl, buffer, size); 2707a4566b0SAneesh Kumar K.V posix_acl_release(acl); 2717a4566b0SAneesh Kumar K.V 2727a4566b0SAneesh Kumar K.V return error; 2737a4566b0SAneesh Kumar K.V } 2747a4566b0SAneesh Kumar K.V 27576381a42SAneesh Kumar K.V static int v9fs_remote_set_acl(struct dentry *dentry, const char *name, 27676381a42SAneesh Kumar K.V const void *value, size_t size, 27776381a42SAneesh Kumar K.V int flags, int type) 27876381a42SAneesh Kumar K.V { 27976381a42SAneesh Kumar K.V char *full_name; 28076381a42SAneesh Kumar K.V 28176381a42SAneesh Kumar K.V switch (type) { 28276381a42SAneesh Kumar K.V case ACL_TYPE_ACCESS: 28376381a42SAneesh Kumar K.V full_name = POSIX_ACL_XATTR_ACCESS; 28476381a42SAneesh Kumar K.V break; 28576381a42SAneesh Kumar K.V case ACL_TYPE_DEFAULT: 28676381a42SAneesh Kumar K.V full_name = POSIX_ACL_XATTR_DEFAULT; 28776381a42SAneesh Kumar K.V break; 28876381a42SAneesh Kumar K.V default: 28976381a42SAneesh Kumar K.V BUG(); 29076381a42SAneesh Kumar K.V } 29176381a42SAneesh Kumar K.V return v9fs_xattr_set(dentry, full_name, value, size, flags); 29276381a42SAneesh Kumar K.V } 29376381a42SAneesh Kumar K.V 29476381a42SAneesh Kumar K.V 2957a4566b0SAneesh Kumar K.V static int v9fs_xattr_set_acl(struct dentry *dentry, const char *name, 2967a4566b0SAneesh Kumar K.V const void *value, size_t size, 2977a4566b0SAneesh Kumar K.V int flags, int type) 2987a4566b0SAneesh Kumar K.V { 29922d8dcdfSAneesh Kumar K.V int retval; 30022d8dcdfSAneesh Kumar K.V struct posix_acl *acl; 30176381a42SAneesh Kumar K.V struct v9fs_session_info *v9ses; 30222d8dcdfSAneesh Kumar K.V struct inode *inode = dentry->d_inode; 30322d8dcdfSAneesh Kumar K.V 30422d8dcdfSAneesh Kumar K.V if (strcmp(name, "") != 0) 30522d8dcdfSAneesh Kumar K.V return -EINVAL; 30676381a42SAneesh Kumar K.V 30776381a42SAneesh Kumar K.V v9ses = v9fs_inode2v9ses(dentry->d_inode); 30876381a42SAneesh Kumar K.V /* 30976381a42SAneesh Kumar K.V * set the attribute on the remote. Without even looking at the 31076381a42SAneesh Kumar K.V * xattr value. We leave it to the server to validate 31176381a42SAneesh Kumar K.V */ 31276381a42SAneesh Kumar K.V if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT) 31376381a42SAneesh Kumar K.V return v9fs_remote_set_acl(dentry, name, 31476381a42SAneesh Kumar K.V value, size, flags, type); 31576381a42SAneesh Kumar K.V 31622d8dcdfSAneesh Kumar K.V if (S_ISLNK(inode->i_mode)) 31722d8dcdfSAneesh Kumar K.V return -EOPNOTSUPP; 31822d8dcdfSAneesh Kumar K.V if (!is_owner_or_cap(inode)) 31922d8dcdfSAneesh Kumar K.V return -EPERM; 32022d8dcdfSAneesh Kumar K.V if (value) { 32122d8dcdfSAneesh Kumar K.V /* update the cached acl value */ 32222d8dcdfSAneesh Kumar K.V acl = posix_acl_from_xattr(value, size); 32322d8dcdfSAneesh Kumar K.V if (IS_ERR(acl)) 32422d8dcdfSAneesh Kumar K.V return PTR_ERR(acl); 32522d8dcdfSAneesh Kumar K.V else if (acl) { 32622d8dcdfSAneesh Kumar K.V retval = posix_acl_valid(acl); 32722d8dcdfSAneesh Kumar K.V if (retval) 32822d8dcdfSAneesh Kumar K.V goto err_out; 32922d8dcdfSAneesh Kumar K.V } 33022d8dcdfSAneesh Kumar K.V } else 33122d8dcdfSAneesh Kumar K.V acl = NULL; 33222d8dcdfSAneesh Kumar K.V 33322d8dcdfSAneesh Kumar K.V switch (type) { 33422d8dcdfSAneesh Kumar K.V case ACL_TYPE_ACCESS: 33522d8dcdfSAneesh Kumar K.V name = POSIX_ACL_XATTR_ACCESS; 33622d8dcdfSAneesh Kumar K.V if (acl) { 33722d8dcdfSAneesh Kumar K.V mode_t mode = inode->i_mode; 33822d8dcdfSAneesh Kumar K.V retval = posix_acl_equiv_mode(acl, &mode); 33922d8dcdfSAneesh Kumar K.V if (retval < 0) 34022d8dcdfSAneesh Kumar K.V goto err_out; 34122d8dcdfSAneesh Kumar K.V else { 34222d8dcdfSAneesh Kumar K.V struct iattr iattr; 34322d8dcdfSAneesh Kumar K.V if (retval == 0) { 34422d8dcdfSAneesh Kumar K.V /* 34522d8dcdfSAneesh Kumar K.V * ACL can be represented 34622d8dcdfSAneesh Kumar K.V * by the mode bits. So don't 34722d8dcdfSAneesh Kumar K.V * update ACL. 34822d8dcdfSAneesh Kumar K.V */ 34922d8dcdfSAneesh Kumar K.V acl = NULL; 35022d8dcdfSAneesh Kumar K.V value = NULL; 35122d8dcdfSAneesh Kumar K.V size = 0; 35222d8dcdfSAneesh Kumar K.V } 35322d8dcdfSAneesh Kumar K.V /* Updte the mode bits */ 35422d8dcdfSAneesh Kumar K.V iattr.ia_mode = ((mode & S_IALLUGO) | 35522d8dcdfSAneesh Kumar K.V (inode->i_mode & ~S_IALLUGO)); 35622d8dcdfSAneesh Kumar K.V iattr.ia_valid = ATTR_MODE; 35722d8dcdfSAneesh Kumar K.V /* FIXME should we update ctime ? 35822d8dcdfSAneesh Kumar K.V * What is the following setxattr update the 35922d8dcdfSAneesh Kumar K.V * mode ? 36022d8dcdfSAneesh Kumar K.V */ 36122d8dcdfSAneesh Kumar K.V v9fs_vfs_setattr_dotl(dentry, &iattr); 36222d8dcdfSAneesh Kumar K.V } 36322d8dcdfSAneesh Kumar K.V } 36422d8dcdfSAneesh Kumar K.V break; 36522d8dcdfSAneesh Kumar K.V case ACL_TYPE_DEFAULT: 36622d8dcdfSAneesh Kumar K.V name = POSIX_ACL_XATTR_DEFAULT; 36722d8dcdfSAneesh Kumar K.V if (!S_ISDIR(inode->i_mode)) { 368*6f81c115SAneesh Kumar K.V retval = acl ? -EINVAL : 0; 36922d8dcdfSAneesh Kumar K.V goto err_out; 37022d8dcdfSAneesh Kumar K.V } 37122d8dcdfSAneesh Kumar K.V break; 37222d8dcdfSAneesh Kumar K.V default: 37322d8dcdfSAneesh Kumar K.V BUG(); 37422d8dcdfSAneesh Kumar K.V } 37522d8dcdfSAneesh Kumar K.V retval = v9fs_xattr_set(dentry, name, value, size, flags); 37622d8dcdfSAneesh Kumar K.V if (!retval) 37722d8dcdfSAneesh Kumar K.V set_cached_acl(inode, type, acl); 37822d8dcdfSAneesh Kumar K.V err_out: 37922d8dcdfSAneesh Kumar K.V posix_acl_release(acl); 38022d8dcdfSAneesh Kumar K.V return retval; 3817a4566b0SAneesh Kumar K.V } 3827a4566b0SAneesh Kumar K.V 3837a4566b0SAneesh Kumar K.V const struct xattr_handler v9fs_xattr_acl_access_handler = { 3847a4566b0SAneesh Kumar K.V .prefix = POSIX_ACL_XATTR_ACCESS, 3857a4566b0SAneesh Kumar K.V .flags = ACL_TYPE_ACCESS, 3867a4566b0SAneesh Kumar K.V .get = v9fs_xattr_get_acl, 3877a4566b0SAneesh Kumar K.V .set = v9fs_xattr_set_acl, 3887a4566b0SAneesh Kumar K.V }; 3897a4566b0SAneesh Kumar K.V 3907a4566b0SAneesh Kumar K.V const struct xattr_handler v9fs_xattr_acl_default_handler = { 3917a4566b0SAneesh Kumar K.V .prefix = POSIX_ACL_XATTR_DEFAULT, 3927a4566b0SAneesh Kumar K.V .flags = ACL_TYPE_DEFAULT, 3937a4566b0SAneesh Kumar K.V .get = v9fs_xattr_get_acl, 3947a4566b0SAneesh Kumar K.V .set = v9fs_xattr_set_acl, 3957a4566b0SAneesh Kumar K.V }; 396