Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add overview and migrate existing to github #1805

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
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
Next Next commit
feat: parse human size for malloc and null bdevs
Parse a size with unit post-fix for the malloc and null bdevs.
This makes it much easier to use, example:
size=1TiB vs size_mb=1048576

Signed-off-by: Tiago Castro <[email protected]>
tiagolobocastro committed Jan 27, 2025
commit cd7020b344c8831407fbbd35d49ecfaa368fbebf
37 changes: 30 additions & 7 deletions io-engine/src/bdev/malloc.rs
Original file line number Diff line number Diff line change
@@ -76,17 +76,40 @@ impl TryFrom<&Url> for Malloc {
512
};

let size: u32 = if let Some(value) = parameters.remove("size_mb") {
value.parse().context(bdev_api::IntParamParseFailed {
let size_mb: Option<u64> = if let Some(value) = parameters.remove("size_mb") {
Some(value.parse().context(bdev_api::IntParamParseFailed {
uri: uri.to_string(),
parameter: String::from("size_mb"),
value: value.clone(),
})?
})?)
} else {
0
None
};

let num_blocks: u32 = if let Some(value) = parameters.remove("num_blocks") {
let size_b: Option<u64> = if let Some(value) = parameters.remove("size") {
Some(
byte_unit::Byte::parse_str(&value, true)
.map_err(|error| BdevError::InvalidUri {
uri: uri.to_string(),
message: format!("'size' is invalid: {error}"),
})?
.as_u64(),
)
} else {
None
};

let size = match (size_mb, size_b) {
(Some(_), Some(_)) => Err(BdevError::InvalidUri {
uri: uri.to_string(),
message: "Can't specify both size and size_mb".to_string(),
}),
(Some(size_mb), None) => Ok(size_mb * 1024 * 1024),
(None, Some(size)) => Ok(size),
(None, None) => Ok(0),
}?;

let num_blocks: u64 = if let Some(value) = parameters.remove("num_blocks") {
value.parse().context(bdev_api::IntParamParseFailed {
uri: uri.to_string(),
parameter: String::from("num_blocks"),
@@ -133,8 +156,8 @@ impl TryFrom<&Url> for Malloc {
num_blocks: if num_blocks != 0 {
num_blocks
} else {
(size << 20) / blk_size
} as u64,
size / (blk_size as u64)
},
blk_size,
uuid,
resizing,
38 changes: 31 additions & 7 deletions io-engine/src/bdev/null_bdev.rs
Original file line number Diff line number Diff line change
@@ -63,16 +63,39 @@ impl TryFrom<&Url> for Null {
});
}

let size: u64 = if let Some(value) = parameters.remove("size_mb") {
value.parse().context(bdev_api::IntParamParseFailed {
let size_mb: Option<u64> = if let Some(value) = parameters.remove("size_mb") {
Some(value.parse().context(bdev_api::IntParamParseFailed {
uri: uri.to_string(),
parameter: String::from("size_mb"),
value: value.clone(),
})?
})?)
} else {
0
None
};

let size_b: Option<u64> = if let Some(value) = parameters.remove("size") {
Some(
byte_unit::Byte::parse_str(&value, true)
.map_err(|error| BdevError::InvalidUri {
uri: uri.to_string(),
message: format!("'size' is invalid: {error}"),
})?
.as_u64(),
)
} else {
None
};

let size = match (size_mb, size_b) {
(Some(_), Some(_)) => Err(BdevError::InvalidUri {
uri: uri.to_string(),
message: "Can't specify both size and size_mb".to_string(),
}),
(Some(size_mb), None) => Ok(size_mb * 1024 * 1024),
(None, Some(size)) => Ok(size),
(None, None) => Ok(0),
}?;

let num_blocks: u64 = if let Some(value) = parameters.remove("num_blocks") {
value.parse().context(bdev_api::IntParamParseFailed {
uri: uri.to_string(),
@@ -86,8 +109,9 @@ impl TryFrom<&Url> for Null {
if size != 0 && num_blocks != 0 {
return Err(BdevError::InvalidUri {
uri: uri.to_string(),
message: "conflicting parameters num_blocks and size_mb are mutually exclusive"
.to_string(),
message:
"conflicting parameters num_blocks and size/size_mb are mutually exclusive"
.to_string(),
});
}

@@ -104,7 +128,7 @@ impl TryFrom<&Url> for Null {
num_blocks: if num_blocks != 0 {
num_blocks
} else {
(size << 20) / (blk_size as u64)
size / (blk_size as u64)
},
blk_size,
uuid: uuid.or_else(|| Some(Uuid::new_v4())),