@@ -81,7 +81,7 @@ struct ns_monitor {
8181struct watch_ctx {
8282 flux_t * h ;
8383 flux_msg_handler_t * * handlers ;
84- zhash_t * namespaces ; // hash of monitored namespaces
84+ zhashx_t * namespaces ; // hash of monitored namespaces
8585};
8686
8787static void watcher_destroy (struct watcher * w )
@@ -164,9 +164,10 @@ static struct commit *commit_create (const char *rootref,
164164 return commit ;
165165}
166166
167- static void namespace_destroy (struct ns_monitor * nsm )
167+ static void namespace_destroy (void * * data )
168168{
169- if (nsm ) {
169+ if (data ) {
170+ struct ns_monitor * nsm = * data ;
170171 int saved_errno = errno ;
171172 commit_destroy (nsm -> commit );
172173 zlistx_destroy (& nsm -> watchers );
@@ -227,7 +228,7 @@ static struct ns_monitor *namespace_create (struct watch_ctx *ctx,
227228 nsm -> subscribed = true;
228229 return nsm ;
229230error :
230- namespace_destroy (nsm );
231+ namespace_destroy (( void * * ) & nsm );
231232 return NULL ;
232233}
233234
@@ -249,7 +250,7 @@ static void watcher_cleanup (struct ns_monitor *nsm, struct watcher *w)
249250 /* if nsm->getrootf, destroy when getroot_continuation completes */
250251 if (zlistx_size (nsm -> watchers ) == 0
251252 && !nsm -> getrootf )
252- zhash_delete (nsm -> ctx -> namespaces , nsm -> ns_name );
253+ zhashx_delete (nsm -> ctx -> namespaces , nsm -> ns_name );
253254}
254255
255256static void handle_load_response (flux_future_t * f , struct watcher * w )
@@ -1072,7 +1073,7 @@ static void watcher_cancel_all (struct watch_ctx *ctx,
10721073 const flux_msg_t * msg ,
10731074 bool cancel )
10741075{
1075- zlist_t * l ;
1076+ zlistx_t * l ;
10761077 char * name ;
10771078 struct ns_monitor * nsm ;
10781079 uint32_t matchtag = FLUX_MATCHTAG_NONE ;
@@ -1083,14 +1084,14 @@ static void watcher_cancel_all (struct watch_ctx *ctx,
10831084 return ;
10841085 }
10851086
1086- if ((l = zhash_keys (ctx -> namespaces ))) {
1087- name = zlist_first (l );
1087+ if ((l = zhashx_keys (ctx -> namespaces ))) {
1088+ name = zlistx_first (l );
10881089 while (name ) {
1089- nsm = zhash_lookup (ctx -> namespaces , name );
1090+ nsm = zhashx_lookup (ctx -> namespaces , name );
10901091 watcher_cancel_ns (nsm , msg , matchtag , cancel );
1091- name = zlist_next (l );
1092+ name = zlistx_next (l );
10921093 }
1093- zlist_destroy (& l );
1094+ zlistx_destroy (& l );
10941095 }
10951096 else
10961097 flux_log_error (ctx -> h , "%s: zhash_keys" , __FUNCTION__ );
@@ -1112,7 +1113,7 @@ static void removed_cb (flux_t *h,
11121113 flux_log_error (h , "%s: flux_event_unpack" , __FUNCTION__ );
11131114 return ;
11141115 }
1115- if ((nsm = zhash_lookup (ctx -> namespaces , ns ))) {
1116+ if ((nsm = zhashx_lookup (ctx -> namespaces , ns ))) {
11161117 nsm -> fatal_errnum = ENOTSUP ;
11171118 watcher_respond_ns (nsm );
11181119 }
@@ -1145,7 +1146,7 @@ static void namespace_created_cb (flux_t *h,
11451146 flux_log_error (h , "%s: flux_event_unpack" , __FUNCTION__ );
11461147 return ;
11471148 }
1148- if (!(nsm = zhash_lookup (ctx -> namespaces , ns ))
1149+ if (!(nsm = zhashx_lookup (ctx -> namespaces , ns ))
11491150 || nsm -> commit )
11501151 return ;
11511152 if (!(commit = commit_create (rootref , rootseq , NULL ))) {
@@ -1189,7 +1190,7 @@ static void setroot_cb (flux_t *h,
11891190 flux_log_error (h , "%s: flux_event_unpack" , __FUNCTION__ );
11901191 return ;
11911192 }
1192- if (!(nsm = zhash_lookup (ctx -> namespaces , ns ))
1193+ if (!(nsm = zhashx_lookup (ctx -> namespaces , ns ))
11931194 || (nsm -> commit && rootseq <= nsm -> commit -> rootseq ))
11941195 return ;
11951196 if (!(commit = commit_create (rootref , rootseq , keys ))) {
@@ -1219,7 +1220,7 @@ static void namespace_getroot_continuation (flux_future_t *f, void *arg)
12191220
12201221 /* small racy chance watcher canceled before getroot completes */
12211222 if (zlistx_size (nsm -> watchers ) == 0 ) {
1222- zhash_delete (nsm -> ctx -> namespaces , nsm -> ns_name );
1223+ zhashx_delete (nsm -> ctx -> namespaces , nsm -> ns_name );
12231224 return ;
12241225 }
12251226 if (nsm -> commit ) {
@@ -1260,21 +1261,19 @@ struct ns_monitor *namespace_monitor (struct watch_ctx *ctx,
12601261{
12611262 struct ns_monitor * nsm ;
12621263
1263- if (!(nsm = zhash_lookup (ctx -> namespaces , ns ))) {
1264+ if (!(nsm = zhashx_lookup (ctx -> namespaces , ns ))) {
12641265 if (!(nsm = namespace_create (ctx , ns )))
12651266 return NULL ;
1266- (void )zhash_insert (ctx -> namespaces , ns , nsm );
1267- zhash_freefn (ctx -> namespaces , ns ,
1268- (zhash_free_fn * )namespace_destroy );
1267+ (void )zhashx_insert (ctx -> namespaces , ns , nsm );
12691268 /* store future in namespace, so namespace can be destroyed
12701269 * appropriately to avoid matchtag leak */
12711270 if (!(nsm -> getrootf = flux_kvs_getroot (ctx -> h , ns , 0 ))) {
1272- zhash_delete (ctx -> namespaces , ns );
1271+ zhashx_delete (ctx -> namespaces , ns );
12731272 return NULL ;
12741273 }
12751274 if (flux_future_then (nsm -> getrootf , -1. ,
12761275 namespace_getroot_continuation , nsm ) < 0 ) {
1277- zhash_delete (ctx -> namespaces , ns );
1276+ zhashx_delete (ctx -> namespaces , ns );
12781277 return NULL ;
12791278 }
12801279 }
@@ -1380,7 +1379,7 @@ static void stats_cb (flux_t *h,
13801379
13811380 if (!(stats = json_object ()))
13821381 goto nomem ;
1383- nsm = zhash_first (ctx -> namespaces );
1382+ nsm = zhashx_first (ctx -> namespaces );
13841383 while (nsm ) {
13851384 json_t * o = json_pack ("{s:i s:i s:s s:i}" ,
13861385 "owner" , (int )nsm -> owner ,
@@ -1396,13 +1395,13 @@ static void stats_cb (flux_t *h,
13961395 goto nomem ;
13971396 }
13981397 watchers += zlistx_size (nsm -> watchers );
1399- nsm = zhash_next (ctx -> namespaces );
1398+ nsm = zhashx_next (ctx -> namespaces );
14001399 }
14011400 if (flux_respond_pack (h ,
14021401 msg ,
14031402 "{s:i s:i s:O}" ,
14041403 "watchers" , watchers ,
1405- "namespace-count" , (int )zhash_size (ctx -> namespaces ),
1404+ "namespace-count" , (int )zhashx_size (ctx -> namespaces ),
14061405 "namespaces" , stats ) < 0 )
14071406 flux_log_error (h ,
14081407 "%s: failed to respond to kvs-watch.stats-get" ,
@@ -1460,7 +1459,7 @@ static void watch_ctx_destroy (struct watch_ctx *ctx)
14601459{
14611460 if (ctx ) {
14621461 int saved_errno = errno ;
1463- zhash_destroy (& ctx -> namespaces );
1462+ zhashx_destroy (& ctx -> namespaces );
14641463 flux_msg_handler_delvec (ctx -> handlers );
14651464 free (ctx );
14661465 errno = saved_errno ;
@@ -1475,8 +1474,10 @@ static struct watch_ctx *watch_ctx_create (flux_t *h)
14751474 ctx -> h = h ;
14761475 if (flux_msg_handler_addvec (h , htab , ctx , & ctx -> handlers ) < 0 )
14771476 goto error ;
1478- if (!(ctx -> namespaces = zhash_new ()))
1477+ if (!(ctx -> namespaces = zhashx_new ()))
14791478 goto error ;
1479+ zhashx_set_destructor (ctx -> namespaces ,
1480+ (zhashx_destructor_fn * )namespace_destroy );
14801481 return ctx ;
14811482error :
14821483 watch_ctx_destroy (ctx );
0 commit comments