Whamcloud - gitweb
LU-14598 ofd: fix for IDIF sequence at ofd_preprw_write
[fs/lustre-release.git] / lustre / ofd / ofd_fs.c
index f2981c2..062bb05 100644 (file)
  * 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/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/ofd/ofd_fs.c
  *
@@ -111,7 +110,7 @@ void ofd_seq_put(const struct lu_env *env, struct ofd_seq *oseq)
        if (atomic_dec_and_test(&oseq->os_refc)) {
                LASSERT(list_empty(&oseq->os_list));
                LASSERT(oseq->os_lastid_obj != NULL);
-               lu_object_put(env, &oseq->os_lastid_obj->do_lu);
+               dt_object_put(env, oseq->os_lastid_obj);
                OBD_FREE_PTR(oseq);
        }
 }
@@ -181,8 +180,12 @@ u64 ofd_seq_last_oid(struct ofd_seq *oseq)
 void ofd_seq_last_oid_set(struct ofd_seq *oseq, u64 id)
 {
        spin_lock(&oseq->os_last_oid_lock);
-       if (likely(ostid_id(&oseq->os_oi) < id))
-               ostid_set_id(&oseq->os_oi, id);
+       if (likely(ostid_id(&oseq->os_oi) < id)) {
+               if (ostid_set_id(&oseq->os_oi, id)) {
+                       CERROR("Bad %llu to set " DOSTID "\n",
+                              (unsigned long long)id, POSTID(&oseq->os_oi));
+               }
+       }
        spin_unlock(&oseq->os_last_oid_lock);
 }
 
@@ -212,6 +215,9 @@ int ofd_seq_last_oid_write(const struct lu_env *env, struct ofd_device *ofd,
 
        ENTRY;
 
+       if (ofd->ofd_osd->dd_rdonly)
+               RETURN(0);
+
        tmp = cpu_to_le64(ofd_seq_last_oid(oseq));
 
        info->fti_buf.lb_buf = &tmp;
@@ -303,18 +309,17 @@ static void ofd_fld_fini(const struct lu_env *env, struct ofd_device *ofd)
  */
 void ofd_seqs_free(const struct lu_env *env, struct ofd_device *ofd)
 {
-       struct ofd_seq          *oseq;
-       struct ofd_seq          *tmp;
-       struct list_head         dispose;
+       struct ofd_seq *oseq;
+       struct ofd_seq *tmp;
+       LIST_HEAD(dispose);
 
-       INIT_LIST_HEAD(&dispose);
        write_lock(&ofd->ofd_seq_list_lock);
        list_for_each_entry_safe(oseq, tmp, &ofd->ofd_seq_list, os_list)
                list_move(&oseq->os_list, &dispose);
        write_unlock(&ofd->ofd_seq_list_lock);
 
        while (!list_empty(&dispose)) {
-               oseq = container_of0(dispose.next, struct ofd_seq, os_list);
+               oseq = container_of(dispose.next, struct ofd_seq, os_list);
                list_del_init(&oseq->os_list);
                ofd_seq_put(env, oseq);
        }
@@ -372,8 +377,11 @@ struct ofd_seq *ofd_seq_load(const struct lu_env *env, struct ofd_device *ofd,
 
        /* if seq is already initialized */
        oseq = ofd_seq_get(ofd, seq);
-       if (oseq != NULL)
+       if (oseq != NULL) {
+               CDEBUG(D_TRACE, "%s: got sequence %#llx "DOSTID"\n",
+                      ofd_name(ofd), seq, POSTID(&oseq->os_oi));
                RETURN(oseq);
+       }
 
        OBD_ALLOC_PTR(oseq);
        if (oseq == NULL)
@@ -400,8 +408,10 @@ struct ofd_seq *ofd_seq_load(const struct lu_env *env, struct ofd_device *ofd,
        mutex_init(&oseq->os_create_lock);
        spin_lock_init(&oseq->os_last_oid_lock);
        ostid_set_seq(&oseq->os_oi, seq);
+       oseq->os_last_id_synced = 0;
 
        atomic_set(&oseq->os_refc, 1);
+       atomic_set(&oseq->os_precreate_in_progress, 0);
 
        rc = dt_attr_get(env, dob, &info->fti_attr);
        if (rc)
@@ -409,7 +419,10 @@ struct ofd_seq *ofd_seq_load(const struct lu_env *env, struct ofd_device *ofd,
 
        if (info->fti_attr.la_size == 0) {
                /* object is just created, initialize last id */
-               ofd_seq_last_oid_set(oseq, OFD_INIT_OBJID);
+               if (OBD_FAIL_CHECK(OBD_FAIL_OFD_SET_OID))
+                       ofd_seq_last_oid_set(oseq, 0xffffff00);
+               else
+                       ofd_seq_last_oid_set(oseq, OFD_INIT_OBJID);
                ofd_seq_last_oid_write(env, ofd, oseq);
        } else if (info->fti_attr.la_size == sizeof(lastid)) {
                info->fti_off = 0;
@@ -429,6 +442,8 @@ struct ofd_seq *ofd_seq_load(const struct lu_env *env, struct ofd_device *ofd,
                GOTO(cleanup, rc = -EINVAL);
        }
 
+       CDEBUG(D_HA, "%s: adding sequence %#llx\n", ofd_name(ofd), seq);
+
        oseq = ofd_seq_add(env, ofd, oseq);
        RETURN((oseq != NULL) ? oseq : ERR_PTR(-ENOENT));
 cleanup:
@@ -677,7 +692,7 @@ void ofd_fs_cleanup(const struct lu_env *env, struct ofd_device *ofd)
                      ofd_name(ofd), rc);
 
        if (ofd->ofd_health_check_file) {
-               lu_object_put(env, &ofd->ofd_health_check_file->do_lu);
+               dt_object_put(env, ofd->ofd_health_check_file);
                ofd->ofd_health_check_file = NULL;
        }