Skip to content

Commit 2b5f52c

Browse files
author
Miklos Szeredi
committed
ocfs2: convert to fileattr
Use the fileattr API to let the VFS handle locking, permission checking and conversion. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Cc: Joel Becker <jlbec@evilplan.org>
1 parent 7c7c436 commit 2b5f52c

5 files changed

Lines changed: 27 additions & 48 deletions

File tree

fs/ocfs2/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,6 +2645,8 @@ const struct inode_operations ocfs2_file_iops = {
26452645
.fiemap = ocfs2_fiemap,
26462646
.get_acl = ocfs2_iop_get_acl,
26472647
.set_acl = ocfs2_iop_set_acl,
2648+
.fileattr_get = ocfs2_fileattr_get,
2649+
.fileattr_set = ocfs2_fileattr_set,
26482650
};
26492651

26502652
const struct inode_operations ocfs2_special_file_iops = {

fs/ocfs2/ioctl.c

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/mount.h>
1111
#include <linux/blkdev.h>
1212
#include <linux/compat.h>
13+
#include <linux/fileattr.h>
1314

1415
#include <cluster/masklog.h>
1516

@@ -61,8 +62,10 @@ static inline int o2info_coherent(struct ocfs2_info_request *req)
6162
return (!(req->ir_flags & OCFS2_INFO_FL_NON_COHERENT));
6263
}
6364

64-
static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
65+
int ocfs2_fileattr_get(struct dentry *dentry, struct fileattr *fa)
6566
{
67+
struct inode *inode = d_inode(dentry);
68+
unsigned int flags;
6669
int status;
6770

6871
status = ocfs2_inode_lock(inode, NULL, 0);
@@ -71,43 +74,46 @@ static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
7174
return status;
7275
}
7376
ocfs2_get_inode_flags(OCFS2_I(inode));
74-
*flags = OCFS2_I(inode)->ip_attr;
77+
flags = OCFS2_I(inode)->ip_attr;
7578
ocfs2_inode_unlock(inode, 0);
7679

80+
fileattr_fill_flags(fa, flags & OCFS2_FL_VISIBLE);
81+
7782
return status;
7883
}
7984

80-
static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
81-
unsigned mask)
85+
int ocfs2_fileattr_set(struct user_namespace *mnt_userns,
86+
struct dentry *dentry, struct fileattr *fa)
8287
{
88+
struct inode *inode = d_inode(dentry);
89+
unsigned int flags = fa->flags;
8390
struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
8491
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
8592
handle_t *handle = NULL;
8693
struct buffer_head *bh = NULL;
8794
unsigned oldflags;
8895
int status;
8996

90-
inode_lock(inode);
97+
if (fileattr_has_fsx(fa))
98+
return -EOPNOTSUPP;
9199

92100
status = ocfs2_inode_lock(inode, &bh, 1);
93101
if (status < 0) {
94102
mlog_errno(status);
95103
goto bail;
96104
}
97105

98-
status = -EACCES;
99-
if (!inode_owner_or_capable(&init_user_ns, inode))
100-
goto bail_unlock;
101-
102106
if (!S_ISDIR(inode->i_mode))
103107
flags &= ~OCFS2_DIRSYNC_FL;
104108

105109
oldflags = ocfs2_inode->ip_attr;
106-
flags = flags & mask;
107-
flags |= oldflags & ~mask;
110+
flags = flags & OCFS2_FL_MODIFIABLE;
111+
flags |= oldflags & ~OCFS2_FL_MODIFIABLE;
108112

109-
status = vfs_ioc_setflags_prepare(inode, oldflags, flags);
110-
if (status)
113+
/* Check already done by VFS, but repeat with ocfs lock */
114+
status = -EPERM;
115+
if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL) &&
116+
!capable(CAP_LINUX_IMMUTABLE))
111117
goto bail_unlock;
112118

113119
handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
@@ -129,8 +135,6 @@ static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
129135
bail_unlock:
130136
ocfs2_inode_unlock(inode, 1);
131137
bail:
132-
inode_unlock(inode);
133-
134138
brelse(bh);
135139

136140
return status;
@@ -836,7 +840,6 @@ static int ocfs2_info_handle(struct inode *inode, struct ocfs2_info *info,
836840
long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
837841
{
838842
struct inode *inode = file_inode(filp);
839-
unsigned int flags;
840843
int new_clusters;
841844
int status;
842845
struct ocfs2_space_resv sr;
@@ -849,24 +852,6 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
849852
void __user *argp = (void __user *)arg;
850853

851854
switch (cmd) {
852-
case OCFS2_IOC_GETFLAGS:
853-
status = ocfs2_get_inode_attr(inode, &flags);
854-
if (status < 0)
855-
return status;
856-
857-
flags &= OCFS2_FL_VISIBLE;
858-
return put_user(flags, (int __user *) arg);
859-
case OCFS2_IOC_SETFLAGS:
860-
if (get_user(flags, (int __user *) arg))
861-
return -EFAULT;
862-
863-
status = mnt_want_write_file(filp);
864-
if (status)
865-
return status;
866-
status = ocfs2_set_inode_attr(inode, flags,
867-
OCFS2_FL_MODIFIABLE);
868-
mnt_drop_write_file(filp);
869-
return status;
870855
case OCFS2_IOC_RESVSP:
871856
case OCFS2_IOC_RESVSP64:
872857
case OCFS2_IOC_UNRESVSP:
@@ -959,12 +944,6 @@ long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
959944
void __user *argp = (void __user *)arg;
960945

961946
switch (cmd) {
962-
case OCFS2_IOC32_GETFLAGS:
963-
cmd = OCFS2_IOC_GETFLAGS;
964-
break;
965-
case OCFS2_IOC32_SETFLAGS:
966-
cmd = OCFS2_IOC_SETFLAGS;
967-
break;
968947
case OCFS2_IOC_RESVSP:
969948
case OCFS2_IOC_RESVSP64:
970949
case OCFS2_IOC_UNRESVSP:

fs/ocfs2/ioctl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#ifndef OCFS2_IOCTL_PROTO_H
1212
#define OCFS2_IOCTL_PROTO_H
1313

14+
int ocfs2_fileattr_get(struct dentry *dentry, struct fileattr *fa);
15+
int ocfs2_fileattr_set(struct user_namespace *mnt_userns,
16+
struct dentry *dentry, struct fileattr *fa);
1417
long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
1518
long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
1619

fs/ocfs2/namei.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "xattr.h"
5151
#include "acl.h"
5252
#include "ocfs2_trace.h"
53+
#include "ioctl.h"
5354

5455
#include "buffer_head_io.h"
5556

@@ -2918,4 +2919,6 @@ const struct inode_operations ocfs2_dir_iops = {
29182919
.fiemap = ocfs2_fiemap,
29192920
.get_acl = ocfs2_iop_get_acl,
29202921
.set_acl = ocfs2_iop_set_acl,
2922+
.fileattr_get = ocfs2_fileattr_get,
2923+
.fileattr_set = ocfs2_fileattr_set,
29212924
};

fs/ocfs2/ocfs2_ioctl.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
#ifndef OCFS2_IOCTL_H
1313
#define OCFS2_IOCTL_H
1414

15-
/*
16-
* ioctl commands
17-
*/
18-
#define OCFS2_IOC_GETFLAGS FS_IOC_GETFLAGS
19-
#define OCFS2_IOC_SETFLAGS FS_IOC_SETFLAGS
20-
#define OCFS2_IOC32_GETFLAGS FS_IOC32_GETFLAGS
21-
#define OCFS2_IOC32_SETFLAGS FS_IOC32_SETFLAGS
22-
2315
/*
2416
* Space reservation / allocation / free ioctls and argument structure
2517
* are designed to be compatible with XFS.

0 commit comments

Comments
 (0)