Whamcloud - gitweb
LU-8856 osd: mark specific transactions netfree
[fs/lustre-release.git] / lustre / osd-zfs / osd_io.c
index 41e6ee7..94c36de 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -37,7 +37,6 @@
 
 #define DEBUG_SUBSYSTEM S_OSD
 
-#include <lustre_ver.h>
 #include <libcfs/libcfs.h>
 #include <obd_support.h>
 #include <lustre_net.h>
@@ -45,7 +44,7 @@
 #include <obd_class.h>
 #include <lustre_disk.h>
 #include <lustre_fid.h>
-#include <lustre/lustre_idl.h> /* LLOG_MIN_CHUNK_SIZE definition */
+#include <lustre_quota.h>
 
 #include "osd_internal.h"
 
@@ -182,8 +181,8 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt,
         * as llog or last_rcvd files. We needn't enforce quota on those
         * objects, so always set the lqi_space as 0. */
        RETURN(osd_declare_quota(env, osd, obj->oo_attr.la_uid,
-                                obj->oo_attr.la_gid, 0, oh, true, NULL,
-                                false));
+                                obj->oo_attr.la_gid, obj->oo_attr.la_projid,
+                                0, oh, NULL, OSD_QID_BLK));
 }
 
 static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
@@ -330,7 +329,13 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj,
         * If we discover this is a vital for good performance we
         * can get own replacement for dmu_buf_hold_array_by_bonus().
         */
-       while (len > 0) {
+       while (len > 0 &&
+              (obj->oo_dn->dn_datablkshift != 0 ||
+               off < obj->oo_dn->dn_datablksz)) {
+               if (obj->oo_dn->dn_datablkshift == 0 &&
+                   off + len > obj->oo_dn->dn_datablksz)
+                       len = obj->oo_dn->dn_datablksz - off;
+
                rc = -dmu_buf_hold_array_by_bonus(&obj->oo_dn->dn_bonus->db,
                                                  off, len, TRUE, osd_0copy_tag,
                                                  &numbufs, &dbp);
@@ -580,10 +585,11 @@ static int osd_declare_write_commit(const struct lu_env *env,
        uint32_t            size = 0;
        uint32_t blksz = obj->oo_dn->dn_datablksz;
        int                 i, rc, flags = 0;
-       bool                ignore_quota = false, synced = false;
+       bool synced = false;
        long long           space = 0;
        struct page        *last_page = NULL;
        unsigned long       discont_pages = 0;
+       enum osd_qid_declare_flags declare_flags = OSD_QID_BLK;
        ENTRY;
 
        LASSERT(dt_object_exists(dt));
@@ -616,7 +622,8 @@ static int osd_declare_write_commit(const struct lu_env *env,
                if ((lnb[i].lnb_flags & OBD_BRW_NOQUOTA) ||
                    (lnb[i].lnb_flags & (OBD_BRW_FROM_GRANT | OBD_BRW_SYNC)) ==
                    OBD_BRW_FROM_GRANT)
-                       ignore_quota = true;
+                       declare_flags |= OSD_QID_FORCE;
+
                if (size == 0) {
                        /* first valid lnb */
                        offset = lnb[i].lnb_file_offset;
@@ -662,8 +669,8 @@ static int osd_declare_write_commit(const struct lu_env *env,
 retry:
        /* acquire quota space if needed */
        rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid,
-                              obj->oo_attr.la_gid, space, oh, true, &flags,
-                              ignore_quota);
+                              obj->oo_attr.la_gid, obj->oo_attr.la_projid,
+                              space, oh, &flags, declare_flags);
 
        if (!synced && rc == -EDQUOT && (flags & QUOTA_FL_SYNC) != 0) {
                dt_sync(env, th->th_dev);
@@ -680,6 +687,10 @@ retry:
                lnb[0].lnb_flags |= OBD_BRW_OVER_USRQUOTA;
        if (flags & QUOTA_FL_OVER_GRPQUOTA)
                lnb[0].lnb_flags |= OBD_BRW_OVER_GRPQUOTA;
+#ifdef ZFS_PROJINHERIT
+       if (flags & QUOTA_FL_OVER_PRJQUOTA)
+               lnb[0].lnb_flags |= OBD_BRW_OVER_PRJQUOTA;
+#endif
 
        RETURN(rc);
 }
@@ -998,14 +1009,15 @@ 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) {
                read_unlock(&obj->oo_attr_lock);
+               dmu_tx_mark_netfree(oh->ot_tx);
                dmu_tx_hold_free(oh->ot_tx, obj->oo_dn->dn_object, start, len);
        } else {
                read_unlock(&obj->oo_attr_lock);
        }
 
        RETURN(osd_declare_quota(env, osd, obj->oo_attr.la_uid,
-                                obj->oo_attr.la_gid, 0, oh, true, NULL,
-                                false));
+                                obj->oo_attr.la_gid, obj->oo_attr.la_projid,
+                                0, oh, NULL, OSD_QID_BLK));
 }
 
 static int osd_ladvise(const struct lu_env *env, struct dt_object *dt,