@@ -224,6 +224,12 @@ static void remove_initpid(struct pidns_store *entry)
224
224
}
225
225
}
226
226
227
+ static bool keep_pidns_entry (struct pidns_store * entry )
228
+ {
229
+ return (entry -> version >= 1 ) && entry -> keep_on_reload &&
230
+ initpid_still_valid (entry );
231
+ }
232
+
227
233
#define PURGE_SECS 5
228
234
/* Must be called under store_lock */
229
235
static void prune_initpid_store (void )
@@ -250,10 +256,11 @@ static void prune_initpid_store(void)
250
256
251
257
for (int i = 0 ; i < PIDNS_HASH_SIZE ; i ++ ) {
252
258
for (struct pidns_store * entry = pidns_hash_table [i ], * prev = NULL ; entry ;) {
253
- if (entry -> lastcheck < threshold ) {
254
- struct pidns_store * cur = entry ;
259
+ struct pidns_store * cur = entry ;
255
260
256
- lxcfs_debug ("Removed cache entry for pid %d to init pid cache" , cur -> initpid );
261
+ if ((entry -> lastcheck < threshold ) &&
262
+ !keep_pidns_entry (cur )) {
263
+ lxcfs_debug ("Removed cache entry for pid %d from init pid cache" , cur -> initpid );
257
264
258
265
if (prev )
259
266
prev -> next = entry -> next ;
@@ -263,6 +270,8 @@ static void prune_initpid_store(void)
263
270
close_prot_errno_disarm (cur -> init_pidfd );
264
271
free_disarm (cur );
265
272
} else {
273
+ lxcfs_debug ("Kept cache entry for pid %d in init pid cache" , cur -> initpid );
274
+
266
275
prev = entry ;
267
276
entry = entry -> next ;
268
277
}
@@ -277,15 +286,25 @@ static void clear_initpid_store(void)
277
286
278
287
store_lock ();
279
288
for (int i = 0 ; i < PIDNS_HASH_SIZE ; i ++ ) {
280
- for (struct pidns_store * entry = pidns_hash_table [i ]; entry ;) {
289
+ for (struct pidns_store * entry = pidns_hash_table [i ], * prev = NULL ; entry ;) {
281
290
struct pidns_store * cur = entry ;
282
291
283
- lxcfs_debug ("Removed cache entry for pid %d to init pid cache" , cur -> initpid );
292
+ if (keep_pidns_entry (cur )) {
293
+ lxcfs_debug ("Kept cache entry for pid %d in init pid cache" , cur -> initpid );
294
+
295
+ prev = entry ;
296
+ entry = entry -> next ;
297
+ } else {
298
+ lxcfs_debug ("Removed cache entry for pid %d from init pid cache" , cur -> initpid );
284
299
285
- pidns_hash_table [i ] = entry -> next ;
286
- entry = entry -> next ;
287
- close_prot_errno_disarm (cur -> init_pidfd );
288
- free_disarm (cur );
300
+ if (prev )
301
+ prev -> next = entry -> next ;
302
+ else
303
+ pidns_hash_table [i ] = entry -> next ;
304
+ entry = entry -> next ;
305
+ close_prot_errno_disarm (cur -> init_pidfd );
306
+ free_disarm (cur );
307
+ }
289
308
}
290
309
}
291
310
store_unlock ();
@@ -320,13 +339,14 @@ static void save_initpid(ino_t pidns_inode, pid_t pid)
320
339
321
340
ino_hash = HASH (pidns_inode );
322
341
* entry = (struct pidns_store ){
323
- .version = 0 ,
342
+ .version = 1 ,
324
343
.ino = pidns_inode ,
325
344
.initpid = pid ,
326
345
.ctime = st .st_ctime ,
327
346
.next = pidns_hash_table [ino_hash ],
328
347
.lastcheck = time (NULL ),
329
348
.init_pidfd = move_fd (pidfd ),
349
+ .keep_on_reload = false,
330
350
};
331
351
pidns_hash_table [ino_hash ] = move_ptr (entry );
332
352
0 commit comments