Whamcloud - gitweb
LU-3906 tests: fix space estimation codes in run_compilebench()
[fs/lustre-release.git] / lustre / osd-zfs / osd_io.c
index 8825892..c041c8e 100644 (file)
@@ -28,7 +28,7 @@
  * Use is subject to license terms.
  */
 /*
- * Copyright (c) 2011, 2012 Whamcloud, Inc.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  * Use is subject to license terms.
  */
 /*
  * Author: Mike Pershin <tappro@whamcloud.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_OSD
 
 #include <lustre_ver.h>
 #include <libcfs/libcfs.h>
-#include <lustre_fsfilt.h>
 #include <obd_support.h>
 #include <lustre_net.h>
 #include <obd.h>
@@ -86,9 +82,9 @@ static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
        LASSERT(dt_object_exists(dt));
        LASSERT(obj->oo_db);
 
-       cfs_read_lock(&obj->oo_attr_lock);
+       read_lock(&obj->oo_attr_lock);
        old_size = obj->oo_attr.la_size;
-       cfs_read_unlock(&obj->oo_attr_lock);
+       read_unlock(&obj->oo_attr_lock);
 
        if (*pos + size > old_size) {
                if (old_size < *pos)
@@ -172,10 +168,10 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
 
        dmu_write(osd->od_objset.os, obj->oo_db->db_object, offset,
                (uint64_t)buf->lb_len, buf->lb_buf, oh->ot_tx);
-       cfs_write_lock(&obj->oo_attr_lock);
+       write_lock(&obj->oo_attr_lock);
        if (obj->oo_attr.la_size < offset + buf->lb_len) {
                obj->oo_attr.la_size = offset + buf->lb_len;
-               cfs_write_unlock(&obj->oo_attr_lock);
+               write_unlock(&obj->oo_attr_lock);
                /* osd_object_sa_update() will be copying directly from oo_attr
                 * into dbuf.  any update within a single txg will copy the
                 * most actual */
@@ -184,7 +180,7 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
                if (unlikely(rc))
                        GOTO(out, rc);
        } else {
-               cfs_write_unlock(&obj->oo_attr_lock);
+               write_unlock(&obj->oo_attr_lock);
        }
 
        *pos += buf->lb_len;
@@ -242,16 +238,12 @@ static int osd_bufs_put(const struct lu_env *env, struct dt_object *dt,
        return 0;
 }
 
-static struct page *kmem_to_page(void *addr)
+static inline struct page *kmem_to_page(void *addr)
 {
-       struct page *page;
-
-       if (kmem_virt(addr))
-               page = vmalloc_to_page(addr);
+       if (is_vmalloc_addr(addr))
+               return vmalloc_to_page(addr);
        else
-               page = virt_to_page(addr);
-
-       return page;
+               return virt_to_page(addr);
 }
 
 static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj,
@@ -271,9 +263,10 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj,
         */
        while (len > 0) {
                rc = -dmu_buf_hold_array_by_bonus(obj->oo_db, off, len, TRUE,
-                                               osd_zerocopy_tag, &numbufs,
-                                               &dbp);
-               LASSERT(rc == 0);
+                                                 osd_zerocopy_tag, &numbufs,
+                                                 &dbp);
+               if (unlikely(rc))
+                       GOTO(err, rc);
 
                for (i = 0; i < numbufs; i++) {
                        int bufoff, tocpy, thispage;
@@ -291,8 +284,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 = CFS_PAGE_SIZE;
-                               thispage -= bufoff & (CFS_PAGE_SIZE - 1);
+                               thispage = PAGE_CACHE_SIZE;
+                               thispage -= bufoff & (PAGE_CACHE_SIZE - 1);
                                thispage = min(tocpy, thispage);
 
                                lnb->rc = 0;
@@ -323,6 +316,11 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj,
        }
 
        RETURN(npages);
+
+err:
+       LASSERT(rc < 0);
+       osd_bufs_put(env, &obj->oo_dt, lnb - npages, npages);
+       RETURN(rc);
 }
 
 static int osd_bufs_get_write(const struct lu_env *env, struct osd_object *obj,
@@ -360,7 +358,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, CFS_PAGE_SIZE);
+                               plen = min_t(int, sz_in_block, PAGE_CACHE_SIZE);
 
                                lnb[i].lnb_file_offset = off;
                                lnb[i].lnb_page_offset = 0;
@@ -394,7 +392,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, CFS_PAGE_SIZE);
+                               plen = min_t(int, sz_in_block, PAGE_CACHE_SIZE);
 
                                lnb[i].lnb_file_offset = off;
                                lnb[i].lnb_page_offset = 0;
@@ -558,10 +556,15 @@ static int osd_declare_write_commit(const struct lu_env *env,
                /* ignore quota for the whole request if any page is from
                 * client cache or written by root.
                 *
+                * XXX once we drop the 1.8 client support, the checking
+                * for whether page is from cache can be simplified as:
+                * !(lnb[i].flags & OBD_BRW_SYNC)
+                *
                 * XXX we could handle this on per-lnb basis as done by
                 * grant. */
                if ((lnb[i].flags & OBD_BRW_NOQUOTA) ||
-                   !(lnb[i].flags & OBD_BRW_SYNC))
+                   (lnb[i].flags & (OBD_BRW_FROM_GRANT | OBD_BRW_SYNC)) ==
+                   OBD_BRW_FROM_GRANT)
                        ignore_quota = true;
                if (size == 0) {
                        /* first valid lnb */
@@ -692,17 +695,17 @@ static int osd_write_commit(const struct lu_env *env, struct dt_object *dt,
                RETURN(0);
        }
 
-       cfs_write_lock(&obj->oo_attr_lock);
+       write_lock(&obj->oo_attr_lock);
        if (obj->oo_attr.la_size < new_size) {
                obj->oo_attr.la_size = new_size;
-               cfs_write_unlock(&obj->oo_attr_lock);
+               write_unlock(&obj->oo_attr_lock);
                /* osd_object_sa_update() will be copying directly from
                 * oo_attr into dbuf. any update within a single txg will copy
                 * the most actual */
                rc = osd_object_sa_update(obj, SA_ZPL_SIZE(uos),
                                        &obj->oo_attr.la_size, 8, oh);
        } else {
-               cfs_write_unlock(&obj->oo_attr_lock);
+               write_unlock(&obj->oo_attr_lock);
        }
 
        RETURN(rc);
@@ -793,21 +796,21 @@ static int osd_punch(const struct lu_env *env, struct dt_object *dt,
        LASSERT(th != NULL);
        oh = container_of0(th, struct osd_thandle, ot_super);
 
-       cfs_write_lock(&obj->oo_attr_lock);
+       write_lock(&obj->oo_attr_lock);
        /* truncate */
        if (end == OBD_OBJECT_EOF || end >= obj->oo_attr.la_size)
                len = DMU_OBJECT_END;
        else
                len = end - start;
-       cfs_write_unlock(&obj->oo_attr_lock);
+       write_unlock(&obj->oo_attr_lock);
 
        rc = __osd_object_punch(osd->od_objset.os, obj->oo_db, oh->ot_tx,
                                obj->oo_attr.la_size, start, len);
        /* set new size */
        if (len == DMU_OBJECT_END) {
-               cfs_write_lock(&obj->oo_attr_lock);
+               write_lock(&obj->oo_attr_lock);
                obj->oo_attr.la_size = start;
-               cfs_write_unlock(&obj->oo_attr_lock);
+               write_unlock(&obj->oo_attr_lock);
                rc = osd_object_sa_update(obj, SA_ZPL_SIZE(uos),
                                        &obj->oo_attr.la_size, 8, oh);
        }
@@ -825,7 +828,7 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt,
 
        oh = container_of0(handle, struct osd_thandle, ot_super);
 
-       cfs_read_lock(&obj->oo_attr_lock);
+       read_lock(&obj->oo_attr_lock);
        if (end == OBD_OBJECT_EOF || end >= obj->oo_attr.la_size)
                len = DMU_OBJECT_END;
        else
@@ -833,10 +836,10 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt,
 
        /* declare we'll free some blocks ... */
        if (start < obj->oo_attr.la_size) {
-               cfs_read_unlock(&obj->oo_attr_lock);
+               read_unlock(&obj->oo_attr_lock);
                dmu_tx_hold_free(oh->ot_tx, obj->oo_db->db_object, start, len);
        } else {
-               cfs_read_unlock(&obj->oo_attr_lock);
+               read_unlock(&obj->oo_attr_lock);
        }
 
        /* ... and we'll modify size attribute */
@@ -858,7 +861,7 @@ struct dt_body_operations osd_body_ops = {
        .dbo_declare_write_commit       = osd_declare_write_commit,
        .dbo_write_commit               = osd_write_commit,
        .dbo_read_prep                  = osd_read_prep,
-       .do_declare_punch               = osd_declare_punch,
-       .do_punch                       = osd_punch,
+       .dbo_declare_punch              = osd_declare_punch,
+       .dbo_punch                      = osd_punch,
 };