/// <summary> /// Create an SVHDX_META_OPERATION_START_APPLY_SNAPSHOT_REQUEST structure and marshal it to a byte array /// </summary> /// <param name="startRequest">Type SVHDX_META_OPERATION_START_REQUEST includes TransactionId and OperationType</param> /// <param name="applySnapshot">Type of SVHDX_APPLY_SNAPSHOT_PARAMS structure</param> /// <returns>The marshalled byte array</returns> public byte[] CreateTunnelMetaOperationStartApplySnapshotRequest( SVHDX_META_OPERATION_START_REQUEST startRequest, SVHDX_APPLY_SNAPSHOT_PARAMS applySnapshot) { SVHDX_META_OPERATION_START_APPLY_SNAPSHOT_REQUEST applySnapshotRequest = new SVHDX_META_OPERATION_START_APPLY_SNAPSHOT_REQUEST(); applySnapshotRequest.startRequest = startRequest; applySnapshotRequest.applySnapshot = applySnapshot; return(TypeMarshal.ToBytes(applySnapshotRequest)); }
public void BVT_ApplySnapshot() { BaseTestSite.Log.Add(LogEntryKind.TestStep, "1. Client opens a shared virtual disk file and expects success."); OpenSharedVHD(TestConfig.NameOfSharedVHDS, RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2); BaseTestSite.Log.Add(LogEntryKind.TestStep, "2. Client reads 512 bytes and saves it for later comparation."); byte[] byteBeforeChanged = null; uint status = client.Read(0, 512, out byteBeforeChanged); BaseTestSite.Assert.AreEqual( (uint)0, status, "Read Status should be {0}, actual is {1}", GetStatus(0), GetStatus(status)); Guid snapshotId = Guid.NewGuid(); BaseTestSite.Log.Add(LogEntryKind.TestStep, "3. Client creates a snapshot."); CreateSnapshot(snapshotId); BaseTestSite.Log.Add(LogEntryKind.TestStep, "4. Client closes the file."); client.CloseSharedVirtualDisk(); BaseTestSite.Log.Add(LogEntryKind.TestStep, "5. Client reopens the shared virtual disk file and expects success."); RequestIdentifier = 0; OpenSharedVHD(TestConfig.NameOfSharedVHDS, RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2); BaseTestSite.Log.Add(LogEntryKind.TestStep, "6. Client sends Write request to change the file and expects success."); byte[] payload = Smb2Utility.CreateRandomByteArray(512); status = client.Write(0, payload); BaseTestSite.Assert.AreEqual( (uint)0, status, "Write Status should be {0}, actual is {1}", GetStatus(0), GetStatus(status)); BaseTestSite.Log.Add(LogEntryKind.TestStep, "7. Client sends Apply Snapshot request to apply the previous snapshot."); SVHDX_APPLY_SNAPSHOT_PARAMS applySnapshot = new SVHDX_APPLY_SNAPSHOT_PARAMS(); applySnapshot.SnapshotID = snapshotId; applySnapshot.SnapshotType = Snapshot_Type.SvhdxSnapshotTypeVM; SVHDX_META_OPERATION_START_REQUEST startRequest = new SVHDX_META_OPERATION_START_REQUEST(); startRequest.TransactionId = Guid.NewGuid(); startRequest.OperationType = Operation_Type.SvhdxMetaOperationTypeApplySnapshot; payload = client.CreateTunnelMetaOperationStartApplySnapshotRequest(startRequest, applySnapshot); SVHDX_TUNNEL_OPERATION_HEADER?header; SVHDX_TUNNEL_OPERATION_HEADER?response; status = client.TunnelOperation <SVHDX_TUNNEL_OPERATION_HEADER>( true, //true for Async operation, false for non-async operation RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_META_OPERATION_START, ++RequestIdentifier, payload, out header, out response); BaseTestSite.Assert.AreEqual( (uint)Smb2Status.STATUS_SUCCESS, status, "Ioctl should succeed, actual status: {0}", GetStatus(status)); VerifyTunnelOperationHeader(header.Value, RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_META_OPERATION_START, (uint)RsvdStatus.STATUS_SVHDX_SUCCESS, RequestIdentifier); BaseTestSite.Log.Add(LogEntryKind.TestStep, "8. Client rereads 512 bytes and compares it with the previously saved bytes."); byte[] byteAfterApplied = null; status = client.Read(0, 512, out byteAfterApplied); BaseTestSite.Assert.AreEqual( (uint)0, status, "Read Status should be {0}, actual is {1}", GetStatus(0), GetStatus(status)); bool equal = ArrayUtility.CompareArrays(byteBeforeChanged, byteAfterApplied); BaseTestSite.Assert.AreEqual( true, equal, "The bytes after snapshot applied should be the same with the original."); BaseTestSite.Log.Add(LogEntryKind.TestStep, "9. Client deletes the snapshot."); DeleteSnapshot(snapshotId); BaseTestSite.Log.Add(LogEntryKind.TestStep, "10. Client closes the file."); client.CloseSharedVirtualDisk(); }