From: adilger Date: Sat, 10 Aug 2002 09:46:25 +0000 (+0000) Subject: Use list_heads properly. In a few places we were using them incorrectly: X-Git-Tag: 0.5.5~178 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=f90f4eb71c7617966b515c09d15706394a21ca1c;p=fs%2Flustre-release.git Use list_heads properly. In a few places we were using them incorrectly: 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(). --- diff --git a/lustre/ldlm/ldlm_lock.c b/lustre/ldlm/ldlm_lock.c index 03b2847..759f91f 100644 --- a/lustre/ldlm/ldlm_lock.c +++ b/lustre/ldlm/ldlm_lock.c @@ -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); diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 8412473..3e05514 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -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)); diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 5139574..776490e 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -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; diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index a58cd21..cdcc6fb 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -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; } diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 4fb18e7..d9e847d 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -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));