Skip to main content

fxfs/serialized_types/
types.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::blob_metadata::{BlobMetadata, BlobMetadataV53};
6use crate::lsm_tree::{
7    PersistentLayerHeader, PersistentLayerHeaderV39, PersistentLayerInfo, PersistentLayerInfoV39,
8};
9use crate::object_store::allocator::{
10    AllocatorInfo, AllocatorInfoV32, AllocatorKey, AllocatorKeyV32, AllocatorValue,
11    AllocatorValueV32,
12};
13use crate::object_store::journal::super_block::{
14    SuperBlockHeader, SuperBlockHeaderV32, SuperBlockRecord, SuperBlockRecordV40,
15    SuperBlockRecordV41, SuperBlockRecordV43, SuperBlockRecordV46, SuperBlockRecordV47,
16    SuperBlockRecordV49, SuperBlockRecordV50, SuperBlockRecordV54, SuperBlockRecordV55,
17    SuperBlockRecordV56,
18};
19use crate::object_store::journal::{
20    JournalRecord, JournalRecordV40, JournalRecordV41, JournalRecordV42, JournalRecordV43,
21    JournalRecordV46, JournalRecordV47, JournalRecordV49, JournalRecordV50, JournalRecordV54,
22    JournalRecordV55, JournalRecordV56,
23};
24use crate::object_store::object_record::{
25    FsverityMetadata, FsverityMetadataV33, FsverityMetadataV50, ObjectKey, ObjectKeyV40,
26    ObjectKeyV43, ObjectKeyV54, ObjectValue, ObjectValueV40, ObjectValueV41, ObjectValueV46,
27    ObjectValueV47, ObjectValueV49, ObjectValueV50, ObjectValueV54, ObjectValueV56,
28};
29use crate::object_store::transaction::{
30    Mutation, MutationV40, MutationV41, MutationV43, MutationV46, MutationV47, MutationV49,
31    MutationV50, MutationV54, MutationV55, MutationV56,
32};
33use crate::object_store::{
34    EncryptedMutations, EncryptedMutationsV40, EncryptedMutationsV49, StoreInfo, StoreInfoV40,
35    StoreInfoV49, StoreInfoV52,
36};
37use crate::serialized_types::{Version, Versioned, VersionedLatest, versioned_type};
38use std::collections::BTreeMap;
39
40/// The latest version of on-disk filesystem format.
41///
42/// If all layer files are compacted the the journal flushed, and super-block
43/// both rewritten, all versions should match this value.
44///
45/// If making a breaking change, please see EARLIEST_SUPPORTED_VERSION (below).
46///
47/// IMPORTANT: When changing this (major or minor), update the list of possible versions at
48/// https://cs.opensource.google/fuchsia/fuchsia/+/main:third_party/cobalt_config/fuchsia/local_storage/versions.txt.
49pub const LATEST_VERSION: Version = Version { major: 56, minor: 0 };
50
51/// From this version of the filesystem, the sequence number is removed from the Item struct.
52pub const REMOVE_ITEM_SEQUENCE_VERSION: u32 = 55;
53
54/// The earliest supported version of the on-disk filesystem format.
55///
56/// When a breaking change is made:
57/// 1) LATEST_VERSION should have it's major component increased (see above).
58/// 2) EARLIEST_SUPPORTED_VERSION should be set to the new LATEST_VERSION.
59/// 3) The SuperBlockHeader version (below) should also be set to the new LATEST_VERSION.
60///
61/// Also check the constant version numbers above for any code cleanup that can happen.
62pub const EARLIEST_SUPPORTED_VERSION: Version = Version { major: 40, minor: 0 };
63
64/// From this version of the filesystem, we shrink the size of the extents that are reserved for
65/// the superblock and root-parent store to a single block.
66pub const SMALL_SUPERBLOCK_VERSION: Version = Version { major: 44, minor: 0 };
67
68/// From this version of the filesystem, the superblock explicitly includes a record for it's
69/// first extent. Prior to this, the first extent was assumed based on hard-coded location.
70pub const FIRST_EXTENT_IN_SUPERBLOCK_VERSION: Version = Version { major: 45, minor: 0 };
71
72/// This trait prevents types from showing up in `versioned_types` multiple times. `versioned_types`
73/// implements this trait for every type passed to it. If a type is listed multiple times then this
74/// trait will be implemented for the type multiple times which will fail to compile.
75#[allow(dead_code)]
76trait UniqueVersionForType {}
77
78macro_rules! versioned_types {
79    ( $( $name:ident { $latest:literal.. => $latest_type:ty $(, $major:literal.. => $type:ty )* $(,)? } )+ ) => {
80        $(
81            static_assertions::assert_type_eq_all!($name, $latest_type);
82
83            versioned_type! {
84                $latest.. => $latest_type,
85                $( $major.. => $type ),*
86            }
87
88            impl UniqueVersionForType for $latest_type {}
89            $( impl UniqueVersionForType for $type {} )*
90        )+
91
92        pub fn get_type_fingerprints(version: Version) -> BTreeMap<String, String> {
93            let mut map = BTreeMap::new();
94            $(
95                let fingerprint = {
96                    let mut fp = None;
97                    const FINGERPRINTS: &[(u32, fn() -> String)] = &[
98                        ($latest, <$latest_type as fprint::TypeFingerprint>::fingerprint),
99                        $( ($major, <$type as fprint::TypeFingerprint>::fingerprint) ),*
100                    ];
101                    for (major, type_fp) in FINGERPRINTS {
102                        if version.major >= *major {
103                            fp = Some(type_fp());
104                            break;
105                        }
106                    }
107                    fp
108                };
109                if let Some(fp) = fingerprint {
110                    map.insert(stringify!($name).to_string(), fp.to_string());
111                }
112            )+
113            map
114        }
115    };
116}
117
118versioned_types! {
119    AllocatorInfo {
120        32.. => AllocatorInfoV32,
121    }
122    AllocatorKey {
123        32.. => AllocatorKeyV32,
124    }
125    AllocatorValue {
126        32.. => AllocatorValueV32,
127    }
128    EncryptedMutations {
129        49.. => EncryptedMutationsV49,
130        40.. => EncryptedMutationsV40,
131    }
132    FsverityMetadata {
133        50.. => FsverityMetadataV50,
134        33.. => FsverityMetadataV33,
135    }
136    JournalRecord {
137        56.. => JournalRecordV56,
138        55.. => JournalRecordV55,
139        54.. => JournalRecordV54,
140        50.. => JournalRecordV50,
141        49.. => JournalRecordV49,
142        47.. => JournalRecordV47,
143        46.. => JournalRecordV46,
144        43.. => JournalRecordV43,
145        42.. => JournalRecordV42,
146        41.. => JournalRecordV41,
147        40.. => JournalRecordV40,
148    }
149    Mutation {
150        56.. => MutationV56,
151        55.. => MutationV55,
152        54.. => MutationV54,
153        50.. => MutationV50,
154        49.. => MutationV49,
155        47.. => MutationV47,
156        46.. => MutationV46,
157        43.. => MutationV43,
158        41.. => MutationV41,
159        40.. => MutationV40,
160    }
161    ObjectKey {
162        54.. => ObjectKeyV54,
163        43.. => ObjectKeyV43,
164        40.. => ObjectKeyV40,
165    }
166    ObjectValue {
167        56.. => ObjectValueV56,
168        54.. => ObjectValueV54,
169        50.. => ObjectValueV50,
170        49.. => ObjectValueV49,
171        47.. => ObjectValueV47,
172        46.. => ObjectValueV46,
173        41.. => ObjectValueV41,
174        40.. => ObjectValueV40,
175    }
176    PersistentLayerHeader {
177        39.. => PersistentLayerHeaderV39,
178    }
179    PersistentLayerInfo {
180        39.. => PersistentLayerInfoV39,
181    }
182    StoreInfo {
183        52.. => StoreInfoV52,
184        49.. => StoreInfoV49,
185        40.. => StoreInfoV40,
186    }
187    SuperBlockHeader {
188        32.. => SuperBlockHeaderV32,
189    }
190    SuperBlockRecord {
191        56.. => SuperBlockRecordV56,
192        55.. => SuperBlockRecordV55,
193        54.. => SuperBlockRecordV54,
194        50.. => SuperBlockRecordV50,
195        49.. => SuperBlockRecordV49,
196        47.. => SuperBlockRecordV47,
197        46.. => SuperBlockRecordV46,
198        43.. => SuperBlockRecordV43,
199        41.. => SuperBlockRecordV41,
200        40.. => SuperBlockRecordV40,
201    }
202    BlobMetadata {
203        53.. => BlobMetadataV53,
204    }
205}