Skip to content

Commit 1f26b06

Browse files
author
Miklos Szeredi
committed
orangefs: 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: Mike Marshall <hubcap@omnibond.com>
1 parent 88b631c commit 1f26b06

2 files changed

Lines changed: 50 additions & 79 deletions

File tree

fs/orangefs/file.c

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -375,84 +375,6 @@ static ssize_t orangefs_file_write_iter(struct kiocb *iocb,
375375
return ret;
376376
}
377377

378-
static int orangefs_getflags(struct inode *inode, unsigned long *uval)
379-
{
380-
__u64 val = 0;
381-
int ret;
382-
383-
ret = orangefs_inode_getxattr(inode,
384-
"user.pvfs2.meta_hint",
385-
&val, sizeof(val));
386-
if (ret < 0 && ret != -ENODATA)
387-
return ret;
388-
else if (ret == -ENODATA)
389-
val = 0;
390-
*uval = val;
391-
return 0;
392-
}
393-
394-
/*
395-
* Perform a miscellaneous operation on a file.
396-
*/
397-
static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
398-
{
399-
struct inode *inode = file_inode(file);
400-
int ret = -ENOTTY;
401-
__u64 val = 0;
402-
unsigned long uval;
403-
404-
gossip_debug(GOSSIP_FILE_DEBUG,
405-
"orangefs_ioctl: called with cmd %d\n",
406-
cmd);
407-
408-
/*
409-
* we understand some general ioctls on files, such as the immutable
410-
* and append flags
411-
*/
412-
if (cmd == FS_IOC_GETFLAGS) {
413-
ret = orangefs_getflags(inode, &uval);
414-
if (ret)
415-
return ret;
416-
gossip_debug(GOSSIP_FILE_DEBUG,
417-
"orangefs_ioctl: FS_IOC_GETFLAGS: %llu\n",
418-
(unsigned long long)uval);
419-
return put_user(uval, (int __user *)arg);
420-
} else if (cmd == FS_IOC_SETFLAGS) {
421-
unsigned long old_uval;
422-
423-
ret = 0;
424-
if (get_user(uval, (int __user *)arg))
425-
return -EFAULT;
426-
/*
427-
* ORANGEFS_MIRROR_FL is set internally when the mirroring mode
428-
* is turned on for a file. The user is not allowed to turn
429-
* on this bit, but the bit is present if the user first gets
430-
* the flags and then updates the flags with some new
431-
* settings. So, we ignore it in the following edit. bligon.
432-
*/
433-
if ((uval & ~ORANGEFS_MIRROR_FL) &
434-
(~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL))) {
435-
gossip_err("orangefs_ioctl: the FS_IOC_SETFLAGS only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n");
436-
return -EINVAL;
437-
}
438-
ret = orangefs_getflags(inode, &old_uval);
439-
if (ret)
440-
return ret;
441-
ret = vfs_ioc_setflags_prepare(inode, old_uval, uval);
442-
if (ret)
443-
return ret;
444-
val = uval;
445-
gossip_debug(GOSSIP_FILE_DEBUG,
446-
"orangefs_ioctl: FS_IOC_SETFLAGS: %llu\n",
447-
(unsigned long long)val);
448-
ret = orangefs_inode_setxattr(inode,
449-
"user.pvfs2.meta_hint",
450-
&val, sizeof(val), 0);
451-
}
452-
453-
return ret;
454-
}
455-
456378
static vm_fault_t orangefs_fault(struct vm_fault *vmf)
457379
{
458380
struct file *file = vmf->vma->vm_file;
@@ -657,7 +579,6 @@ const struct file_operations orangefs_file_operations = {
657579
.read_iter = orangefs_file_read_iter,
658580
.write_iter = orangefs_file_write_iter,
659581
.lock = orangefs_lock,
660-
.unlocked_ioctl = orangefs_ioctl,
661582
.mmap = orangefs_file_mmap,
662583
.open = generic_file_open,
663584
.splice_read = generic_file_splice_read,

fs/orangefs/inode.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
#include <linux/bvec.h>
14+
#include <linux/fileattr.h>
1415
#include "protocol.h"
1516
#include "orangefs-kernel.h"
1617
#include "orangefs-bufmap.h"
@@ -954,6 +955,53 @@ int orangefs_update_time(struct inode *inode, struct timespec64 *time, int flags
954955
return __orangefs_setattr(inode, &iattr);
955956
}
956957

958+
static int orangefs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
959+
{
960+
u64 val = 0;
961+
int ret;
962+
963+
gossip_debug(GOSSIP_FILE_DEBUG, "%s: called on %pd\n", __func__,
964+
dentry);
965+
966+
ret = orangefs_inode_getxattr(d_inode(dentry),
967+
"user.pvfs2.meta_hint",
968+
&val, sizeof(val));
969+
if (ret < 0 && ret != -ENODATA)
970+
return ret;
971+
972+
gossip_debug(GOSSIP_FILE_DEBUG, "%s: flags=%u\n", __func__, (u32) val);
973+
974+
fileattr_fill_flags(fa, val);
975+
return 0;
976+
}
977+
978+
static int orangefs_fileattr_set(struct user_namespace *mnt_userns,
979+
struct dentry *dentry, struct fileattr *fa)
980+
{
981+
u64 val = 0;
982+
983+
gossip_debug(GOSSIP_FILE_DEBUG, "%s: called on %pd\n", __func__,
984+
dentry);
985+
/*
986+
* ORANGEFS_MIRROR_FL is set internally when the mirroring mode is
987+
* turned on for a file. The user is not allowed to turn on this bit,
988+
* but the bit is present if the user first gets the flags and then
989+
* updates the flags with some new settings. So, we ignore it in the
990+
* following edit. bligon.
991+
*/
992+
if (fileattr_has_fsx(fa) ||
993+
(fa->flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL | ORANGEFS_MIRROR_FL))) {
994+
gossip_err("%s: only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n",
995+
__func__);
996+
return -EOPNOTSUPP;
997+
}
998+
val = fa->flags;
999+
gossip_debug(GOSSIP_FILE_DEBUG, "%s: flags=%u\n", __func__, (u32) val);
1000+
return orangefs_inode_setxattr(d_inode(dentry),
1001+
"user.pvfs2.meta_hint",
1002+
&val, sizeof(val), 0);
1003+
}
1004+
9571005
/* ORANGEFS2 implementation of VFS inode operations for files */
9581006
static const struct inode_operations orangefs_file_inode_operations = {
9591007
.get_acl = orangefs_get_acl,
@@ -963,6 +1011,8 @@ static const struct inode_operations orangefs_file_inode_operations = {
9631011
.listxattr = orangefs_listxattr,
9641012
.permission = orangefs_permission,
9651013
.update_time = orangefs_update_time,
1014+
.fileattr_get = orangefs_fileattr_get,
1015+
.fileattr_set = orangefs_fileattr_set,
9661016
};
9671017

9681018
static int orangefs_init_iops(struct inode *inode)

0 commit comments

Comments
 (0)