Whamcloud - gitweb
LU-15803 sec: correctly handle page lock in ll_io_zero_page
[fs/lustre-release.git] / lustre / llite / llite_lib.c
index 77aa3a7..3d200d7 100644 (file)
@@ -1932,7 +1932,6 @@ int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
        struct cl_2queue *queue = NULL;
        struct cl_sync_io *anchor = NULL;
        bool holdinglock = false;
-       bool lockedbymyself = true;
        int rc;
 
        ENTRY;
@@ -1987,27 +1986,31 @@ int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
        if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
            !PageWriteback(vmpage)) {
                /* read page */
-               /* set PagePrivate2 to detect special case of empty page
-                * in osc_brw_fini_request()
+               /* Set PagePrivate2 to detect special case of empty page
+                * in osc_brw_fini_request().
+                * It is also used to tell ll_io_read_page() that we do not
+                * want the vmpage to be unlocked.
                 */
                SetPagePrivate2(vmpage);
                rc = ll_io_read_page(env, io, clpage, NULL);
-               if (!PagePrivate2(vmpage))
+               if (!PagePrivate2(vmpage)) {
                        /* PagePrivate2 was cleared in osc_brw_fini_request()
                         * meaning we read an empty page. In this case, in order
                         * to avoid allocating unnecessary block in truncated
                         * file, we must not zero and write as below. Subsequent
                         * server-side truncate will handle things correctly.
                         */
+                       cl_page_unassume(env, io, clpage);
                        GOTO(clpfini, rc = 0);
+               }
                ClearPagePrivate2(vmpage);
                if (rc)
                        GOTO(clpfini, rc);
-               lockedbymyself = trylock_page(vmpage);
-               cl_page_assume(env, io, clpage);
        }
 
-       /* zero range in page */
+       /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
+        * the vmpage, so we are good to proceed and zero range in page.
+        */
        zero_user(vmpage, offset, len);
 
        if (holdinglock && clpage) {
@@ -2037,10 +2040,8 @@ clpfini:
        if (clpage)
                cl_page_put(env, clpage);
 pagefini:
-       if (lockedbymyself) {
-               unlock_page(vmpage);
-               put_page(vmpage);
-       }
+       unlock_page(vmpage);
+       put_page(vmpage);
 rellock:
        if (holdinglock)
                cl_lock_release(env, lock);