Skip to content

Commit

Permalink
zonefs: Fix active zone accounting
Browse files Browse the repository at this point in the history
If a file zone transitions to the offline or readonly state from an
active state, we must clear the zone active flag and decrement the
active seq file counter. Do so in zonefs_account_active() using the new
zonefs inode flags ZONEFS_ZONE_OFFLINE and ZONEFS_ZONE_READONLY. These
flags are set if necessary in zonefs_check_zone_condition() based on the
result of report zones operation after an IO error.

Fixes: 87c9ce3 ("zonefs: Add active seq file accounting")
Cc: [email protected]
Signed-off-by: Damien Le Moal <[email protected]>
Reviewed-by: Johannes Thumshirn <[email protected]>
  • Loading branch information
Damien Le Moal committed Nov 25, 2022
1 parent 4e45886 commit db58653
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions fs/zonefs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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:
/*
Expand All @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions fs/zonefs/zonefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ static inline enum zonefs_ztype zonefs_zone_type(struct blk_zone *zone)
return ZONEFS_ZTYPE_SEQ;
}

#define ZONEFS_ZONE_OPEN (1 << 0)
#define ZONEFS_ZONE_ACTIVE (1 << 1)
#define ZONEFS_ZONE_OPEN (1U << 0)
#define ZONEFS_ZONE_ACTIVE (1U << 1)
#define ZONEFS_ZONE_OFFLINE (1U << 2)
#define ZONEFS_ZONE_READONLY (1U << 3)

/*
* In-memory inode data.
Expand Down

0 comments on commit db58653

Please sign in to comment.