Whamcloud - gitweb
LU-5047 tests: correct cleanup files in sanity.sh
[fs/lustre-release.git] / lustre / osd-zfs / osd_io.c
index 3fe29ef..98e359e 100644 (file)
@@ -51,6 +51,7 @@
 #include <obd_class.h>
 #include <lustre_disk.h>
 #include <lustre_fid.h>
+#include <lustre/lustre_idl.h> /* LLOG_CHUNK_SIZE definition */
 
 #include "osd_internal.h"
 
@@ -108,7 +109,7 @@ static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
 }
 
 static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt,
-                               const loff_t size, loff_t pos,
+                               const struct lu_buf *buf, loff_t pos,
                                struct thandle *th)
 {
        struct osd_object  *obj  = osd_dt_obj(dt);
@@ -137,7 +138,13 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt,
                dmu_tx_hold_sa_create(oh->ot_tx, ZFS_SA_BASE_ATTR_SIZE);
        }
 
-       dmu_tx_hold_write(oh->ot_tx, oid, pos, size);
+       /* XXX: we still miss for append declaration support in ZFS
+        *      -1 means append which is used by llog mostly, llog
+        *      can grow upto LLOG_CHUNK_SIZE*8 records */
+       if (pos == -1)
+               pos = max_t(loff_t, 256 * 8 * LLOG_CHUNK_SIZE,
+                           obj->oo_attr.la_size + (2 << 20));
+       dmu_tx_hold_write(oh->ot_tx, oid, pos, buf->lb_len);
 
        /* dt_declare_write() is usually called for system objects, such
         * as llog or last_rcvd files. We needn't enforce quota on those
@@ -218,17 +225,17 @@ static int osd_bufs_put(const struct lu_env *env, struct dt_object *dt,
                        /* this is anonymous page allocated for copy-write */
                        lnb[i].page->mapping = NULL;
                        __free_page(lnb[i].page);
-                       cfs_atomic_dec(&osd->od_zerocopy_alloc);
+                       atomic_dec(&osd->od_zerocopy_alloc);
                } else {
                        /* see comment in osd_bufs_get_read() */
                        ptr = (unsigned long)lnb[i].dentry;
                        if (ptr & 1UL) {
                                ptr &= ~1UL;
                                dmu_buf_rele((void *)ptr, osd_zerocopy_tag);
-                               cfs_atomic_dec(&osd->od_zerocopy_pin);
+                               atomic_dec(&osd->od_zerocopy_pin);
                        } else if (lnb[i].dentry != NULL) {
                                dmu_return_arcbuf((void *)lnb[i].dentry);
-                               cfs_atomic_dec(&osd->od_zerocopy_loan);
+                               atomic_dec(&osd->od_zerocopy_loan);
                        }
                }
                lnb[i].page = NULL;
@@ -274,7 +281,7 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj,
 
                        LASSERT(len > 0);
 
-                       cfs_atomic_inc(&osd->od_zerocopy_pin);
+                       atomic_inc(&osd->od_zerocopy_pin);
 
                        bufoff = off - dbp[i]->db_offset;
                        tocpy = min_t(int, dbp[i]->db_size - bufoff, len);
@@ -353,7 +360,7 @@ static int osd_bufs_get_write(const struct lu_env *env, struct osd_object *obj,
                        if (unlikely(abuf == NULL))
                                GOTO(out_err, rc = -ENOMEM);
 
-                       cfs_atomic_inc(&osd->od_zerocopy_loan);
+                       atomic_inc(&osd->od_zerocopy_loan);
 
                        /* go over pages arcbuf contains, put them as
                         * local niobufs for ptlrpc's bulks */
@@ -407,7 +414,7 @@ static int osd_bufs_get_write(const struct lu_env *env, struct osd_object *obj,
                                LASSERT(lnb[i].page->mapping == NULL);
                                lnb[i].page->mapping = (void *)obj;
 
-                               cfs_atomic_inc(&osd->od_zerocopy_alloc);
+                               atomic_inc(&osd->od_zerocopy_alloc);
                                lprocfs_counter_add(osd->od_stats,
                                                LPROC_OSD_COPY_IO, 1);
 
@@ -578,20 +585,21 @@ static int osd_declare_write_commit(const struct lu_env *env,
                        continue;
                }
 
-               dmu_tx_hold_write(oh->ot_tx, obj->oo_db->db_object, offset,size);
-
+               dmu_tx_hold_write(oh->ot_tx, obj->oo_db->db_object,
+                                 offset, size);
                /* estimating space that will be consumed by a write is rather
                 * complicated with ZFS. As a consequence, we don't account for
                 * indirect blocks and quota overrun will be adjusted once the
                 * operation is committed, if required. */
                space += osd_count_not_mapped(obj, offset, size);
 
-               offset = lnb->lnb_file_offset;
-               size = lnb->len;
+               offset = lnb[i].lnb_file_offset;
+               size = lnb[i].len;
        }
 
        if (size) {
-               dmu_tx_hold_write(oh->ot_tx, obj->oo_db->db_object, offset,size);
+               dmu_tx_hold_write(oh->ot_tx, obj->oo_db->db_object,
+                                 offset, size);
                space += osd_count_not_mapped(obj, offset, size);
        }
 
@@ -680,7 +688,7 @@ static int osd_write_commit(const struct lu_env *env, struct dt_object *dt,
                        /* drop the reference, otherwise osd_put_bufs()
                         * will be releasing it - bad! */
                        lnb[i].dentry = NULL;
-                       cfs_atomic_dec(&osd->od_zerocopy_loan);
+                       atomic_dec(&osd->od_zerocopy_loan);
                }
 
                if (new_size < lnb[i].lnb_file_offset + lnb[i].len)