address regression in duplicate map entry order
Subsystems (2)
RFC PATCH 1/1 address regression in duplicate map entry order
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in lookup_ghost, and then go ahead and only insert new entries (instead of overwriting what was there).
So, I've implemented this, though it isn't tested just yet. There were some other bugs.
In lookup_multi, we iterate through each map's lookup_ghost function. The problem here is that you will end up doing the following:
static int read_map(const char *root, struct lookup_context *ctxt)
{
char key[KEY_MAX_LEN + 1];
char mapent[MAPENT_MAX_LEN + 1];
char *mapname;
FILE *f;
int entry;
time_t age = time(NULL); <=================
mapname = alloca(strlen(ctxt->mapname) + 6);
sprintf(mapname, "file:%s", ctxt->mapname);
f = fopen(ctxt->mapname, "r");
if (!f) {
error(MODPREFIX "could not open map file %s", ctxt->mapname);
return 0;
}
while(1) {
entry = read_one(f, key, mapent);
if (entry)
cache_update(root, key, mapent, age); <==========
if (feof(f))
break;
}
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); <=============
return 1;
}Notice the lines I've pointed out. We decide what the expiration age should be at the beginning of the function. We update entries and give them that "age." And finally, we expire all entries that were made prior to that. The problem arises in that we call the read_map routine for each map in the list in order. What will happen is that each map, as it is processed, will end up with a new value for age. Thus, we expire all of the work done by the previous read_maps! This is bad. To fix this, I've passed in the age field from the top-level.
I've changed ldap's lookup_ghost routine (well, a function it calls, anyway) to use cache_insert_unique instead of cache_add.
Please let me know what you think. If you only like some parts, let me know which ones and I'll break them out from the rest of the patch. BTW, this patch is applied on top of your map expiration changes. I can rediff the thing to any version of the code you want.
-Jeff
Only in autofs-4.1.3-new: Makefile.conf
Only in autofs-4.1.3-new: config.log
Only in autofs-4.1.3-new: config.status
Only in autofs-4.1.3-new/daemon: automount
daemon/automount.c +8 -4
@@ -825,7 +825,8 @@ static int st_readmap(void) {int status; - status = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context); + status = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context, +time (NULL ));debug ("st_readmap: status %d\n" , status);
@@ -1502,7 +1503,8 @@ static void sig_supervisor(int sig)break ;case SIGHUP : - ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context); + ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context, +time (NULL ));/* Pass on the reread event and ignore self signal */ kill (0 ,SIGHUP );
@@ -1520,7 +1522,8 @@ int supervisor(char *path) ap.path =alloca (strlen (path) +1 );strcpy (ap.path, path); - map = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context); + map = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context, +time (NULL ));if (map &LKP_FAIL ) {error ("failed to load map exiting" );cleanup_exit (ap.path,1 );
@@ -1588,7 +1591,8 @@ int handle_mounts(char *path)alarm (ap.exp_runfreq + my_pid % ap.exp_runfreq); } - map = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context); + map = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context, +time (NULL ));if (map &LKP_FAIL ) {if (map &LKP_INDIRECT ) { error("bad map format: found indirect, "
Only in autofs-4.1.3-new/daemon: automount.c~
Only in autofs-4.1.3-new/daemon: automount.o
Only in autofs-4.1.3-new/daemon: module.o
Only in autofs-4.1.3-new/daemon: mount.o
Only in autofs-4.1.3-new/daemon: spawn.o
include/automount.h +3 -2
@@ -140,12 +140,12 @@ int is_mounted(const char *path);#ifdef MODULE_LOOKUP int lookup_init (const char *mapfmt,int argc,const char *const *argv,void **context); -int lookup_ghost (const char *,int ,void *); +int lookup_ghost (const char *,int ,void *,time_t );int lookup_mount (const char *,const char *,int ,void *);int lookup_done (void *);#endif typedef int (*lookup_init_t ) (const char *,int ,const char *const *,void **); -typedef int (*lookup_ghost_t ) (const char *,int ,void *); +typedef int (*lookup_ghost_t ) (const char *,int ,void *,time_t );typedef int (*lookup_mount_t ) (const char *,const char *,int ,void *);typedef int (*lookup_done_t ) (void *);
@@ -236,6 +236,7 @@ struct mapent_cache *cache_lookup_first(struct mapent_cache *cache_partial_match (const char *prefix);int cache_add (const char *root,const char *key,const char *mapent,time_t age);int cache_update (const char *root,const char *key,const char *mapent,time_t age); +int cache_insert_unique (const char *root,const char *key,const char *mapent,time_t age);int cache_delete (const char *root,const char *key,int rmpath);void cache_clean (const char *root,time_t age);void cache_release (void );
Only in autofs-4.1.3-new/include: automount.h~
Only in autofs-4.1.3-new/include: config.h
Only in autofs-4.1.3-new/lib: autofs.a
lib/cache.c +24 -0
@@ -197,6 +197,30 @@ int cache_add(const char *root, const chreturn CHE_OK ; } +int cache_insert_unique (const char *root,const char *key,const char *mapent,time_t age) +{ +struct mapent_cache *s, *me =NULL ; +char *pent; +int ret =CHE_OK ; + +for (s = mapent_hash[hash (key)]; s !=NULL ; s = s->next) +if (strcmp (key, s->key) ==0 ) { + me = s; +break ; + } + +if (!me) { + ret =cache_add (root, key, mapent, age); +if (!ret) { +debug ("cache_add: failed for %s" , key); +return CHE_FAIL ; + } + ret =CHE_UPDATED ; + } + +return ret; +} +int cache_update (const char *root,const char *key,const char *mapent,time_t age) {struct mapent_cache *s, *me =NULL ;
Only in autofs-4.1.3-new/lib: cache.c~
Only in autofs-4.1.3-new/lib: cache.o
Only in autofs-4.1.3-new/lib: cat_path.o
Only in autofs-4.1.3-new/lib: listmount.o
Only in autofs-4.1.3-new/lib: mount.h
Only in autofs-4.1.3-new/lib: mount_clnt.c
Only in autofs-4.1.3-new/lib: mount_clnt.o
Only in autofs-4.1.3-new/lib: mount_xdr.c
Only in autofs-4.1.3-new/lib: mount_xdr.o
Only in autofs-4.1.3-new/lib: rpc_subs.o
Only in autofs-4.1.3-new/man: autofs.8
modules/lookup_file.c +6 -8
@@ -227,14 +227,13 @@ static int read_one(FILE *f, char *key,return 0 ; } -static int read_map (const char *root,struct lookup_context *ctxt) +static int read_map (const char *root,struct lookup_context *ctxt,time_t age) {char key[KEY_MAX_LEN +1 ];char mapent[MAPENT_MAX_LEN +1 ];char *mapname;FILE *f;int entry; -time_t age =time (NULL ); mapname =alloca (strlen (ctxt->mapname) +6 );sprintf (mapname,"file:%s" , ctxt->mapname);
@@ -245,10 +244,12 @@ static int read_map(const char *root, streturn 0 ; } +/* Clean all entries from the cache */ +cache_clean (root, age);while (1 ) { entry =read_one (f, key, mapent);if (entry) -cache_update (root, key, mapent, age); +cache_insert_unique (root, key, mapent, age);if (feof (f))break ;
@@ -256,20 +257,17 @@ static int read_map(const char *root, stfclose (f); -/* Clean stale entries from the cache */ -cache_clean (root, age); -return 1 ; } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,void *context,time_t age) {struct lookup_context *ctxt = (struct lookup_context *) context;struct mapent_cache *me;struct stat st;int status =1 ; -if (!read_map (root, ctxt)) +if (!read_map (root, ctxt, age))return LKP_FAIL ;if (stat (ctxt->mapname, &st)) {
Only in autofs-4.1.3-new/modules: lookup_file.c~
Only in autofs-4.1.3-new/modules: lookup_file.so
modules/lookup_hesiod.c +1 -1
@@ -66,7 +66,7 @@ int lookup_init(const char *mapfmt, intreturn !(ctxt->parser =open_parse (mapfmt,MODPREFIX , argc -1 , argv +1 )); } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,void *context,time_t age) {return LKP_NOTSUP ; }
Only in autofs-4.1.3-new/modules: lookup_hesiod.c~ Only in autofs-4.1.3-new/modules: lookup_hesiod.so
modules/lookup_ldap.c +8 -8
@@ -262,7 +262,7 @@ static int read_one_map(const char *rootfor (i =0 ; i < count; i++) {if (**keyValue =='/' &&strlen (*keyValue) ==1 ) **keyValue ='*' ; -cache_add (root, *keyValue, values[i], age); +cache_insert_unique (root, *keyValue, values[i], age); }ldap_value_free (values);
@@ -280,11 +280,14 @@ static int read_one_map(const char *root }static int read_map (const char *root,struct lookup_context *ctxt, -const char *key,int keyvallen,int *result_ldap) +const char *key,int keyvallen,int *result_ldap, +time_t age) { -time_t age =time (NULL );int rv =LDAP_SUCCESS ; +/* Clean all entries from the cache */ +cache_clean (root, age); +/* all else fails read entire map */ if (!read_one_map (root,"nisObject" ,"cn" , key, keyvallen,"nisMapEntry" , ctxt, &rv)) {
@@ -297,13 +300,10 @@ static int read_map(const char *root, st } } -/* Clean stale entries from the cache */ -cache_clean (root, age); -return 1 ; } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,void *context,time_t age) {struct lookup_context *ctxt = (struct lookup_context *) context;struct mapent_cache *me;
@@ -312,7 +312,7 @@ int lookup_ghost(const char *root, int gchdir ("/" ); -if (!read_map (root, ctxt,NULL ,0 , &rv)) +if (!read_map (root, ctxt,NULL ,0 , &rv, age))switch (rv) {case LDAP_SIZELIMIT_EXCEEDED :case LDAP_UNWILLING_TO_PERFORM :
Only in autofs-4.1.3-new/modules: lookup_ldap.c~
Only in autofs-4.1.3-new/modules: lookup_ldap.so
modules/lookup_multi.c +2 -2
@@ -111,14 +111,14 @@ int lookup_init(const char *my_mapfmt, ireturn 1 ; } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,void *context,time_t age) {struct lookup_context *ctxt = (struct lookup_context *) context;int i, ret, at_least_1 =0 ;for (i =0 ; i < ctxt->n; i++) { ret = ctxt->m[i].mod->lookup_ghost (root, ghost, - ctxt->m[i].mod->context); + ctxt->m[i].mod->context, age);if (ret &LKP_FAIL )continue ;
Only in autofs-4.1.3-new/modules: lookup_multi.c~
Only in autofs-4.1.3-new/modules: lookup_multi.so
modules/lookup_nisplus.c +1 -1
@@ -59,7 +59,7 @@ int lookup_init(const char *mapfmt, intreturn !(ctxt->parse =open_parse (mapfmt,MODPREFIX , argc -1 , argv +1 )); } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,void *context,time_t age) {return LKP_NOTSUP ; }
Only in autofs-4.1.3-new/modules: lookup_nisplus.c~ Only in autofs-4.1.3-new/modules: lookup_nisplus.so
modules/lookup_program.c +1 -1
@@ -76,7 +76,7 @@ int lookup_init(const char *mapfmt, intreturn !(ctxt->parse =open_parse (mapfmt,MODPREFIX , argc -1 , argv +1 )); } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,void *context,time_t age) {return LKP_NOTSUP ; }
Only in autofs-4.1.3-new/modules: lookup_program.c~ Only in autofs-4.1.3-new/modules: lookup_program.so
modules/lookup_userhome.c +1 -1
@@ -36,7 +36,7 @@ int lookup_init(const char *mapfmt, intreturn 0 ;/* Nothing to do */ } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,void *context,time_t age) {return LKP_NOTSUP ; }
Only in autofs-4.1.3-new/modules: lookup_userhome.c~ Only in autofs-4.1.3-new/modules: lookup_userhome.so
modules/lookup_yp.c +7 -8
@@ -109,18 +109,20 @@ int yp_all_callback(int status, char *ypstrncpy (mapent, val, vallen); *(mapent + vallen) ='\0' ; -cache_update (root, key, mapent, age); +cache_insert_unique (root, key, mapent, age);return 0 ; } -static int read_map (const char *root,struct lookup_context *context) +static int read_map (const char *root,struct lookup_context *context,time_t age) {struct lookup_context *ctxt = (struct lookup_context *) context;struct ypall_callback ypcb; -time_t age =time (NULL );int err; +/* Clean all entries from the cache */ +cache_clean (root, age); + ypcb.foreach = yp_all_callback; ypcb.data = (char *) root;
@@ -132,19 +134,16 @@ static int read_map(const char *root, streturn 0 ; } -/* Clean stale entries from the cache */ -cache_clean (root, age); -return 1 ; } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,void *context,time_t age) {struct lookup_context *ctxt = (struct lookup_context *) context;struct mapent_cache *me;int status =1 ; -if (!read_map (root, ctxt)) +if (!read_map (root, ctxt, age))return LKP_FAIL ; status =cache_ghost (root, ghost, ctxt->mapname,"yp" , ctxt->parse);
Only in autofs-4.1.3-new/modules: lookup_yp.c~ Only in autofs-4.1.3-new/modules: lookup_yp.so Only in autofs-4.1.3-new/modules: mount_afs.so Only in autofs-4.1.3-new/modules: mount_autofs.so Only in autofs-4.1.3-new/modules: mount_bind.so Only in autofs-4.1.3-new/modules: mount_changer.so Only in autofs-4.1.3-new/modules: mount_ext2.so Only in autofs-4.1.3-new/modules: mount_generic.so Only in autofs-4.1.3-new/modules: mount_nfs.so Only in autofs-4.1.3-new/modules: parse_hesiod.so Only in autofs-4.1.3-new/modules: parse_sun.so Only in autofs-4.1.3-new/samples: autofs-ldap-auto-master Only in autofs-4.1.3-new/samples: autofs-ldap-auto-master.o Only in autofs-4.1.3-new/samples: rc.autofs
[email protected]
maintainerQuoted 57 lines · Jeff Moyer
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead and only insert new entries (instead of overwriting what was there).So, I've implemented this, though it isn't tested just yet. There were some other bugs.
In
lookup_multi, we iterate through each map'slookup_ghostfunction. The problem here is that you will end up doing the following:static int
read_map(const char *root, struct lookup_context *ctxt){ char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char *mapname; FILE *f; int entry; time_t age = time(NULL); <================= mapname = alloca(strlen(ctxt->mapname) + 6); sprintf(mapname, "file:%s", ctxt->mapname); f = fopen(ctxt->mapname, "r"); if (!f) { error(MODPREFIX "could not open map file %s", ctxt->mapname); return 0; } while(1) { entry = read_one(f, key, mapent); if (entry) cache_update(root, key, mapent, age); <========== if (feof(f)) break; } fclose(f); /* Clean stale entries from the cache */ cache_clean(root, age); <============= return 1; }Notice the lines I've pointed out. We decide what the expiration age should be at the beginning of the function. We update entries and give them that "age." And finally, we expire all entries that were made prior to that. The problem arises in that we call the
read_maproutine for each map in the list in order. What will happen is that each map, as it is processed, will end up with a new value for age. Thus, we expire all of the work done by the previousread_maps! This is bad. To fix this, I've passed in the age field from the top-level.
Quoted 7 lines
I've changed ldap's
lookup_ghostroutine (well, a function it calls, anyway) to usecache_insert_uniqueinstead ofcache_add.Please let me know what you think. If you only like some parts, let me know which ones and I'll break them out from the rest of the patch. BTW, this patch is applied on top of your map expiration changes. I can rediff the thing to any version of the code you want.
Understand the problem.
I've had a look at the patch and it looks good.
I had a slightly different idea though.
I think the cache_insert_unique might be a problem later as if people add multiple attributes (map entries) for multi-mount keys, instead of one attribute containing multiple mounts, in what they think is "the LDAP way" it probably won't work. I can't say we've seen this problem yet but I have been trying to allow for it in the code.
The other thing that occured to me was that, together with passing the time to keep things consistent, processing the maps in reverse order in lookup_ghost of the multi map module would fix most of the issues. Along with modifying cache_add to append to any existing entries, rather than prepend.
I spotted something you missed in the yp module. Have a look at the lookup_yp patch chunks in the attached map-entry-order patch.
Have a look at what I've tried to do and let me know what you think. I've done some basic testing but not against the issue we are trying to fix. So let me know how it goes.
Also, I found a couple of other bugs and have attached a couple of other patches as well.
Ian
daemon/automount.c renamed from daemon/automount.c.map-entry-order +4 -4
@@ -825,7 +825,7 @@ static int st_readmap(void) {int status; - status = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context); + status = ap.lookup->lookup_ghost (ap.path, ap.ghost,0 , ap.lookup->context);debug ("st_readmap: status %d\n" , status);
@@ -1502,7 +1502,7 @@ static void sig_supervisor(int sig)break ;case SIGHUP : - ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context); + ap.lookup->lookup_ghost (ap.path, ap.ghost,0 , ap.lookup->context);/* Pass on the reread event and ignore self signal */ kill (0 ,SIGHUP );
@@ -1520,7 +1520,7 @@ int supervisor(char *path) ap.path =alloca (strlen (path) +1 );strcpy (ap.path, path); - map = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context); + map = ap.lookup->lookup_ghost (ap.path, ap.ghost,0 , ap.lookup->context);if (map &LKP_FAIL ) {error ("failed to load map exiting" );cleanup_exit (ap.path,1 );
@@ -1588,7 +1588,7 @@ int handle_mounts(char *path)alarm (ap.exp_runfreq + my_pid % ap.exp_runfreq); } - map = ap.lookup->lookup_ghost (ap.path, ap.ghost, ap.lookup->context); + map = ap.lookup->lookup_ghost (ap.path, ap.ghost,0 , ap.lookup->context);if (map &LKP_FAIL ) {if (map &LKP_INDIRECT ) { error("bad map format: found indirect, "
include/automount.h renamed from include/automount.h.map-entry-order +2 -2
@@ -140,12 +140,12 @@ int is_mounted(const char *path);#ifdef MODULE_LOOKUP int lookup_init (const char *mapfmt,int argc,const char *const *argv,void **context); -int lookup_ghost (const char *,int ,void *); +int lookup_ghost (const char *,int ,time_t ,void *);int lookup_mount (const char *,const char *,int ,void *);int lookup_done (void *);#endif typedef int (*lookup_init_t ) (const char *,int ,const char *const *,void **); -typedef int (*lookup_ghost_t ) (const char *,int ,void *); +typedef int (*lookup_ghost_t ) (const char *,int ,time_t ,void *);typedef int (*lookup_mount_t ) (const char *,const char *,int ,void *);typedef int (*lookup_done_t ) (void *);
lib/cache.c renamed from lib/cache.c.map-entry-order +22 -3
@@ -165,7 +165,7 @@ struct mapent_cache *cache_partial_matchint cache_add (const char *root,const char *key,const char *mapent,time_t age) { -struct mapent_cache *me =NULL ; +struct mapent_cache *me =NULL , *existing =NULL ;char *pkey, *pent;unsigned int hashval =hash (key);char *path;
@@ -191,8 +191,27 @@ int cache_add(const char *root, const ch me->mapent =strcpy (pent, mapent); me->age = age; - me->next = mapent_hash[hashval]; - mapent_hash[hashval] = me; +/* +* We need to add to the end if values exist in order to +* preserve the order in which the map was read on lookup. +*/ + existing =cache_lookup (key); +if (!existing) { + me->next = mapent_hash[hashval]; + mapent_hash[hashval] = me; + }else { +while (1 ) { +struct mapent_cache *next; + + next =cache_lookup_next (existing); +if (!next) +break ; + + existing = next; + } + me->next = existing->next; + existing->next = me; + }return CHE_OK ; }
modules/lookup_file.c renamed from modules/lookup_file.c.map-entry-order +4 -4
@@ -227,14 +227,14 @@ static int read_one(FILE *f, char *key,return 0 ; } -static int read_map (const char *root,struct lookup_context *ctxt) +static int read_map (const char *root,time_t now,struct lookup_context *ctxt) {char key[KEY_MAX_LEN +1 ];char mapent[MAPENT_MAX_LEN +1 ];char *mapname;FILE *f;int entry; -time_t age =time (NULL ); +time_t age = now ? now :time (NULL ); mapname =alloca (strlen (ctxt->mapname) +6 );sprintf (mapname,"file:%s" , ctxt->mapname);
@@ -262,14 +262,14 @@ static int read_map(const char *root, streturn 1 ; } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,time_t now,void *context) {struct lookup_context *ctxt = (struct lookup_context *) context;struct mapent_cache *me;struct stat st;int status =1 ; -if (!read_map (root, ctxt)) +if (!read_map (root, now, ctxt))return LKP_FAIL ;if (stat (ctxt->mapname, &st)) {
modules/lookup_hesiod.c renamed from modules/lookup_hesiod.c.map-entry-order +1 -1
@@ -66,7 +66,7 @@ int lookup_init(const char *mapfmt, intreturn !(ctxt->parser =open_parse (mapfmt,MODPREFIX , argc -1 , argv +1 )); } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,time_t now,void *context) {return LKP_NOTSUP ; }
modules/lookup_ldap.c renamed from modules/lookup_ldap.c.map-entry-order +7 -8
@@ -174,10 +174,9 @@ static int read_one_map(const char *root const char *class, char *key, const char *keyval, int keyvallen, char *type, struct lookup_context *ctxt, - int *result_ldap) + time_t age, int *result_ldap) { int rv, i, l, count; -time_t age =time (NULL );char *query;LDAPMessage *result, *e;char **keyValue =NULL ;
@@ -280,17 +279,16 @@ static int read_one_map(const char *root }static int read_map (const char *root,struct lookup_context *ctxt, -const char *key,int keyvallen,int *result_ldap) +const char *key,int keyvallen,time_t age,int *result_ldap) { -time_t age =time (NULL );int rv =LDAP_SUCCESS ;/* all else fails read entire map */ if (!read_one_map (root,"nisObject" ,"cn" , - key, keyvallen,"nisMapEntry" , ctxt, &rv)) { + key, keyvallen,"nisMapEntry" , ctxt, age, &rv)) {if ((rv !=LDAP_SUCCESS ) || !read_one_map (root,"automount" ,"cn" , key, keyvallen, -"automountInformation" , ctxt, &rv)) { +"automountInformation" , ctxt, age, &rv)) {if (result_ldap !=NULL ) *result_ldap = rv;return 0 ;
@@ -303,16 +301,17 @@ static int read_map(const char *root, streturn 1 ; } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,time_t now,void *context) {struct lookup_context *ctxt = (struct lookup_context *) context;struct mapent_cache *me;int status =1 , rv =LDAP_SUCCESS ;char *mapname; +time_t age = now ? now :time (NULL );chdir ("/" ); -if (!read_map (root, ctxt,NULL ,0 , &rv)) +if (!read_map (root, ctxt,NULL ,0 , age, &rv))switch (rv) {case LDAP_SIZELIMIT_EXCEEDED :case LDAP_UNWILLING_TO_PERFORM :
modules/lookup_multi.c renamed from modules/lookup_multi.c.map-entry-order +7 -3
@@ -111,13 +111,17 @@ int lookup_init(const char *my_mapfmt, ireturn 1 ; } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,time_t now,void *context) {struct lookup_context *ctxt = (struct lookup_context *) context;int i, ret, at_least_1 =0 ; -for (i =0 ; i < ctxt->n; i++) { - ret = ctxt->m[i].mod->lookup_ghost (root, ghost, +/* +* Read each map in reverse order to ensure that when we lookup a key +* in the cache we get what would be seen first. +*/ +for (i = ctxt->n -1 ; i >=0 ; i--) { + ret = ctxt->m[i].mod->lookup_ghost (root, ghost, now, ctxt->m[i].mod->context);if (ret &LKP_FAIL )continue ;
modules/lookup_nisplus.c renamed from modules/lookup_nisplus.c.map-entry-order +1 -1
@@ -59,7 +59,7 @@ int lookup_init(const char *mapfmt, intreturn !(ctxt->parse =open_parse (mapfmt,MODPREFIX , argc -1 , argv +1 )); } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,time_t now,void *context) {return LKP_NOTSUP ; }
modules/lookup_program.c renamed from modules/lookup_program.c.map-entry-order +1 -1
@@ -76,7 +76,7 @@ int lookup_init(const char *mapfmt, intreturn !(ctxt->parse =open_parse (mapfmt,MODPREFIX , argc -1 , argv +1 )); } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,time_t now,void *context) {return LKP_NOTSUP ; }
modules/lookup_userhome.c renamed from modules/lookup_userhome.c.map-entry-order +1 -1
@@ -36,7 +36,7 @@ int lookup_init(const char *mapfmt, intreturn 0 ;/* Nothing to do */ } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,time_t now,void *context) {return LKP_NOTSUP ; }
modules/lookup_yp.c renamed from modules/lookup_yp.c.map-entry-order +12 -15
@@ -44,16 +44,8 @@ struct lookup_context { };struct callback_data { -int status; -int map;const char *root; -char direct_base[KEY_MAX_LEN +1 ]; -const char *name; -int name_len; -unsigned long type; -const char *mapname;time_t age; -struct lookup_context *context; };int lookup_version =AUTOFS_LOOKUP_VERSION ;/* Required by protocol */
@@ -93,8 +85,9 @@ int lookup_init(const char *mapfmt, intint yp_all_callback (int status,char *ypkey,int ypkeylen,char *val,int vallen,char *ypcb_data) { -time_t age =time (NULL ); -char *root = ypcb_data; +struct callback_data *cbdata = (struct callback_data *) ypcb_data; +char *root = cbdata->root; +time_t age = cbdata->age;char *key;char *mapent;
@@ -114,15 +107,18 @@ int yp_all_callback(int status, char *ypreturn 0 ; } -static int read_map (const char *root,struct lookup_context *context) +static int read_map (const char *root,time_t age,struct lookup_context *context) {struct lookup_context *ctxt = (struct lookup_context *) context;struct ypall_callback ypcb; -time_t age =time (NULL ); +struct callback_data ypcb_data;int err; + ypcb_data.root = root; + ypcb_data.age = age; + ypcb.foreach = yp_all_callback; - ypcb.data = (char *) root; + ypcb.data = (char *) &ypcb_data; err =yp_all ((char *) ctxt->domainname, (char *) ctxt->mapname, &ypcb);
@@ -138,13 +134,14 @@ static int read_map(const char *root, streturn 1 ; } -int lookup_ghost (const char *root,int ghost,void *context) +int lookup_ghost (const char *root,int ghost,time_t now,void *context) {struct lookup_context *ctxt = (struct lookup_context *) context; +time_t age = now ? now :time (NULL );struct mapent_cache *me;int status =1 ; -if (!read_map (root, ctxt)) +if (!read_map (root, age, ctxt))return LKP_FAIL ; status =cache_ghost (root, ghost, ctxt->mapname,"yp" , ctxt->parse);
modules/lookup_yp.c renamed from modules/lookup_yp.c.direct-lookup +1 -1
@@ -235,7 +235,7 @@ int lookup_mount(const char *root, constreturn 1 ;/* check map and if change is detected re-read map */ - ret =lookup_one (root, name, name_len, ctxt); + ret =lookup_one (root, key, key_len, ctxt);debug ("ret = %d" , ret);
modules/lookup_file.c renamed from modules/lookup_file.c.map-expiry-fix +3 -1
@@ -323,8 +323,10 @@ static int lookup_one(const char *root,while (1 ) { entry =read_one (f, mkey, mapent);if (entry) -if (strncmp (mkey, key, key_len) ==0 ) +if (strncmp (mkey, key, key_len) ==0 ) { +fclose (f);return cache_update (root, key, mapent, age); + }if (feof (f))break ;
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; [email protected] adds:
Quoted 45 lines · Jeff Moyer
Quoted 45 lines
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead and only insert new entries (instead of overwriting what was there).So, I've implemented this, though it isn't tested just yet. There were some other bugs.
In
lookup_multi, we iterate through each map'slookup_ghostfunction. The problem here is that you will end up doing the following:static int
read_map(const char *root, struct lookup_context *ctxt){ char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char *mapname; FILE *f; int entry;time_tage = time(NULL); <=================mapname =
alloca(strlen(ctxt->mapname) + 6);sprintf(mapname, "file:%s", ctxt->mapname);f =
fopen(ctxt->mapname, "r"); if (!f) {error(MODPREFIX "could not open map file %s", ctxt->mapname); return 0; }while(1) { entry =
read_one(f, key, mapent); if (entry)cache_update(root, key, mapent, age); <==========if (feof(f)) break; }
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); <=============return 1; }
Notice the lines I've pointed out. We decide what the expiration age should be at the beginning of the function. We update entries and give them that "age." And finally, we expire all entries that were made prior to that. The problem arises in that we call the
read_maproutine for each map in the list in order. What will happen is that each map, as it is processed, will end up with a new value for age. Thus, we expire all of the work done by the previousread_maps! This is bad. To fix this, I've passed in the age field from the top-level.
Quoted 7 lines
Quoted 7 lines
I've changed ldap's
lookup_ghostroutine (well, a function it calls, anyway) to usecache_insert_uniqueinstead ofcache_add.Please let me know what you think. If you only like some parts, let me know which ones and I'll break them out from the rest of the patch. BTW, this patch is applied on top of your map expiration changes. I can rediff the thing to any version of the code you want.
raven> Understand the problem.
raven> I've had a look at the patch and it looks good.
raven> I had a slightly different idea though.
raven> I think the cache_insert_unique might be a problem later as if raven> people add multiple attributes (map entries) for multi-mount keys, raven> instead of one attribute containing multiple mounts, in what they raven> think is "the LDAP way" it probably won't work. I can't say we've raven> seen this problem yet but I have been trying to allow for it in the raven> code.
raven> The other thing that occured to me was that, together with passing raven> the time to keep things consistent, processing the maps in reverse raven> order in lookup_ghost of the multi map module would fix most of the raven> issues. Along with modifying cache_add to append to any existing raven> entries, rather than prepend.
raven> I spotted something you missed in the yp module. Have a look at the raven> lookup_yp patch chunks in the attached map-entry-order patch.
raven> Have a look at what I've tried to do and let me know what you raven> think. I've done some basic testing but not against the issue we are raven> trying to fix. So let me know how it goes.
raven> Also, I found a couple of other bugs and have attached a couple of raven> other patches as well.
Thanks, Ian! This all looks good to me, though I haven't been able to test. What version of the tree was this applied to?
-Jeff
Ian Kent
maintainerQuoted 82 lines · Jeff Moyer
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; [email protected] adds:
Quoted 45 lines · Jeff Moyer
Quoted 45 lines
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead and only insert new entries (instead of overwriting what was there).So, I've implemented this, though it isn't tested just yet. There were some other bugs.
In
lookup_multi, we iterate through each map'slookup_ghostfunction. The problem here is that you will end up doing the following:static int
read_map(const char *root, struct lookup_context *ctxt){ char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char *mapname; FILE *f; int entry;time_tage = time(NULL); <=================mapname =
alloca(strlen(ctxt->mapname) + 6);sprintf(mapname, "file:%s", ctxt->mapname);f =
fopen(ctxt->mapname, "r"); if (!f) {error(MODPREFIX "could not open map file %s", ctxt->mapname); return 0; }while(1) { entry =
read_one(f, key, mapent); if (entry)cache_update(root, key, mapent, age); <==========if (feof(f)) break; }
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); <=============return 1; }
Notice the lines I've pointed out. We decide what the expiration age should be at the beginning of the function. We update entries and give them that "age." And finally, we expire all entries that were made prior to that. The problem arises in that we call the
read_maproutine for each map in the list in order. What will happen is that each map, as it is processed, will end up with a new value for age. Thus, we expire all of the work done by the previousread_maps! This is bad. To fix this, I've passed in the age field from the top-level.Quoted 7 lines
Quoted 7 lines
I've changed ldap's
lookup_ghostroutine (well, a function it calls, anyway) to usecache_insert_uniqueinstead ofcache_add.Please let me know what you think. If you only like some parts, let me know which ones and I'll break them out from the rest of the patch. BTW, this patch is applied on top of your map expiration changes. I can rediff the thing to any version of the code you want.
raven> Understand the problem.
raven> I've had a look at the patch and it looks good.
raven> I had a slightly different idea though.
raven> I think the
cache_insert_uniquemight be a problem later as if raven> people add multiple attributes (map entries) for multi-mount keys, raven> instead of one attribute containing multiple mounts, in what they raven> think is "the LDAP way" it probably won't work. I can't say we've raven> seen this problem yet but I have been trying to allow for it in the raven> code.raven> The other thing that occured to me was that, together with passing raven> the time to keep things consistent, processing the maps in reverse raven> order in
lookup_ghostof the multi map module would fix most of the raven> issues. Along with modifyingcache_addto append to any existing raven> entries, rather than prepend.raven> I spotted something you missed in the yp module. Have a look at the raven>
lookup_yppatch chunks in the attached map-entry-order patch.raven> Have a look at what I've tried to do and let me know what you raven> think. I've done some basic testing but not against the issue we are raven> trying to fix. So let me know how it goes.
Quoted 5 lines
raven> Also, I found a couple of other bugs and have attached a couple of raven> other patches as well.
Thanks, Ian! This all looks good to me, though I haven't been able to test. What version of the tree was this applied to?
That's a rather interesting question.
I originally made the patch against your 55.1 but couldn't get rpmbuild to work OK under Gentoo so I added approiate patches to my Gentoo portage install and built there. Only minor changes were needed, which I believe would have been needed for the rpm as well.
Hopefully, it will also apply to earlier rpms without much trouble as the changes appear to be mostly outside of the areas with lots of change.
Ian
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; [email protected] adds:
Quoted 46 lines · Jeff Moyer
Quoted 46 lines
Quoted 8 lines
Quoted 8 lines
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead and only insert new entries (instead of overwriting what was there).So, I've implemented this, though it isn't tested just yet. There
were >> some other bugs.
Quoted 6 lines
Quoted 6 lines
In
lookup_multi, we iterate through each map'slookup_ghostfunction. The problem here is that you will end up doing the following:static int
read_map(const char *root, struct lookup_context *ctxt){ char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char >>*mapname; FILE *f; int entry;
time_tage = time(NULL); >> <=================Quoted 2 lines
Quoted 2 lines
mapname =
alloca(strlen(ctxt->mapname) + 6); sprintf(mapname,"file:%s", >>
ctxt->mapname);Quoted 2 lines
Quoted 2 lines
f =
fopen(ctxt->mapname, "r"); if (!f) { error(MODPREFIX "could notopen >> map file %s",
ctxt->mapname); return 0; }Quoted 2 lines
Quoted 2 lines
while(1) { entry =
read_one(f, key, mapent); if (entry) >>
cache_update(root, key, mapent, age); <==========Quoted 6 lines
Quoted 6 lines
if (feof(f)) break; }
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); >><=============
Quoted 5 lines
Quoted 5 lines
return 1; }
Notice the lines I've pointed out. We decide what the expiration age should be at the beginning of the function. We update entries and
give >> them that "age." And finally, we expire all entries that were made >> prior to that. The problem arises in that we call the
read_maproutine >> for each map in the list in order. What will happen is that each map, >> as it is processed, will end up with a new value for age. Thus, we >> expire all of the work done by the previousread_maps! This is bad. To >> fix this, I've passed in the age field from the top-level.Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
I've changed ldap's
lookup_ghostroutine (well, a function it calls, anyway) to usecache_insert_uniqueinstead ofcache_add.Please let me know what you think. If you only like some parts, let
me >> know which ones and I'll break them out from the rest of the patch. >> BTW, this patch is applied on top of your map expiration changes. I can >> rediff the thing to any version of the code you want.
raven> Understand the problem.
Quoted 1 line
Quoted 1 line
raven> I've had a look at the patch and it looks good.
Quoted 1 line
Quoted 1 line
raven> I had a slightly different idea though.
Quoted 1 line
Quoted 1 line
raven> I think the cache_insert_unique might be a problem later as if raven> people add multiple attributes (map entries) for multi-mount keys, raven> instead of one attribute containing multiple mounts, in what they raven> think is "the LDAP way" it probably won't work. I can't say we've raven> seen this problem yet but I have been trying to allow for it in the raven> code.
Quoted 1 line
Quoted 1 line
raven> The other thing that occured to me was that, together with passing raven> the time to keep things consistent, processing the maps in reverse raven> order in lookup_ghost of the multi map module would fix most of the raven> issues. Along with modifying cache_add to append to any existing raven> entries, rather than prepend.
Quoted 1 line
Quoted 1 line
raven> I spotted something you missed in the yp module. Have a look at the raven> lookup_yp patch chunks in the attached map-entry-order patch.
Quoted 1 line
Quoted 1 line
raven> Have a look at what I've tried to do and let me know what you raven> think. I've done some basic testing but not against the issue we are raven> trying to fix. So let me know how it goes.
Quoted 1 line
Quoted 1 line
raven> Also, I found a couple of other bugs and have attached a couple of raven> other patches as well.
Quoted 2 lines
Quoted 2 lines
Thanks, Ian! This all looks good to me, though I haven't been able to test. What version of the tree was this applied to?
raven> That's a rather interesting question.
raven> I originally made the patch against your 55.1 but couldn't get raven> rpmbuild to work OK under Gentoo so I added approiate patches to my raven> Gentoo portage install and built there. Only minor changes were raven> needed, which I believe would have been needed for the rpm as well.
raven> Hopefully, it will also apply to earlier rpms without much trouble raven> as the changes appear to be mostly outside of the areas with lots of raven> change.
In testing 4.1.4 beta 1, this problem still isn't addressed. Automount will use the last of the duplicate entries in an indirect map, precisely the opposite behaviour as before.
-Jeff
Ian Kent
maintainerQuoted 99 lines · Jeff Moyer
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; [email protected] adds:
Quoted 46 lines · Jeff Moyer
Quoted 46 lines
Quoted 8 lines
Quoted 8 lines
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead and only insert new entries (instead of overwriting what was there).So, I've implemented this, though it isn't tested just yet. There
were >> some other bugs.
Quoted 6 lines
Quoted 6 lines
In
lookup_multi, we iterate through each map'slookup_ghostfunction. The problem here is that you will end up doing the following:static int
read_map(const char *root, struct lookup_context *ctxt){ char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char >>*mapname; FILE *f; int entry;
time_tage = time(NULL); >> <=================Quoted 2 lines
Quoted 2 lines
mapname =
alloca(strlen(ctxt->mapname) + 6); sprintf(mapname,"file:%s", >>
ctxt->mapname);Quoted 2 lines
Quoted 2 lines
f =
fopen(ctxt->mapname, "r"); if (!f) { error(MODPREFIX "could notopen >> map file %s",
ctxt->mapname); return 0; }Quoted 2 lines
Quoted 2 lines
while(1) { entry =
read_one(f, key, mapent); if (entry) >>
cache_update(root, key, mapent, age); <==========Quoted 6 lines
Quoted 6 lines
if (feof(f)) break; }
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); >><=============
Quoted 5 lines
Quoted 5 lines
return 1; }
Notice the lines I've pointed out. We decide what the expiration age should be at the beginning of the function. We update entries and
give >> them that "age." And finally, we expire all entries that were made >> prior to that. The problem arises in that we call the
read_maproutine >> for each map in the list in order. What will happen is that each map, >> as it is processed, will end up with a new value for age. Thus, we >> expire all of the work done by the previousread_maps! This is bad. To >> fix this, I've passed in the age field from the top-level.Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
I've changed ldap's
lookup_ghostroutine (well, a function it calls, anyway) to usecache_insert_uniqueinstead ofcache_add.Please let me know what you think. If you only like some parts, let
me >> know which ones and I'll break them out from the rest of the patch. >> BTW, this patch is applied on top of your map expiration changes. I can >> rediff the thing to any version of the code you want.
raven> Understand the problem.
Quoted 1 line
Quoted 1 line
raven> I've had a look at the patch and it looks good.
Quoted 1 line
Quoted 1 line
raven> I had a slightly different idea though.
Quoted 1 line
Quoted 1 line
raven> I think the
cache_insert_uniquemight be a problem later as if raven> people add multiple attributes (map entries) for multi-mount keys, raven> instead of one attribute containing multiple mounts, in what they raven> think is "the LDAP way" it probably won't work. I can't say we've raven> seen this problem yet but I have been trying to allow for it in the raven> code.Quoted 1 line
Quoted 1 line
raven> The other thing that occured to me was that, together with passing raven> the time to keep things consistent, processing the maps in reverse raven> order in
lookup_ghostof the multi map module would fix most of the raven> issues. Along with modifyingcache_addto append to any existing raven> entries, rather than prepend.Quoted 1 line
Quoted 1 line
raven> I spotted something you missed in the yp module. Have a look at the raven>
lookup_yppatch chunks in the attached map-entry-order patch.Quoted 1 line
Quoted 1 line
raven> Have a look at what I've tried to do and let me know what you raven> think. I've done some basic testing but not against the issue we are raven> trying to fix. So let me know how it goes.
Quoted 1 line
Quoted 1 line
raven> Also, I found a couple of other bugs and have attached a couple of raven> other patches as well.
Quoted 2 lines
Quoted 2 lines
Thanks, Ian! This all looks good to me, though I haven't been able to test. What version of the tree was this applied to?
raven> That's a rather interesting question.
raven> I originally made the patch against your 55.1 but couldn't get raven> rpmbuild to work OK under Gentoo so I added approiate patches to my raven> Gentoo portage install and built there. Only minor changes were raven> needed, which I believe would have been needed for the rpm as well.
Quoted 7 lines
raven> Hopefully, it will also apply to earlier rpms without much trouble raven> as the changes appear to be mostly outside of the areas with lots of raven> change.
In testing 4.1.4 beta 1, this problem still isn't addressed. Automount will use the last of the duplicate entries in an indirect map, precisely the opposite behaviour as before.
The last !!??
Bizare ....
At least the idea was good but .....
More things to fix.
Ian
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
Quoted 1 line
Quoted 1 line
==> Regarding Re: [patch rfc] address regression in duplicate map
entry >> order; [email protected] adds:
Quoted 1 line
Quoted 1 line
Quoted 48 lines · Jeff Moyer
Quoted 48 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead andonly >> >> insert new entries (instead of overwriting what was there).
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
So, I've implemented this, though it isn't tested just yet. There
were >> some other bugs.
Quoted 2 lines
Quoted 2 lines
In
lookup_multi, we iterate through each map'slookup_ghostfunction. >> >> The problem here is that you will end up doing the following:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
static int
read_map(const char *root, struct lookup_context *ctxt){ >> >> char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
*mapname; FILE *f; int entry;
time_tage = time(NULL); >> >><=================
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
mapname =
alloca(strlen(ctxt->mapname) + 6); sprintf(mapname, >>"file:%s", >>
ctxt->mapname);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
f =
fopen(ctxt->mapname, "r"); if (!f) { error(MODPREFIX "couldnot >> open >> map file %s",
ctxt->mapname); return 0; }Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
while(1) { entry =
read_one(f, key, mapent); if (entry) >> >>
cache_update(root, key, mapent, age); <==========Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
if (feof(f)) break; }
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); <=============return 1; }
Notice the lines I've pointed out. We decide what the expiration
age >> >> should be at the beginning of the function. We update entries and >> give >> them that "age." And finally, we expire all entries that were >> made >> prior to that. The problem arises in that we call the
read_map>> routine >> for each map in the list in order. What will happen is that >> each map, >> as it is processed, will end up with a new value for age. >> Thus, we >> expire all of the work done by the previousread_maps! This >> is bad. To >> fix this, I've passed in the age field from the >> top-level.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I've changed ldap's
lookup_ghostroutine (well, a function it
Quoted 8 lines
Quoted 8 lines
calls, >> >> anyway) to use
cache_insert_uniqueinstead ofcache_add.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Please let me know what you think. If you only like some parts,
let >> me >> know which ones and I'll break them out from the rest of the >> patch. >> BTW, this patch is applied on top of your map expiration >> changes. I can >> rediff the thing to any version of the code you want.
Quoted 1 line
Quoted 1 line
raven> Understand the problem.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I've had a look at the patch and it looks good.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I had a slightly different idea though.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I think the cache_insert_unique might be a problem later as if raven> people add multiple attributes (map entries) for multi-mount keys, raven> instead of one attribute containing multiple mounts, in what they raven> think is "the LDAP way" it probably won't work. I can't say we've raven> seen this problem yet but I have been trying to allow for it in the raven> code.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> The other thing that occured to me was that, together with passing raven> the time to keep things consistent, processing the maps in reverse raven> order in lookup_ghost of the multi map module would fix most of the raven> issues. Along with modifying cache_add to append to any existing raven> entries, rather than prepend.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I spotted something you missed in the yp module. Have a look at the raven> lookup_yp patch chunks in the attached map-entry-order patch.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Have a look at what I've tried to do and let me know what you raven> think. I've done some basic testing but not against the issue we are raven> trying to fix. So let me know how it goes.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Also, I found a couple of other bugs and have attached a couple of raven> other patches as well.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Thanks, Ian! This all looks good to me, though I haven't been able
to >> test. What version of the tree was this applied to?
raven> That's a rather interesting question.
Quoted 1 line
Quoted 1 line
raven> I originally made the patch against your 55.1 but couldn't get raven> rpmbuild to work OK under Gentoo so I added approiate patches to my raven> Gentoo portage install and built there. Only minor changes were raven> needed, which I believe would have been needed for the rpm as well.
Quoted 1 line
Quoted 1 line
raven> Hopefully, it will also apply to earlier rpms without much trouble raven> as the changes appear to be mostly outside of the areas with lots of raven> change.
Quoted 3 lines
Quoted 3 lines
In testing 4.1.4 beta 1, this problem still isn't addressed. Automount will use the last of the duplicate entries in an indirect map, precisely the opposite behaviour as before.
raven> The last !!??
raven> Bizare ....
raven> At least the idea was good but .....
raven> More things to fix.
Regressions are priority 1. Customers hate them! ;-)
So, here is the offending code:
lookup_ghost calls read_map, which does this:
while(1) {
entry = read_one(f, key, mapent);
if (entry)
cache_update(root, key, mapent, age);
if (feof(f))
break;
}This is the first time the map is read. If cache_update doesn't find a previous entry, it creates one. If it does find an entry, it /replaces/ it with what you pass in. Thus, the last entry in an indirect map shows up as the only entry.
This is a bit of a tricky problem. It could be addressed in one of a number of ways, but before I go off implementing anything, I wanted to get your input on the matter.
The cache wasn't really meant to have multiple copies of the same key with different values. What you really want, I guess is something that conceptually works like this:
cache_update: change key X value Y to key X value Z
I guess we could get the current versions from the cache, but is there a deterministic way of mapping old key/value pairs to updated ones in the presence of multiple entries per key? (confusing question? read it a few more times ;)
So, I'll ponder this for a bit, and maybe come up with a patch that you can tear to shreds, but I'd really like your input on the matter.
-Jeff
[email protected]
maintainerQuoted 126 lines · Jeff Moyer
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
Quoted 1 line
Quoted 1 line
==> Regarding Re: [patch rfc] address regression in duplicate map
entry >> order; [email protected] adds:
Quoted 1 line
Quoted 1 line
Quoted 48 lines · Jeff Moyer
Quoted 48 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead andonly >> >> insert new entries (instead of overwriting what was there).
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
So, I've implemented this, though it isn't tested just yet. There
were >> some other bugs.
Quoted 2 lines
Quoted 2 lines
In
lookup_multi, we iterate through each map'slookup_ghostfunction. >> >> The problem here is that you will end up doing the following:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
static int
read_map(const char *root, struct lookup_context *ctxt){ >> >> char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
*mapname; FILE *f; int entry;
time_tage = time(NULL); >> >><=================
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
mapname =
alloca(strlen(ctxt->mapname) + 6); sprintf(mapname, >>"file:%s", >>
ctxt->mapname);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
f =
fopen(ctxt->mapname, "r"); if (!f) { error(MODPREFIX "couldnot >> open >> map file %s",
ctxt->mapname); return 0; }Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
while(1) { entry =
read_one(f, key, mapent); if (entry) >> >>
cache_update(root, key, mapent, age); <==========Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
if (feof(f)) break; }
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); <=============return 1; }
Notice the lines I've pointed out. We decide what the expiration
age >> >> should be at the beginning of the function. We update entries and >> give >> them that "age." And finally, we expire all entries that were >> made >> prior to that. The problem arises in that we call the
read_map>> routine >> for each map in the list in order. What will happen is that >> each map, >> as it is processed, will end up with a new value for age. >> Thus, we >> expire all of the work done by the previousread_maps! This >> is bad. To >> fix this, I've passed in the age field from the >> top-level.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I've changed ldap's
lookup_ghostroutine (well, a function itQuoted 8 lines
Quoted 8 lines
calls, >> >> anyway) to use
cache_insert_uniqueinstead ofcache_add.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Please let me know what you think. If you only like some parts,
let >> me >> know which ones and I'll break them out from the rest of the >> patch. >> BTW, this patch is applied on top of your map expiration >> changes. I can >> rediff the thing to any version of the code you want.
Quoted 1 line
Quoted 1 line
raven> Understand the problem.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I've had a look at the patch and it looks good.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I had a slightly different idea though.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I think the
cache_insert_uniquemight be a problem later as if raven> people add multiple attributes (map entries) for multi-mount keys, raven> instead of one attribute containing multiple mounts, in what they raven> think is "the LDAP way" it probably won't work. I can't say we've raven> seen this problem yet but I have been trying to allow for it in the raven> code.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> The other thing that occured to me was that, together with passing raven> the time to keep things consistent, processing the maps in reverse raven> order in
lookup_ghostof the multi map module would fix most of the raven> issues. Along with modifyingcache_addto append to any existing raven> entries, rather than prepend.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I spotted something you missed in the yp module. Have a look at the raven>
lookup_yppatch chunks in the attached map-entry-order patch.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Have a look at what I've tried to do and let me know what you raven> think. I've done some basic testing but not against the issue we are raven> trying to fix. So let me know how it goes.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Also, I found a couple of other bugs and have attached a couple of raven> other patches as well.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Thanks, Ian! This all looks good to me, though I haven't been able
to >> test. What version of the tree was this applied to?
raven> That's a rather interesting question.
Quoted 1 line
Quoted 1 line
raven> I originally made the patch against your 55.1 but couldn't get raven> rpmbuild to work OK under Gentoo so I added approiate patches to my raven> Gentoo portage install and built there. Only minor changes were raven> needed, which I believe would have been needed for the rpm as well.
Quoted 1 line
Quoted 1 line
raven> Hopefully, it will also apply to earlier rpms without much trouble raven> as the changes appear to be mostly outside of the areas with lots of raven> change.
Quoted 3 lines
Quoted 3 lines
In testing 4.1.4 beta 1, this problem still isn't addressed. Automount will use the last of the duplicate entries in an indirect map, precisely the opposite behaviour as before.
raven> The last !!??
raven> Bizare ....
raven> At least the idea was good but .....
raven> More things to fix.
Regressions are priority 1. Customers hate them! ;-)
So, here is the offending code:
lookup_ghostcallsread_map, which does this:
Quoted 8 lines
while(1) {
entry = read_one(f, key, mapent);
if (entry)
cache_update(root, key, mapent, age);
if (feof(f))
break;
}Yes. I see that in the lookup_yp module as well but the lookup_ldap module doesn't have the same problem.
Quoted 5 lines
This is the first time the map is read. If
cache_updatedoesn't find a previous entry, it creates one. If it does find an entry, it /replaces/ it with what you pass in. Thus, the last entry in an indirect map shows up as the only entry.
Yep. I see that's the way it behaves.
Quoted 10 lines
This is a bit of a tricky problem. It could be addressed in one of a number of ways, but before I go off implementing anything, I wanted to get your input on the matter.
The cache wasn't really meant to have multiple copies of the same key with different values. What you really want, I guess is something that conceptually works like this:
cache_update: change key X value Y to key X value Z
After looking at this more closely I think the problem might not be so hard to solve after all.
I don't really care if there's multiple entries for a key. To maintain sensible behaviour we should return the first match on lookup and that's what happens now anyway. As you point out the problem happens when we populate the cache.
But there's more. See below.
Quoted 5 lines
I guess we could get the current versions from the cache, but is there a deterministic way of mapping old key/value pairs to updated ones in the presence of multiple entries per key? (confusing question? read it a few more times ;)
This is the bit I'm not sure about yet.
Perhaps we need to carry a map id in cache entries or in the context to identify them when we lookup them up later and possibly update them?
Anyway we'll always be updating the first match (as the semantic requires) so it might not matter.
The question that arises from this is "will we allow duplicate keys within individual maps"?
That would make things much more difficult and probably won't give functionality that's needed or used.
Quoted 3 lines
So, I'll ponder this for a bit, and maybe come up with a patch that you can tear to shreds, but I'd really like your input on the matter.
It seems that our first attempt at solving this (the bad bits due to me of course) did two things.
1) Changed cache_add to add if no key is present but to append to the end of the hash chain for that key if it is present.
That would be OK if we called cache_add (as we do in lookup_ldap) instead of cache_update (as we do in lookup_file and lookup_yp) (doh!).
2) I changed the lookup_multi module to populate the cache in reverse map order.
Now that's just broken.
So consider the following patch together with the original patch. I think this might be all that's needed, at least in populating the cache.
It reverts the change in 2) and changes cache_update to cache_add in the needed places.
What do you think?
As I said above the other question that needs to be answered is whether this will have undesirable side affects at lookup time?
Ian
modules/lookup_multi.c renamed from modules/lookup_multi.c.map-entry-order-fix +2 -6
@@ -116,12 +116,8 @@struct lookup_context *ctxt = (struct lookup_context *) context;int i, ret, at_least_1 =0 ; -/* - * Read each map in reverse order to ensure that when we lookup a key -* in the cache we get what would be seen first. -*/ -for (i = ctxt->n -1 ; i >=0 ; i--) { - ret = ctxt->m[i].mod->lookup_ghost (root, ghost, now, +for (i =0 ; i < ctxt->n; i++) { + ret = ctxt->m[i].mod->lookup_ghost (root, ghost, ctxt->m[i].mod->context);if (ret &LKP_FAIL )continue ; --- autofs-4.1.3/modules/lookup_file.c.map-entry-order-fix 2005-02-05 11:37:38.000000000 +0800
+++ autofs-4.1.3/modules/lookup_file.c 2005-02-05 11:38:22.000000000 +0800
@@ -248,7 +248,7 @@
while(1) {
entry = read_one(f, key, mapent);
if (entry)
- cache_update(root, key, mapent, age);
+ cache_add(root, key, mapent, age);
if (feof(f))
break;
modules/lookup_yp.c renamed from modules/lookup_yp.c.map-entry-order-fix +1 -1
@@ -102,7 +102,7 @@strncpy (mapent, val, vallen); *(mapent + vallen) ='\0' ; -cache_update (root, key, mapent, age); +cache_add (root, key, mapent, age);return 0 ; }
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; [email protected] adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
==> Regarding Re: [patch rfc] address regression in duplicate map
entry >> order; [email protected] adds:
Quoted 1 line
Quoted 1 line
Quoted 40 lines · Jeff Moyer
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead andonly >> >> insert new entries (instead of overwriting what was there).
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, I've implemented this, though it isn't tested just yet. There
were >> some other bugs.
Quoted 1 line
Quoted 1 line
In
lookup_multi, we iterate through each map'slookup_ghostfunction. >> >> The problem here is that you will end up doing the following:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
static int
read_map(const char *root, struct lookup_context *ctxt){ >> >> char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
*mapname; FILE *f; int entry;
time_tage = time(NULL); >> >><=================
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
mapname =
alloca(strlen(ctxt->mapname) + 6); sprintf(mapname, >>"file:%s", >>
ctxt->mapname);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
f =
fopen(ctxt->mapname, "r"); if (!f) { error(MODPREFIX "couldnot >> open >> map file %s",
ctxt->mapname); return 0; }Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
while(1) { entry =
read_one(f, key, mapent); if (entry) >> >>
cache_update(root, key, mapent, age); <==========Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
if (feof(f)) break; }
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); <=============return 1; }
Notice the lines I've pointed out. We decide what the expiration
age >> >> should be at the beginning of the function. We update entries and >> give >> them that "age." And finally, we expire all entries that were >> made >> prior to that. The problem arises in that we call the
read_map>> routine >> for each map in the list in order. What will happen is that >> each map, >> as it is processed, will end up with a new value for age. >> Thus, we >> expire all of the work done by the previousread_maps! This >> is bad. To >> fix this, I've passed in the age field from the >> top-level.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
I've changed ldap's
lookup_ghostroutine (well, a function itcalls, >> >> anyway) to use
cache_insert_uniqueinstead ofcache_add.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Please let me know what you think. If you only like some parts,
let >> me >> know which ones and I'll break them out from the rest of the >> patch. >> BTW, this patch is applied on top of your map expiration >> changes. I can >> rediff the thing to any version of the code you want.
Quoted 1 line
Quoted 1 line
raven> Understand the problem.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I've had a look at the patch and it looks good.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I had a slightly different idea though.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I think the cache_insert_unique might be a problem later as if raven> people add multiple attributes (map entries) for multi-mount keys, raven> instead of one attribute containing multiple mounts, in what they raven> think is "the LDAP way" it probably won't work. I can't say we've raven> seen this problem yet but I have been trying to allow for it in the raven> code.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> The other thing that occured to me was that, together with passing raven> the time to keep things consistent, processing the maps in reverse raven> order in lookup_ghost of the multi map module would fix most of the raven> issues. Along with modifying cache_add to append to any existing raven> entries, rather than prepend.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I spotted something you missed in the yp module. Have a look at the raven> lookup_yp patch chunks in the attached map-entry-order patch.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Have a look at what I've tried to do and let me know what you raven> think. I've done some basic testing but not against the issue we are raven> trying to fix. So let me know how it goes.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Also, I found a couple of other bugs and have attached a couple of raven> other patches as well.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Thanks, Ian! This all looks good to me, though I haven't been able
to >> test. What version of the tree was this applied to?
raven> That's a rather interesting question.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I originally made the patch against your 55.1 but couldn't get raven> rpmbuild to work OK under Gentoo so I added approiate patches to my raven> Gentoo portage install and built there. Only minor changes were raven> needed, which I believe would have been needed for the rpm as well.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Hopefully, it will also apply to earlier rpms without much trouble raven> as the changes appear to be mostly outside of the areas with lots of raven> change.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
In testing 4.1.4 beta 1, this problem still isn't addressed. Automount will use the last of the duplicate entries in an indirect map, precisely the opposite behaviour as before.
raven> The last !!??
Quoted 1 line
Quoted 1 line
raven> Bizare ....
Quoted 1 line
Quoted 1 line
raven> At least the idea was good but .....
Quoted 1 line
Quoted 1 line
raven> More things to fix.
Quoted 10 lines
Quoted 10 lines
Regressions are priority 1. Customers hate them! ;-)
So, here is the offending code:
lookup_ghostcallsread_map, which does this:while(1) { entry =
read_one(f, key, mapent); if (entry)cache_update(root, key, mapent, age);if (feof(f)) break; }
raven> Yes. I see that in the lookup_yp module as well but the lookup_ldap raven> module doesn't have the same problem.
Quoted 4 lines
Quoted 4 lines
This is the first time the map is read. If
cache_updatedoesn't find a previous entry, it creates one. If it does find an entry, it /replaces/ it with what you pass in. Thus, the last entry in an indirect map shows up as the only entry.
raven> Yep. I see that's the way it behaves.
Quoted 9 lines
Quoted 9 lines
This is a bit of a tricky problem. It could be addressed in one of a number of ways, but before I go off implementing anything, I wanted to get your input on the matter.
The cache wasn't really meant to have multiple copies of the same key with different values. What you really want, I guess is something that conceptually works like this:
cache_update: change key X value Y to key X value Z
raven> After looking at this more closely I think the problem might not be raven> so hard to solve after all.
raven> I don't really care if there's multiple entries for a key. To raven> maintain sensible behaviour we should return the first match on raven> lookup and that's what happens now anyway. As you point out the raven> problem happens when we populate the cache.
raven> But there's more. See below.
Quoted 4 lines
Quoted 4 lines
I guess we could get the current versions from the cache, but is there a deterministic way of mapping old key/value pairs to updated ones in the presence of multiple entries per key? (confusing question? read it a few more times ;)
raven> This is the bit I'm not sure about yet.
raven> Perhaps we need to carry a map id in cache entries or in the context raven> to identify them when we lookup them up later and possibly update raven> them?
How? There is no deterministic way to do this because the backing store (whether it's a file or nis or ldap) does not keep this information. At the end of the day, I don't really think it matters, though. What I think should happen is that we simply preserve the order in the map.
Instead of only updating one key in the cache, if the cache has gone stale we should re-read the whole thing.
Note that current behaviour is pretty broken for things like files. If the modification time changes on a file, we revert to always bypassing the cache! We never re-read the entire map, and even if we have the freshest copy of a data item in the cache, we still go to disk.
raven> Anyway we'll always be updating the first match (as the semantic raven> requires) so it might not matter.
I think we're on the same page here, but to be sure: map entries should be read in and populated in the cache in the order they appear in the map. The first entry should always be returned.
raven> The question that arises from this is "will we allow duplicate keys raven> within individual maps"?
raven> That would make things much more difficult and probably won't give raven> functionality that's needed or used.
No need.
Quoted 2 lines
Quoted 2 lines
So, I'll ponder this for a bit, and maybe come up with a patch that you can tear to shreds, but I'd really like your input on the matter.
raven> It seems that our first attempt at solving this (the bad bits due to raven> me of course) did two things.
raven> 1) Changed cache_add to add if no key is present but to append to raven> the end of the hash chain for that key if it is present.
raven> That would be OK if we called cache_add (as we do in lookup_ldap) raven> instead of cache_update (as we do in lookup_file and lookup_yp) raven> (doh!).
raven> 2) I changed the lookup_multi module to populate the cache in raven> reverse map order.
raven> Now that's just broken.
raven> So consider the following patch together with the original patch. I raven> think this might be all that's needed, at least in populating the raven> cache.
raven> It reverts the change in 2) and changes cache_update to cache_add in raven> the needed places.
raven> What do you think?
I'll take a look.
raven> As I said above the other question that needs to be answered is raven> whether this will have undesirable side affects at lookup time?
So long as we return the first entry that appears in the map, we are doing the right thing. The hard part is handling updates, and I think we need more code to account for that.
-Jeff
Ian Kent
maintainerQuoted 167 lines · Jeff Moyer
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; [email protected] adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; Ian Kent <[email protected]> adds:
Quoted 3 lines · Jeff Moyer
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
==> Regarding Re: [patch rfc] address regression in duplicate map
entry >> order; [email protected] adds:
Quoted 1 line
Quoted 1 line
Quoted 40 lines · Jeff Moyer
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Hi, Ian, list,
In my proposed fix, I meant to say:
We could expire the cache in
lookup_ghost, and then go ahead andonly >> >> insert new entries (instead of overwriting what was there).
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
So, I've implemented this, though it isn't tested just yet. There
were >> some other bugs.
Quoted 1 line
Quoted 1 line
In
lookup_multi, we iterate through each map'slookup_ghostfunction. >> >> The problem here is that you will end up doing the following:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
static int
read_map(const char *root, struct lookup_context *ctxt){ >> >> char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
*mapname; FILE *f; int entry;
time_tage = time(NULL); >> >><=================
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
mapname =
alloca(strlen(ctxt->mapname) + 6); sprintf(mapname, >>"file:%s", >>
ctxt->mapname);Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
f =
fopen(ctxt->mapname, "r"); if (!f) { error(MODPREFIX "couldnot >> open >> map file %s",
ctxt->mapname); return 0; }Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
while(1) { entry =
read_one(f, key, mapent); if (entry) >> >>
cache_update(root, key, mapent, age); <==========Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
if (feof(f)) break; }
fclose(f);
/* Clean stale entries from the cache */
cache_clean(root, age); <=============return 1; }
Notice the lines I've pointed out. We decide what the expiration
age >> >> should be at the beginning of the function. We update entries and >> give >> them that "age." And finally, we expire all entries that were >> made >> prior to that. The problem arises in that we call the
read_map>> routine >> for each map in the list in order. What will happen is that >> each map, >> as it is processed, will end up with a new value for age. >> Thus, we >> expire all of the work done by the previousread_maps! This >> is bad. To >> fix this, I've passed in the age field from the >> top-level.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
I've changed ldap's
lookup_ghostroutine (well, a function itcalls, >> >> anyway) to use
cache_insert_uniqueinstead ofcache_add.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Please let me know what you think. If you only like some parts,
let >> me >> know which ones and I'll break them out from the rest of the >> patch. >> BTW, this patch is applied on top of your map expiration >> changes. I can >> rediff the thing to any version of the code you want.
Quoted 1 line
Quoted 1 line
raven> Understand the problem.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I've had a look at the patch and it looks good.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I had a slightly different idea though.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I think the
cache_insert_uniquemight be a problem later as if raven> people add multiple attributes (map entries) for multi-mount keys, raven> instead of one attribute containing multiple mounts, in what they raven> think is "the LDAP way" it probably won't work. I can't say we've raven> seen this problem yet but I have been trying to allow for it in the raven> code.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> The other thing that occured to me was that, together with passing raven> the time to keep things consistent, processing the maps in reverse raven> order in
lookup_ghostof the multi map module would fix most of the raven> issues. Along with modifyingcache_addto append to any existing raven> entries, rather than prepend.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I spotted something you missed in the yp module. Have a look at the raven>
lookup_yppatch chunks in the attached map-entry-order patch.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Have a look at what I've tried to do and let me know what you raven> think. I've done some basic testing but not against the issue we are raven> trying to fix. So let me know how it goes.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Also, I found a couple of other bugs and have attached a couple of raven> other patches as well.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Thanks, Ian! This all looks good to me, though I haven't been able
to >> test. What version of the tree was this applied to?
raven> That's a rather interesting question.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> I originally made the patch against your 55.1 but couldn't get raven> rpmbuild to work OK under Gentoo so I added approiate patches to my raven> Gentoo portage install and built there. Only minor changes were raven> needed, which I believe would have been needed for the rpm as well.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
raven> Hopefully, it will also apply to earlier rpms without much trouble raven> as the changes appear to be mostly outside of the areas with lots of raven> change.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
In testing 4.1.4 beta 1, this problem still isn't addressed. Automount will use the last of the duplicate entries in an indirect map, precisely the opposite behaviour as before.
raven> The last !!??
Quoted 1 line
Quoted 1 line
raven> Bizare ....
Quoted 1 line
Quoted 1 line
raven> At least the idea was good but .....
Quoted 1 line
Quoted 1 line
raven> More things to fix.
Quoted 10 lines
Quoted 10 lines
Regressions are priority 1. Customers hate them! ;-)
So, here is the offending code:
lookup_ghostcallsread_map, which does this:while(1) { entry =
read_one(f, key, mapent); if (entry)cache_update(root, key, mapent, age);if (feof(f)) break; }
raven> Yes. I see that in the
lookup_ypmodule as well but thelookup_ldapraven> module doesn't have the same problem.Quoted 4 lines
Quoted 4 lines
This is the first time the map is read. If
cache_updatedoesn't find a previous entry, it creates one. If it does find an entry, it /replaces/ it with what you pass in. Thus, the last entry in an indirect map shows up as the only entry.raven> Yep. I see that's the way it behaves.
Quoted 9 lines
Quoted 9 lines
This is a bit of a tricky problem. It could be addressed in one of a number of ways, but before I go off implementing anything, I wanted to get your input on the matter.
The cache wasn't really meant to have multiple copies of the same key with different values. What you really want, I guess is something that conceptually works like this:
cache_update: change key X value Y to key X value Zraven> After looking at this more closely I think the problem might not be raven> so hard to solve after all.
raven> I don't really care if there's multiple entries for a key. To raven> maintain sensible behaviour we should return the first match on raven> lookup and that's what happens now anyway. As you point out the raven> problem happens when we populate the cache.
raven> But there's more. See below.
Quoted 4 lines
Quoted 4 lines
I guess we could get the current versions from the cache, but is there a deterministic way of mapping old key/value pairs to updated ones in the presence of multiple entries per key? (confusing question? read it a few more times ;)
raven> This is the bit I'm not sure about yet.
raven> Perhaps we need to carry a map id in cache entries or in the context raven> to identify them when we lookup them up later and possibly update raven> them?
Quoted 7 lines
How? There is no deterministic way to do this because the backing store (whether it's a file or nis or ldap) does not keep this information. At the end of the day, I don't really think it matters, though. What I think should happen is that we simply preserve the order in the map.
Instead of only updating one key in the cache, if the cache has gone stale we should re-read the whole thing.
It's not quite like that.
Locating an updated entry is a clue we need to reread the whole map. It's not possible to reread the whole map during a lookup as it's done in a subprocess. However, if a change is found then a HUP signal is sent to the parent so it does reread the whole map.
Quoted 48 lines
Note that current behaviour is pretty broken for things like files. If the modification time changes on a file, we revert to always bypassing the cache! We never re-read the entire map, and even if we have the freshest copy of a data item in the cache, we still go to disk.
raven> Anyway we'll always be updating the first match (as the semantic raven> requires) so it might not matter.
I think we're on the same page here, but to be sure: map entries should be read in and populated in the cache in the order they appear in the map. The first entry should always be returned.
raven> The question that arises from this is "will we allow duplicate keys raven> within individual maps"?
raven> That would make things much more difficult and probably won't give raven> functionality that's needed or used.
No need.
Quoted 2 lines
Quoted 2 lines
So, I'll ponder this for a bit, and maybe come up with a patch that you can tear to shreds, but I'd really like your input on the matter.
raven> It seems that our first attempt at solving this (the bad bits due to raven> me of course) did two things.
raven> 1) Changed
cache_addto add if no key is present but to append to raven> the end of the hash chain for that key if it is present.raven> That would be OK if we called
cache_add(as we do inlookup_ldap) raven> instead ofcache_update(as we do inlookup_fileandlookup_yp) raven> (doh!).raven> 2) I changed the
lookup_multimodule to populate the cache in raven> reverse map order.raven> Now that's just broken.
raven> So consider the following patch together with the original patch. I raven> think this might be all that's needed, at least in populating the raven> cache.
raven> It reverts the change in 2) and changes
cache_updatetocache_addin raven> the needed places.raven> What do you think?
Quoted 8 lines
I'll take a look.
raven> As I said above the other question that needs to be answered is raven> whether this will have undesirable side affects at lookup time?
So long as we return the first entry that appears in the map, we are doing the right thing. The hard part is handling updates, and I think we need more code to account for that.
Looks to me like this should be able to be achieved without much change.
It really shouldn't be that difficult to do. I hope that the patch in my last mail will acheive it.
Ian
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; [email protected] adds:
[snip]
raven> So consider the following patch together with the original patch. I raven> think this might be all that's needed, at least in populating the raven> cache.
raven> It reverts the change in 2) and changes cache_update to cache_add in raven> the needed places.
raven> What do you think?
raven> As I said above the other question that needs to be answered is raven> whether this will have undesirable side affects at lookup time?
Hi, Ian,
I've tested this patch and it resolves the problem. We should pursue the other map expiry related problem I described in my last mail separately, I think.
Thanks!
-Jeff
Ian Kent
maintainerQuoted 13 lines · Jeff Moyer
==> Regarding Re: [patch rfc] address regression in duplicate map entry order; [email protected] adds:
[snip]
raven> So consider the following patch together with the original patch. I raven> think this might be all that's needed, at least in populating the raven> cache.
raven> It reverts the change in 2) and changes
cache_updatetocache_addin raven> the needed places.raven> What do you think?
Quoted 8 lines
raven> As I said above the other question that needs to be answered is raven> whether this will have undesirable side affects at lookup time?
Hi, Ian,
I've tested this patch and it resolves the problem. We should pursue the other map expiry related problem I described in my last mail separately, I think.
Great.
I'll assume that at least this change is in the rpm and merge it into the beta.
Ian