Whamcloud - gitweb
LU-359 llite: no close error if application has known failure
[fs/lustre-release.git] / lustre / llite / rw.c
index db4d451..310cf45 100644 (file)
@@ -43,7 +43,6 @@
 #include <linux/string.h>
 #include <linux/stat.h>
 #include <linux/errno.h>
-#include <linux/smp_lock.h>
 #include <linux/unistd.h>
 #include <linux/version.h>
 #include <asm/system.h>
@@ -54,7 +53,6 @@
 #include <asm/uaccess.h>
 #include <linux/mm.h>
 #include <linux/pagemap.h>
-#include <linux/smp_lock.h>
 /* current_is_kswapd() */
 #include <linux/swap.h>
 
@@ -144,8 +142,8 @@ static struct ll_cl_context *ll_cl_init(struct file *file,
                struct inode *inode = vmpage->mapping->host;
                loff_t pos;
 
-               if (TRYLOCK_INODE_MUTEX(inode)) {
-                       UNLOCK_INODE_MUTEX(inode);
+               if (mutex_trylock(&inode->i_mutex)) {
+                       mutex_unlock(&(inode)->i_mutex);
 
                        /* this is too bad. Someone is trying to write the
                         * page w/o holding inode mutex. This means we can
@@ -1161,31 +1159,33 @@ out_unlock:
 
 int ll_writepage(struct page *vmpage, struct writeback_control *wbc)
 {
-        struct inode           *inode = vmpage->mapping->host;
+       struct inode           *inode = vmpage->mapping->host;
+       struct ll_inode_info   *lli   = ll_i2info(inode);
         struct lu_env          *env;
         struct cl_io           *io;
         struct cl_page         *page;
         struct cl_object       *clob;
         struct cl_env_nest      nest;
-       int redirtied = 0;
+       bool redirtied = false;
+       bool unlocked = false;
         int result;
         ENTRY;
 
         LASSERT(PageLocked(vmpage));
         LASSERT(!PageWriteback(vmpage));
 
-        if (ll_i2dtexp(inode) == NULL)
-                RETURN(-EINVAL);
+       LASSERT(ll_i2dtexp(inode) != NULL);
 
-        env = cl_env_nested_get(&nest);
-        if (IS_ERR(env))
-                RETURN(PTR_ERR(env));
+       env = cl_env_nested_get(&nest);
+       if (IS_ERR(env))
+               GOTO(out, result = PTR_ERR(env));
 
         clob  = ll_i2info(inode)->lli_clob;
         LASSERT(clob != NULL);
 
         io = ccc_env_thread_io(env);
         io->ci_obj = clob;
+       io->ci_ignore_layout = 1;
         result = cl_io_init(env, io, CIT_MISC, clob);
         if (result == 0) {
                 page = cl_page_find(env, clob, vmpage->index,
@@ -1204,14 +1204,17 @@ int ll_writepage(struct page *vmpage, struct writeback_control *wbc)
                                if (!PageError(vmpage)) {
                                        redirty_page_for_writepage(wbc, vmpage);
                                        result = 0;
-                                       redirtied = 1;
+                                       redirtied = true;
                                }
                        }
                        cl_page_disown(env, io, page);
+                       unlocked = true;
                         lu_ref_del(&page->cp_reference,
                                    "writepage", cfs_current());
                         cl_page_put(env, page);
-                }
+               } else {
+                       result = PTR_ERR(page);
+               }
         }
         cl_io_fini(env, io);
 
@@ -1235,7 +1238,17 @@ int ll_writepage(struct page *vmpage, struct writeback_control *wbc)
        }
 
         cl_env_nested_put(&nest, env);
-        RETURN(result);
+       GOTO(out, result);
+
+out:
+       if (result < 0) {
+               if (!lli->lli_async_rc)
+                       lli->lli_async_rc = result;
+               SetPageError(vmpage);
+               if (!unlocked)
+                       unlock_page(vmpage);
+       }
+       return result;
 }
 
 int ll_writepages(struct address_space *mapping, struct writeback_control *wbc)
@@ -1296,7 +1309,7 @@ int ll_readpage(struct file *file, struct page *vmpage)
                         result = cl_io_read_page(env, io, page);
                 } else {
                         /* Page from a non-object file. */
-                        LASSERT(!ll_i2info(vmpage->mapping->host)->lli_smd);
+                       LASSERT(!ll_i2info(vmpage->mapping->host)->lli_has_smd);
                         unlock_page(vmpage);
                         result = 0;
                 }