// SPDX-License-Identifier: GPL-2.0
/*
* Simple file system for zoned block devices exposing zones as files.
*
* Copyright (C) 2019 Western Digital Corporation or its affiliates.
*/
#include <linux/module.h>
#include <linux/pagemap.h>
#include <linux/magic.h>
#include <linux/iomap.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/blkdev.h>
#include <linux/statfs.h>
#include <linux/writeback.h>
#include <linux/quotaops.h>
#include <linux/seq_file.h>
#include <linux/parser.h>
#include <linux/uio.h>
#include <linux/mman.h>
#include <linux/sched/mm.h>
#include <linux/crc32.h>
#include <linux/task_io_accounting_ops.h>
#include "zonefs.h"
#define CREATE_TRACE_POINTS
#include "trace.h"
/*
* Get the name of a zone group directory.
*/
static const char *zonefs_zgroup_name(enum zonefs_ztype ztype)
{
switch (ztype) {
case ZONEFS_ZTYPE_CNV:
return "cnv";
case ZONEFS_ZTYPE_SEQ:
return "seq";
default:
WARN_ON_ONCE(1);
return "???";
}
}
/*
* Manage the active zone count.
*/
static void zonefs_account_active(struct super_block *sb,
struct zonefs_zone *z)
{
struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
if (zonefs_zone_is_cnv(z))
return;
/*
* For zones that transitioned to the offline or readonly condition,
* we only need to clear the active state.
*/
if (z->z_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.
*/
if ((z->z_flags & ZONEFS_ZONE_OPEN) ||
(z->z_wpoffset &g