Unionfs: implement sendfile directly
authorErez Zadok <ezk@cs.sunysb.edu>
Tue, 15 Apr 2008 20:20:58 +0000 (16:20 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Tue, 15 Apr 2008 20:20:58 +0000 (16:20 -0400)
Must implement sendfile, because we can no longer rely on
generic_file_sendfile: it needs the ->readpage address_space_operation
implemented, which we no longer have.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/file.c

index 6141efc6cccead018c7f0ff735445891b2c7acaf..df18f5536a93f2c1b6926b165764b8bc60977deb 100644 (file)
@@ -233,6 +233,41 @@ out:
        return err;
 }
 
+static ssize_t unionfs_sendfile(struct file *file, loff_t *ppos, size_t count,
+                               read_actor_t actor, void *target)
+{
+       ssize_t err;
+       struct file *lower_file;
+       struct dentry *dentry = file->f_path.dentry;
+
+       unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+       unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
+       err = unionfs_file_revalidate(file, false);
+       if (unlikely(err))
+               goto out;
+
+       lower_file = unionfs_lower_file(file);
+
+       if (!lower_file->f_op || !lower_file->f_op->sendfile) {
+               err = -EINVAL;
+               goto out;
+       }
+
+       err = lower_file->f_op->sendfile(lower_file, ppos, count,
+                                        actor, target);
+       /* update our inode atime upon a successful lower sendfile */
+       if (err >= 0) {
+               fsstack_copy_attr_atime(dentry->d_inode,
+                                       lower_file->f_path.dentry->d_inode);
+               unionfs_check_file(file);
+       }
+
+out:
+       unionfs_unlock_dentry(dentry);
+       unionfs_read_unlock(dentry->d_sb);
+       return err;
+}
+
 struct file_operations unionfs_main_fops = {
        .llseek         = generic_file_llseek,
        .read           = do_sync_read,
@@ -247,7 +282,7 @@ struct file_operations unionfs_main_fops = {
        .release        = unionfs_file_release,
        .fsync          = unionfs_fsync,
        .fasync         = unionfs_fasync,
-       .sendfile       = generic_file_sendfile,
+       .sendfile       = unionfs_sendfile,
        .splice_read    = unionfs_splice_read,
        .splice_write   = unionfs_splice_write,
 };