1// Copyright 2019 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// Package btrfs provides access to statistics exposed by Btrfs filesystems.
15package btrfs
16
17// Stats contains statistics for a single Btrfs filesystem.
18// See Linux fs/btrfs/sysfs.c for more information.
19type Stats struct {
20	UUID, Label    string
21	Allocation     Allocation
22	Devices        map[string]*Device
23	Features       []string
24	CloneAlignment uint64
25	NodeSize       uint64
26	QuotaOverride  uint64
27	SectorSize     uint64
28}
29
30// Allocation contains allocation statistics for data, metadata and system data.
31type Allocation struct {
32	GlobalRsvReserved, GlobalRsvSize uint64
33	Data, Metadata, System           *AllocationStats
34}
35
36// AllocationStats contains allocation statistics for a data type.
37type AllocationStats struct {
38	// Usage statistics
39	DiskUsedBytes    uint64
40	DiskTotalBytes   uint64
41	MayUseBytes      uint64
42	PinnedBytes      uint64
43	TotalPinnedBytes uint64
44	ReadOnlyBytes    uint64
45	ReservedBytes    uint64
46	UsedBytes        uint64
47	TotalBytes       uint64
48
49	// Flags marking filesystem state
50	// See Linux fs/btrfs/ctree.h for more information.
51	Flags uint64
52
53	// Additional disk usage statistics depending on the disk layout.
54	// At least one of these will exist and not be nil.
55	Layouts map[string]*LayoutUsage
56}
57
58// LayoutUsage contains additional usage statistics for a disk layout.
59type LayoutUsage struct {
60	UsedBytes, TotalBytes uint64
61	Ratio                 float64
62}
63
64// Device contains information about a device that is part of a Btrfs filesystem.
65type Device struct {
66	Size uint64
67}
68