Merge tag 'zonefs-6.1-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal...
[sfrench/cifs-2.6.git] / fs / zonefs / super.c
index abc9a85106f24fad4834f8fdd6148ffbde2d8868..2c53fbb8d918e5ca63ab3a620455b1f173883251 100644 (file)
@@ -40,6 +40,13 @@ static void zonefs_account_active(struct inode *inode)
        if (zi->i_ztype != ZONEFS_ZTYPE_SEQ)
                return;
 
+       /*
+        * For zones that transitioned to the offline or readonly condition,
+        * we only need to clear the active state.
+        */
+       if (zi->i_flags & (ZONEFS_ZONE_OFFLINE | ZONEFS_ZONE_READONLY))
+               goto out;
+
        /*
         * If the zone is active, that is, if it is explicitly open or
         * partially written, check if it was already accounted as active.
@@ -53,6 +60,7 @@ static void zonefs_account_active(struct inode *inode)
                return;
        }
 
+out:
        /* The zone is not active. If it was, update the active count */
        if (zi->i_flags & ZONEFS_ZONE_ACTIVE) {
                zi->i_flags &= ~ZONEFS_ZONE_ACTIVE;
@@ -324,6 +332,7 @@ static loff_t zonefs_check_zone_condition(struct inode *inode,
                inode->i_flags |= S_IMMUTABLE;
                inode->i_mode &= ~0777;
                zone->wp = zone->start;
+               zi->i_flags |= ZONEFS_ZONE_OFFLINE;
                return 0;
        case BLK_ZONE_COND_READONLY:
                /*
@@ -342,8 +351,10 @@ static loff_t zonefs_check_zone_condition(struct inode *inode,
                        zone->cond = BLK_ZONE_COND_OFFLINE;
                        inode->i_mode &= ~0777;
                        zone->wp = zone->start;
+                       zi->i_flags |= ZONEFS_ZONE_OFFLINE;
                        return 0;
                }
+               zi->i_flags |= ZONEFS_ZONE_READONLY;
                inode->i_mode &= ~0222;
                return i_size_read(inode);
        case BLK_ZONE_COND_FULL:
@@ -1922,18 +1933,18 @@ static int __init zonefs_init(void)
        if (ret)
                return ret;
 
-       ret = register_filesystem(&zonefs_type);
+       ret = zonefs_sysfs_init();
        if (ret)
                goto destroy_inodecache;
 
-       ret = zonefs_sysfs_init();
+       ret = register_filesystem(&zonefs_type);
        if (ret)
-               goto unregister_fs;
+               goto sysfs_exit;
 
        return 0;
 
-unregister_fs:
-       unregister_filesystem(&zonefs_type);
+sysfs_exit:
+       zonefs_sysfs_exit();
 destroy_inodecache:
        zonefs_destroy_inodecache();
 
@@ -1942,9 +1953,9 @@ destroy_inodecache:
 
 static void __exit zonefs_exit(void)
 {
+       unregister_filesystem(&zonefs_type);
        zonefs_sysfs_exit();
        zonefs_destroy_inodecache();
-       unregister_filesystem(&zonefs_type);
 }
 
 MODULE_AUTHOR("Damien Le Moal");