Skip to content

Commit 7c7c436

Browse files
author
Miklos Szeredi
committed
nilfs2: 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: Ryusuke Konishi <konishi.ryusuke@gmail.com>
1 parent 2ca58e3 commit 7c7c436

4 files changed

Lines changed: 25 additions & 43 deletions

File tree

fs/nilfs2/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ const struct inode_operations nilfs_file_inode_operations = {
148148
.setattr = nilfs_setattr,
149149
.permission = nilfs_permission,
150150
.fiemap = nilfs_fiemap,
151+
.fileattr_get = nilfs_fileattr_get,
152+
.fileattr_set = nilfs_fileattr_set,
151153
};
152154

153155
/* end of file */

fs/nilfs2/ioctl.c

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/compat.h> /* compat_ptr() */
1717
#include <linux/mount.h> /* mnt_want_write_file(), mnt_drop_write_file() */
1818
#include <linux/buffer_head.h>
19+
#include <linux/fileattr.h>
1920
#include "nilfs.h"
2021
#include "segment.h"
2122
#include "bmap.h"
@@ -113,63 +114,47 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
113114
}
114115

115116
/**
116-
* nilfs_ioctl_getflags - ioctl to support lsattr
117+
* nilfs_fileattr_get - ioctl to support lsattr
117118
*/
118-
static int nilfs_ioctl_getflags(struct inode *inode, void __user *argp)
119+
int nilfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
119120
{
120-
unsigned int flags = NILFS_I(inode)->i_flags & FS_FL_USER_VISIBLE;
121+
struct inode *inode = d_inode(dentry);
121122

122-
return put_user(flags, (int __user *)argp);
123+
fileattr_fill_flags(fa, NILFS_I(inode)->i_flags & FS_FL_USER_VISIBLE);
124+
125+
return 0;
123126
}
124127

125128
/**
126-
* nilfs_ioctl_setflags - ioctl to support chattr
129+
* nilfs_fileattr_set - ioctl to support chattr
127130
*/
128-
static int nilfs_ioctl_setflags(struct inode *inode, struct file *filp,
129-
void __user *argp)
131+
int nilfs_fileattr_set(struct user_namespace *mnt_userns,
132+
struct dentry *dentry, struct fileattr *fa)
130133
{
134+
struct inode *inode = d_inode(dentry);
131135
struct nilfs_transaction_info ti;
132136
unsigned int flags, oldflags;
133137
int ret;
134138

135-
if (!inode_owner_or_capable(&init_user_ns, inode))
136-
return -EACCES;
137-
138-
if (get_user(flags, (int __user *)argp))
139-
return -EFAULT;
140-
141-
ret = mnt_want_write_file(filp);
142-
if (ret)
143-
return ret;
144-
145-
flags = nilfs_mask_flags(inode->i_mode, flags);
146-
147-
inode_lock(inode);
148-
149-
oldflags = NILFS_I(inode)->i_flags;
139+
if (fileattr_has_fsx(fa))
140+
return -EOPNOTSUPP;
150141

151-
ret = vfs_ioc_setflags_prepare(inode, oldflags, flags);
152-
if (ret)
153-
goto out;
142+
flags = nilfs_mask_flags(inode->i_mode, fa->flags);
154143

155144
ret = nilfs_transaction_begin(inode->i_sb, &ti, 0);
156145
if (ret)
157-
goto out;
146+
return ret;
158147

159-
NILFS_I(inode)->i_flags = (oldflags & ~FS_FL_USER_MODIFIABLE) |
160-
(flags & FS_FL_USER_MODIFIABLE);
148+
oldflags = NILFS_I(inode)->i_flags & ~FS_FL_USER_MODIFIABLE;
149+
NILFS_I(inode)->i_flags = oldflags | (flags & FS_FL_USER_MODIFIABLE);
161150

162151
nilfs_set_inode_flags(inode);
163152
inode->i_ctime = current_time(inode);
164153
if (IS_SYNC(inode))
165154
nilfs_set_transaction_flag(NILFS_TI_SYNC);
166155

167156
nilfs_mark_inode_dirty(inode);
168-
ret = nilfs_transaction_commit(inode->i_sb);
169-
out:
170-
inode_unlock(inode);
171-
mnt_drop_write_file(filp);
172-
return ret;
157+
return nilfs_transaction_commit(inode->i_sb);
173158
}
174159

175160
/**
@@ -1282,10 +1267,6 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
12821267
void __user *argp = (void __user *)arg;
12831268

12841269
switch (cmd) {
1285-
case FS_IOC_GETFLAGS:
1286-
return nilfs_ioctl_getflags(inode, argp);
1287-
case FS_IOC_SETFLAGS:
1288-
return nilfs_ioctl_setflags(inode, filp, argp);
12891270
case FS_IOC_GETVERSION:
12901271
return nilfs_ioctl_getversion(inode, argp);
12911272
case NILFS_IOCTL_CHANGE_CPMODE:
@@ -1331,12 +1312,6 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
13311312
long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
13321313
{
13331314
switch (cmd) {
1334-
case FS_IOC32_GETFLAGS:
1335-
cmd = FS_IOC_GETFLAGS;
1336-
break;
1337-
case FS_IOC32_SETFLAGS:
1338-
cmd = FS_IOC_SETFLAGS;
1339-
break;
13401315
case FS_IOC32_GETVERSION:
13411316
cmd = FS_IOC_GETVERSION;
13421317
break;

fs/nilfs2/namei.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ const struct inode_operations nilfs_dir_inode_operations = {
552552
.setattr = nilfs_setattr,
553553
.permission = nilfs_permission,
554554
.fiemap = nilfs_fiemap,
555+
.fileattr_get = nilfs_fileattr_get,
556+
.fileattr_set = nilfs_fileattr_set,
555557
};
556558

557559
const struct inode_operations nilfs_special_inode_operations = {

fs/nilfs2/nilfs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ extern void nilfs_set_link(struct inode *, struct nilfs_dir_entry *,
243243
extern int nilfs_sync_file(struct file *, loff_t, loff_t, int);
244244

245245
/* ioctl.c */
246+
int nilfs_fileattr_get(struct dentry *dentry, struct fileattr *m);
247+
int nilfs_fileattr_set(struct user_namespace *mnt_userns,
248+
struct dentry *dentry, struct fileattr *fa);
246249
long nilfs_ioctl(struct file *, unsigned int, unsigned long);
247250
long nilfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
248251
int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *, struct nilfs_argv *,

0 commit comments

Comments
 (0)