Whamcloud - gitweb
LU-6158 mdt: always shrink_capsule in getxattr_all
[fs/lustre-release.git] / lustre / fld / fld_index.c
index d6bdee7..efff9fe 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define DEBUG_SUBSYSTEM S_FLD
 
-#ifdef __KERNEL__
-# include <libcfs/libcfs.h>
-# include <linux/module.h>
-#else /* __KERNEL__ */
-# include <liblustre.h>
-#endif
-
+#include <libcfs/libcfs.h>
+#include <linux/module.h>
 #include <obd_support.h>
 #include <dt_object.h>
 #include <lustre_fid.h>
@@ -79,8 +74,8 @@ static const struct lu_seq_range ROOT_FLD_RANGE = {
 
 static const struct dt_index_features fld_index_features = {
        .dif_flags       = DT_IND_UPDATE,
-       .dif_keysize_min = sizeof(seqno_t),
-       .dif_keysize_max = sizeof(seqno_t),
+       .dif_keysize_min = sizeof(u64),
+       .dif_keysize_max = sizeof(u64),
        .dif_recsize_min = sizeof(struct lu_seq_range),
        .dif_recsize_max = sizeof(struct lu_seq_range),
        .dif_ptrsize     = 4
@@ -159,6 +154,8 @@ out:
  * changed between declare and create.
  * Because the fld entry can only be increamental, so we will only check
  * whether it can be merged from the left.
+ *
+ * Caller must hold fld->lsf_lock
  **/
 int fld_index_create(const struct lu_env *env, struct lu_server_fld *fld,
                     const struct lu_seq_range *new_range, struct thandle *th)
@@ -188,8 +185,7 @@ int fld_index_create(const struct lu_env *env, struct lu_server_fld *fld,
            range_compare_loc(new_range, range) == 0) {
                range_cpu_to_be(tmp, range);
                rc = dt_delete(env, fld->lsf_obj,
-                              (struct dt_key *)&tmp->lsr_start, th,
-                               BYPASS_CAPA);
+                              (struct dt_key *)&tmp->lsr_start, th);
                if (rc != 0)
                        GOTO(out, rc);
                *tmp = *new_range;
@@ -201,7 +197,7 @@ int fld_index_create(const struct lu_env *env, struct lu_server_fld *fld,
 
        range_cpu_to_be(tmp, tmp);
        rc = dt_insert(env, fld->lsf_obj, (struct dt_rec *)tmp,
-                      (struct dt_key *)&tmp->lsr_start, th, BYPASS_CAPA, 1);
+                      (struct dt_key *)&tmp->lsr_start, th, 1);
        if (rc != 0) {
                CERROR("%s: insert range "DRANGE" failed: rc = %d\n",
                       fld->lsf_name, PRANGE(new_range), rc);
@@ -235,7 +231,7 @@ out:
  * \retval  -ve         other error;
  */
 int fld_index_lookup(const struct lu_env *env, struct lu_server_fld *fld,
-                    seqno_t seq, struct lu_seq_range *range)
+                    u64 seq, struct lu_seq_range *range)
 {
         struct lu_seq_range     *fld_rec;
         struct fld_thread_info  *info;
@@ -261,6 +257,19 @@ int fld_index_lookup(const struct lu_env *env, struct lu_server_fld *fld,
         RETURN(rc);
 }
 
+/**
+ * insert entry in fld store.
+ *
+ * \param  env    relevant lu_env
+ * \param  fld    fld store
+ * \param  range  range to be inserted
+ *
+ * \retval  0  success
+ * \retval  -ve error
+ *
+ * Caller must hold fld->lsf_lock
+ **/
+
 int fld_insert_entry(const struct lu_env *env,
                     struct lu_server_fld *fld,
                     const struct lu_seq_range *range)
@@ -269,6 +278,8 @@ int fld_insert_entry(const struct lu_env *env,
        int rc;
        ENTRY;
 
+       LASSERT(mutex_is_locked(&fld->lsf_lock));
+
        th = dt_trans_create(env, lu2dt_dev(fld->lsf_obj->do_lu.lo_dev));
        if (IS_ERR(th))
                RETURN(PTR_ERR(th));
@@ -313,7 +324,7 @@ static int fld_insert_special_entries(const struct lu_env *env,
 }
 
 int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld,
-                  struct dt_device *dt)
+                  struct dt_device *dt, int type)
 {
        struct dt_object        *dt_obj = NULL;
        struct lu_fid           fid;
@@ -373,7 +384,7 @@ int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld,
        range = &info->fti_rec;
        /* Load fld entry to cache */
        iops = &dt_obj->do_index_ops->dio_it;
-       it = iops->init(env, dt_obj, 0, NULL);
+       it = iops->init(env, dt_obj, 0);
        if (IS_ERR(it))
                GOTO(out, rc = PTR_ERR(it));
 
@@ -404,7 +415,7 @@ int fld_index_init(const struct lu_env *env, struct lu_server_fld *fld,
        else
                rc = 0;
 
-       if (index == 0) {
+       if (index == 0 && type == LU_SEQ_RANGE_MDT) {
                /* Note: fld_insert_entry will detect whether these
                 * special entries already exist inside FLDB */
                mutex_lock(&fld->lsf_lock);
@@ -458,7 +469,7 @@ int fld_server_read(const struct lu_env *env, struct lu_server_fld *fld,
 
        lsra->lsra_count = 0;
        iops = &dt_obj->do_index_ops->dio_it;
-       it = iops->init(env, dt_obj, 0, NULL);
+       it = iops->init(env, dt_obj, 0);
        if (IS_ERR(it))
                RETURN(PTR_ERR(it));