linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Finney <sean.finney@sonyericsson.com>
To: <linux-nfs@vger.kernel.org>
Cc: <bfields@fieldses.org>, Sean Finney <sean.finney@sonyericsson.com>
Subject: [PATCH v2 1/2] nfs-utils: mountd: Use a dynamic buffer for storing lists of gid's
Date: Thu, 7 Apr 2011 09:22:27 +0200	[thread overview]
Message-ID: <1302160948-5628-1-git-send-email-sean.finney@sonyericsson.com> (raw)
In-Reply-To: <20110405233552.GB27961@fieldses.org>

Previously, in auth_unix_gid, group lists were stored in an array of
hard-coded length 100, and in the situation that the group lists for a
particular call were too large, the array was swapped with a dynamically
allocated/freed buffer.  For environments where users are commonly in
a large number of groups, this isn't an ideal approach.

Instead, make the group list static scoped to the function, and
use malloc/realloc to grow it on an as-needed basis.

Signed-off-by: Sean Finney <sean.finney@sonyericsson.com>
---
 utils/mountd/cache.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c
index 9bbbfb3..7deb050 100644
--- a/utils/mountd/cache.c
+++ b/utils/mountd/cache.c
@@ -37,6 +37,7 @@
 #include "blkid/blkid.h"
 #endif
 
+#define INITIAL_MANAGED_GROUPS 100
 
 enum nfsd_fsid {
 	FSID_DEV = 0,
@@ -127,11 +128,21 @@ void auth_unix_gid(FILE *f)
 	 */
 	int uid;
 	struct passwd *pw;
-	gid_t glist[100], *groups = glist;
-	int ngroups = 100;
+	static gid_t *groups = NULL;
+	static int groups_len = 0;
+	gid_t *more_groups;
+	int ngroups = 0;
 	int rv, i;
 	char *cp;
 
+	if (groups_len == 0) {
+		groups = malloc(sizeof(gid_t)*INITIAL_MANAGED_GROUPS);
+		if (!groups)
+			return;
+
+		groups_len = ngroups = INITIAL_MANAGED_GROUPS;
+	}
+
 	if (readline(fileno(f), &lbuf, &lbuflen) != 1)
 		return;
 
@@ -144,13 +155,16 @@ void auth_unix_gid(FILE *f)
 		rv = -1;
 	else {
 		rv = getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups);
-		if (rv == -1 && ngroups >= 100) {
-			groups = malloc(sizeof(gid_t)*ngroups);
-			if (!groups)
+		if (rv == -1 && ngroups >= groups_len) {
+			more_groups = realloc(groups, sizeof(gid_t)*ngroups);
+			if (!more_groups)
 				rv = -1;
-			else
+			else {
+				groups = more_groups;
+				groups_len = ngroups;
 				rv = getgrouplist(pw->pw_name, pw->pw_gid,
 						  groups, &ngroups);
+			}
 		}
 	}
 	qword_printint(f, uid);
@@ -162,9 +176,6 @@ void auth_unix_gid(FILE *f)
 	} else
 		qword_printint(f, 0);
 	qword_eol(f);
-
-	if (groups != glist)
-		free(groups);
 }
 
 #if USE_BLKID
-- 
1.7.4.1


  parent reply	other threads:[~2011-04-07  7:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-04  8:02 Fixes for NFS in environments with large group memberships Finney, Sean
     [not found] ` <A50602A820F61543B29992A418BB321B66E18F8A4A-g6SuDuYnGwoBLpZRX7oUTsm4BeyDBExM@public.gmane.org>
2011-04-05 23:35   ` J. Bruce Fields
2011-04-07  5:53     ` Finney, Sean
2011-04-07  7:22     ` Sean Finney [this message]
2011-04-07  7:22       ` [PATCH v2 2/2] nfs-utils: Increase the stdio file buffer size for procfs files Sean Finney
2011-04-07 12:22       ` [PATCH v2 1/2] nfs-utils: mountd: Use a dynamic buffer for storing lists of gid's Jim Rees
2011-04-07 14:15         ` Finney, Sean
2011-04-07 14:29           ` Chuck Lever
2011-04-07 15:01           ` Jim Rees

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302160948-5628-1-git-send-email-sean.finney@sonyericsson.com \
    --to=sean.finney@sonyericsson.com \
    --cc=bfields@fieldses.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).