Bugzilla – Attachment 1779 Details for
Bug 1495
sftp performance of "ls -l" cmd is slow on network-authed servers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
sftp-namecache.patch
sftp-namecache.patch (text/plain), 3.41 KB, created by
Darren Tucker
on 2010-01-14 16:24:08 AEDT
(
hide
)
Description:
sftp-namecache.patch
Filename:
MIME Type:
Creator:
Darren Tucker
Created:
2010-01-14 16:24:08 AEDT
Size:
3.41 KB
patch
obsolete
>Index: sftp-common.c >=================================================================== >RCS file: /cvs/src/usr.bin/ssh/sftp-common.c,v >retrieving revision 1.21 >diff -u -p -r1.21 sftp-common.c >--- sftp-common.c 13 Jan 2010 01:40:16 -0000 1.21 >+++ sftp-common.c 14 Jan 2010 06:17:00 -0000 >@@ -25,6 +25,7 @@ > */ > > #include <sys/types.h> >+#include <sys/queue.h> > #include <sys/stat.h> > #include <sys/param.h> > >@@ -179,6 +180,89 @@ fx2txt(int status) > /* NOTREACHED */ > } > >+#define ID_CACHE_SIZE 32 >+ >+struct identry { >+ TAILQ_ENTRY(identry) next; >+ id_t id; >+ char *name; >+}; >+struct idcache { >+ int nentries; >+ TAILQ_HEAD(idlist, identry) idlist; >+}; >+ >+struct idcache uidcache; >+struct idcache gidcache; >+ >+static char * >+lookup_uid(id_t id) >+{ >+ struct passwd *pw; >+ >+ if ((pw = getpwuid((uid_t)id)) == NULL) >+ return NULL; >+ else { >+ debug3("lookup_uid %u found %s", (u_int)id, pw->pw_name); >+ return xstrdup(pw->pw_name); >+ } >+} >+ >+static char * >+lookup_gid(id_t id) >+{ >+ struct group *gr; >+ >+ if ((gr = getgrgid((gid_t)id)) == NULL) >+ return NULL; >+ else { >+ debug3("lookup_gid %u found %s", (u_int)id, gr->gr_name); >+ return xstrdup(gr->gr_name); >+ } >+} >+ >+static char * >+lookup_id(struct idcache *idcache, char * (*lookup_func)(id_t), id_t id, >+ int remote) >+{ >+ char *name; >+ struct identry *entry; >+ >+ if (idcache->nentries == 0) >+ TAILQ_INIT(&(idcache->idlist)); >+ >+ /* search for exising entry */ >+ TAILQ_FOREACH(entry, &(idcache->idlist), next) >+ if (entry->id == id) { >+ debug3("id cache hit for %u (%s)", (uid_t)id, >+ entry->name); >+ TAILQ_REMOVE(&(idcache->idlist), entry, next); >+ goto out; >+ } >+ /* not found, either recycle oldest entry or create a new one */ >+ if (idcache->nentries > ID_CACHE_SIZE) { >+ entry = TAILQ_LAST(&(idcache->idlist), idlist); >+ TAILQ_REMOVE(&(idcache->idlist), entry, next); >+ debug3("recycling last cache entry: %u (%s)", >+ (u_int)entry->id, entry->name); >+ xfree(entry->name); >+ } else { >+ entry = xmalloc(sizeof(*entry)); >+ idcache->nentries++; >+ } >+ /* lookup name, if that fails populate with numeric id */ >+ if (remote || (name = (lookup_func)(id)) == NULL) >+ xasprintf(&name, "%u", (u_int)id); >+ entry->id = id; >+ entry->name = name; >+ >+ out: >+ debug3("inserting cache entry for %u (%s)", (u_int)entry->id, >+ entry->name); >+ TAILQ_INSERT_HEAD(&(idcache->idlist), entry, next); >+ return entry->name; >+} >+ > /* > * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh > */ >@@ -186,26 +270,14 @@ char * > ls_file(const char *name, const struct stat *st, int remote, int si_units) > { > int ulen, glen, sz = 0; >- struct passwd *pw; >- struct group *gr; > struct tm *ltime = localtime(&st->st_mtime); > char *user, *group; >- char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1]; >+ char buf[1024], mode[11+1], tbuf[12+1]; > char sbuf[FMT_SCALED_STRSIZE]; > > strmode(st->st_mode, mode); >- if (!remote && (pw = getpwuid(st->st_uid)) != NULL) { >- user = pw->pw_name; >- } else { >- snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid); >- user = ubuf; >- } >- if (!remote && (gr = getgrgid(st->st_gid)) != NULL) { >- group = gr->gr_name; >- } else { >- snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid); >- group = gbuf; >- } >+ user = lookup_id(&uidcache, lookup_uid, st->st_uid, remote); >+ group = lookup_id(&gidcache, lookup_gid, st->st_gid, remote); > if (ltime != NULL) { > if (time(NULL) - st->st_mtime < (365*24*60*60)/2) > sz = strftime(tbuf, sizeof tbuf, "%b %e %H:%M", ltime);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1495
: 1779