From 32bcf25f99a6ea1ba91d68fbb3d3dc80ae008da5 Mon Sep 17 00:00:00 2001
From: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Date: Thu, 13 Jun 2024 17:22:23 +0200
Subject: [PATCH 1/2] virtio-blkd: Do not crash when the disk is empty
---
storage/virtio-blkd/src/main.rs | 2 --
storage/virtio-blkd/src/scheme.rs | 6 +++---
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/storage/virtio-blkd/src/main.rs b/storage/virtio-blkd/src/main.rs
index 1c13166341..9d71b3a8d1 100644
--- a/storage/virtio-blkd/src/main.rs
+++ b/storage/virtio-blkd/src/main.rs
@@ -1,8 +1,6 @@
#![deny(trivial_numeric_casts, unused_allocation)]
#![feature(int_roundings)]
-// TODO(andypython): driver panic with an empty disk.
-
use std::fs::File;
use std::io::{Read, Write};
use std::os::fd::{FromRawFd, RawFd};
diff --git a/storage/virtio-blkd/src/scheme.rs b/storage/virtio-blkd/src/scheme.rs
index e981de0369..3eec34d69b 100644
--- a/storage/virtio-blkd/src/scheme.rs
+++ b/storage/virtio-blkd/src/scheme.rs
@@ -184,10 +184,10 @@ impl<'a> DiskScheme<'a> {
};
let part_table = partitionlib::get_partitions(&mut shim, LogicalBlockSize::Lb512)
- .unwrap()
- .expect("virtiod: no partitions found");
+ .ok()
+ .flatten();
- this.part_table = Some(part_table);
+ this.part_table = part_table;
this
}
}
From 47ce36741e4fc5c3d81fc172e560573327dfb50c Mon Sep 17 00:00:00 2001
From: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Date: Thu, 13 Jun 2024 21:47:22 +0200
Subject: [PATCH 2/2] virtio-blkd: Avoid crash on ls /scheme
---
storage/virtio-blkd/src/scheme.rs | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/storage/virtio-blkd/src/scheme.rs b/storage/virtio-blkd/src/scheme.rs
index 3eec34d69b..3b37b547ff 100644
--- a/storage/virtio-blkd/src/scheme.rs
+++ b/storage/virtio-blkd/src/scheme.rs
@@ -210,10 +210,10 @@ impl<'a> SchemeBlockMut for DiskScheme<'a> {
// to the namespace id).
write!(list, "{}\n", 0).unwrap();
- let part_table = self.part_table.as_ref().unwrap();
-
- for part_num in 0..part_table.partitions.len() {
- write!(list, "{}p{}\n", 0, part_num).unwrap();
+ if let Some(part_table) = &self.part_table {
+ for part_num in 0..part_table.partitions.len() {
+ write!(list, "{}p{}\n", 0, part_num).unwrap();
+ }
}
let id = self.next_id;
@@ -389,8 +389,11 @@ impl<'a> SchemeBlockMut for DiskScheme<'a> {
todo!()
}
- fn fstat(&mut self, _id: usize, _stat: &mut syscall::Stat) -> syscall::Result