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