Whamcloud - gitweb
LU-359 llite: no close error if application has known failure
authorFan Yong <yong.fan@whamcloud.com>
Wed, 1 Aug 2012 13:02:36 +0000 (21:02 +0800)
committerJohann Lombardi <johann@whamcloud.com>
Tue, 21 Aug 2012 12:37:00 +0000 (08:37 -0400)
Don't return error again when close if the application has known
former write failure to avoid potenical rdundant error handling,
like confused error message.

Signed-off-by: Fan Yong <yong.fan@whamcloud.com>
Change-Id: I62d9cd83fc03fad22c994f2a77774ca113a6c057
Reviewed-on: http://review.whamcloud.com/596
Reviewed-by: Niu Yawei <niu@whamcloud.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@whamcloud.com>
Reviewed-by: Johann Lombardi <johann@whamcloud.com>
lustre/llite/file.c
lustre/llite/llite_internal.h

index e13b1a0..750de2b 100644 (file)
 /* also used by llite/special.c:ll_special_open() */
 struct ll_file_data *ll_file_data_get(void)
 {
-        struct ll_file_data *fd;
+       struct ll_file_data *fd;
 
-        OBD_SLAB_ALLOC_PTR(fd, ll_file_data_slab);
-        return fd;
+       OBD_SLAB_ALLOC_PTR(fd, ll_file_data_slab);
+       fd->fd_write_failed = false;
+       return fd;
 }
 
 static void ll_file_data_put(struct ll_file_data *fd)
@@ -1778,7 +1779,7 @@ static ssize_t ll_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
         unsigned long nrsegs_copy, nrsegs_orig = 0;
         size_t count, iov_offset = 0;
         int got_write_sem = 0;
-        struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
+       struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
         ENTRY;
 
         count = ll_file_get_iov_count(iov, &nr_segs);
@@ -1979,6 +1980,10 @@ out:
         retval = (sum > 0) ? sum : retval;
         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_WRITE_BYTES,
                            retval > 0 ? retval : 0);
+       if (retval < 0)
+               fd->fd_write_failed = true;
+       else
+               fd->fd_write_failed = false;
         RETURN(retval);
 }
 
@@ -3083,22 +3088,27 @@ int ll_flush(struct file *file, fl_owner_t id)
 int ll_flush(struct file *file)
 #endif
 {
-        struct inode *inode = file->f_dentry->d_inode;
-        struct ll_inode_info *lli = ll_i2info(inode);
-        struct lov_stripe_md *lsm = lli->lli_smd;
-        int rc, err;
-
-        /* catch async errors that were recorded back when async writeback
-         * failed for pages in this mapping. */
-        rc = lli->lli_async_rc;
-        lli->lli_async_rc = 0;
-        if (lsm) {
-                err = lov_test_and_clear_async_rc(lsm);
-                if (rc == 0)
-                        rc = err;
-        }
-
-        return rc ? -EIO : 0;
+       struct inode *inode = file->f_dentry->d_inode;
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct lov_stripe_md *lsm = lli->lli_smd;
+       struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
+       int rc, err;
+
+       /* catch async errors that were recorded back when async writeback
+        * failed for pages in this mapping. */
+       rc = lli->lli_async_rc;
+       lli->lli_async_rc = 0;
+       if (lsm) {
+               err = lov_test_and_clear_async_rc(lsm);
+               if (rc == 0)
+                       rc = err;
+       }
+
+       /* The application has been told write failure already.
+        * Do not report failure again. */
+       if (fd->fd_write_failed)
+               return 0;
+       return rc ? -EIO : 0;
 }
 
 int ll_fsync(struct file *file, struct dentry *dentry, int data)
@@ -3139,6 +3149,7 @@ int ll_fsync(struct file *file, struct dentry *dentry, int data)
 
         if (data && lsm) {
                 struct obd_info *oinfo;
+               struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
 
                 OBD_ALLOC_PTR(oinfo);
                 if (!oinfo)
@@ -3161,6 +3172,10 @@ int ll_fsync(struct file *file, struct dentry *dentry, int data)
                         rc = err;
                 OBDO_FREE(oinfo->oi_oa);
                 OBD_FREE_PTR(oinfo);
+               if (rc < 0)
+                       fd->fd_write_failed = true;
+               else
+                       fd->fd_write_failed = false;
         }
 
         RETURN(rc);
index c1fd4b6..f8c552f 100644 (file)
@@ -585,6 +585,10 @@ struct ll_file_data {
         unsigned long fd_gid;
         struct ll_file_dir fd_dir;
         __u32 fd_flags;
+       /* Indicate whether need to report failure when close.
+        * true: failure is known, not report again.
+        * false: unknown failure, should report. */
+       bool fd_write_failed;
 };
 
 struct lov_stripe_md;