1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

r24639: Add parameter "directory name cache size" - parameterize

use of directory name cache, 100 by default. Will be needed
to turn this off for *BSD systems.
Jeremy.
(This used to be commit bea8e9840f)
This commit is contained in:
Jeremy Allison 2007-08-23 21:53:00 +00:00 committed by Gerald (Jerry) Carter
parent a689f6082b
commit f1041f98ce
2 changed files with 41 additions and 21 deletions

View File

@ -471,6 +471,7 @@ typedef struct {
int iAioReadSize; int iAioReadSize;
int iAioWriteSize; int iAioWriteSize;
int iMap_readonly; int iMap_readonly;
int iDirectoryNameCacheSize;
param_opt_struct *param_opt; param_opt_struct *param_opt;
char dummy[3]; /* for alignment */ char dummy[3]; /* for alignment */
@ -611,7 +612,11 @@ static service sDefault = {
0, /* iAioReadSize */ 0, /* iAioReadSize */
0, /* iAioWriteSize */ 0, /* iAioWriteSize */
MAP_READONLY_YES, /* iMap_readonly */ MAP_READONLY_YES, /* iMap_readonly */
#ifdef BROKEN_DIRECTORY_HANDLING
0, /* iDirectoryNameCacheSize */
#else
100, /* iDirectoryNameCacheSize */
#endif
NULL, /* Parametric options */ NULL, /* Parametric options */
"" /* dummy */ "" /* dummy */
@ -1031,6 +1036,7 @@ static struct parm_struct parm_table[] = {
{"getwd cache", P_BOOL, P_GLOBAL, &use_getwd_cache, NULL, NULL, FLAG_ADVANCED}, {"getwd cache", P_BOOL, P_GLOBAL, &use_getwd_cache, NULL, NULL, FLAG_ADVANCED},
{"keepalive", P_INTEGER, P_GLOBAL, &Globals.iKeepalive, NULL, NULL, FLAG_ADVANCED}, {"keepalive", P_INTEGER, P_GLOBAL, &Globals.iKeepalive, NULL, NULL, FLAG_ADVANCED},
{"change notify", P_BOOL, P_LOCAL, &sDefault.bChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE }, {"change notify", P_BOOL, P_LOCAL, &sDefault.bChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
{"directory name cache size", P_INTEGER, P_LOCAL, &sDefault.iDirectoryNameCacheSize, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
{"kernel change notify", P_BOOL, P_LOCAL, &sDefault.bKernelChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE }, {"kernel change notify", P_BOOL, P_LOCAL, &sDefault.bKernelChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
{"lpq cache time", P_INTEGER, P_GLOBAL, &Globals.lpqcachetime, NULL, NULL, FLAG_ADVANCED}, {"lpq cache time", P_INTEGER, P_GLOBAL, &Globals.lpqcachetime, NULL, NULL, FLAG_ADVANCED},
@ -2178,6 +2184,7 @@ FN_LOCAL_INTEGER(lp_allocation_roundup_size, iallocation_roundup_size)
FN_LOCAL_INTEGER(lp_aio_read_size, iAioReadSize) FN_LOCAL_INTEGER(lp_aio_read_size, iAioReadSize)
FN_LOCAL_INTEGER(lp_aio_write_size, iAioWriteSize) FN_LOCAL_INTEGER(lp_aio_write_size, iAioWriteSize)
FN_LOCAL_INTEGER(lp_map_readonly, iMap_readonly) FN_LOCAL_INTEGER(lp_map_readonly, iMap_readonly)
FN_LOCAL_INTEGER(lp_directory_name_cache_size, iDirectoryNameCacheSize)
FN_LOCAL_CHAR(lp_magicchar, magic_char) FN_LOCAL_CHAR(lp_magicchar, magic_char)
FN_GLOBAL_INTEGER(lp_winbind_cache_time, &Globals.winbind_cache_time) FN_GLOBAL_INTEGER(lp_winbind_cache_time, &Globals.winbind_cache_time)
FN_GLOBAL_LIST(lp_winbind_nss_info, &Globals.szWinbindNssInfo) FN_GLOBAL_LIST(lp_winbind_nss_info, &Globals.szWinbindNssInfo)

View File

@ -32,8 +32,6 @@ extern struct current_user current_user;
/* Make directory handle internals available. */ /* Make directory handle internals available. */
#define NAME_CACHE_SIZE 100
struct name_cache_entry { struct name_cache_entry {
char *name; char *name;
long offset; long offset;
@ -44,6 +42,7 @@ struct smb_Dir {
SMB_STRUCT_DIR *dir; SMB_STRUCT_DIR *dir;
long offset; long offset;
char *dir_path; char *dir_path;
size_t name_cache_size;
struct name_cache_entry *name_cache; struct name_cache_entry *name_cache;
unsigned int name_cache_index; unsigned int name_cache_index;
unsigned int file_number; unsigned int file_number;
@ -1061,12 +1060,14 @@ BOOL is_visible_file(connection_struct *conn, const char *dir_path, const char *
struct smb_Dir *OpenDir(connection_struct *conn, const char *name, const char *mask, uint32 attr) struct smb_Dir *OpenDir(connection_struct *conn, const char *name, const char *mask, uint32 attr)
{ {
struct smb_Dir *dirp = SMB_MALLOC_P(struct smb_Dir); struct smb_Dir *dirp = SMB_MALLOC_P(struct smb_Dir);
if (!dirp) { if (!dirp) {
return NULL; return NULL;
} }
ZERO_STRUCTP(dirp); ZERO_STRUCTP(dirp);
dirp->conn = conn; dirp->conn = conn;
dirp->name_cache_size = lp_directory_name_cache_size(SNUM(conn));
dirp->dir_path = SMB_STRDUP(name); dirp->dir_path = SMB_STRDUP(name);
if (!dirp->dir_path) { if (!dirp->dir_path) {
@ -1078,9 +1079,14 @@ struct smb_Dir *OpenDir(connection_struct *conn, const char *name, const char *m
goto fail; goto fail;
} }
dirp->name_cache = SMB_CALLOC_ARRAY(struct name_cache_entry, NAME_CACHE_SIZE); if (dirp->name_cache_size) {
if (!dirp->name_cache) { dirp->name_cache = SMB_CALLOC_ARRAY(struct name_cache_entry,
goto fail; dirp->name_cache_size);
if (!dirp->name_cache) {
goto fail;
}
} else {
dirp->name_cache = NULL;
} }
dirhandles_open++; dirhandles_open++;
@ -1113,7 +1119,7 @@ int CloseDir(struct smb_Dir *dirp)
} }
SAFE_FREE(dirp->dir_path); SAFE_FREE(dirp->dir_path);
if (dirp->name_cache) { if (dirp->name_cache) {
for (i = 0; i < NAME_CACHE_SIZE; i++) { for (i = 0; i < dirp->name_cache_size; i++) {
SAFE_FREE(dirp->name_cache[i].name); SAFE_FREE(dirp->name_cache[i].name);
} }
} }
@ -1229,7 +1235,12 @@ void DirCacheAdd(struct smb_Dir *dirp, const char *name, long offset)
{ {
struct name_cache_entry *e; struct name_cache_entry *e;
dirp->name_cache_index = (dirp->name_cache_index+1) % NAME_CACHE_SIZE; if (!dirp->name_cache_size || !dirp->name_cache) {
return;
}
dirp->name_cache_index = (dirp->name_cache_index+1) %
dirp->name_cache_size;
e = &dirp->name_cache[dirp->name_cache_index]; e = &dirp->name_cache[dirp->name_cache_index];
SAFE_FREE(e->name); SAFE_FREE(e->name);
e->name = SMB_STRDUP(name); e->name = SMB_STRDUP(name);
@ -1248,20 +1259,22 @@ BOOL SearchDir(struct smb_Dir *dirp, const char *name, long *poffset)
connection_struct *conn = dirp->conn; connection_struct *conn = dirp->conn;
/* Search back in the name cache. */ /* Search back in the name cache. */
for (i = dirp->name_cache_index; i >= 0; i--) { if (dirp->name_cache_size && dirp->name_cache) {
struct name_cache_entry *e = &dirp->name_cache[i]; for (i = dirp->name_cache_index; i >= 0; i--) {
if (e->name && (conn->case_sensitive ? (strcmp(e->name, name) == 0) : strequal(e->name, name))) { struct name_cache_entry *e = &dirp->name_cache[i];
*poffset = e->offset; if (e->name && (conn->case_sensitive ? (strcmp(e->name, name) == 0) : strequal(e->name, name))) {
SeekDir(dirp, e->offset); *poffset = e->offset;
return True; SeekDir(dirp, e->offset);
return True;
}
} }
} for (i = dirp->name_cache_size - 1; i > dirp->name_cache_index; i--) {
for (i = NAME_CACHE_SIZE-1; i > dirp->name_cache_index; i--) { struct name_cache_entry *e = &dirp->name_cache[i];
struct name_cache_entry *e = &dirp->name_cache[i]; if (e->name && (conn->case_sensitive ? (strcmp(e->name, name) == 0) : strequal(e->name, name))) {
if (e->name && (conn->case_sensitive ? (strcmp(e->name, name) == 0) : strequal(e->name, name))) { *poffset = e->offset;
*poffset = e->offset; SeekDir(dirp, e->offset);
SeekDir(dirp, e->offset); return True;
return True; }
} }
} }