Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / ofd / ofd_fs.c
index 7fbce7b..2c2bea9 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lustre/ofd/ofd_fs.c
  *
@@ -88,7 +87,7 @@ struct ofd_seq *ofd_seq_get(struct ofd_device *ofd, u64 seq)
        read_lock(&ofd->ofd_seq_list_lock);
        list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
                if (ostid_seq(&oseq->os_oi) == seq) {
-                       atomic_inc(&oseq->os_refc);
+                       refcount_inc(&oseq->os_refc);
                        read_unlock(&ofd->ofd_seq_list_lock);
                        return oseq;
                }
@@ -108,7 +107,7 @@ struct ofd_seq *ofd_seq_get(struct ofd_device *ofd, u64 seq)
  */
 void ofd_seq_put(const struct lu_env *env, struct ofd_seq *oseq)
 {
-       if (atomic_dec_and_test(&oseq->os_refc)) {
+       if (refcount_dec_and_test(&oseq->os_refc)) {
                LASSERT(list_empty(&oseq->os_list));
                LASSERT(oseq->os_lastid_obj != NULL);
                dt_object_put(env, oseq->os_lastid_obj);
@@ -140,14 +139,14 @@ static struct ofd_seq *ofd_seq_add(const struct lu_env *env,
        write_lock(&ofd->ofd_seq_list_lock);
        list_for_each_entry(os, &ofd->ofd_seq_list, os_list) {
                if (ostid_seq(&os->os_oi) == ostid_seq(&new_seq->os_oi)) {
-                       atomic_inc(&os->os_refc);
+                       refcount_inc(&os->os_refc);
                        write_unlock(&ofd->ofd_seq_list_lock);
                        /* The seq has not been added to the list */
                        ofd_seq_put(env, new_seq);
                        return os;
                }
        }
-       atomic_inc(&new_seq->os_refc);
+       refcount_inc(&new_seq->os_refc);
        list_add_tail(&new_seq->os_list, &ofd->ofd_seq_list);
        ofd->ofd_seq_count++;
        write_unlock(&ofd->ofd_seq_list_lock);
@@ -320,7 +319,7 @@ void ofd_seqs_free(const struct lu_env *env, struct ofd_device *ofd)
        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);
        }
@@ -378,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)
@@ -407,8 +409,7 @@ struct ofd_seq *ofd_seq_load(const struct lu_env *env, struct ofd_device *ofd,
        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);
+       refcount_set(&oseq->os_refc, 1);
        atomic_set(&oseq->os_precreate_in_progress, 0);
 
        rc = dt_attr_get(env, dob, &info->fti_attr);
@@ -417,10 +418,18 @@ 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 */
-               if (OBD_FAIL_CHECK(OBD_FAIL_OFD_SET_OID))
-                       ofd_seq_last_oid_set(oseq, 0xffffff00);
-               else
+               if (CFS_FAIL_CHECK(OBD_FAIL_OFD_SET_OID)) {
+                       struct seq_server_site *ss = &ofd->ofd_seq_site;
+                       struct lu_client_seq *client_seq = ss->ss_client_seq;
+                       __u64 seq_width = fid_seq_is_norm(seq) ?
+                               min(OBIF_MAX_OID, client_seq->lcs_width) :
+                               min(IDIF_MAX_OID, client_seq->lcs_width);
+
+                       ofd_seq_last_oid_set(oseq, seq_width > 255 ?
+                                               seq_width - 255 : seq_width);
+               } 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;
@@ -440,6 +449,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:
@@ -642,7 +653,7 @@ int ofd_fs_setup(const struct lu_env *env, struct ofd_device *ofd,
        if (rc)
                GOTO(out, rc);
 
-       if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP))
+       if (CFS_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP))
                GOTO(out_seqs, rc = -ENOENT);
 
        lu_local_obj_fid(&info->fti_fid, OFD_HEALTH_CHECK_OID);