Skip to content

Commit 61536be

Browse files
amir73ilMiklos Szeredi
authored andcommitted
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: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 8f6ee74 commit 61536be

3 files changed

Lines changed: 51 additions & 12 deletions

File tree

fs/overlayfs/file.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
136136

137137
static int ovl_real_fdget(const struct file *file, struct fd *real)
138138
{
139+
if (d_is_dir(file_dentry(file))) {
140+
real->flags = 0;
141+
real->file = ovl_dir_real_file(file, false);
142+
143+
return PTR_ERR_OR_ZERO(real->file);
144+
}
145+
139146
return ovl_real_fdget_meta(file, real, false);
140147
}
141148

@@ -648,7 +655,7 @@ static long ovl_ioctl_set_fsxflags(struct file *file, unsigned int cmd,
648655
ovl_fsxflags_to_iflags(fa.fsx_xflags));
649656
}
650657

651-
static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
658+
long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
652659
{
653660
long ret;
654661

@@ -673,8 +680,8 @@ static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
673680
return ret;
674681
}
675682

676-
static long ovl_compat_ioctl(struct file *file, unsigned int cmd,
677-
unsigned long arg)
683+
#ifdef CONFIG_COMPAT
684+
long ovl_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
678685
{
679686
switch (cmd) {
680687
case FS_IOC32_GETFLAGS:
@@ -691,6 +698,7 @@ static long ovl_compat_ioctl(struct file *file, unsigned int cmd,
691698

692699
return ovl_ioctl(file, cmd, arg);
693700
}
701+
#endif
694702

695703
enum ovl_copyop {
696704
OVL_COPY,
@@ -792,7 +800,9 @@ const struct file_operations ovl_file_operations = {
792800
.fallocate = ovl_fallocate,
793801
.fadvise = ovl_fadvise,
794802
.unlocked_ioctl = ovl_ioctl,
803+
#ifdef CONFIG_COMPAT
795804
.compat_ioctl = ovl_compat_ioctl,
805+
#endif
796806
.splice_read = ovl_splice_read,
797807
.splice_write = ovl_splice_write,
798808

fs/overlayfs/overlayfs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ static inline int ovl_verify_upper(struct ovl_fs *ofs, struct dentry *index,
416416

417417
/* readdir.c */
418418
extern const struct file_operations ovl_dir_operations;
419+
struct file *ovl_dir_real_file(const struct file *file, bool want_upper);
419420
int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list);
420421
void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list);
421422
void ovl_cache_free(struct list_head *list);
@@ -503,6 +504,8 @@ struct dentry *ovl_create_temp(struct dentry *workdir, struct ovl_cattr *attr);
503504
extern const struct file_operations ovl_file_operations;
504505
int __init ovl_aio_request_cache_init(void);
505506
void ovl_aio_request_cache_destroy(void);
507+
long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
508+
long ovl_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
506509

507510
/* copy_up.c */
508511
int ovl_copy_up(struct dentry *dentry);

fs/overlayfs/readdir.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static loff_t ovl_dir_llseek(struct file *file, loff_t offset, int origin)
840840
return res;
841841
}
842842

843-
static struct file *ovl_dir_open_realfile(struct file *file,
843+
static struct file *ovl_dir_open_realfile(const struct file *file,
844844
struct path *realpath)
845845
{
846846
struct file *res;
@@ -853,19 +853,22 @@ static struct file *ovl_dir_open_realfile(struct file *file,
853853
return res;
854854
}
855855

856-
static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
857-
int datasync)
856+
/*
857+
* Like ovl_real_fdget(), returns upperfile if dir was copied up since open.
858+
* Unlike ovl_real_fdget(), this caches upperfile in file->private_data.
859+
*
860+
* TODO: use same abstract type for file->private_data of dir and file so
861+
* upperfile could also be cached for files as well.
862+
*/
863+
struct file *ovl_dir_real_file(const struct file *file, bool want_upper)
858864
{
865+
859866
struct ovl_dir_file *od = file->private_data;
860867
struct dentry *dentry = file->f_path.dentry;
861868
struct file *realfile = od->realfile;
862869

863-
/* Nothing to sync for lower */
864870
if (!OVL_TYPE_UPPER(ovl_path_type(dentry)))
865-
return 0;
866-
867-
if (!ovl_should_sync(OVL_FS(dentry->d_sb)))
868-
return 0;
871+
return want_upper ? NULL : realfile;
869872

870873
/*
871874
* 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,
884887
if (!od->upperfile) {
885888
if (IS_ERR(realfile)) {
886889
inode_unlock(inode);
887-
return PTR_ERR(realfile);
890+
return realfile;
888891
}
889892
smp_store_release(&od->upperfile, realfile);
890893
} else {
@@ -897,6 +900,25 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
897900
}
898901
}
899902

903+
return realfile;
904+
}
905+
906+
static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
907+
int datasync)
908+
{
909+
struct file *realfile;
910+
int err;
911+
912+
if (!ovl_should_sync(OVL_FS(file->f_path.dentry->d_sb)))
913+
return 0;
914+
915+
realfile = ovl_dir_real_file(file, true);
916+
err = PTR_ERR_OR_ZERO(realfile);
917+
918+
/* Nothing to sync for lower */
919+
if (!realfile || err)
920+
return err;
921+
900922
return vfs_fsync_range(realfile, start, end, datasync);
901923
}
902924

@@ -949,6 +971,10 @@ const struct file_operations ovl_dir_operations = {
949971
.llseek = ovl_dir_llseek,
950972
.fsync = ovl_dir_fsync,
951973
.release = ovl_dir_release,
974+
.unlocked_ioctl = ovl_ioctl,
975+
#ifdef CONFIG_COMPAT
976+
.compat_ioctl = ovl_compat_ioctl,
977+
#endif
952978
};
953979

954980
int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)

0 commit comments

Comments
 (0)