Unionfs: copyup only if file is being written to
authorErez Zadok <ezk@cs.sunysb.edu>
Wed, 16 Apr 2008 00:22:15 +0000 (20:22 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Wed, 16 Apr 2008 00:22:15 +0000 (20:22 -0400)
Before, we used to copyup on an open(2) call which used flags implying
writing (O_RDWR, O_WRONLY, O_APPEND).  This meant that a file being opened
for writing, then immediately closed (without actually writing to the file),
will still have been copied up.  Now, we don't copyup such files in ->open,
but defer the copyup till later. [Bug #591].

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

index e46ae76acdbe7900319007842f99b1c0f64e08a1..1e8101bb66681aab46a54146f9c34b35ba15ca27 100644 (file)
@@ -635,7 +635,7 @@ int unionfs_file_release(struct inode *inode, struct file *file)
         * This is important for open-but-unlinked files, as well as mmap
         * support.
         */
-       err = unionfs_file_revalidate(file, true);
+       err = unionfs_file_revalidate(file, UNIONFS_F(file)->wrote_to_file);
        if (unlikely(err))
                goto out;
        unionfs_check_file(file);
@@ -817,7 +817,7 @@ int unionfs_flush(struct file *file)
        unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
        unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
 
-       err = unionfs_file_revalidate(file, true);
+       err = unionfs_file_revalidate(file, UNIONFS_F(file)->wrote_to_file);
        if (unlikely(err))
                goto out;
        unionfs_check_file(file);
index 985b759167622a451f517ad65e8a68f70d4a97b3..e0869ea7e6ef33f3d75cd85fb632b62494f086f4 100644 (file)
@@ -67,6 +67,7 @@ static ssize_t unionfs_write(struct file *file, const char __user *buf,
                                        lower_file->f_dentry->d_inode);
                fsstack_copy_attr_times(dentry->d_inode,
                                        lower_file->f_dentry->d_inode);
+               UNIONFS_F(file)->wrote_to_file = true; /* for delayed copyup */
                unionfs_check_file(file);
        }
 
index 38c8d59124b1eda562a0b76bfb4b3ec1567cb814..95659fac6b95547a7b8d8863eb776e285405bc68 100644 (file)
@@ -101,6 +101,7 @@ struct unionfs_file_info {
        struct file **lower_files;
        int *saved_branch_ids; /* IDs of branches when file was opened */
        struct vm_operations_struct *lower_vm_ops;
+       bool wrote_to_file;     /* for delayed copyup */
 };
 
 /* unionfs inode data in memory */