Whamcloud - gitweb
LU-683: handle short write in cl_io_commit_write
authorJinshan Xiong <jay@whamcloud.com>
Thu, 15 Sep 2011 05:49:21 +0000 (22:49 -0700)
committerOleg Drokin <green@whamcloud.com>
Fri, 16 Sep 2011 16:21:29 +0000 (12:21 -0400)
CLIO has to handle short write case where no bytes were
actually copied from user space. In this case, we should
avoid adding that page into cache.

Change-Id: I78c870e741d7bdb2a9c4c0bfba1adc50a6e814e7
Signed-off-by: Jinshan Xiong <jay@whamcloud.com>
Reviewed-on: http://review.whamcloud.com/1383
Tested-by: Hudson
Tested-by: Yu Jian <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@whamcloud.com>
lustre/llite/rw.c
lustre/llite/rw26.c

index 25f45fb..d5e012e 100644 (file)
@@ -294,7 +294,7 @@ int ll_commit_write(struct file *file, struct page *vmpage, unsigned from,
         struct lu_env    *env;
         struct cl_io     *io;
         struct cl_page   *page;
-        int result;
+        int result = 0;
         ENTRY;
 
         lcc  = ll_cl_get();
@@ -303,11 +303,14 @@ int ll_commit_write(struct file *file, struct page *vmpage, unsigned from,
         io   = lcc->lcc_io;
 
         LASSERT(cl_page_is_owned(page, io));
-        result = cl_io_commit_write(env, io, page, from, to);
+        LASSERT(from <= to);
+        if (from != to) /* handle short write case. */
+                result = cl_io_commit_write(env, io, page, from, to);
         if (cl_page_is_owned(page, io))
                 cl_page_unassume(env, io, page);
+
         /*
-         * Release reference acquired by cl_io_prepare_write().
+         * Release reference acquired by ll_prepare_write().
          */
         lu_ref_del(&page->cp_reference, "prepare_write", cfs_current());
         cl_page_put(env, page);
index b931dfa..15df5fc 100644 (file)
@@ -506,11 +506,12 @@ static int ll_write_end(struct file *file, struct address_space *mapping,
 {
         unsigned from = pos & (PAGE_CACHE_SIZE - 1);
         int rc;
-        rc = ll_commit_write(file, page, from, from + copied);
 
+        rc = ll_commit_write(file, page, from, from + copied);
         unlock_page(page);
         page_cache_release(page);
-        return rc?rc:copied;
+
+        return rc ?: copied;
 }
 #endif