Skip to content

Commit

Permalink
fix(snapshot): fix alloc value for thik and thin provisioned lvol whe…
Browse files Browse the repository at this point in the history
…n snapshot is created from it

Signed-off-by: Hrudaya <[email protected]>
  • Loading branch information
hrudaya21 committed Jul 19, 2023
1 parent e551de7 commit 93d175e
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 8 deletions.
100 changes: 98 additions & 2 deletions io-engine/tests/snapshot_lvol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,91 @@ async fn clean_snapshots(snapshot_list: Vec<VolumeSnapshotDescriptor>) {
}
}

async fn test_lvol_alloc_after_snapshot(index: u32, thin: bool) {
let ms = get_ms();
const LVOL_SIZE: u64 = 24 * 1024 * 1024;
let pool_name = format!("pool_{index}");
let disk = format!("malloc:///disk{index}?size_mb=64");
let lvol_name = format!("lvol_{index}");

ms.spawn(async move {
// Create a pool and lvol.
let pool = create_test_pool(&pool_name, disk).await;
let cluster_size = pool.blob_cluster_size();
let lvol = pool
.create_lvol(
&lvol_name,
LVOL_SIZE,
Some(&Uuid::new_v4().to_string()),
thin,
)
.await
.expect("Failed to create test lvol");

// Create a snapshot-1
let entity_id = format!("{lvol_name}_e1");
let parent_id = lvol.uuid();
let txn_id = Uuid::new_v4().to_string();
let snap_name = format!("{lvol_name}_snap1");
let snapshot_uuid = Uuid::new_v4().to_string();

let snapshot_params = SnapshotParams::new(
Some(entity_id),
Some(parent_id),
Some(txn_id),
Some(snap_name),
Some(snapshot_uuid),
Some(Utc::now().to_string()),
);
lvol.create_snapshot(snapshot_params.clone())
.await
.expect("Failed to create a snapshot");
// Original Lvol Size to be 0 after snapshot is created.
assert_eq!(
lvol.usage().allocated_bytes,
0,
"Volume still has some space allocated after taking a snapshot"
);
// Write some data to original lvol.
bdev_io::write_some(&lvol_name, 0, 16, 0xccu8)
.await
.expect("Failed to write data to volume");

assert_eq!(
lvol.usage().allocated_bytes,
cluster_size,
"Volume still has some space allocated after taking a snapshot"
);

// Create a snapshot-2 after io done to lvol.
let entity_id = format!("{lvol_name}_e2");
let parent_id = lvol.uuid();
let txn_id = Uuid::new_v4().to_string();
let snap_name = format!("{lvol_name}_snap2");
let snapshot_uuid = Uuid::new_v4().to_string();

let snapshot_params = SnapshotParams::new(
Some(entity_id),
Some(parent_id),
Some(txn_id),
Some(snap_name),
Some(snapshot_uuid),
Some(Utc::now().to_string()),
);
lvol.create_snapshot(snapshot_params.clone())
.await
.expect("Failed to create a snapshot");

// Original Lvol Size to be 0 after snapshot is created.
assert_eq!(
lvol.usage().allocated_bytes,
0,
"Volume still has some space allocated after taking a snapshot"
);
})
.await;
}

fn check_snapshot_descriptor(
params: &SnapshotParams,
descr: &VolumeSnapshotDescriptor,
Expand Down Expand Up @@ -720,10 +805,10 @@ async fn test_snapshot_referenced_size() {
})
.expect("No second snapshot found");

// Before a new data is written to the volume, volume's space accounts snapshot space too.
// Snapshot takes the ownership of the data and lvol allocation becomes 0.
assert_eq!(
lvol.usage().allocated_bytes,
2 * cluster_size,
0,
"Volume still has some space allocated after taking a snapshot"
);

Expand Down Expand Up @@ -911,3 +996,14 @@ async fn test_snapshot_volume_provisioning_mode() {
})
.await;
}
#[tokio::test]
async fn test_thin_provision_lvol_alloc_after_snapshot() {
const IDX: u32 = 11;
test_lvol_alloc_after_snapshot(IDX, true).await;
}

#[tokio::test]
async fn test_thik_provision_lvol_alloc_after_snapshot() {
const IDX: u32 = 12;
test_lvol_alloc_after_snapshot(IDX, false).await;
}
6 changes: 3 additions & 3 deletions nix/pkgs/libspdk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ let
# 7. Copy SHA256 from 'got' of the error message to 'sha256' field.
# 8. 'nix-shell' build must now succeed.
drvAttrs = rec {
version = "23.01-7ca587a";
version = "23.01-38c2e17";

src = fetchFromGitHub {
owner = "openebs";
repo = "spdk";
rev = "7ca587aa9989ffb88c30be9112dc3a3722b40316";
sha256 = "sha256-DFTaeXhdaWQrbN9CJxdU6JjDBSQ1U+wwhTi7fRc5LBQ=";
rev = "38c2e17a120ad5c78f5ebea03a0e75738b712a0e";
sha256 = "sha256-O51JXQNVTft5Q5Bf5BK81+++lMT6fhFNp+Q6alE9/ho=";
fetchSubmodules = true;
};

Expand Down
6 changes: 3 additions & 3 deletions test/python/tests/nexus_fault/test_nexus_fault.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def _(mounted_nexus):
"""the initiator filesystem should not be shutdown."""
try:
# xfs_info should still be working as the fs is not shutdown
run_cmd(f"xfs_info {mounted_nexus}")
except:
pytest.fail(f"Filesystem on {mounted_nexus} should not be shutdown")
run_cmd(f"sudo xfs_info {mounted_nexus}")
except Exception as e:
pytest.fail(f"Filesystem on {mounted_nexus} should not be shutdown: {e}")


@pytest.fixture(scope="module")
Expand Down

0 comments on commit 93d175e

Please sign in to comment.