summaryrefslogtreecommitdiff
path: root/fs/xfs/libxfs/xfs_zones.c
blob: 24e350c31933e6eac7e8b16dd4dadfce55959831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2023-2025 Christoph Hellwig.
 * Copyright (c) 2024-2025, Western Digital Corporation or its affiliates.
 */
#include "xfs_platform.h"
#include "xfs_fs.h"
#include "xfs_shared.h"
#include "xfs_format.h"
#include "xfs_log_format.h"
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
#include "xfs_inode.h"
#include "xfs_rtgroup.h"
#include "xfs_zones.h"

static bool
xfs_validate_blk_zone_seq(
	struct xfs_mount	*mp,
	struct blk_zone		*zone,
	unsigned int		zone_no,
	xfs_rgblock_t		*write_pointer)
{
	switch (zone->cond) {
	case BLK_ZONE_COND_EMPTY:
		*write_pointer = 0;
		return true;
	case BLK_ZONE_COND_IMP_OPEN:
	case BLK_ZONE_COND_EXP_OPEN:
	case BLK_ZONE_COND_CLOSED:
	case BLK_ZONE_COND_ACTIVE:
		if (zone->wp < zone->start ||
		    zone->wp >= zone->start + zone->capacity) {
			xfs_warn(mp,
	"zone %u write pointer (%llu) outside of zone.",
				zone_no, zone->wp);
			return false;
		}

		*write_pointer = XFS_BB_TO_FSB(mp, zone->wp - zone->start);
		return true;
	case BLK_ZONE_COND_FULL:
		*write_pointer = XFS_BB_TO_FSB(mp, zone->capacity);
		return true;
	case BLK_ZONE_COND_NOT_WP:
	case BLK_ZONE_COND_OFFLINE:
	case BLK_ZONE_COND_READONLY:
		xfs_warn(mp, "zone %u has unsupported zone condition 0x%x.",
			zone_no, zone->cond);
		return false;
	default:
		xfs_warn(mp, "zone %u has unknown zone condition 0x%x.",
			zone_no, zone->cond);
		return false;
	}
}

static bool
xfs_validate_blk_zone_conv(
	struct xfs_mount	*mp,
	struct blk_zone		*zone,
	unsigned int		zone_no)
{
	switch (zone->cond) {
	case BLK_ZONE_COND_NOT_WP:
		return true;
	default:
		xfs_warn(mp,
"conventional zone %u has unsupported zone condition 0x%x.",
			 zone_no, zone->cond);
		return false;
	}
}

bool
xfs_validate_blk_zone(
	struct xfs_mount	*mp,
	struct blk_zone		*zone,
	unsigned int		zone_no,
	uint32_t		expected_size,
	uint32_t		expected_capacity,
	xfs_rgblock_t		*write_pointer)
{
	/*
	 * Check that the zone capacity matches the rtgroup size stored in the
	 * superblock.  Note that all zones including the last one must have a
	 * uniform capacity.
	 */
	if (XFS_BB_TO_FSB(mp, zone->capacity) != expected_capacity) {
		xfs_warn(mp,
"zone %u capacity (%llu) does not match RT group size (%u).",
			zone_no, XFS_BB_TO_FSB(mp, zone->capacity),
			expected_capacity);
		return false;
	}

	if (XFS_BB_TO_FSB(mp, zone->len) != expected_size) {
		xfs_warn(mp,
"zone %u length (%llu) does not match geometry (%u).",
			zone_no, XFS_BB_TO_FSB(mp, zone->len),
			expected_size);
		return false;
	}

	switch (zone->type) {
	case BLK_ZONE_TYPE_CONVENTIONAL:
		return xfs_validate_blk_zone_conv(mp, zone, zone_no);
	case BLK_ZONE_TYPE_SEQWRITE_REQ:
		return xfs_validate_blk_zone_seq(mp, zone, zone_no,
				write_pointer);
	default:
		xfs_warn(mp, "zoned %u has unsupported type 0x%x.",
			zone_no, zone->type);
		return false;
	}
}