
hulk inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT -------------------------------- Introduce "dir_has_put" in "struct cachefiles_volume" to indicate whether the cache directory has been put. It is used to replace the previous method of determining whether __cachefiles_free_volume() has been called by checking if "vcookie->cache_priv" is NULL. __cachefiles_free_volume() function primarily performs cleanup operations related to "cachefiles_volume". Therefore, it is more appropriate to set "vcookie->cache_priv" to NULL within cachefiles_free_volume() as it interacts more directly with "fscache_volume". It also prepares for subsequent patches. Signed-off-by: Zizhi Wo <wozizhi@huawei.com> --- fs/cachefiles/internal.h | 1 + fs/cachefiles/volume.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 111ad6ecd4ba..cb9607d643c7 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -40,6 +40,7 @@ struct cachefiles_volume { struct cachefiles_cache *cache; struct list_head cache_link; /* Link in cache->volumes */ struct fscache_volume *vcookie; /* The netfs's representation */ + bool dir_has_put; /* Indicates cache dir has been put */ struct dentry *dentry; /* The volume dentry */ struct dentry *fanout[256]; /* Fanout subdirs */ }; diff --git a/fs/cachefiles/volume.c b/fs/cachefiles/volume.c index 781aac4ef274..aa5467335d85 100644 --- a/fs/cachefiles/volume.c +++ b/fs/cachefiles/volume.c @@ -111,7 +111,10 @@ static void __cachefiles_free_volume(struct cachefiles_volume *volume) _enter(""); - volume->vcookie->cache_priv = NULL; + if (volume->dir_has_put) + return; + + volume->dir_has_put = true; for (i = 0; i < 256; i++) cachefiles_put_directory(volume->fanout[i]); @@ -123,12 +126,11 @@ void cachefiles_free_volume(struct fscache_volume *vcookie) { struct cachefiles_volume *volume = vcookie->cache_priv; - if (volume) { - spin_lock(&volume->cache->object_list_lock); - list_del_init(&volume->cache_link); - spin_unlock(&volume->cache->object_list_lock); - __cachefiles_free_volume(volume); - } + spin_lock(&volume->cache->object_list_lock); + list_del_init(&volume->cache_link); + spin_unlock(&volume->cache->object_list_lock); + vcookie->cache_priv = NULL; + __cachefiles_free_volume(volume); } void cachefiles_withdraw_volume(struct cachefiles_volume *volume) -- 2.46.1