Skip to content

Commit 12dd816

Browse files
feat: call spdk_bs_get_max_growable_size for max_expandable_size
Signed-off-by: Abhilash Shetty <[email protected]>
1 parent 9fbb3a4 commit 12dd816

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

io-engine-tests/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ pub fn truncate_file_bytes(path: &str, size: u64) {
196196
assert!(output.status.success());
197197
}
198198

199+
pub fn expand_tempfs_file_bytes(path: &str, size: u64) {
200+
let output = Command::new("truncate")
201+
.args(["-s", &format!("+{size}"), path])
202+
.output()
203+
.expect("failed exec truncate");
204+
assert!(output.status.success());
205+
}
206+
199207
/// Automatically assign a loopdev to path
200208
pub fn setup_loopdev_file(path: &str, sector_size: Option<u64>) -> String {
201209
let log_sec = sector_size.unwrap_or(512);

io-engine/src/lvs/lvs_store.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ use pin_utils::core_reexport::fmt::Formatter;
99

1010
use spdk_rs::libspdk::{
1111
bdev_aio_rescan, spdk_bdev_update_bs_blockcnt, spdk_blob_store, spdk_bs_free_cluster_count,
12-
spdk_bs_get_cluster_size, spdk_bs_get_md_len, spdk_bs_get_page_size, spdk_bs_get_used_md,
13-
spdk_bs_total_data_cluster_count, spdk_lvol, spdk_lvol_opts, spdk_lvol_opts_init,
14-
spdk_lvol_store, spdk_lvs_grow_live, vbdev_get_lvol_store_by_name,
15-
vbdev_get_lvol_store_by_uuid, vbdev_get_lvs_bdev_by_lvs, vbdev_lvol_create_with_opts,
16-
vbdev_lvs_create, vbdev_lvs_create_with_uuid, vbdev_lvs_destruct, vbdev_lvs_import,
17-
vbdev_lvs_unload, LVOL_CLEAR_WITH_NONE, LVOL_CLEAR_WITH_UNMAP, LVS_CLEAR_WITH_NONE,
12+
spdk_bs_get_cluster_size, spdk_bs_get_max_growable_size, spdk_bs_get_md_len,
13+
spdk_bs_get_page_size, spdk_bs_get_used_md, spdk_bs_total_data_cluster_count, spdk_lvol,
14+
spdk_lvol_opts, spdk_lvol_opts_init, spdk_lvol_store, spdk_lvs_grow_live,
15+
vbdev_get_lvol_store_by_name, vbdev_get_lvol_store_by_uuid, vbdev_get_lvs_bdev_by_lvs,
16+
vbdev_lvol_create_with_opts, vbdev_lvs_create, vbdev_lvs_create_with_uuid, vbdev_lvs_destruct,
17+
vbdev_lvs_import, vbdev_lvs_unload, LVOL_CLEAR_WITH_NONE, LVOL_CLEAR_WITH_UNMAP,
18+
LVS_CLEAR_WITH_NONE,
1819
};
1920
use url::Url;
2021

@@ -211,8 +212,8 @@ impl Lvs {
211212

212213
/// Size upto which blobstore can be expanded.
213214
pub fn max_expandable_size(&self) -> Option<u64> {
214-
// TODO: Use spdk function when changes gets merged.
215-
Some(0)
215+
let s = unsafe { spdk_bs_get_max_growable_size(self.blob_store()) };
216+
Some(s)
216217
}
217218

218219
/// returns the UUID of the lvs

io-engine/tests/lvs_grow.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ fn approx_eq(a: f64, b: f64, t: f64) -> bool {
4444
}
4545

4646
/// Pool stats.
47+
#[derive(Debug)]
4748
struct TestPoolStats {
4849
capacity: u64,
4950
disk_capacity: u64,
51+
max_expandable_size: u64,
5052
}
5153

5254
impl TestPoolStats {
@@ -60,6 +62,7 @@ impl From<&Lvs> for TestPoolStats {
6062
Self {
6163
capacity: lvs.capacity(),
6264
disk_capacity: lvs.disk_capacity(),
65+
max_expandable_size: lvs.max_expandable_size().unwrap(),
6366
}
6467
}
6568
}
@@ -75,6 +78,7 @@ impl From<Pool> for TestPoolStats {
7578
Self {
7679
capacity: p.capacity,
7780
disk_capacity: p.disk_capacity,
81+
max_expandable_size: p.max_expandable_size.unwrap(),
7882
}
7983
}
8084
}
@@ -356,9 +360,11 @@ async fn lvs_grow_api_aio() {
356360
}
357361

358362
async fn grow_device(&mut self) -> u64 {
359-
// Resize bdev's backing file.
360-
common::truncate_file(DISK_NAME, 128 * 1024);
361-
self.device_size().await + (128 * 1024)
363+
let pool = self.pool_stats().await;
364+
// Resize bdev's backing file to maximum expandable size.
365+
let expand_by = pool.max_expandable_size - pool.disk_capacity;
366+
common::expand_tempfs_file_bytes(DISK_NAME, expand_by);
367+
self.device_size().await + expand_by
362368
}
363369

364370
fn is_malloc(&self) -> bool {

spdk-rs

0 commit comments

Comments
 (0)