Whamcloud - gitweb
LU-8066 obd: collect all resource releasing for obj_type.
[fs/lustre-release.git] / lustre / obdclass / dt_object.c
index 95a9070..3bec5f7 100644 (file)
@@ -141,26 +141,6 @@ int dt_txn_hook_stop(const struct lu_env *env, struct thandle *th)
 }
 EXPORT_SYMBOL(dt_txn_hook_stop);
 
-void dt_txn_hook_commit(struct thandle *th)
-{
-       struct dt_txn_callback *cb;
-
-       if (th->th_local)
-               return;
-
-       list_for_each_entry(cb, &th->th_dev->dd_txn_callbacks,
-                           dtc_linkage) {
-               /*
-                * Right now, the bottom device (OSD) will use this hook
-                * commit to notify OSP, so we do not check and replace
-                * the thandle to top thandle now
-                */
-               if (cb->dtc_txn_commit)
-                       cb->dtc_txn_commit(th, cb->dtc_cookie);
-       }
-}
-EXPORT_SYMBOL(dt_txn_hook_commit);
-
 int dt_device_init(struct dt_device *dev, struct lu_device_type *t)
 {
        INIT_LIST_HEAD(&dev->dd_txn_callbacks);
@@ -721,8 +701,12 @@ static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
        struct idx_info *ii = (struct idx_info *)arg;
        struct lu_idxpage *lip = &lp->lp_idx;
        char *entry;
-       size_t size;
+       __u64 hash;
+       __u16 hashsize = 0;
+       __u16 keysize = 0;
+       __u16 recsize;
        int rc;
+
        ENTRY;
 
        if (nob < LIP_HDR_SIZE)
@@ -733,20 +717,12 @@ static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
        lip->lip_magic = LIP_MAGIC;
        nob           -= LIP_HDR_SIZE;
 
-       /* compute size needed to store a key/record pair */
-       size = ii->ii_recsize + ii->ii_keysize;
-       if ((ii->ii_flags & II_FL_NOHASH) == 0)
-               /* add hash if the client wants it */
-               size += sizeof(__u64);
+       /* client wants to the 64-bit hash value associated with each record */
+       if (!(ii->ii_flags & II_FL_NOHASH))
+               hashsize = sizeof(hash);
 
        entry = lip->lip_entries;
        do {
-               char *tmp_entry = entry;
-               struct dt_key *key;
-               __u64 hash;
-               __u16 keysize;
-               __u16 recsize;
-
                /* fetch 64-bit hash value */
                hash = iops->store(env, it);
                ii->ii_hash_end = hash;
@@ -756,58 +732,54 @@ static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
                                GOTO(out, rc = 0);
                }
 
-               if (nob < size) {
-                       if (lip->lip_nr == 0)
+               if (!(ii->ii_flags & II_FL_NOKEY)) {
+                       keysize = iops->key_size(env, it);
+                       if (!(ii->ii_flags & II_FL_VARKEY) &&
+                           keysize != ii->ii_keysize) {
+                               CERROR("keysize mismatch %hu != %hu.\n",
+                                      keysize, ii->ii_keysize);
                                GOTO(out, rc = -EINVAL);
-                       GOTO(out, rc = 0);
+                       }
                }
 
-               if (!(ii->ii_flags & II_FL_NOHASH)) {
-                       /*
-                        * client wants to the 64-bit hash value associated
-                        * with each record
-                        */
-                       memcpy(tmp_entry, &hash, sizeof(hash));
-                       tmp_entry += sizeof(hash);
-               }
-
-               if (ii->ii_flags & II_FL_VARKEY)
-                       keysize = iops->key_size(env, it);
+               /* and finally the record */
+               if (ii->ii_flags & II_FL_VARREC)
+                       recsize = iops->rec_size(env, it, attr);
                else
-                       keysize = ii->ii_keysize;
+                       recsize = ii->ii_recsize;
 
-               if (!(ii->ii_flags & II_FL_NOKEY)) {
-                       /* then the key value */
-                       key = iops->key(env, it);
-                       memcpy(tmp_entry, key, keysize);
-                       tmp_entry += keysize;
+               if (nob < hashsize + keysize + recsize) {
+                       if (lip->lip_nr == 0)
+                               GOTO(out, rc = -E2BIG);
+                       GOTO(out, rc = 0);
                }
 
-               /* and finally the record */
-               rc = iops->rec(env, it, (struct dt_rec *)tmp_entry, attr);
-               if (rc != -ESTALE) {
-                       if (rc != 0)
-                               GOTO(out, rc);
-
+               rc = iops->rec(env, it,
+                              (struct dt_rec *)(entry + hashsize + keysize),
+                              attr);
+               if (!rc) {
+                       if (hashsize)
+                               memcpy(entry, &hash, hashsize);
+                       if (keysize) {
+                               struct dt_key *key;
+
+                               key = iops->key(env, it);
+                               memcpy(entry + hashsize, key, keysize);
+                       }
                        /* hash/key/record successfully copied! */
                        lip->lip_nr++;
                        if (unlikely(lip->lip_nr == 1 && ii->ii_count == 0))
                                ii->ii_hash_start = hash;
-
-                       if (ii->ii_flags & II_FL_VARREC)
-                               recsize = iops->rec_size(env, it, attr);
-                       else
-                               recsize = ii->ii_recsize;
-
-                       entry = tmp_entry + recsize;
-                       nob -= size;
+                       entry += hashsize + keysize + recsize;
+                       nob -= hashsize + keysize + recsize;
+               } else if (rc != -ESTALE) {
+                       GOTO(out, rc);
                }
 
                /* move on to the next record */
                do {
                        rc = iops->next(env, it);
                } while (rc == -ESTALE);
-
        } while (rc == 0);
 
        GOTO(out, rc);
@@ -1263,6 +1235,9 @@ static void dt_sysfs_release(struct kobject *kobj)
        struct dt_device *dt = container_of(kobj, struct dt_device,
                                            dd_kobj);
 
+       debugfs_remove_recursive(dt->dd_debugfs_entry);
+       dt->dd_debugfs_entry = NULL;
+
        complete(&dt->dd_kobj_unregister);
 }
 
@@ -1271,9 +1246,6 @@ int dt_tunables_fini(struct dt_device *dt)
        if (!dt)
                return -EINVAL;
 
-       if (!IS_ERR_OR_NULL(dt->dd_debugfs_entry))
-               ldebugfs_remove(&dt->dd_debugfs_entry);
-
        if (dt->dd_def_attrs)
                sysfs_remove_files(&dt->dd_kobj, dt->dd_def_attrs);
 
@@ -1293,7 +1265,7 @@ int dt_tunables_init(struct dt_device *dt, struct obd_type *type,
        dt->dd_ktype.release = dt_sysfs_release;
 
        init_completion(&dt->dd_kobj_unregister);
-       rc = kobject_init_and_add(&dt->dd_kobj, &dt->dd_ktype, type->typ_kobj,
+       rc = kobject_init_and_add(&dt->dd_kobj, &dt->dd_ktype, &type->typ_kobj,
                                  "%s", name);
        if (rc)
                return rc;