Whamcloud - gitweb
LU-8731 utils: propagate errors in lfs df
[fs/lustre-release.git] / lustre / osd-zfs / osd_io.c
index 85e8310..389213d 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
  */
@@ -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;
@@ -168,18 +164,11 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt,
         * LOHA_EXISTs is supposed to be the last step in the
         * initialization */
 
-       /* declare possible size change. notice we can't check
-        * current size here as another thread can change it */
-
-       if (dt_object_exists(dt)) {
-               LASSERT(obj->oo_db);
+       /* size change (in dnode) will be declared by dmu_tx_hold_write() */
+       if (dt_object_exists(dt))
                oid = obj->oo_db->db_object;
-
-               dmu_tx_hold_sa(oh->ot_tx, obj->oo_sa_hdl, 0);
-       } else {
+       else
                oid = DMU_NEW_OBJECT;
-               dmu_tx_hold_sa_create(oh->ot_tx, ZFS_SA_BASE_ATTR_SIZE);
-       }
 
        /* XXX: we still miss for append declaration support in ZFS
         *      -1 means append which is used by llog mostly, llog
@@ -215,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);
@@ -238,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);
 }
 
@@ -361,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;
@@ -439,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;
@@ -473,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;
@@ -653,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);
@@ -685,8 +669,8 @@ retry:
 /**
  * Policy to grow ZFS block size by write pattern.
  * For sequential write, it grows block size gradually until it reaches the
- * maximum blocksize the dataset can support. Otherwise, it will just use
- * the maximum block size.
+ * maximum blocksize the dataset can support. Otherwise, it will pick a
+ * a block size by the writing region of this I/O.
  */
 static int osd_grow_blocksize(struct osd_object *obj, struct osd_thandle *oh,
                              uint64_t start, uint64_t end)
@@ -696,6 +680,7 @@ static int osd_grow_blocksize(struct osd_object *obj, struct osd_thandle *oh,
        dnode_t                 *dn;
        uint32_t                 blksz;
        int                      rc = 0;
+
        ENTRY;
 
        DB_DNODE_ENTER(db);
@@ -704,24 +689,40 @@ static int osd_grow_blocksize(struct osd_object *obj, struct osd_thandle *oh,
        if (dn->dn_maxblkid > 0) /* can't change block size */
                GOTO(out, rc);
 
-       blksz = dn->dn_datablksz;
-       if (blksz >= osd->od_max_blksz)
+       if (dn->dn_datablksz >= osd->od_max_blksz)
                GOTO(out, rc);
 
+       down_write(&obj->oo_guard);
+
+       blksz = dn->dn_datablksz;
+       if (blksz >= osd->od_max_blksz) /* check again after grabbing lock */
+               GOTO(out_unlock, rc);
+
        /* now ZFS can support up to 16MB block size, and if the write
         * is sequential, it just increases the block size gradually */
        if (start <= blksz) { /* sequential */
                blksz = (uint32_t)min_t(uint64_t, osd->od_max_blksz, end);
-               if (!is_power_of_2(blksz))
-                       blksz = size_roundup_power2(blksz);
-       } else { /* otherwise, use maximum block size */
-               blksz = osd->od_max_blksz;
+       } else { /* sparse, pick a block size by write region */
+               blksz = (uint32_t)min_t(uint64_t, osd->od_max_blksz,
+                                       end - start);
        }
 
-       if (blksz > dn->dn_datablksz)
+       if (!is_power_of_2(blksz))
+               blksz = size_roundup_power2(blksz);
+
+       if (blksz > dn->dn_datablksz) {
                rc = -dmu_object_set_blocksize(osd->od_os, dn->dn_object,
                                               blksz, 0, oh->ot_tx);
+               LASSERT(ergo(rc == 0, dn->dn_datablksz >= blksz));
+               if (rc < 0)
+                       CDEBUG(D_INODE, "object "DFID": change block size"
+                              "%u -> %u error rc = %d\n",
+                              PFID(lu_object_fid(&obj->oo_dt.do_lu)),
+                              dn->dn_datablksz, blksz, rc);
+       }
        EXIT;
+out_unlock:
+       up_write(&obj->oo_guard);
 out:
        DB_DNODE_EXIT(db);
        return rc;
@@ -746,13 +747,9 @@ static int osd_write_commit(const struct lu_env *env, struct dt_object *dt,
        oh = container_of0(th, struct osd_thandle, ot_super);
 
        /* adjust block size. Assume the buffers are sorted. */
-       rc = osd_grow_blocksize(obj, oh, lnb[0].lnb_file_offset,
-                               lnb[npages - 1].lnb_file_offset +
-                               lnb[npages - 1].lnb_len);
-       if (rc < 0) /* ignore the error */
-               CDEBUG(D_INODE, "obj "DFID": change block size error rc=%d\n",
-                      PFID(lu_object_fid(&dt->do_lu)), rc);
-
+       (void)osd_grow_blocksize(obj, oh, lnb[0].lnb_file_offset,
+                                lnb[npages - 1].lnb_file_offset +
+                                lnb[npages - 1].lnb_len);
        for (i = 0; i < npages; i++) {
                CDEBUG(D_INODE, "write %u bytes at %u\n",
                        (unsigned) lnb[i].lnb_len,
@@ -959,6 +956,20 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt,
                                 false));
 }
 
+static int osd_ladvise(const struct lu_env *env, struct dt_object *dt,
+                      __u64 start, __u64 end, enum lu_ladvise_type advice)
+{
+       int     rc;
+       ENTRY;
+
+       switch (advice) {
+       default:
+               rc = -ENOTSUPP;
+               break;
+       }
+
+       RETURN(rc);
+}
 
 struct dt_body_operations osd_body_ops = {
        .dbo_read                       = osd_read,
@@ -972,4 +983,5 @@ struct dt_body_operations osd_body_ops = {
        .dbo_read_prep                  = osd_read_prep,
        .dbo_declare_punch              = osd_declare_punch,
        .dbo_punch                      = osd_punch,
+       .dbo_ladvise                    = osd_ladvise,
 };