Whamcloud - gitweb
LU-7910 osd: do not lookup child objects in osd_dir_insert()
[fs/lustre-release.git] / lustre / osd-zfs / osd_io.c
index d94bc97..4721706 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2015, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -143,7 +139,7 @@ static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
                        buf->lb_buf, DMU_READ_PREFETCH);
 
        record_end_io(osd, READ, cfs_time_current() - start, size,
-                     size >> PAGE_CACHE_SHIFT);
+                     size >> PAGE_SHIFT);
        if (rc == 0) {
                rc = size;
                *pos += size;
@@ -208,8 +204,6 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
        LASSERT(th != NULL);
        oh = container_of0(th, struct osd_thandle, ot_super);
 
-       record_start_io(osd, WRITE, 0);
-
        dmu_write(osd->od_os, obj->oo_db->db_object, offset,
                (uint64_t)buf->lb_len, buf->lb_buf, oh->ot_tx);
        write_lock(&obj->oo_attr_lock);
@@ -231,9 +225,6 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
        rc = buf->lb_len;
 
 out:
-       record_end_io(osd, WRITE, 0, buf->lb_len,
-                     buf->lb_len >> PAGE_CACHE_SHIFT);
-
        RETURN(rc);
 }
 
@@ -354,8 +345,8 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj,
                        dbf = (void *) ((unsigned long)dbp[i] | 1);
 
                        while (tocpy > 0) {
-                               thispage = PAGE_CACHE_SIZE;
-                               thispage -= bufoff & (PAGE_CACHE_SIZE - 1);
+                               thispage = PAGE_SIZE;
+                               thispage -= bufoff & (PAGE_SIZE - 1);
                                thispage = min(tocpy, thispage);
 
                                lnb->lnb_rc = 0;
@@ -432,7 +423,7 @@ static int osd_bufs_get_write(const struct lu_env *env, struct osd_object *obj,
                        /* go over pages arcbuf contains, put them as
                         * local niobufs for ptlrpc's bulks */
                        while (sz_in_block > 0) {
-                               plen = min_t(int, sz_in_block, PAGE_CACHE_SIZE);
+                               plen = min_t(int, sz_in_block, PAGE_SIZE);
 
                                lnb[i].lnb_file_offset = off;
                                lnb[i].lnb_page_offset = 0;
@@ -466,7 +457,7 @@ static int osd_bufs_get_write(const struct lu_env *env, struct osd_object *obj,
 
                        /* can't use zerocopy, allocate temp. buffers */
                        while (sz_in_block > 0) {
-                               plen = min_t(int, sz_in_block, PAGE_CACHE_SIZE);
+                               plen = min_t(int, sz_in_block, PAGE_SIZE);
 
                                lnb[i].lnb_file_offset = off;
                                lnb[i].lnb_page_offset = 0;
@@ -646,7 +637,7 @@ static int osd_declare_write_commit(const struct lu_env *env,
         * copies */
        space  *= osd->od_os->os_copies;
        space   = toqb(space);
-       CDEBUG(D_QUOTA, "writing %d pages, reserving "LPD64"K of quota space\n",
+       CDEBUG(D_QUOTA, "writing %d pages, reserving %lldK of quota space\n",
               npages, space);
 
        record_start_io(osd, WRITE, discont_pages);
@@ -759,6 +750,32 @@ static int osd_write_commit(const struct lu_env *env, struct dt_object *dt,
        (void)osd_grow_blocksize(obj, oh, lnb[0].lnb_file_offset,
                                 lnb[npages - 1].lnb_file_offset +
                                 lnb[npages - 1].lnb_len);
+
+       /* LU-8791: take oo_guard to avoid the deadlock that changing block
+        * size and assigning arcbuf take place at the same time.
+        *
+        * Thread 1:
+        * osd_write_commit()
+        *  -> osd_grow_blocksize() with osd_object::oo_guard held
+        *   -> dmu_object_set_blocksize()
+        *    -> dnode_set_blksz(), with dnode_t::dn_struct_rwlock
+        *       write lock held
+        *     -> dbuf_new_size()
+        *      -> dmu_buf_will_dirty()
+        *       -> dbuf_read()
+        *        -> wait for the dbuf state to change
+        * Thread 2:
+        * osd_write_commit()
+        *  -> dmu_assign_arcbuf()
+        *   -> dbuf_assign_arcbuf(), set dbuf state to DB_FILL
+        *    -> dbuf_dirty()
+        *     -> try to hold the read lock of dnode_t::dn_struct_rwlock
+        *
+        * By taking the read lock, it can avoid thread 2 to enter into the
+        * critical section of assigning the arcbuf, while thread 1 is
+        * changing the block size.
+        */
+       down_read(&obj->oo_guard);
        for (i = 0; i < npages; i++) {
                CDEBUG(D_INODE, "write %u bytes at %u\n",
                        (unsigned) lnb[i].lnb_len,
@@ -797,6 +814,7 @@ static int osd_write_commit(const struct lu_env *env, struct dt_object *dt,
                        new_size = lnb[i].lnb_file_offset + lnb[i].lnb_len;
                iosize += lnb[i].lnb_len;
        }
+       up_read(&obj->oo_guard);
 
        if (unlikely(new_size == 0)) {
                /* no pages to write, no transno is needed */