fs: reintroduce freezing nesting
PATCH 1/1 fs: reintroduce freezing nesting
The behavior was removed in 18e9e5104fcd9a973ffe3eed3816c87f2a1b6cd2 noting that this was a better idea than using a counter. However, this behavior is actually wanted if multiple applications want to freeze concurrently while remaining non-racy.
This patch reintroduces this feature by using a counter.
---
fs/super.c | 15 +++++++++++----
include/linux/fs.h | 1 +
2 files changed, 12 insertions(+), 4 deletions(-)
fs/super.c +0 -0
@@ -231,6 +231,7 @@ static struct super_block *alloc_super(struct
file_system_type *type, int flags)
*/
down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING); s->s_count = 1;
+ s->s_freezers = 0;
atomic_set(&s->s_active, 1); mutex_init(&s->s_vfs_rename_mutex); lockdep_set_class(&s->s_vfs_rename_mutex, &type-
Quoted 1 line
s_vfs_rename_key);
@@ -1275,12 +1276,12 @@ int freeze_super(struct super_block *sb) {
int ret;
+ sb->s_freezers++;
+ if (sb->s_writers.frozen != SB_UNFROZEN)
+ return 0;
+
atomic_inc(&sb->s_active); down_write(&sb->s_umount);
- if (sb->s_writers.frozen != SB_UNFROZEN) {
- deactivate_locked_super(sb);
- return -EBUSY;
- }
if (!(sb->s_flags & MS_BORN)) { up_write(&sb->s_umount);
@@ -1338,14 +1339,20 @@ EXPORT_SYMBOL(freeze_super);
* @sb: the super to thaw
*
* Unlocks the filesystem and marks it writeable again after freeze_super().
+ * Since nesting freezes is allowed, only the last freeze actually unlocks.
*/
int thaw_super(struct super_block *sb)
{
int error;
+ sb->s_freezers--;
+ if (sb->s_freezers > 0)
+ return 0;
+
down_write(&sb->s_umount);
if (sb->s_writers.frozen == SB_UNFROZEN) { up_write(&sb->s_umount);
+ sb->s_freezers++;
return -EINVAL;
}
include/linux/fs.h +0 -0
@@ -1333,6 +1333,7 @@ struct super_block {
struct quota_info s_dquot; /* Diskquota specific
options */
struct sb_writers s_writers;
+ int s_freezers;
char s_id[32]; /* Informational
name */
u8 s_uuid[16]; /* UUID */
--
2.8.0
Quoted 7 lines · Florian Margaine
The behavior was removed in 18e9e5104fcd9a973ffe3eed3816c87f2a1b6cd2 noting that this was a better idea than using a counter. However, this behavior is actually wanted if multiple applications want to freeze concurrently while remaining non-racy.
This patch reintroduces this feature by using a counter.
This patch is wrong.
It uses non-atomic ops to modify the counter and no locks are held to protect it.
I would argue the code should track that freezing has started and additional freezers must only return when the state is SB_FREEZE_COMPLETE.
Quoted 80 lines
---
fs/super.c | 15 +++++++++++----
include/linux/fs.h | 1 +2 files changed, 12 insertions(+), 4 deletions(-)fs/super.c +1
-0@@ -231,6 +231,7 @@ static struct super_block *alloc_super(structfile_system_type *type, int flags) */ down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING); s->s_count = 1; + s->s_freezers =0 ; atomic_set(&s->s_active, 1); mutex_init(&s->s_vfs_rename_mutex);lockdep_set_class(&s->s_vfs_rename_mutex, &type-
Quoted 1 line
s_vfs_rename_key);fs/super.c +0
-0@@ -1275,12 +1276,12 @@ int freeze_super(struct super_block *sb) { int ret;fs/super.c +4
-0+ sb->s_freezers++; +if (sb->s_writers.frozen !=SB_UNFROZEN ) +return 0 ; +
atomic_inc(&sb->s_active);
down_write(&sb->s_umount);fs/super.c +0
-4-if (sb->s_writers.frozen !=SB_UNFROZEN ) { -deactivate_locked_super (sb); -return -EBUSY ; - }
if (!(sb->s_flags &MS_BORN)) {
up_write(&sb->s_umount);fs/super.c +0
-0@@ -1338,14 +1339,20 @@ EXPORT_SYMBOL(freeze_super); * @sb: the super to thaw * * Unlocks the filesystem and marks it writeable again after
freeze_super().
+ * Since nesting freezes is allowed, only the last freeze actually unlocks.
*/
intthaw_super(struct super_block *sb)
{
int error;fs/super.c +4
-0+ sb->s_freezers--; +if (sb->s_freezers >0 ) +return 0 ; +
down_write(&sb->s_umount);
if (sb->s_writers.frozen==SB_UNFROZEN) {up_write(&sb->s_umount);fs/super.c +1
-0+ sb->s_freezers++;return
-EINVAL;
}include/linux/fs.h +0
-0@@ -1333,6 +1333,7 @@ struct super_block {struct
quota_infos_dquot; /* Diskquota specific
options */
structsb_writerss_writers;include/linux/fs.h +1
-0+int s_freezers;
char s_id[32]; /* Informational
name */
u8 s_uuid[16]; /* UUID */
--
2.8.0--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Mateusz Guzik
Quoted 9 lines · Mateusz Guzik
Quoted 7 lines · Florian Margaine
The behavior was removed in
18e9e5104fcd9a973ffe3eed3816c87f2a1b6cd2noting that this was a better idea than using a counter. However, this behavior is actually wanted if multiple applications want to freeze concurrently while remaining non-racy.This patch reintroduces this feature by using a counter.
Quoted 8 lines
This patch is wrong.
It uses non-atomic ops to modify the counter and no locks are held to protect it.
I would argue the code should track that freezing has started and additional freezers must only return when the state is
SB_FREEZE_COMPLETE.
Does it all additional freezers must return in order, or all additional freezers can return asap when SB_FREEZE_COMPLETE is set? I'm not sure the former is easily doable.
Quoted 84 lines
Quoted 77 lines
--- fs/super.c | 15 +++++++++++---- include/linux/fs.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)fs/super.c +1
-0@@ -231,6 +231,7 @@ static struct super_block *alloc_super(structfile_system_type *type, int flags) */ down_write_nested (&s->s_umount,SINGLE_DEPTH_NESTING ); s->s_count =1 ; + s->s_freezers =0 ;atomic_set (&s->s_active,1 );mutex_init (&s->s_vfs_rename_mutex);lockdep_set_class(&s->s_vfs_rename_mutex, &type-Quoted 1 line
s_vfs_rename_key);fs/super.c +4
-4@@ -1275,12 +1276,12 @@ int freeze_super(struct super_block *sb) {int ret; + sb->s_freezers++; +if (sb->s_writers.frozen !=SB_UNFROZEN ) +return 0 ; +atomic_inc (&sb->s_active);down_write (&sb->s_umount); -if (sb->s_writers.frozen !=SB_UNFROZEN ) { -deactivate_locked_super (sb); -return -EBUSY ; - }if (!(sb->s_flags &MS_BORN )) {up_write (&sb->s_umount);@@ -1338,14 +1339,20 @@ EXPORT_SYMBOL(freeze_super);* @sb: the super to thaw * * Unlocks the filesystem and marks it writeable again after
freeze_super().
+ * Since nesting freezes is allowed, only the last freeze actually unlocks.
*/
intthaw_super(struct super_block *sb){ int error;fs/super.c +5
-0+ sb->s_freezers--; +if (sb->s_freezers >0 ) +return 0 ; +down_write (&sb->s_umount);if (sb->s_writers.frozen ==SB_UNFROZEN ) {up_write (&sb->s_umount); + sb->s_freezers++;return -EINVAL ; }include/linux/fs.h +0
-0@@ -1333,6 +1333,7 @@ struct super_block {struct quota_info s_dquot;/* Diskquota specific options */
struct sb_writers s_writers;+ int
s_freezers;char s_id[32]; /* Informational
name */
u8 s_uuid[16]; /* UUID */
--
2.8.0Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Mateusz Guzik
Signature · 1 line
Florian Margaine