Whamcloud - gitweb
LU-11462 osd-zfs: skip sync if object is not dirty
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
index 02983ac..3329093 100644 (file)
@@ -2105,15 +2105,22 @@ 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;
 
-       /* XXX: no other option than syncing the whole filesystem until we
-        * support ZIL.  If the object tracked the txg that it was last
-        * modified in, it could pass that txg here instead of "0".  Maybe
-        * the changes are already committed, so no wait is needed at all? */
-       if (!osd->od_dt_dev.dd_rdonly) {
+       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);
+
+       if (txg) {
+               /* the object is dirty or being synced */
                if (osd_object_sync_delay_us < 0)
-                       txg_wait_synced(dmu_objset_pool(osd->od_os), 0ULL);
+                       txg_wait_synced(dmu_objset_pool(osd->od_os), txg);
                else
                        udelay(osd_object_sync_delay_us);
        }