@@ -97,7 +97,8 @@ static noinline void cachefiles_printk_object(struct cachefiles_object *object,
9797 * call vfs_unlink(), vfs_rmdir() or vfs_rename()
9898 */
9999static void cachefiles_mark_object_buried (struct cachefiles_cache * cache ,
100- struct dentry * dentry )
100+ struct dentry * dentry ,
101+ enum fscache_why_object_killed why )
101102{
102103 struct cachefiles_object * object ;
103104 struct rb_node * p ;
@@ -132,8 +133,9 @@ static void cachefiles_mark_object_buried(struct cachefiles_cache *cache,
132133 pr_err ("\n" );
133134 pr_err ("Error: Can't preemptively bury live object\n" );
134135 cachefiles_printk_object (object , NULL );
135- } else if (test_and_set_bit (CACHEFILES_OBJECT_BURIED , & object -> flags )) {
136- pr_err ("Error: Object already preemptively buried\n" );
136+ } else {
137+ if (why != FSCACHE_OBJECT_IS_STALE )
138+ fscache_object_mark_killed (& object -> fscache , why );
137139 }
138140
139141 write_unlock (& cache -> active_lock );
@@ -265,7 +267,8 @@ static int cachefiles_mark_object_active(struct cachefiles_cache *cache,
265267static int cachefiles_bury_object (struct cachefiles_cache * cache ,
266268 struct dentry * dir ,
267269 struct dentry * rep ,
268- bool preemptive )
270+ bool preemptive ,
271+ enum fscache_why_object_killed why )
269272{
270273 struct dentry * grave , * trap ;
271274 struct path path , path_to_graveyard ;
@@ -289,7 +292,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
289292 ret = vfs_unlink (dir -> d_inode , rep , NULL );
290293
291294 if (preemptive )
292- cachefiles_mark_object_buried (cache , rep );
295+ cachefiles_mark_object_buried (cache , rep , why );
293296 }
294297
295298 mutex_unlock (& dir -> d_inode -> i_mutex );
@@ -394,7 +397,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
394397 "Rename failed with error %d" , ret );
395398
396399 if (preemptive )
397- cachefiles_mark_object_buried (cache , rep );
400+ cachefiles_mark_object_buried (cache , rep , why );
398401 }
399402
400403 unlock_rename (cache -> graveyard , dir );
@@ -422,7 +425,7 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
422425
423426 mutex_lock_nested (& dir -> d_inode -> i_mutex , I_MUTEX_PARENT );
424427
425- if (test_bit (CACHEFILES_OBJECT_BURIED , & object -> flags )) {
428+ if (test_bit (FSCACHE_OBJECT_KILLED_BY_CACHE , & object -> fscache . flags )) {
426429 /* object allocation for the same key preemptively deleted this
427430 * object's file so that it could create its own file */
428431 _debug ("object preemptively buried" );
@@ -433,7 +436,8 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
433436 * may have been renamed */
434437 if (dir == object -> dentry -> d_parent ) {
435438 ret = cachefiles_bury_object (cache , dir ,
436- object -> dentry , false);
439+ object -> dentry , false,
440+ FSCACHE_OBJECT_WAS_RETIRED );
437441 } else {
438442 /* it got moved, presumably by cachefilesd culling it,
439443 * so it's no longer in the key path and we can ignore
@@ -522,7 +526,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
522526 if (!next -> d_inode ) {
523527 ret = cachefiles_has_space (cache , 1 , 0 );
524528 if (ret < 0 )
525- goto create_error ;
529+ goto no_space_error ;
526530
527531 path .dentry = dir ;
528532 ret = security_path_mkdir (& path , next , 0 );
@@ -551,7 +555,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
551555 if (!next -> d_inode ) {
552556 ret = cachefiles_has_space (cache , 1 , 0 );
553557 if (ret < 0 )
554- goto create_error ;
558+ goto no_space_error ;
555559
556560 path .dentry = dir ;
557561 ret = security_path_mknod (& path , next , S_IFREG , 0 );
@@ -602,14 +606,16 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
602606 * mutex) */
603607 object -> dentry = NULL ;
604608
605- ret = cachefiles_bury_object (cache , dir , next , true);
609+ ret = cachefiles_bury_object (cache , dir , next , true,
610+ FSCACHE_OBJECT_IS_STALE );
606611 dput (next );
607612 next = NULL ;
608613
609614 if (ret < 0 )
610615 goto delete_error ;
611616
612617 _debug ("redo lookup" );
618+ fscache_object_retrying_stale (& object -> fscache );
613619 goto lookup_again ;
614620 }
615621 }
@@ -662,6 +668,8 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
662668 _leave (" = 0 [%lu]" , object -> dentry -> d_inode -> i_ino );
663669 return 0 ;
664670
671+ no_space_error :
672+ fscache_object_mark_killed (& object -> fscache , FSCACHE_OBJECT_NO_SPACE );
665673create_error :
666674 _debug ("create error %d" , ret );
667675 if (ret == - EIO )
@@ -927,7 +935,8 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
927935 /* actually remove the victim (drops the dir mutex) */
928936 _debug ("bury" );
929937
930- ret = cachefiles_bury_object (cache , dir , victim , false);
938+ ret = cachefiles_bury_object (cache , dir , victim , false,
939+ FSCACHE_OBJECT_WAS_CULLED );
931940 if (ret < 0 )
932941 goto error ;
933942
0 commit comments