fix clean state bookkeeping on the basisroot cache record

This commit is contained in:
bunnie 2021-11-18 02:13:05 +08:00
parent a5da30de37
commit e1d00ef57c

View file

@ -555,34 +555,37 @@ impl BasisCacheEntry {
/// Syncs this cache entry to the hardware. /// Syncs this cache entry to the hardware.
pub(crate) fn basis_sync(&mut self, hw: &mut PddbOs) { pub(crate) fn basis_sync(&mut self, hw: &mut PddbOs) {
let basis_root = BasisRoot { if !self.clean {
magic: PDDB_MAGIC, let basis_root = BasisRoot {
version: PDDB_VERSION, magic: PDDB_MAGIC,
name: BasisRootName::try_from_str(&self.name).unwrap(), version: PDDB_VERSION,
age: self.age, name: BasisRootName::try_from_str(&self.name).unwrap(),
num_dictionaries: self.num_dicts, age: self.age,
}; num_dictionaries: self.num_dicts,
let aad = basis_root.aad(hw.dna()); };
let pp = self.v2p_map.get(&VirtAddr::new(1 * VPAGE_SIZE as u64).unwrap()) let aad = basis_root.aad(hw.dna());
.expect("Internal consistency error: Basis exists, but its root map was not allocated!"); let pp = self.v2p_map.get(&VirtAddr::new(1 * VPAGE_SIZE as u64).unwrap())
self.journal = self.journal.saturating_add(1); .expect("Internal consistency error: Basis exists, but its root map was not allocated!");
let journal_bytes = self.journal.to_le_bytes(); self.journal = self.journal.saturating_add(1);
let slice_iter = let journal_bytes = self.journal.to_le_bytes();
journal_bytes.iter() // journal rev let slice_iter =
.chain(basis_root.as_ref().iter()); journal_bytes.iter() // journal rev
let mut block = [0 as u8; VPAGE_SIZE + size_of::<JournalType>()]; .chain(basis_root.as_ref().iter());
for (&src, dst) in slice_iter.zip(block.iter_mut()) { let mut block = [0 as u8; VPAGE_SIZE + size_of::<JournalType>()];
*dst = src; for (&src, dst) in slice_iter.zip(block.iter_mut()) {
} *dst = src;
let nonce = hw.nonce_gen();
let ciphertext = self.cipher.encrypt(
&nonce,
Payload {
aad: &aad,
msg: &block,
} }
).unwrap(); let nonce = hw.nonce_gen();
hw.patch_data(&[nonce.as_slice(), &ciphertext].concat(), pp.page_number() * PAGE_SIZE as u32); let ciphertext = self.cipher.encrypt(
&nonce,
Payload {
aad: &aad,
msg: &block,
}
).unwrap();
hw.patch_data(&[nonce.as_slice(), &ciphertext].concat(), pp.page_number() * PAGE_SIZE as u32);
self.clean = true;
}
} }
} }