From 010d0ee15c400ee25ee314ee0bd94afdad8b6778 Mon Sep 17 00:00:00 2001 From: Aneesh Kumar K.V Date: Mon, 23 Nov 2009 12:21:54 +0530 Subject: [RFC PATCH 14/14] richacl: Delete posix acl if present on richacl set 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 --- fs/ext4/acl.c | 2 +- fs/ext4/acl.h | 2 ++ fs/ext4/richacl.c | 25 ++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c index cadf389..b67246d 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 diff --git a/fs/ext4/richacl.c b/fs/ext4/richacl.c index 9ffb033..165830f 100644 --- a/fs/ext4/richacl.c +++ b/fs/ext4/richacl.c @@ -368,6 +368,7 @@ ext4_xattr_set_richacl(struct inode *inode, const char *name, { handle_t *handle; struct richacl *acl = NULL; + struct posix_acl *pacl = NULL, *pdacl = NULL; int retval, retries = 0; if (!richacl_enabled(inode)) @@ -389,16 +390,38 @@ ext4_xattr_set_richacl(struct inode *inode, const char *name, 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.6.5.2.74.g610f9