Whamcloud - gitweb
Use list_heads properly. In a few places we were using them incorrectly:
authoradilger <adilger>
Sat, 10 Aug 2002 09:46:25 +0000 (09:46 +0000)
committeradilger <adilger>
Sat, 10 Aug 2002 09:46:25 +0000 (09:46 +0000)
BAD:  list_add(&list_item, list_head.prev);  Overwrites the adjacent field.
GOOD: list_add_tail(&list_item, list_head);

While the following usage is technically correct, it does encourage people
to use the above (incorrect) usage pattern, so it should be avoided:

BAD:  list_add(&list_item, list_head.next);
GOOD: list_add_tail(&list_item, &list_head);

Just FYI - list_add() is like a queue, while list_add_tail() is like a stack,
when iterating over items via list_for_each().

lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_resource.c
lustre/obdclass/class_obd.c
lustre/obdclass/genops.c
lustre/obdfilter/filter.c

index 03b2847..759f91f 100644 (file)
@@ -805,7 +805,7 @@ struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
                                 lock->l_completion_ast(lock, 0);
                 }
         } else
-                list_add(&lock->l_res_link, res->lr_converting.prev);
+                list_add_tail(&lock->l_res_link, &res->lr_converting);
 
         l_unlock(&ns->ns_lock);
 
index 8412473..3e05514 100644 (file)
@@ -55,6 +55,7 @@ struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
                 LBUG();
                 GOTO(out, ns);
         }
+        obd_memory += sizeof(*ns->ns_hash) * RES_HASH_SIZE;
 
         OBD_ALLOC(ns->ns_name, strlen(name) + 1);
         if (!ns->ns_name) {
@@ -85,8 +86,10 @@ struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
         RETURN(ns);
 
  out:
-        if (ns && ns->ns_hash)
+        if (ns && ns->ns_hash) {
                 vfree(ns->ns_hash);
+                obd_memory -= sizeof(*ns->ns_hash) * RES_HASH_SIZE;
+        }
         if (ns && ns->ns_name)
                 OBD_FREE(ns->ns_name, strlen(name) + 1);
         if (ns)
@@ -165,7 +168,8 @@ int ldlm_namespace_free(struct ldlm_namespace *ns)
                 }
         }
 
-        vfree(ns->ns_hash /* , sizeof(struct list_head) * RES_HASH_SIZE */);
+        vfree(ns->ns_hash /* , sizeof(*ns->ns_hash) * RES_HASH_SIZE */);
+        obd_memory -= sizeof(*ns->ns_hash) * RES_HASH_SIZE;
         ptlrpc_cleanup_client(&ns->ns_rpc_client);
         OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
         OBD_FREE(ns, sizeof(*ns));
index 5139574..776490e 100644 (file)
@@ -283,7 +283,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp,
                 INIT_LIST_HEAD(&obd->obd_exports);
 
                 /* do the attach */
-                if (OBT(obd) && OBP(obd, attach))
+                if (OBP(obd, attach))
                         err = OBP(obd,attach)(obd, sizeof(*data), data);
                 if (err) {
                         obd->obd_type = NULL;
index a58cd21..cdcc6fb 100644 (file)
@@ -80,7 +80,7 @@ int class_register_type(struct obd_ops *ops, char *nm)
                 RETURN(-ENOMEM);
         INIT_LIST_HEAD(&type->typ_chain);
         MOD_INC_USE_COUNT;
-        list_add(&type->typ_chain, obd_types.next);
+        list_add(&type->typ_chain, &obd_types);
         type->typ_ops = ops;
         type->typ_name = nm;
         RETURN(0);
@@ -92,12 +92,12 @@ int class_unregister_type(char *nm)
 
         ENTRY;
 
-        if ( !type ) {
+        if (!type) {
                 CERROR("unknown obd type\n");
                 RETURN(-EINVAL);
         }
 
-        if ( type->typ_refcnt ) {
+        if (type->typ_refcnt) {
                 CERROR("type %s has refcount (%d)\n", nm, type->typ_refcnt);
                 RETURN(-EBUSY);
         }
@@ -275,7 +275,7 @@ struct obd_export *class_new_export(struct obd_device *obddev)
         get_random_bytes(&export->exp_cookie, sizeof(__u64));
         export->exp_obd = obddev;
         INIT_LIST_HEAD(&export->exp_mds_data.med_open_head);
-        list_add(&(export->exp_chain), export->exp_obd->obd_exports.prev);
+        list_add(&(export->exp_chain), &export->exp_obd->obd_exports);
         return export;
 }
 
index 4fb18e7..d9e847d 100644 (file)
@@ -1123,8 +1123,7 @@ static int filter_preprw(int cmd, struct lustre_handle *conn,
                 struct inode *inode;
                 int j;
 
-                dentry = filter_fid2dentry(obd,
-                                           filter_parent(obd, S_IFREG),
+                dentry = filter_fid2dentry(obd, filter_parent(obd, S_IFREG),
                                            o->ioo_id, S_IFREG);
                 if (IS_ERR(dentry))
                         GOTO(out_clean, rc = PTR_ERR(dentry));