Re: [PATCH 2/2] SUNRPC: Optimize 'svc_print_xprts()'

From: Christophe JAILLET
Date: Thu Mar 26 2020 - 08:19:25 EST


Le 25/03/2020 Ã 23:53, NeilBrown a ÃcritÂ:
Can I suggest something more like this:
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index de3c077733a7..0292f45b70f6 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -115,16 +115,9 @@ int svc_print_xprts(char *buf, int maxlen)
buf[0] = '\0';
spin_lock(&svc_xprt_class_lock);
- list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) {
- int slen;
-
- sprintf(tmpstr, "%s %d\n", xcl->xcl_name, xcl->xcl_max_payload);
- slen = strlen(tmpstr);
- if (len + slen > maxlen)
- break;
- len += slen;
- strcat(buf, tmpstr);
- }
+ list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list)
+ len += scnprintf(buf + len, maxlen - len, "%s %d\n",
+ xcl->xcl_name, xcl->xcl_max_payload);
spin_unlock(&svc_xprt_class_lock);
return len;

NeilBrown

Hi,

this was what I suggested in the patch:
ÂÂÂ ---
ÂÂÂ This patch should have no functional change.
ÂÂÂ We could go further, use scnprintf and write directly in the destination
ÂÂÂ buffer. However, this could lead to a truncated last line.
ÂÂÂ ---

And Chuck Lever confirmed that:
ÂÂÂ That's exactly what this function is trying to avoid. As part of any
ÂÂÂ change in this area, it would be good to replace the current block
ÂÂÂ comment before this function with a Doxygen-format comment that
ÂÂÂ documents that goal.

So, I will only send a V2 based on comments already received.

CJ