Whamcloud - gitweb
LU-12336 build: Update ZFS version to 0.8.1
[fs/lustre-release.git] / lustre / ofd / ofd_objects.c
index 8ba286b..53e5b64 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, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -160,6 +160,68 @@ int ofd_object_ff_load(const struct lu_env *env, struct ofd_object *fo)
        return 0;
 }
 
+struct ofd_precreate_cb {
+       struct dt_txn_commit_cb  opc_cb;
+       struct ofd_seq          *opc_oseq;
+       int                      opc_objects;
+};
+
+static void ofd_cb_precreate(struct lu_env *env, struct thandle *th,
+                            struct dt_txn_commit_cb *cb, int err)
+{
+       struct ofd_precreate_cb *opc;
+       struct ofd_seq *oseq;
+
+       opc = container_of(cb, struct ofd_precreate_cb, opc_cb);
+       oseq = opc->opc_oseq;
+
+       CDEBUG(D_OTHER, "Sub %d from %d for "DFID", th_sync %d\n",
+              opc->opc_objects, atomic_read(&oseq->os_precreate_in_progress),
+              PFID(&oseq->os_oi.oi_fid), th->th_sync);
+       atomic_sub(opc->opc_objects, &oseq->os_precreate_in_progress);
+       ofd_seq_put(env, opc->opc_oseq);
+       OBD_FREE_PTR(opc);
+}
+
+static int ofd_precreate_cb_add(const struct lu_env *env, struct thandle *th,
+                               struct ofd_seq *oseq, int objects)
+{
+       struct ofd_precreate_cb *opc;
+       struct dt_txn_commit_cb *dcb;
+       int precreate, rc;
+
+       OBD_ALLOC_PTR(opc);
+       if (!opc)
+               return -ENOMEM;
+
+       precreate = atomic_read(&oseq->os_precreate_in_progress);
+       atomic_inc(&oseq->os_refc);
+       opc->opc_oseq = oseq;
+       opc->opc_objects = objects;
+       CDEBUG(D_OTHER, "Add %d to %d for "DFID", th_sync %d\n",
+              opc->opc_objects, precreate,
+              PFID(&oseq->os_oi.oi_fid), th->th_sync);
+
+       if ((precreate + objects) >= (5 * OST_MAX_PRECREATE))
+               th->th_sync = 1;
+
+       dcb = &opc->opc_cb;
+       dcb->dcb_func = ofd_cb_precreate;
+       INIT_LIST_HEAD(&dcb->dcb_linkage);
+       strlcpy(dcb->dcb_name, "ofd_cb_precreate", sizeof(dcb->dcb_name));
+
+       rc = dt_trans_cb_add(th, dcb);
+       if (rc) {
+               ofd_seq_put(env, oseq);
+               OBD_FREE_PTR(opc);
+               return rc;
+       }
+
+       atomic_add(objects, &oseq->os_precreate_in_progress);
+
+       return 0;
+}
+
 /**
  * Precreate the given number \a nr of objects in the given sequence \a oseq.
  *
@@ -207,12 +269,12 @@ int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd,
 
        /* Don't create objects beyond the valid range for this SEQ */
        if (unlikely(fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) &&
-                    (id + nr) >= IDIF_MAX_OID)) {
+                    (id + nr) > IDIF_MAX_OID)) {
                CERROR("%s:"DOSTID" hit the IDIF_MAX_OID (1<<48)!\n",
                       ofd_name(ofd), id, ostid_seq(&oseq->os_oi));
                RETURN(rc = -ENOSPC);
        } else if (unlikely(!fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) &&
-                           (id + nr) >= OBIF_MAX_OID)) {
+                           (id + nr) > OBIF_MAX_OID)) {
                CERROR("%s:"DOSTID" hit the OBIF_MAX_OID (1<<32)!\n",
                       ofd_name(ofd), id, ostid_seq(&oseq->os_oi));
                RETURN(rc = -ENOSPC);
@@ -320,7 +382,7 @@ int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd,
          * may cannot get latest last_id although new OST-object created. */
        if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_SKIP_LASTID)) {
                tmp = cpu_to_le64(id + nr - 1);
-               dt_write_lock(env, oseq->os_lastid_obj, 0);
+               dt_write_lock(env, oseq->os_lastid_obj, DT_LASTID);
                rc = dt_record_write(env, oseq->os_lastid_obj,
                                     &info->fti_buf, &info->fti_off, th);
                dt_write_unlock(env, oseq->os_lastid_obj);
@@ -368,7 +430,7 @@ int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd,
 
                info->fti_off = 0;
                tmp = cpu_to_le64(ofd_seq_last_oid(oseq));
-               dt_write_lock(env, oseq->os_lastid_obj, 0);
+               dt_write_lock(env, oseq->os_lastid_obj, DT_LASTID);
                rc1 = dt_record_write(env, oseq->os_lastid_obj,
                                      &info->fti_buf, &info->fti_off, th);
                dt_write_unlock(env, oseq->os_lastid_obj);
@@ -379,6 +441,8 @@ int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd,
                               ofd_seq_last_oid(oseq));
        }
 
+       if (objects)
+               ofd_precreate_cb_add(env, th, oseq, objects);
 trans_stop:
        rc2 = ofd_trans_stop(env, ofd, th, rc);
        if (rc2)
@@ -585,26 +649,21 @@ int ofd_object_ff_update(const struct lu_env *env, struct ofd_object *fo,
 int ofd_attr_set(const struct lu_env *env, struct ofd_object *fo,
                 struct lu_attr *la, struct obdo *oa)
 {
-       struct ofd_thread_info  *info = ofd_info(env);
-       struct ofd_device       *ofd = ofd_obj2dev(fo);
-       struct filter_fid       *ff = &info->fti_mds_fid;
-       struct thandle          *th;
-       struct ofd_mod_data     *fmd;
-       int                     fl;
-       int                     rc;
-       int                     rc2;
+       struct ofd_thread_info *info = ofd_info(env);
+       struct ofd_device *ofd = ofd_obj2dev(fo);
+       struct filter_fid *ff = &info->fti_mds_fid;
+       struct thandle *th;
+       int fl, rc, rc2;
+
        ENTRY;
 
        ofd_write_lock(env, fo);
        if (!ofd_object_exists(fo))
                GOTO(unlock, rc = -ENOENT);
 
-       if (la->la_valid & (LA_ATIME | LA_MTIME | LA_CTIME)) {
-               fmd = ofd_fmd_get(info->fti_exp, &fo->ofo_header.loh_fid);
-               if (fmd && fmd->fmd_mactime_xid < info->fti_xid)
-                       fmd->fmd_mactime_xid = info->fti_xid;
-               ofd_fmd_put(info->fti_exp, fmd);
-       }
+       if (la->la_valid & (LA_ATIME | LA_MTIME | LA_CTIME))
+               tgt_fmd_update(info->fti_exp, &fo->ofo_header.loh_fid,
+                              info->fti_xid);
 
        /* VBR: version recovery check */
        rc = ofd_version_get_check(info, fo);
@@ -700,15 +759,12 @@ int ofd_object_punch(const struct lu_env *env, struct ofd_object *fo,
                     __u64 start, __u64 end, struct lu_attr *la,
                     struct obdo *oa)
 {
-       struct ofd_thread_info  *info = ofd_info(env);
-       struct ofd_device       *ofd = ofd_obj2dev(fo);
-       struct ofd_mod_data     *fmd;
-       struct dt_object        *dob = ofd_object_child(fo);
-       struct filter_fid       *ff = &info->fti_mds_fid;
-       struct thandle          *th;
-       int                     fl;
-       int                     rc;
-       int                     rc2;
+       struct ofd_thread_info *info = ofd_info(env);
+       struct ofd_device *ofd = ofd_obj2dev(fo);
+       struct dt_object *dob = ofd_object_child(fo);
+       struct filter_fid *ff = &info->fti_mds_fid;
+       struct thandle *th;
+       int fl, rc, rc2;
 
        ENTRY;
 
@@ -716,10 +772,9 @@ int ofd_object_punch(const struct lu_env *env, struct ofd_object *fo,
        LASSERT(end == OBD_OBJECT_EOF);
 
        ofd_write_lock(env, fo);
-       fmd = ofd_fmd_get(info->fti_exp, &fo->ofo_header.loh_fid);
-       if (fmd && fmd->fmd_mactime_xid < info->fti_xid)
-               fmd->fmd_mactime_xid = info->fti_xid;
-       ofd_fmd_put(info->fti_exp, fmd);
+       if (la->la_valid & (LA_ATIME | LA_MTIME | LA_CTIME))
+               tgt_fmd_update(info->fti_exp, &fo->ofo_header.loh_fid,
+                              info->fti_xid);
 
        if (!ofd_object_exists(fo))
                GOTO(unlock, rc = -ENOENT);
@@ -863,7 +918,7 @@ int ofd_destroy(const struct lu_env *env, struct ofd_object *fo,
        if (rc)
                GOTO(stop, rc);
 
-       ofd_fmd_drop(ofd_info(env)->fti_exp, &fo->ofo_header.loh_fid);
+       tgt_fmd_drop(ofd_info(env)->fti_exp, &fo->ofo_header.loh_fid);
 
        dt_ref_del(env, ofd_object_child(fo), th);
        dt_destroy(env, ofd_object_child(fo), th);