[PATCH 15/23] richacl: Delete posix acl if present on richacl set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When trying to set richacl on a file system object if we
have ACL4_POSIX_MAPPED flag set on the acl delete posix
acl stored with the object. This helps us to migrate from
posix acl to richacl. If we have posix acl stored with
the inode, a getxattr on the inode would return a mapped
richacl with ACL4_POSIX_MAPPED set. Now when we set the
acl back it will result in posix acl being deleted and
richacl being stored.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxxxxxxx>
---
 fs/ext4/acl.c     |    2 +-
 fs/ext4/acl.h     |    2 ++
 fs/ext4/richacl.c |   26 ++++++++++++++++++++++++--
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
index e17e1a9..3dd3058 100644
--- a/fs/ext4/acl.c
+++ b/fs/ext4/acl.c
@@ -203,7 +203,7 @@ ext4_get_acl(struct inode *inode, int type)
  *
  * inode->i_mutex: down unless called from ext4_new_inode
  */
-static int
+int
 ext4_set_acl(handle_t *handle, struct inode *inode, int type,
 	     struct posix_acl *acl)
 {
diff --git a/fs/ext4/acl.h b/fs/ext4/acl.h
index 3e47cf3..adcb6e7 100644
--- a/fs/ext4/acl.h
+++ b/fs/ext4/acl.h
@@ -58,6 +58,8 @@ extern int ext4_check_acl(struct inode *, int);
 extern int ext4_acl_chmod(struct inode *);
 extern int ext4_init_acl(handle_t *, struct inode *, struct inode *);
 extern struct posix_acl *ext4_get_acl(struct inode *inode, int type);
+extern int ext4_set_acl(handle_t *handle, struct inode *inode, int type,
+			struct posix_acl *acl);
 
 #else  /* CONFIG_EXT4_FS_POSIX_ACL */
 #include <linux/sched.h>
diff --git a/fs/ext4/richacl.c b/fs/ext4/richacl.c
index 73c14dd..ca8f28e 100644
--- a/fs/ext4/richacl.c
+++ b/fs/ext4/richacl.c
@@ -368,6 +368,7 @@ ext4_xattr_set_richacl(struct dentry *dentry, const char *name,
 {
 	handle_t *handle;
 	struct richacl *acl = NULL;
+	struct posix_acl *pacl = NULL, *pdacl = NULL;
 	int retval, retries = 0;
 	struct inode *inode = dentry->d_inode;
 
@@ -388,18 +389,39 @@ ext4_xattr_set_richacl(struct dentry *dentry, const char *name,
 
 		inode->i_mode &= ~S_IRWXUGO;
 		inode->i_mode |= richacl_masks_to_mode(acl);
-	}
+		/*
+		 * check whether we have posix acl. If so delete them
+		 *
+		 */
 
+		if (acl->a_flags & ACL4_POSIX_MAPPED) {
+			pacl  = ext4_get_acl(inode, ACL_TYPE_ACCESS);
+			pdacl = ext4_get_acl(inode, ACL_TYPE_DEFAULT);
+			acl->a_flags &= ~ACL4_POSIX_MAPPED;
+		}
+	}
 retry:
 	handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
 	if (IS_ERR(handle))
 		return PTR_ERR(handle);
 	ext4_mark_inode_dirty(handle, inode);
+	if (pacl)
+		ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, NULL);
+	if (pdacl)
+		ext4_set_acl(handle, inode, ACL_TYPE_DEFAULT, NULL);
+
 	retval = ext4_set_richacl(handle, inode, acl);
 	ext4_journal_stop(handle);
-	if (retval == ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
+	if (retval == ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) {
+		posix_acl_release(pacl);
+		posix_acl_release(pdacl);
+		pacl = pdacl = NULL;
 		goto retry;
+	}
 	richacl_put(acl);
+	posix_acl_release(pacl);
+	posix_acl_release(pdacl);
+	pacl = pdacl = NULL;
 	return retval;
 }
 
-- 
1.7.0.rc0.48.gdace5

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux