Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2432,7 +2432,20 @@ async fn cmd_db_disk_info(
datastore: &DataStore,
args: &DiskInfoArgs,
) -> Result<(), anyhow::Error> {
match datastore.disk_get(opctx, args.uuid).await? {
let disk = {
use nexus_db_schema::schema::disk::dsl;

let conn = datastore.pool_connection_for_tests().await?;

dsl::disk
.filter(dsl::id.eq(args.uuid))
.select(nexus_db_model::Disk::as_select())
.get_result_async(&*conn)
.await
.unwrap()
};

match datastore.disk_get_with_model(opctx, disk).await? {
Disk::Crucible(disk) => {
crucible_disk_info(opctx, datastore, disk).await
}
Expand Down
18 changes: 18 additions & 0 deletions nexus/db-queries/src/db/datastore/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ impl Into<api::external::Disk> for Disk {
}

impl DataStore {
/// Return a `datastore::Disk` given a disk's UUID. Will perform a
/// LookupPath in order to retrive the `model::Disk`, then call
/// `disk_get_with_model`.
pub async fn disk_get(
&self,
opctx: &OpContext,
Expand All @@ -310,6 +313,21 @@ impl DataStore {
let (.., disk) =
LookupPath::new(opctx, self).disk_id(disk_id).fetch().await?;

self.disk_get_with_model(opctx, disk).await
}

/// Return a `datastore::Disk` given a `model::Disk`
///
/// Prefer to use `disk_get` instead: this version of the function bypasses
/// the LookupPath induced permissions check and is (currently) only called
/// from omdb.
pub async fn disk_get_with_model(
&self,
opctx: &OpContext,
disk: model::Disk,
) -> LookupResult<Disk> {
let disk_id = disk.id();

let conn = self.pool_connection_authorized(opctx).await?;

let disk = match disk.disk_type {
Expand Down
Loading