Whamcloud - gitweb
LU-13946 build: OpenZFS 2.0 compatibility 22/39822/5
authorBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 3 Sep 2020 16:23:17 +0000 (09:23 -0700)
committerOleg Drokin <green@whamcloud.com>
Mon, 19 Oct 2020 03:13:28 +0000 (03:13 +0000)
* Update zfs_refcount_add() configure check.  OpenZFS 2.0 has renamed
  the sys/refcount.h header to sys/zfs_refcount.h to avoid a conflict
  with this header on FreeBSD.  Since Lustre never directly includes
  this header by name adjust the configure check to indirectly include
  it through sys/dnode.h.  This was we don't need a separate check to
  determine the expected header name.

* Add db->db_dirty_records check.  The db->db_last_dirty field was
  replaced by a proper db->db_dirty_records list_t.  Detect the code
  change and add a osd_db_dirty_txg() helper function which returns
  the largest dirty txg for the dbuf or zero when clean.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Change-Id: Ifc9573ec410f50f46f2c601368639453e78b291d
Reviewed-on: https://review.whamcloud.com/39822
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
config/lustre-build-zfs.m4
lustre/osd-zfs/osd_internal.h
lustre/osd-zfs/osd_io.c
lustre/osd-zfs/osd_object.c

index 873ad8a..acacf34 100644 (file)
@@ -698,11 +698,14 @@ your distribution.
                                [Have inode_timespec_t])
                ])
                dnl # ZFS 0.7.12/0.8.x uses zfs_refcount_add() instead of
-               dnl # refcount_add().
+               dnl # refcount_add().  ZFS 2.0 renamed sys/refcount.h to
+               dnl # sys/zfs_refcount.h, rather the add another check to
+               dnl # determine the correct header name include it
+               dnl # indirectly through sys/dnode.h.
                dnl #
                LB_CHECK_COMPILE([if ZFS has 'zfs_refcount_add'],
                zfs_refcount_add, [
-                       #include <sys/refcount.h>
+                       #include <sys/dnode.h>
                ],[
                        zfs_refcount_add((zfs_refcount_t *) NULL, NULL);
                ],[
@@ -749,6 +752,21 @@ your distribution.
                        AC_DEFINE(HAVE_DMU_OFFSET_NEXT, 1,
                                [Have dmu_offset_next() exported])
                ])
+               dnl #
+               dnl # ZFS 2.0 replaced .db_last_dirty / .dr_next with a list_t
+               dnl # and list_node_t named .db_dirty_records / .dr_dbuf_node.
+               dnl #
+               LB_CHECK_COMPILE([if ZFS has 'db_dirty_records' list_t],
+               db_dirty_records, [
+                       #include <sys/dbuf.h>
+               ],[
+                       dmu_buf_impl_t db;
+                       dbuf_dirty_record_t *dr;
+                       dr = list_head(&db.db_dirty_records);
+               ],[
+                       AC_DEFINE(HAVE_DB_DIRTY_RECORDS_LIST, 1,
+                               [Have db_dirty_records list_t])
+               ])
        ])
 
        AS_IF([test "x$enable_zfs" = xyes], [
index 9887b58..499108e 100644 (file)
@@ -963,6 +963,24 @@ static inline void osd_dnode_rele(dnode_t *dn)
        dmu_buf_rele(&db->db, osd_obj_tag);
 }
 
+static inline uint64_t osd_db_dirty_txg(dmu_buf_impl_t *db)
+{
+       dbuf_dirty_record_t *dr;
+       uint64_t txg = 0;
+
+       mutex_enter(&db->db_mtx);
+#ifdef HAVE_DB_DIRTY_RECORDS_LIST
+       dr = list_head(&db->db_dirty_records);
+#else
+       dr = db->db_last_dirty;
+#endif
+       if (dr != NULL)
+               txg = dr->dr_txg;
+       mutex_exit(&db->db_mtx);
+
+       return txg;
+}
+
 #ifdef HAVE_DMU_USEROBJ_ACCOUNTING
 
 #define OSD_DMU_USEROBJ_PREFIX         DMU_OBJACCT_PREFIX
index 063607f..1f71bd9 100644 (file)
@@ -141,14 +141,14 @@ static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
 {
        struct osd_device *osd = osd_obj2dev(osd_dt_obj(dt));
        size_t size = buf->lb_len;
-       ktime_t start;
+       hrtime_t start = gethrtime();
        s64 delta_ms;
        int rc;
 
-       start = ktime_get();
        record_start_io(osd, READ, 0);
        rc = __osd_read(env, dt, buf, pos, &size);
-       delta_ms = ktime_ms_delta(ktime_get(), start);
+       delta_ms = gethrtime() - start;
+       do_div(delta_ms, NSEC_PER_MSEC);
        record_end_io(osd, READ, delta_ms, size, size >> PAGE_SHIFT);
 
        return rc;
@@ -334,7 +334,7 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj,
 {
        struct osd_device *osd = osd_obj2dev(obj);
        int rc, i, numbufs, npages = 0, drop_cache = 0;
-       ktime_t start = ktime_get();
+       hrtime_t start = gethrtime();
        dmu_buf_t **dbp;
        s64 delta_ms;
 
@@ -422,7 +422,8 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj,
                dmu_buf_rele_array(dbp, numbufs, osd_0copy_tag);
        }
 
-       delta_ms = ktime_ms_delta(ktime_get(), start);
+       delta_ms = gethrtime() - start;
+       do_div(delta_ms, NSEC_PER_MSEC);
        record_end_io(osd, READ, delta_ms, npages * PAGE_SIZE, npages);
 
        RETURN(npages);
index 4eb433f..0812a34 100644 (file)
@@ -2124,18 +2124,13 @@ static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
                           __u64 start, __u64 end)
 {
        struct osd_device *osd = osd_obj2dev(osd_dt_obj(dt));
-       struct dmu_buf_impl *db = osd_dt_obj(dt)->oo_dn->dn_dbuf;
        uint64_t txg = 0;
        ENTRY;
 
        if (osd->od_dt_dev.dd_rdonly)
                RETURN(0);
 
-       mutex_enter(&db->db_mtx);
-       if (db->db_last_dirty)
-               txg = db->db_last_dirty->dr_txg;
-       mutex_exit(&db->db_mtx);
-
+       txg = osd_db_dirty_txg(osd_dt_obj(dt)->oo_dn->dn_dbuf);
        if (txg) {
                /* the object is dirty or being synced */
                if (osd_object_sync_delay_us < 0)