[lustre-devel] [PATCH 2/6] lustre: lnet/config: convert list_for_each to list_for_each_entry

Andreas Dilger adilger at whamcloud.com
Mon Jul 30 13:42:05 PDT 2018



> On Jul 29, 2018, at 21:45, NeilBrown <neilb at suse.com> wrote:
> 
> This conversion to list_for_each_entry isn't quite trivial
> as the 'tmp' loop variables are used elsewhere in the function.
> This means we cannot just delete them, and so must inspect the
> code to ensure the values aren't used elsewhere - they aren't.
> 
> Also we need to introduce new loop variables: ltb1 and ltb2 as
> the lnet_text_buf was the some for both the original (nested) loops.
> 
> Signed-off-by: NeilBrown <neilb at suse.com>

Reviewed-by: Andreas Dilger <adilger at whamcloud.com>

> ---
> drivers/staging/lustre/lnet/lnet/config.c |   11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c
> index 96336ecdacaf..091c4f714e84 100644
> --- a/drivers/staging/lustre/lnet/lnet/config.c
> +++ b/drivers/staging/lustre/lnet/lnet/config.c
> @@ -662,6 +662,7 @@ lnet_parse_route(char *str, int *im_a_router)
> 	__u32 net;
> 	lnet_nid_t nid;
> 	struct lnet_text_buf *ltb;
> +	struct lnet_text_buf *ltb1, *ltb2;
> 	int rc;
> 	char *sep;
> 	char *token = str;
> @@ -760,14 +761,12 @@ lnet_parse_route(char *str, int *im_a_router)
> 	LASSERT(!list_empty(&nets));
> 	LASSERT(!list_empty(&gateways));
> 
> -	list_for_each(tmp1, &nets) {
> -		ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
> -		net = libcfs_str2net(ltb->ltb_text);
> +	list_for_each_entry(ltb1, &nets, ltb_list) {
> +		net = libcfs_str2net(ltb1->ltb_text);
> 		LASSERT(net != LNET_NIDNET(LNET_NID_ANY));
> 
> -		list_for_each(tmp2, &gateways) {
> -			ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
> -			nid = libcfs_str2nid(ltb->ltb_text);
> +		list_for_each_entry(ltb2, &gateways, ltb_list) {
> +			nid = libcfs_str2nid(ltb2->ltb_text);
> 			LASSERT(nid != LNET_NID_ANY);
> 
> 			if (lnet_islocalnid(nid)) {
> 
> 

Cheers, Andreas
---
Andreas Dilger
Principal Lustre Architect
Whamcloud







-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180730/db409863/attachment.sig>


More information about the lustre-devel mailing list