Wrapfs: fix ->llseek to update upper and lower offsets
authorErez Zadok <ezk@cs.sunysb.edu>
Thu, 26 Jun 2014 03:36:32 +0000 (23:36 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Thu, 26 Jun 2014 03:36:32 +0000 (23:36 -0400)
Fixes bug: xfstests generic/257. f_pos consistently is required by and
only by dir_ops->wrapfs_readdir, main_ops is not affected.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Mengyang Li <li.mengyang@stonybrook.edu>
fs/wrapfs/file.c

index 842ac9e34c76752c8b36898df0fb57d5d20b0d64..06dcfb209b7c6311bf98987d892e3e87487f967c 100644 (file)
@@ -303,6 +303,28 @@ out:
        return err;
 }
 
+/*
+ * Wrapfs cannot use generic_file_llseek as ->llseek, because it would
+ * only set the offset of the upper file.  So we have to implement our
+ * own method to set both the upper and lower file offsets
+ * consistently.
+ */
+static loff_t wrapfs_file_llseek(struct file *file, loff_t offset, int whence)
+{
+       int err;
+       struct file *lower_file;
+
+       err = generic_file_llseek(file, offset, whence);
+       if (err < 0)
+               goto out;
+
+       lower_file = wrapfs_lower_file(file);
+       err = generic_file_llseek(lower_file, offset, whence);
+
+out:
+       return err;
+}
+
 const struct file_operations wrapfs_main_fops = {
        .llseek         = generic_file_llseek,
        .read           = wrapfs_read,
@@ -323,7 +345,7 @@ const struct file_operations wrapfs_main_fops = {
 
 /* trimmed directory options */
 const struct file_operations wrapfs_dir_fops = {
-       .llseek         = generic_file_llseek,
+       .llseek         = wrapfs_file_llseek,
        .read           = generic_read_dir,
        .readdir        = wrapfs_readdir,
        .unlocked_ioctl = wrapfs_unlocked_ioctl,