Commit 61536bed authored by Amir Goldstein's avatar Amir Goldstein Committed by Miklos Szeredi

ovl: support [S|G]ETFLAGS and FS[S|G]ETXATTR ioctls for directories

[S|G]ETFLAGS and FS[S|G]ETXATTR ioctls are applicable to both files and
directories, so add ioctl operations to dir as well.

We teach ovl_real_fdget() to get the realfile of directories which use
a different type of file->private_data.

Ifdef away compat ioctl implementation to conform to standard practice.

With this change, xfstest generic/079 which tests these ioctls on files
and directories passes.
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarXiao Yang <yangx.jy@cn.fujitsu.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 8f6ee74c
...@@ -136,6 +136,13 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real, ...@@ -136,6 +136,13 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
static int ovl_real_fdget(const struct file *file, struct fd *real) static int ovl_real_fdget(const struct file *file, struct fd *real)
{ {
if (d_is_dir(file_dentry(file))) {
real->flags = 0;
real->file = ovl_dir_real_file(file, false);
return PTR_ERR_OR_ZERO(real->file);
}
return ovl_real_fdget_meta(file, real, false); return ovl_real_fdget_meta(file, real, false);
} }
...@@ -648,7 +655,7 @@ static long ovl_ioctl_set_fsxflags(struct file *file, unsigned int cmd, ...@@ -648,7 +655,7 @@ static long ovl_ioctl_set_fsxflags(struct file *file, unsigned int cmd,
ovl_fsxflags_to_iflags(fa.fsx_xflags)); ovl_fsxflags_to_iflags(fa.fsx_xflags));
} }
static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
long ret; long ret;
...@@ -673,8 +680,8 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -673,8 +680,8 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
return ret; return ret;
} }
static long ovl_compat_ioctl(struct file *file, unsigned int cmd, #ifdef CONFIG_COMPAT
unsigned long arg) long ovl_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
switch (cmd) { switch (cmd) {
case FS_IOC32_GETFLAGS: case FS_IOC32_GETFLAGS:
...@@ -691,6 +698,7 @@ static long ovl_compat_ioctl(struct file *file, unsigned int cmd, ...@@ -691,6 +698,7 @@ static long ovl_compat_ioctl(struct file *file, unsigned int cmd,
return ovl_ioctl(file, cmd, arg); return ovl_ioctl(file, cmd, arg);
} }
#endif
enum ovl_copyop { enum ovl_copyop {
OVL_COPY, OVL_COPY,
...@@ -792,7 +800,9 @@ const struct file_operations ovl_file_operations = { ...@@ -792,7 +800,9 @@ const struct file_operations ovl_file_operations = {
.fallocate = ovl_fallocate, .fallocate = ovl_fallocate,
.fadvise = ovl_fadvise, .fadvise = ovl_fadvise,
.unlocked_ioctl = ovl_ioctl, .unlocked_ioctl = ovl_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = ovl_compat_ioctl, .compat_ioctl = ovl_compat_ioctl,
#endif
.splice_read = ovl_splice_read, .splice_read = ovl_splice_read,
.splice_write = ovl_splice_write, .splice_write = ovl_splice_write,
......
...@@ -416,6 +416,7 @@ static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index, ...@@ -416,6 +416,7 @@ static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index,
/* readdir.c */ /* readdir.c */
extern const struct file_operations ovl_dir_operations; extern const struct file_operations ovl_dir_operations;
struct file *ovl_dir_real_file(const struct file *file, bool want_upper);
int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list); int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list); void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list);
void ovl_cache_free(struct list_head *list); void ovl_cache_free(struct list_head *list);
...@@ -503,6 +504,8 @@ struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr); ...@@ -503,6 +504,8 @@ struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr);
extern const struct file_operations ovl_file_operations; extern const struct file_operations ovl_file_operations;
int __init ovl_aio_request_cache_init(void); int __init ovl_aio_request_cache_init(void);
void ovl_aio_request_cache_destroy(void); void ovl_aio_request_cache_destroy(void);
long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
long ovl_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
/* copy_up.c */ /* copy_up.c */
int ovl_copy_up(struct dentry *dentry); int ovl_copy_up(struct dentry *dentry);
......
...@@ -840,7 +840,7 @@ static loff_t ovl_dir_llseek(struct file *file, loff_t offset, int origin) ...@@ -840,7 +840,7 @@ static loff_t ovl_dir_llseek(struct file *file, loff_t offset, int origin)
return res; return res;
} }
static struct file *ovl_dir_open_realfile(struct file *file, static struct file *ovl_dir_open_realfile(const struct file *file,
struct path *realpath) struct path *realpath)
{ {
struct file *res; struct file *res;
...@@ -853,19 +853,22 @@ static struct file *ovl_dir_open_realfile(struct file *file, ...@@ -853,19 +853,22 @@ static struct file *ovl_dir_open_realfile(struct file *file,
return res; return res;
} }
static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end, /*
int datasync) * Like ovl_real_fdget(), returns upperfile if dir was copied up since open.
* Unlike ovl_real_fdget(), this caches upperfile in file->private_data.
*
* TODO: use same abstract type for file->private_data of dir and file so
* upperfile could also be cached for files as well.
*/
struct file *ovl_dir_real_file(const struct file *file, bool want_upper)
{ {
struct ovl_dir_file *od = file->private_data; struct ovl_dir_file *od = file->private_data;
struct dentry *dentry = file->f_path.dentry; struct dentry *dentry = file->f_path.dentry;
struct file *realfile = od->realfile; struct file *realfile = od->realfile;
/* Nothing to sync for lower */
if (!OVL_TYPE_UPPER(ovl_path_type(dentry))) if (!OVL_TYPE_UPPER(ovl_path_type(dentry)))
return 0; return want_upper ? NULL : realfile;
if (!ovl_should_sync(OVL_FS(dentry->d_sb)))
return 0;
/* /*
* Need to check if we started out being a lower dir, but got copied up * Need to check if we started out being a lower dir, but got copied up
...@@ -884,7 +887,7 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end, ...@@ -884,7 +887,7 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
if (!od->upperfile) { if (!od->upperfile) {
if (IS_ERR(realfile)) { if (IS_ERR(realfile)) {
inode_unlock(inode); inode_unlock(inode);
return PTR_ERR(realfile); return realfile;
} }
smp_store_release(&od->upperfile, realfile); smp_store_release(&od->upperfile, realfile);
} else { } else {
...@@ -897,6 +900,25 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end, ...@@ -897,6 +900,25 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
} }
} }
return realfile;
}
static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
int datasync)
{
struct file *realfile;
int err;
if (!ovl_should_sync(OVL_FS(file->f_path.dentry->d_sb)))
return 0;
realfile = ovl_dir_real_file(file, true);
err = PTR_ERR_OR_ZERO(realfile);
/* Nothing to sync for lower */
if (!realfile || err)
return err;
return vfs_fsync_range(realfile, start, end, datasync); return vfs_fsync_range(realfile, start, end, datasync);
} }
...@@ -949,6 +971,10 @@ const struct file_operations ovl_dir_operations = { ...@@ -949,6 +971,10 @@ const struct file_operations ovl_dir_operations = {
.llseek = ovl_dir_llseek, .llseek = ovl_dir_llseek,
.fsync = ovl_dir_fsync, .fsync = ovl_dir_fsync,
.release = ovl_dir_release, .release = ovl_dir_release,
.unlocked_ioctl = ovl_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = ovl_compat_ioctl,
#endif
}; };
int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list) int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment