Skip to content

Commit bc26ab5

Browse files
author
Al Viro
committed
kill boilerplate around posix_acl_chmod_masq()
new helper: posix_acl_chmod(&acl, gfp, mode). Replaces acl with modified clone or with NULL if that has failed; returns 0 or -ve on error. All callers of posix_acl_chmod_masq() switched to that - they'd been doing exactly the same thing. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 4482a08 commit bc26ab5

14 files changed

Lines changed: 139 additions & 168 deletions

File tree

‎fs/9p/acl.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,18 @@ static int v9fs_set_acl(struct dentry *dentry, int type, struct posix_acl *acl)
162162
int v9fs_acl_chmod(struct dentry *dentry)
163163
{
164164
int retval = 0;
165-
struct posix_acl *acl, *clone;
165+
struct posix_acl *acl;
166166
struct inode *inode = dentry->d_inode;
167167

168168
if (S_ISLNK(inode->i_mode))
169169
return -EOPNOTSUPP;
170170
acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
171171
if (acl) {
172-
clone = posix_acl_clone(acl, GFP_KERNEL);
172+
retval = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
173+
if (retval)
174+
return retval;
175+
retval = v9fs_set_acl(dentry, ACL_TYPE_ACCESS, acl);
173176
posix_acl_release(acl);
174-
if (!clone)
175-
return -ENOMEM;
176-
retval = posix_acl_chmod_masq(clone, inode->i_mode);
177-
if (!retval)
178-
retval = v9fs_set_acl(dentry, ACL_TYPE_ACCESS, clone);
179-
posix_acl_release(clone);
180177
}
181178
return retval;
182179
}

‎fs/btrfs/acl.c‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
272272

273273
int btrfs_acl_chmod(struct inode *inode)
274274
{
275-
struct posix_acl *acl, *clone;
275+
struct posix_acl *acl;
276276
int ret = 0;
277277

278278
if (S_ISLNK(inode->i_mode))
@@ -285,17 +285,11 @@ int btrfs_acl_chmod(struct inode *inode)
285285
if (IS_ERR_OR_NULL(acl))
286286
return PTR_ERR(acl);
287287

288-
clone = posix_acl_clone(acl, GFP_KERNEL);
288+
ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
289+
if (ret)
290+
return ret;
291+
ret = btrfs_set_acl(NULL, inode, acl, ACL_TYPE_ACCESS);
289292
posix_acl_release(acl);
290-
if (!clone)
291-
return -ENOMEM;
292-
293-
ret = posix_acl_chmod_masq(clone, inode->i_mode);
294-
if (!ret)
295-
ret = btrfs_set_acl(NULL, inode, clone, ACL_TYPE_ACCESS);
296-
297-
posix_acl_release(clone);
298-
299293
return ret;
300294
}
301295

‎fs/ext2/acl.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
316316
int
317317
ext2_acl_chmod(struct inode *inode)
318318
{
319-
struct posix_acl *acl, *clone;
319+
struct posix_acl *acl;
320320
int error;
321321

322322
if (!test_opt(inode->i_sb, POSIX_ACL))
@@ -326,14 +326,11 @@ ext2_acl_chmod(struct inode *inode)
326326
acl = ext2_get_acl(inode, ACL_TYPE_ACCESS);
327327
if (IS_ERR(acl) || !acl)
328328
return PTR_ERR(acl);
329-
clone = posix_acl_clone(acl, GFP_KERNEL);
329+
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
330+
if (error)
331+
return error;
332+
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
330333
posix_acl_release(acl);
331-
if (!clone)
332-
return -ENOMEM;
333-
error = posix_acl_chmod_masq(clone, inode->i_mode);
334-
if (!error)
335-
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, clone);
336-
posix_acl_release(clone);
337334
return error;
338335
}
339336

‎fs/ext3/acl.c‎

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
326326
int
327327
ext3_acl_chmod(struct inode *inode)
328328
{
329-
struct posix_acl *acl, *clone;
329+
struct posix_acl *acl;
330+
handle_t *handle;
331+
int retries = 0;
330332
int error;
331333

332334
if (S_ISLNK(inode->i_mode))
@@ -336,31 +338,24 @@ ext3_acl_chmod(struct inode *inode)
336338
acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
337339
if (IS_ERR(acl) || !acl)
338340
return PTR_ERR(acl);
339-
clone = posix_acl_clone(acl, GFP_KERNEL);
340-
posix_acl_release(acl);
341-
if (!clone)
342-
return -ENOMEM;
343-
error = posix_acl_chmod_masq(clone, inode->i_mode);
344-
if (!error) {
345-
handle_t *handle;
346-
int retries = 0;
347-
348-
retry:
349-
handle = ext3_journal_start(inode,
350-
EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
351-
if (IS_ERR(handle)) {
352-
error = PTR_ERR(handle);
353-
ext3_std_error(inode->i_sb, error);
354-
goto out;
355-
}
356-
error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, clone);
357-
ext3_journal_stop(handle);
358-
if (error == -ENOSPC &&
359-
ext3_should_retry_alloc(inode->i_sb, &retries))
360-
goto retry;
341+
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
342+
if (error)
343+
return error;
344+
retry:
345+
handle = ext3_journal_start(inode,
346+
EXT3_DATA_TRANS_BLOCKS(inode->i_sb));
347+
if (IS_ERR(handle)) {
348+
error = PTR_ERR(handle);
349+
ext3_std_error(inode->i_sb, error);
350+
goto out;
361351
}
352+
error = ext3_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
353+
ext3_journal_stop(handle);
354+
if (error == -ENOSPC &&
355+
ext3_should_retry_alloc(inode->i_sb, &retries))
356+
goto retry;
362357
out:
363-
posix_acl_release(clone);
358+
posix_acl_release(acl);
364359
return error;
365360
}
366361

‎fs/ext4/acl.c‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -324,41 +324,37 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
324324
int
325325
ext4_acl_chmod(struct inode *inode)
326326
{
327-
struct posix_acl *acl, *clone;
327+
struct posix_acl *acl;
328+
handle_t *handle;
329+
int retries = 0;
328330
int error;
329331

332+
330333
if (S_ISLNK(inode->i_mode))
331334
return -EOPNOTSUPP;
332335
if (!test_opt(inode->i_sb, POSIX_ACL))
333336
return 0;
334337
acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
335338
if (IS_ERR(acl) || !acl)
336339
return PTR_ERR(acl);
337-
clone = posix_acl_clone(acl, GFP_KERNEL);
338-
posix_acl_release(acl);
339-
if (!clone)
340-
return -ENOMEM;
341-
error = posix_acl_chmod_masq(clone, inode->i_mode);
342-
if (!error) {
343-
handle_t *handle;
344-
int retries = 0;
345-
346-
retry:
347-
handle = ext4_journal_start(inode,
348-
EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
349-
if (IS_ERR(handle)) {
350-
error = PTR_ERR(handle);
351-
ext4_std_error(inode->i_sb, error);
352-
goto out;
353-
}
354-
error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, clone);
355-
ext4_journal_stop(handle);
356-
if (error == -ENOSPC &&
357-
ext4_should_retry_alloc(inode->i_sb, &retries))
358-
goto retry;
340+
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
341+
if (error)
342+
return error;
343+
retry:
344+
handle = ext4_journal_start(inode,
345+
EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
346+
if (IS_ERR(handle)) {
347+
error = PTR_ERR(handle);
348+
ext4_std_error(inode->i_sb, error);
349+
goto out;
359350
}
351+
error = ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, acl);
352+
ext4_journal_stop(handle);
353+
if (error == -ENOSPC &&
354+
ext4_should_retry_alloc(inode->i_sb, &retries))
355+
goto retry;
360356
out:
361-
posix_acl_release(clone);
357+
posix_acl_release(acl);
362358
return error;
363359
}
364360

‎fs/generic_acl.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,18 @@ generic_acl_init(struct inode *inode, struct inode *dir)
170170
int
171171
generic_acl_chmod(struct inode *inode)
172172
{
173-
struct posix_acl *acl, *clone;
173+
struct posix_acl *acl;
174174
int error = 0;
175175

176176
if (S_ISLNK(inode->i_mode))
177177
return -EOPNOTSUPP;
178178
acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
179179
if (acl) {
180-
clone = posix_acl_clone(acl, GFP_KERNEL);
180+
error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
181+
if (error)
182+
return error;
183+
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
181184
posix_acl_release(acl);
182-
if (!clone)
183-
return -ENOMEM;
184-
error = posix_acl_chmod_masq(clone, inode->i_mode);
185-
if (!error)
186-
set_cached_acl(inode, ACL_TYPE_ACCESS, clone);
187-
posix_acl_release(clone);
188185
}
189186
return error;
190187
}

‎fs/gfs2/acl.c‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)
187187

188188
int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
189189
{
190-
struct posix_acl *acl, *clone;
190+
struct posix_acl *acl;
191191
char *data;
192192
unsigned int len;
193193
int error;
@@ -198,25 +198,19 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
198198
if (!acl)
199199
return gfs2_setattr_simple(ip, attr);
200200

201-
clone = posix_acl_clone(acl, GFP_NOFS);
201+
error = posix_acl_chmod(&acl, GFP_NOFS, attr->ia_mode);
202+
if (error)
203+
return error;
204+
205+
len = posix_acl_to_xattr(acl, NULL, 0);
206+
data = kmalloc(len, GFP_NOFS);
202207
error = -ENOMEM;
203-
if (!clone)
208+
if (data == NULL)
204209
goto out;
205-
posix_acl_release(acl);
206-
acl = clone;
207-
208-
error = posix_acl_chmod_masq(acl, attr->ia_mode);
209-
if (!error) {
210-
len = posix_acl_to_xattr(acl, NULL, 0);
211-
data = kmalloc(len, GFP_NOFS);
212-
error = -ENOMEM;
213-
if (data == NULL)
214-
goto out;
215-
posix_acl_to_xattr(acl, data, len);
216-
error = gfs2_xattr_acl_chmod(ip, attr, data);
217-
kfree(data);
218-
set_cached_acl(&ip->i_inode, ACL_TYPE_ACCESS, acl);
219-
}
210+
posix_acl_to_xattr(acl, data, len);
211+
error = gfs2_xattr_acl_chmod(ip, attr, data);
212+
kfree(data);
213+
set_cached_acl(&ip->i_inode, ACL_TYPE_ACCESS, acl);
220214

221215
out:
222216
posix_acl_release(acl);

‎fs/jffs2/acl.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,22 +332,19 @@ int jffs2_init_acl_post(struct inode *inode)
332332

333333
int jffs2_acl_chmod(struct inode *inode)
334334
{
335-
struct posix_acl *acl, *clone;
335+
struct posix_acl *acl;
336336
int rc;
337337

338338
if (S_ISLNK(inode->i_mode))
339339
return -EOPNOTSUPP;
340340
acl = jffs2_get_acl(inode, ACL_TYPE_ACCESS);
341341
if (IS_ERR(acl) || !acl)
342342
return PTR_ERR(acl);
343-
clone = posix_acl_clone(acl, GFP_KERNEL);
343+
rc = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
344+
if (rc)
345+
return rc;
346+
rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, acl);
344347
posix_acl_release(acl);
345-
if (!clone)
346-
return -ENOMEM;
347-
rc = posix_acl_chmod_masq(clone, inode->i_mode);
348-
if (!rc)
349-
rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, clone);
350-
posix_acl_release(clone);
351348
return rc;
352349
}
353350

‎fs/jfs/acl.c‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
177177

178178
int jfs_acl_chmod(struct inode *inode)
179179
{
180-
struct posix_acl *acl, *clone;
180+
struct posix_acl *acl;
181181
int rc;
182+
tid_t tid;
182183

183184
if (S_ISLNK(inode->i_mode))
184185
return -EOPNOTSUPP;
@@ -187,22 +188,18 @@ int jfs_acl_chmod(struct inode *inode)
187188
if (IS_ERR(acl) || !acl)
188189
return PTR_ERR(acl);
189190

190-
clone = posix_acl_clone(acl, GFP_KERNEL);
191-
posix_acl_release(acl);
192-
if (!clone)
193-
return -ENOMEM;
194-
195-
rc = posix_acl_chmod_masq(clone, inode->i_mode);
196-
if (!rc) {
197-
tid_t tid = txBegin(inode->i_sb, 0);
198-
mutex_lock(&JFS_IP(inode)->commit_mutex);
199-
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, clone);
200-
if (!rc)
201-
rc = txCommit(tid, 1, &inode, 0);
202-
txEnd(tid);
203-
mutex_unlock(&JFS_IP(inode)->commit_mutex);
204-
}
191+
rc = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
192+
if (rc)
193+
return rc;
205194

206-
posix_acl_release(clone);
195+
tid = txBegin(inode->i_sb, 0);
196+
mutex_lock(&JFS_IP(inode)->commit_mutex);
197+
rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
198+
if (!rc)
199+
rc = txCommit(tid, 1, &inode, 0);
200+
txEnd(tid);
201+
mutex_unlock(&JFS_IP(inode)->commit_mutex);
202+
203+
posix_acl_release(acl);
207204
return rc;
208205
}

‎fs/ocfs2/acl.c‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ int ocfs2_check_acl(struct inode *inode, int mask)
327327
int ocfs2_acl_chmod(struct inode *inode)
328328
{
329329
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
330-
struct posix_acl *acl, *clone;
330+
struct posix_acl *acl;
331331
int ret;
332332

333333
if (S_ISLNK(inode->i_mode))
@@ -339,15 +339,12 @@ int ocfs2_acl_chmod(struct inode *inode)
339339
acl = ocfs2_get_acl(inode, ACL_TYPE_ACCESS);
340340
if (IS_ERR(acl) || !acl)
341341
return PTR_ERR(acl);
342-
clone = posix_acl_clone(acl, GFP_KERNEL);
342+
ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
343+
if (ret)
344+
return ret;
345+
ret = ocfs2_set_acl(NULL, inode, NULL, ACL_TYPE_ACCESS,
346+
acl, NULL, NULL);
343347
posix_acl_release(acl);
344-
if (!clone)
345-
return -ENOMEM;
346-
ret = posix_acl_chmod_masq(clone, inode->i_mode);
347-
if (!ret)
348-
ret = ocfs2_set_acl(NULL, inode, NULL, ACL_TYPE_ACCESS,
349-
clone, NULL, NULL);
350-
posix_acl_release(clone);
351348
return ret;
352349
}
353350

0 commit comments

Comments
 (0)