]> err.no Git - linux-2.6/commitdiff
[PATCH] Fix and add EXPORT_SYMBOL(filemap_write_and_wait)
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Sun, 8 Jan 2006 09:02:14 +0000 (01:02 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 9 Jan 2006 04:13:47 +0000 (20:13 -0800)
This patch add EXPORT_SYMBOL(filemap_write_and_wait) and use it.

See mm/filemap.c:

And changes the filemap_write_and_wait() and filemap_write_and_wait_range().

Current filemap_write_and_wait() doesn't wait if filemap_fdatawrite()
returns error.  However, even if filemap_fdatawrite() returned an
error, it may have submitted the partially data pages to the device.
(e.g. in the case of -ENOSPC)

<quotation>
Andrew Morton writes,

If filemap_fdatawrite() returns an error, this might be due to some
I/O problem: dead disk, unplugged cable, etc.  Given the generally
crappy quality of the kernel's handling of such exceptions, there's a
good chance that the filemap_fdatawait() will get stuck in D state
forever.
</quotation>

So, this patch doesn't wait if filemap_fdatawrite() returns the -EIO.

Trond, could you please review the nfs part?  Especially I'm not sure,
nfs must use the "filemap_fdatawrite(inode->i_mapping) == 0", or not.

Acked-by: Trond Myklebust <trond.myklebust@fys.uio.no>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
16 files changed:
fs/9p/vfs_dir.c
fs/9p/vfs_file.c
fs/buffer.c
fs/cifs/file.c
fs/cifs/inode.c
fs/jfs/jfs_dmap.c
fs/jfs/jfs_imap.c
fs/jfs/jfs_txnmgr.c
fs/jfs/jfs_umount.c
fs/jfs/resize.c
fs/jfs/super.c
fs/nfs/inode.c
fs/smbfs/file.c
fs/smbfs/inode.c
fs/xfs/linux-2.6/xfs_fs_subr.c
mm/filemap.c

index 57a43b8feef56e9f257434129edcb9b72a07016b..17089d1905ffdb4b38adb2f70ba94fd921e42aa1 100644 (file)
@@ -193,8 +193,7 @@ int v9fs_dir_release(struct inode *inode, struct file *filp)
                fid->fid);
        fidnum = fid->fid;
 
-       filemap_fdatawrite(inode->i_mapping);
-       filemap_fdatawait(inode->i_mapping);
+       filemap_write_and_wait(inode->i_mapping);
 
        if (fidnum >= 0) {
                dprintk(DEBUG_VFS, "fidopen: %d v9f->fid: %d\n", fid->fidopen,
index 89c849da85040edeb0794a93a2a0ad5ba5352387..e13577da913020616706d3a231a8c9ceac1b6bbf 100644 (file)
@@ -165,8 +165,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
                return -ENOLCK;
 
        if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
-               filemap_fdatawrite(inode->i_mapping);
-               filemap_fdatawait(inode->i_mapping);
+               filemap_write_and_wait(inode->i_mapping);
                invalidate_inode_pages(&inode->i_data);
        }
 
index 55023231e460c57470f46b200ae21b0d3700325f..263df0f192aa2bdcf458810669c370a48385213b 100644 (file)
@@ -153,14 +153,8 @@ int sync_blockdev(struct block_device *bdev)
 {
        int ret = 0;
 
-       if (bdev) {
-               int err;
-
-               ret = filemap_fdatawrite(bdev->bd_inode->i_mapping);
-               err = filemap_fdatawait(bdev->bd_inode->i_mapping);
-               if (!ret)
-                       ret = err;
-       }
+       if (bdev)
+               ret = filemap_write_and_wait(bdev->bd_inode->i_mapping);
        return ret;
 }
 EXPORT_SYMBOL(sync_blockdev);
index 14a1c72ced92e1cc98024494ea217b2a7413921d..5ade53d7bca89624cd6b9381d4e6ba91543517be 100644 (file)
@@ -127,8 +127,7 @@ static inline int cifs_open_inode_helper(struct inode *inode, struct file *file,
                if (file->f_dentry->d_inode->i_mapping) {
                /* BB no need to lock inode until after invalidate
                   since namei code should already have it locked? */
-                       filemap_fdatawrite(file->f_dentry->d_inode->i_mapping);
-                       filemap_fdatawait(file->f_dentry->d_inode->i_mapping);
+                       filemap_write_and_wait(file->f_dentry->d_inode->i_mapping);
                }
                cFYI(1, ("invalidating remote inode since open detected it "
                         "changed"));
@@ -419,8 +418,7 @@ static int cifs_reopen_file(struct inode *inode, struct file *file,
                pCifsInode = CIFS_I(inode);
                if (pCifsInode) {
                        if (can_flush) {
-                               filemap_fdatawrite(inode->i_mapping);
-                               filemap_fdatawait(inode->i_mapping);
+                               filemap_write_and_wait(inode->i_mapping);
                        /* temporarily disable caching while we
                           go to server to get inode info */
                                pCifsInode->clientCanCacheAll = FALSE;
index 411c1f7f84da6074efd483e27df1221db4647df1..9558f51bca55a1bd1c12a0140075013ea02628b5 100644 (file)
@@ -1148,8 +1148,7 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
        /* BB check if we need to refresh inode from server now ? BB */
 
        /* need to flush data before changing file size on server */
-       filemap_fdatawrite(direntry->d_inode->i_mapping);
-       filemap_fdatawait(direntry->d_inode->i_mapping);
+       filemap_write_and_wait(direntry->d_inode->i_mapping);
 
        if (attrs->ia_valid & ATTR_SIZE) {
                /* To avoid spurious oplock breaks from server, in the case of
index 68000a50ceb60610e796e184ba6384af47e1cb7e..2967b73934151f2291b2d0123dacb2f125239020 100644 (file)
@@ -302,8 +302,7 @@ int dbSync(struct inode *ipbmap)
        /*
         * write out dirty pages of bmap
         */
-       filemap_fdatawrite(ipbmap->i_mapping);
-       filemap_fdatawait(ipbmap->i_mapping);
+       filemap_write_and_wait(ipbmap->i_mapping);
 
        diWriteSpecial(ipbmap, 0);
 
index 28201b194f531ba10aa819abccb030bc7ea88cd0..31b4aa13dd4b988e9a6d8bb9ee071f56e5d524aa 100644 (file)
@@ -265,8 +265,7 @@ int diSync(struct inode *ipimap)
        /*
         * write out dirty pages of imap
         */
-       filemap_fdatawrite(ipimap->i_mapping);
-       filemap_fdatawait(ipimap->i_mapping);
+       filemap_write_and_wait(ipimap->i_mapping);
 
        diWriteSpecial(ipimap, 0);
 
@@ -565,8 +564,7 @@ void diFreeSpecial(struct inode *ip)
                jfs_err("diFreeSpecial called with NULL ip!");
                return;
        }
-       filemap_fdatawrite(ip->i_mapping);
-       filemap_fdatawait(ip->i_mapping);
+       filemap_write_and_wait(ip->i_mapping);
        truncate_inode_pages(ip->i_mapping, 0);
        iput(ip);
 }
index b660c93c92deaf112c7b7955743c41e6a39c929a..2ddb6b892bcf17b80d75b2fb20b8d573fafb30b0 100644 (file)
@@ -1231,10 +1231,8 @@ int txCommit(tid_t tid,          /* transaction identifier */
                 * when we don't need to worry about it at all.
                 *
                 * if ((!S_ISDIR(ip->i_mode))
-                *    && (tblk->flag & COMMIT_DELETE) == 0) {
-                *      filemap_fdatawrite(ip->i_mapping);
-                *      filemap_fdatawait(ip->i_mapping);
-                * }
+                *    && (tblk->flag & COMMIT_DELETE) == 0)
+                *      filemap_write_and_wait(ip->i_mapping);
                 */
 
                /*
index 5cf91785b5416be6016ab720871cd0b3bcc9477c..21eaf7ac0fcb6c46ebfc784bc9a9a24a32e18339 100644 (file)
@@ -108,8 +108,7 @@ int jfs_umount(struct super_block *sb)
         * Make sure all metadata makes it to disk before we mark
         * the superblock as clean
         */
-       filemap_fdatawrite(sbi->direct_inode->i_mapping);
-       filemap_fdatawait(sbi->direct_inode->i_mapping);
+       filemap_write_and_wait(sbi->direct_inode->i_mapping);
 
        /*
         * ensure all file system file pages are propagated to their
@@ -161,8 +160,7 @@ int jfs_umount_rw(struct super_block *sb)
         * mark the superblock clean before everything is flushed to
         * disk.
         */
-       filemap_fdatawrite(sbi->direct_inode->i_mapping);
-       filemap_fdatawait(sbi->direct_inode->i_mapping);
+       filemap_write_and_wait(sbi->direct_inode->i_mapping);
 
        updateSuper(sb, FM_CLEAN);
 
index c6dc254d325325ba247142e39d75abfb072b7a58..45180361871c9a98e04db73506a973e0c0dce0c1 100644 (file)
@@ -376,8 +376,7 @@ int jfs_extendfs(struct super_block *sb, s64 newLVSize, int newLogSize)
         * by txCommit();
         */
        filemap_fdatawait(ipbmap->i_mapping);
-       filemap_fdatawrite(ipbmap->i_mapping);
-       filemap_fdatawait(ipbmap->i_mapping);
+       filemap_write_and_wait(ipbmap->i_mapping);
        diWriteSpecial(ipbmap, 0);
 
        newPage = nPages;       /* first new page number */
index 4226af3ea91bc18dbdf414f63738101babca9cf8..8d31f1336431a916e7947f0381ec439d61705bbb 100644 (file)
@@ -502,8 +502,7 @@ out_no_rw:
                jfs_err("jfs_umount failed with return code %d", rc);
        }
 out_mount_failed:
-       filemap_fdatawrite(sbi->direct_inode->i_mapping);
-       filemap_fdatawait(sbi->direct_inode->i_mapping);
+       filemap_write_and_wait(sbi->direct_inode->i_mapping);
        truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
        make_bad_inode(sbi->direct_inode);
        iput(sbi->direct_inode);
index e7bd0d92600f6e34e65574bb464f03c45a17a033..3e4ba9cb7f806c7ee8681e97398f51001a288b69 100644 (file)
@@ -644,10 +644,7 @@ int nfs_sync_mapping(struct address_space *mapping)
        if (mapping->nrpages == 0)
                return 0;
        unmap_mapping_range(mapping, 0, 0, 0);
-       ret = filemap_fdatawrite(mapping);
-       if (ret != 0)
-               goto out;
-       ret = filemap_fdatawait(mapping);
+       ret = filemap_write_and_wait(mapping);
        if (ret != 0)
                goto out;
        ret = nfs_wb_all(mapping->host);
@@ -864,8 +861,7 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
        nfs_begin_data_update(inode);
        /* Write all dirty data if we're changing file permissions or size */
        if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE)) != 0) {
-               if (filemap_fdatawrite(inode->i_mapping) == 0)
-                       filemap_fdatawait(inode->i_mapping);
+               filemap_write_and_wait(inode->i_mapping);
                nfs_wb_all(inode);
        }
        /*
index b4fcfa8b55a149d3e16e995cab6cae0342fb3bf5..3c6eb3ba718e28b10c786fcbde4c95e811b364a2 100644 (file)
@@ -374,8 +374,7 @@ smb_file_release(struct inode *inode, struct file * file)
                /* We must flush any dirty pages now as we won't be able to
                   write anything after close. mmap can trigger this.
                   "openers" should perhaps include mmap'ers ... */
-               filemap_fdatawrite(inode->i_mapping);
-               filemap_fdatawait(inode->i_mapping);
+               filemap_write_and_wait(inode->i_mapping);
                smb_close(inode);
        }
        unlock_kernel();
index 10b994428fef29e6c43747ed2ae5345d264f8bbb..6ec88bf59b2def7aa402d060c0fd84dc770741a6 100644 (file)
@@ -697,8 +697,7 @@ smb_notify_change(struct dentry *dentry, struct iattr *attr)
                        DENTRY_PATH(dentry),
                        (long) inode->i_size, (long) attr->ia_size);
 
-               filemap_fdatawrite(inode->i_mapping);
-               filemap_fdatawait(inode->i_mapping);
+               filemap_write_and_wait(inode->i_mapping);
 
                error = smb_open(dentry, O_WRONLY);
                if (error)
index f89340c61bf289ddc1dd81ce9580e3b97a36ef41..4fa4b1a5187e095fbe9a3dfb9d324d9aad9c4d5b 100644 (file)
@@ -79,8 +79,7 @@ fs_flushinval_pages(
        struct inode    *ip = LINVFS_GET_IP(vp);
 
        if (VN_CACHED(vp)) {
-               filemap_fdatawrite(ip->i_mapping);
-               filemap_fdatawait(ip->i_mapping);
+               filemap_write_and_wait(ip->i_mapping);
 
                truncate_inode_pages(ip->i_mapping, first);
        }
index 8fdf36508023ff27598d57bb44962a9cde08a37a..478f4c74cc31e31b01855e0d5ac20ec6e088e5ce 100644 (file)
@@ -343,30 +343,44 @@ EXPORT_SYMBOL(filemap_fdatawait);
 
 int filemap_write_and_wait(struct address_space *mapping)
 {
-       int retval = 0;
+       int err = 0;
 
        if (mapping->nrpages) {
-               retval = filemap_fdatawrite(mapping);
-               if (retval == 0)
-                       retval = filemap_fdatawait(mapping);
+               err = filemap_fdatawrite(mapping);
+               /*
+                * Even if the above returned error, the pages may be
+                * written partially (e.g. -ENOSPC), so we wait for it.
+                * But the -EIO is special case, it may indicate the worst
+                * thing (e.g. bug) happened, so we avoid waiting for it.
+                */
+               if (err != -EIO) {
+                       int err2 = filemap_fdatawait(mapping);
+                       if (!err)
+                               err = err2;
+               }
        }
-       return retval;
+       return err;
 }
+EXPORT_SYMBOL(filemap_write_and_wait);
 
 int filemap_write_and_wait_range(struct address_space *mapping,
                                 loff_t lstart, loff_t lend)
 {
-       int retval = 0;
+       int err = 0;
 
        if (mapping->nrpages) {
-               retval = __filemap_fdatawrite_range(mapping, lstart, lend,
-                                                   WB_SYNC_ALL);
-               if (retval == 0)
-                       retval = wait_on_page_writeback_range(mapping,
-                                                   lstart >> PAGE_CACHE_SHIFT,
-                                                   lend >> PAGE_CACHE_SHIFT);
+               err = __filemap_fdatawrite_range(mapping, lstart, lend,
+                                                WB_SYNC_ALL);
+               /* See comment of filemap_write_and_wait() */
+               if (err != -EIO) {
+                       int err2 = wait_on_page_writeback_range(mapping,
+                                               lstart >> PAGE_CACHE_SHIFT,
+                                               lend >> PAGE_CACHE_SHIFT);
+                       if (!err)
+                               err = err2;
+               }
        }
-       return retval;
+       return err;
 }
 
 /*