aboutsummaryrefslogtreecommitdiffstats
path: root/fs/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/super.c')
-rw-r--r--fs/super.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/fs/super.c b/fs/super.c
index 65a53efc1cf4..2b7dc90ccdbb 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -71,7 +71,7 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
71 if (!(sc->gfp_mask & __GFP_FS)) 71 if (!(sc->gfp_mask & __GFP_FS))
72 return SHRINK_STOP; 72 return SHRINK_STOP;
73 73
74 if (!grab_super_passive(sb)) 74 if (!trylock_super(sb))
75 return SHRINK_STOP; 75 return SHRINK_STOP;
76 76
77 if (sb->s_op->nr_cached_objects) 77 if (sb->s_op->nr_cached_objects)
@@ -105,7 +105,7 @@ static unsigned long super_cache_scan(struct shrinker *shrink,
105 freed += sb->s_op->free_cached_objects(sb, sc); 105 freed += sb->s_op->free_cached_objects(sb, sc);
106 } 106 }
107 107
108 drop_super(sb); 108 up_read(&sb->s_umount);
109 return freed; 109 return freed;
110} 110}
111 111
@@ -118,7 +118,7 @@ static unsigned long super_cache_count(struct shrinker *shrink,
118 sb = container_of(shrink, struct super_block, s_shrink); 118 sb = container_of(shrink, struct super_block, s_shrink);
119 119
120 /* 120 /*
121 * Don't call grab_super_passive as it is a potential 121 * Don't call trylock_super as it is a potential
122 * scalability bottleneck. The counts could get updated 122 * scalability bottleneck. The counts could get updated
123 * between super_cache_count and super_cache_scan anyway. 123 * between super_cache_count and super_cache_scan anyway.
124 * Call to super_cache_count with shrinker_rwsem held 124 * Call to super_cache_count with shrinker_rwsem held
@@ -348,35 +348,31 @@ static int grab_super(struct super_block *s) __releases(sb_lock)
348} 348}
349 349
350/* 350/*
351 * grab_super_passive - acquire a passive reference 351 * trylock_super - try to grab ->s_umount shared
352 * @sb: reference we are trying to grab 352 * @sb: reference we are trying to grab
353 * 353 *
354 * Tries to acquire a passive reference. This is used in places where we 354 * Try to prevent fs shutdown. This is used in places where we
355 * cannot take an active reference but we need to ensure that the 355 * cannot take an active reference but we need to ensure that the
356 * superblock does not go away while we are working on it. It returns 356 * filesystem is not shut down while we are working on it. It returns
357 * false if a reference was not gained, and returns true with the s_umount 357 * false if we cannot acquire s_umount or if we lose the race and
358 * lock held in read mode if a reference is gained. On successful return, 358 * filesystem already got into shutdown, and returns true with the s_umount
359 * the caller must drop the s_umount lock and the passive reference when 359 * lock held in read mode in case of success. On successful return,
360 * done. 360 * the caller must drop the s_umount lock when done.
361 *
362 * Note that unlike get_super() et.al. this one does *not* bump ->s_count.
363 * The reason why it's safe is that we are OK with doing trylock instead
364 * of down_read(). There's a couple of places that are OK with that, but
365 * it's very much not a general-purpose interface.
361 */ 366 */
362bool grab_super_passive(struct super_block *sb) 367bool trylock_super(struct super_block *sb)
363{ 368{
364 spin_lock(&sb_lock);
365 if (hlist_unhashed(&sb->s_instances)) {
366 spin_unlock(&sb_lock);
367 return false;
368 }
369
370 sb->s_count++;
371 spin_unlock(&sb_lock);
372
373 if (down_read_trylock(&sb->s_umount)) { 369 if (down_read_trylock(&sb->s_umount)) {
374 if (sb->s_root && (sb->s_flags & MS_BORN)) 370 if (!hlist_unhashed(&sb->s_instances) &&
371 sb->s_root && (sb->s_flags & MS_BORN))
375 return true; 372 return true;
376 up_read(&sb->s_umount); 373 up_read(&sb->s_umount);
377 } 374 }
378 375
379 put_super(sb);
380 return false; 376 return false;
381} 377}
382 378