private void SendAndReceiveSCSICommand(RsvdClient rsvdClient, byte cdbLength, byte[] cdbBuffer, byte[] dataBuffer, out byte scsiStatus)
        {
            SVHDX_TUNNEL_OPERATION_HEADER?header;
            SVHDX_TUNNEL_SCSI_RESPONSE?   response;

            byte[] payload = rsvdClient.CreateTunnelScsiRequest(
                RsvdConst.SVHDX_TUNNEL_SCSI_REQUEST_LENGTH,
                cdbLength,
                (byte)RsvdConst.RSVD_SCSI_SENSE_BUFFER_SIZE,
                false,
                SRB_FLAGS.SRB_FLAGS_DATA_OUT,
                (byte)dataBuffer.Length,
                cdbBuffer,
                dataBuffer);

            uint status = rsvdClient.TunnelOperation <SVHDX_TUNNEL_SCSI_RESPONSE>(
                false,//true for Async operation, false for non-async operation
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_SCSI_OPERATION,
                ++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_SCSI_OPERATION, (uint)RsvdStatus.STATUS_SVHDX_SUCCESS, RequestIdentifier);
            VerifyFieldInResponse("DataIn", false, response.Value.DataIn); // the CDB buffer specified is to receive data from the server.
            VerifyFieldInResponse("Length", 36, response.Value.Length);    // the size of the SVHDX_TUNNEL_SCSI_REQUEST structure excluding the DataBuffer field; This field MUST be set to 36.

            scsiStatus = response.Value.ScsiStatus;
        }
        public void TwoClientsReadSameSharedVHD()
        {
            ulong requestIdforFirstClient = 0;
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1.	The first client opens a shared virtual disk file and expects success.");
            OpenSharedVHD(TestConfig.NameOfSharedVHDX, requestIdforFirstClient++);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2.	The first client reads file content and expects success.");
            byte[] payload;
            uint status = client.Read(0, 512, out payload);
            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Read content of shared virtual disk file from the first client should succeed, actual status: {0}",
                GetStatus(status));

            ulong requestIdforSecondClient = 0;
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "3.	The second client opens a shared virtual disk file and expects success.");
            this.secondClient = new RsvdClient(TestConfig.Timeout);
            OpenSharedVHD(TestConfig.NameOfSharedVHDX, requestIdforSecondClient, rsvdClient: secondClient);
            requestIdforSecondClient++;

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "4.	The second client reads file content and expects success.");
            status = secondClient.Read(0, 512, out payload);
            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Read content of shared virtual disk file from the second client should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "5.	The first client closes the file.");
            client.CloseSharedVirtualDisk();
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "6.	The second client closes the file.");
            secondClient.CloseSharedVirtualDisk();
        }
        /// <summary>
        /// Delete the existing snapshots for the VHD set file
        /// </summary>
        /// <param name="requestId">Tunnel operation request id</param>
        /// <param name="snapshotId">The snapshot id to be deleted</param>
        /// <param name="rsvdClient">The instance of rsvd client. NULL stands for the default client</param>
        public void DeleteSnapshot(ref ulong requestId, Guid snapshotId, RsvdClient rsvdClient = null)
        {
            if (rsvdClient == null)
            {
                rsvdClient = this.client;
            }

            SVHDX_TUNNEL_OPERATION_HEADER?       header;
            SVHDX_TUNNEL_DELETE_SNAPSHOT_REQUEST deleteRequest = new SVHDX_TUNNEL_DELETE_SNAPSHOT_REQUEST();

            deleteRequest.SnapshotId       = snapshotId;
            deleteRequest.PersistReference = PersistReference_Flags.PersistReferenceFalse;
            deleteRequest.SnapshotType     = Snapshot_Type.SvhdxSnapshotTypeVM;
            byte[] payload = rsvdClient.CreateTunnelMetaOperationDeleteSnapshotRequest(deleteRequest);
            SVHDX_TUNNEL_OPERATION_HEADER?deleteResponse;
            uint status = rsvdClient.TunnelOperation <SVHDX_TUNNEL_OPERATION_HEADER>(
                false,
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_DELETE_SNAPSHOT,
                requestId,
                payload,
                out header,
                out deleteResponse);

            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_DELETE_SNAPSHOT, (uint)RsvdStatus.STATUS_SVHDX_SUCCESS, requestId++);
        }
        private void CheckSnapshotExisted(ref ulong requestId, RsvdClient client, System.Guid snapshotId)
        {
            SetFile_InformationType       setFileInforType = SetFile_InformationType.SvhdxSetFileInformationTypeSnapshotEntry;
            Snapshot_Type                 snapshotType     = Snapshot_Type.SvhdxSnapshotTypeVM;
            SVHDX_TUNNEL_OPERATION_HEADER?header;
            SVHDX_TUNNEL_VHDSET_FILE_QUERY_INFORMATION_SNAPSHOT_ENTRY_RESPONSE?snapshotEntryResponse;

            byte[] payload = client.CreateTunnelGetVHDSetFileInfoRequest(
                setFileInforType,
                snapshotType,
                snapshotId);
            uint status = client.TunnelOperation <SVHDX_TUNNEL_VHDSET_FILE_QUERY_INFORMATION_SNAPSHOT_ENTRY_RESPONSE>(
                false,//true for Async operation, false for non-async operation
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_VHDSET_QUERY_INFORMATION,
                requestId,
                payload,
                out header,
                out snapshotEntryResponse);

            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_VHDSET_QUERY_INFORMATION, (uint)RsvdStatus.STATUS_SVHDX_SUCCESS, requestId++);
        }
        public void TwoClientsReadSameSharedVHD()
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1.	The first client opens a shared virtual disk file and expects success.");
            OpenSharedVHD(TestConfig.NameOfSharedVHDX, RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1, 0);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2.	The first client reads file content and expects success.");
            byte[] payload;
            uint   status = client.Read(0, 512, out payload);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Read content of shared virtual disk file from the first client should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "3.	The second client opens a shared virtual disk file and expects success.");
            this.secondClient = new RsvdClient(TestConfig.Timeout);
            OpenSharedVHD(TestConfig.NameOfSharedVHDX, RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1, 0, rsvdClient: secondClient);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "4.	The second client reads file content and expects success.");
            status = secondClient.Read(0, 512, out payload);
            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Read content of shared virtual disk file from the second client should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "5.	The first client closes the file.");
            client.CloseSharedVirtualDisk();
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "6.	The second client closes the file.");
            secondClient.CloseSharedVirtualDisk();
        }
        protected override void TestInitialize()
        {
            base.TestInitialize();

            testConfig = new RSVDTestConfig(BaseTestSite);

            BaseTestSite.DefaultProtocolDocShortName = "MS-RSVD";

            client = new RsvdClient(TestConfig.Timeout);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Open the shared virtual disk file.
 /// </summary>
 /// <param name="fileName">The virtual disk file name to be used</param>
 /// <param name="version">Version of the open device context</param>
 /// <param name="openRequestId">OpenRequestId, same with other operations' request id</param>
 /// <param name="hasInitiatorId">If the SVHDX_OPEN_DEVICE_CONTEXT contains InitiatorId</param>
 /// <param name="rsvdClient">The instance of rsvd client. NULL stands for the default client</param>
 public void OpenSharedVHD(
     string fileName,
     RSVD_PROTOCOL_VERSION version,
     ulong?openRequestId   = null,
     bool hasInitiatorId   = true,
     RsvdClient rsvdClient = null)
 {
     Smb2CreateContextResponse[] serverContextResponse;
     OpenSharedVHD(fileName, version, openRequestId, hasInitiatorId, rsvdClient, out serverContextResponse);
 }
        protected override void TestInitialize()
        {
            base.TestInitialize();

            testConfig = new RSVDTestConfig(BaseTestSite);

            BaseTestSite.DefaultProtocolDocShortName = "MS-RSVD";

            client            = new RsvdClient(TestConfig.Timeout);
            RequestIdentifier = 0; // Follow windows client behaviour. Initialize it to zero.

            // Copy the data used in test cases to the share of the SUT, e.g. the shared virtual disk files.
            sutProtocolController.CopyFile(TestConfig.FullPathShareContainingSharedVHD, @"data\*.*");
        }
        private void CheckDiskFormat()
        {
            RsvdClient newClient    = new RsvdClient(TestConfig.Timeout);
            ulong      newRequestId = 0;

            OpenSharedVHD(TestConfig.NameOfConvertedSharedVHDS, newRequestId++, rsvdClient: newClient);
            SVHDX_TUNNEL_DISK_INFO_RESPONSE?diskInfo = GetVirtualDiskInfo(ref newRequestId, newClient);

            BaseTestSite.Assert.AreEqual(
                DISK_FORMAT.VIRTUAL_STORAGE_TYPE_DEVICE_VHDS,
                diskInfo.Value.DiskFormat,
                "Disk format should have been changed into VIRTUAL_STORAGE_TYPE_DEVICE_VHDS, the actual value is: {0}",
                diskInfo.Value.DiskFormat);
        }
        public void TwoClientsWriteSameSharedVHD()
        {
            ulong requestIdforFirstClient = 0;

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1.	The first client opens a shared virtual disk file and expects success.");
            OpenSharedVHD(TestConfig.NameOfSharedVHDX, requestIdforFirstClient++);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2.	The first client writes file content and expects success.");
            byte[] payload = new byte[512];
            uint   status  = client.Write(0, payload);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Write content of shared virtual disk file from the first client should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "3.	The second client opens a shared virtual disk file and expects success.");
            ulong requestIdforSecondClient = 0;

            this.secondClient = new RsvdClient(TestConfig.Timeout);
            OpenSharedVHD(TestConfig.NameOfSharedVHDX, requestIdforSecondClient, rsvdClient: secondClient);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "4.	The second client writes file content and expects success.");
            status = secondClient.Write(0, payload);
            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Write content of shared virtual disk file from the second client should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "5.	The first client closes the file.");
            client.CloseSharedVirtualDisk();
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "6.	The second client closes the file.");
            secondClient.CloseSharedVirtualDisk();
        }
        /// <summary>
        /// Create snapshot for the VHD set file
        /// </summary>
        /// <param name="requestId">Tunnel operation request id</param>
        /// <param name="rsvdClient">The instance of rsvd client. NULL stands for the default client</param>
        /// <returns>Return a snapshot id</returns>
        public Guid CreateSnapshot(ref ulong requestId, RsvdClient rsvdClient = null)
        {
            if (rsvdClient == null)
            {
                rsvdClient = this.client;
            }

            SVHDX_META_OPERATION_START_REQUEST startRequest = new SVHDX_META_OPERATION_START_REQUEST();

            startRequest.TransactionId = System.Guid.NewGuid();
            startRequest.OperationType = Operation_Type.SvhdxMetaOperationTypeCreateSnapshot;
            startRequest.Padding       = new byte[4];
            SVHDX_META_OPERATION_CREATE_SNAPSHOT createsnapshot = new SVHDX_META_OPERATION_CREATE_SNAPSHOT();

            createsnapshot.SnapshotType          = Snapshot_Type.SvhdxSnapshotTypeVM;
            createsnapshot.Flags                 = Snapshot_Flags.SVHDX_SNAPSHOT_DISK_FLAG_ENABLE_CHANGE_TRACKING;
            createsnapshot.Stage1                = Stage_Values.SvhdxSnapshotStageInitialize;
            createsnapshot.Stage2                = Stage_Values.SvhdxSnapshotStageInvalid;
            createsnapshot.Stage3                = Stage_Values.SvhdxSnapshotStageInvalid;
            createsnapshot.Stage4                = Stage_Values.SvhdxSnapshotStageInvalid;
            createsnapshot.Stage5                = Stage_Values.SvhdxSnapshotStageInvalid;
            createsnapshot.Stage6                = Stage_Values.SvhdxSnapshotStageInvalid;
            createsnapshot.SnapshotId            = System.Guid.NewGuid();
            createsnapshot.ParametersPayloadSize = (uint)0x00000000;
            createsnapshot.Padding               = new byte[24];
            byte[] payload = rsvdClient.CreateTunnelMetaOperationStartCreateSnapshotRequest(
                startRequest,
                createsnapshot);

            SVHDX_TUNNEL_OPERATION_HEADER?header;
            SVHDX_TUNNEL_OPERATION_HEADER?response;
            //For RSVD_TUNNEL_META_OPERATION_START operation code, the IOCTL code should be FSCTL_SVHDX_ASYNC_TUNNEL_REQUEST
            uint status = rsvdClient.TunnelOperation <SVHDX_TUNNEL_OPERATION_HEADER>(
                true,
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_META_OPERATION_START,
                requestId++,
                payload,
                out header,
                out response);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Ioctl should succeed, actual status: {0}",
                GetStatus(status));

            createsnapshot.Flags  = Snapshot_Flags.SVHDX_SNAPSHOT_FLAG_ZERO;
            createsnapshot.Stage1 = Stage_Values.SvhdxSnapshotStageBlockIO;
            createsnapshot.Stage2 = Stage_Values.SvhdxSnapshotStageSwitchObjectStore;
            createsnapshot.Stage3 = Stage_Values.SvhdxSnapshotStageUnblockIO;
            createsnapshot.Stage4 = Stage_Values.SvhdxSnapshotStageFinalize;
            createsnapshot.Stage5 = Stage_Values.SvhdxSnapshotStageInvalid;
            createsnapshot.Stage6 = Stage_Values.SvhdxSnapshotStageInvalid;
            payload = rsvdClient.CreateTunnelMetaOperationStartCreateSnapshotRequest(
                startRequest,
                createsnapshot);

            //For RSVD_TUNNEL_META_OPERATION_START operation code, the IOCTL code should be FSCTL_SVHDX_ASYNC_TUNNEL_REQUEST
            status = rsvdClient.TunnelOperation <SVHDX_TUNNEL_OPERATION_HEADER>(
                true,
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_META_OPERATION_START,
                requestId++,
                payload,
                out header,
                out response);
            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Ioctl should succeed, actual status: {0}",
                GetStatus(status));

            SetFile_InformationType setFileInforType = SetFile_InformationType.SvhdxSetFileInformationTypeSnapshotEntry;
            Snapshot_Type           snapshotType     = Snapshot_Type.SvhdxSnapshotTypeVM;
            SVHDX_TUNNEL_VHDSET_FILE_QUERY_INFORMATION_SNAPSHOT_ENTRY_RESPONSE?snapshotEntryResponse;

            payload = client.CreateTunnelGetVHDSetFileInfoRequest(
                setFileInforType,
                snapshotType,
                createsnapshot.SnapshotId);
            status = client.TunnelOperation <SVHDX_TUNNEL_VHDSET_FILE_QUERY_INFORMATION_SNAPSHOT_ENTRY_RESPONSE>(
                false,//true for Async operation, false for non-async operation
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_VHDSET_QUERY_INFORMATION,
                requestId++,
                payload,
                out header,
                out snapshotEntryResponse);
            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Ioctl should succeed, actual status: {0}",
                GetStatus(status));

            return(createsnapshot.SnapshotId);
        }
        /// <summary>
        /// Connect to the share VHD file.
        /// </summary>
        private bool TestRsvdVersion(
            string vhdxName,
            string share,
            RSVD_PROTOCOL_VERSION version)
        {
            using (RsvdClient client = new RsvdClient(new TimeSpan(0, 0, defaultTimeoutInSeconds)))
            {
                CREATE_Response             response;
                Smb2CreateContextResponse[] serverContexts;
                client.Connect(SUTName, SUTIpAddress, Credential.DomainName, Credential.AccountName, Credential.Password, SecurityPackageType, true, share);

                Smb2CreateContextRequest[] contexts;
                if (version == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2)
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContextV2
                        {
                            Version                          = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2,
                            OriginatorFlags                  = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName                = initiatorHostName,
                            InitiatorHostNameLength          = (ushort)(initiatorHostName.Length * 2), // InitiatorHostName is a null-terminated Unicode UTF-16 string
                            VirtualDiskPropertiesInitialized = 0,
                            ServerServiceVersion             = 0,
                            VirtualSectorSize                = 0,
                            PhysicalSectorSize               = 0,
                            VirtualSize                      = 0
                        }
                    };
                }
                else
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContext
                        {
                            Version                 = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1,
                            OriginatorFlags         = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName       = initiatorHostName,
                            InitiatorHostNameLength = (ushort)(initiatorHostName.Length * 2)  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                        }
                    };
                }

                uint status;
                status = client.OpenSharedVirtualDisk(
                    vhdxName,
                    TestTools.StackSdk.FileAccessService.FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                    contexts,
                    out serverContexts,
                    out response);

                bool result = false;

                if (status != Smb2Status.STATUS_SUCCESS)
                {
                    result = false;
                    logWriter.AddLog(LogLevel.Information, string.Format("{0} is found not supported.", version));
                    return(result);
                }

                result = CheckOpenDeviceContext(serverContexts, version);
                client.CloseSharedVirtualDisk();

                return(result);
            }
        }
        private void SendAndReceiveSCSICommand(RsvdClient rsvdClient, byte cdbLength, byte[] cdbBuffer, byte[] dataBuffer, out byte scsiStatus)
        {
            SVHDX_TUNNEL_OPERATION_HEADER? header;
            SVHDX_TUNNEL_SCSI_RESPONSE? response;

            byte[] payload = rsvdClient.CreateTunnelScsiRequest(
                RsvdConst.SVHDX_TUNNEL_SCSI_REQUEST_LENGTH,
                cdbLength,
                (byte)RsvdConst.RSVD_SCSI_SENSE_BUFFER_SIZE,
                false,
                SRB_FLAGS.SRB_FLAGS_DATA_OUT,
                (byte)dataBuffer.Length,
                cdbBuffer,
                dataBuffer);

            uint status = rsvdClient.TunnelOperation<SVHDX_TUNNEL_SCSI_RESPONSE>(
                false,//true for Async operation, false for non-async operation
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_SCSI_OPERATION,
                ++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_SCSI_OPERATION, (uint)RsvdStatus.STATUS_SVHDX_SUCCESS, RequestIdentifier);
            VerifyFieldInResponse("DataIn", false, response.Value.DataIn); // the CDB buffer specified is to receive data from the server.
            VerifyFieldInResponse("Length", 36, response.Value.Length);// the size of the SVHDX_TUNNEL_SCSI_REQUEST structure excluding the DataBuffer field; This field MUST be set to 36.

            scsiStatus = response.Value.ScsiStatus;
        }
        protected override void TestInitialize()
        {
            base.TestInitialize();

            secondClient = new RsvdClient(TestConfig.Timeout);
        }
        private void CheckSnapshotExisted(ref ulong requestId, RsvdClient client, System.Guid snapshotId)
        {
            SetFile_InformationType setFileInforType = SetFile_InformationType.SvhdxSetFileInformationTypeSnapshotEntry;
            Snapshot_Type snapshotType = Snapshot_Type.SvhdxSnapshotTypeVM;
            SVHDX_TUNNEL_OPERATION_HEADER? header;
            SVHDX_TUNNEL_VHDSET_FILE_QUERY_INFORMATION_SNAPSHOT_ENTRY_RESPONSE? snapshotEntryResponse;
            byte[] payload = client.CreateTunnelGetVHDSetFileInfoRequest(
                setFileInforType,
                snapshotType,
                snapshotId);
            uint status = client.TunnelOperation<SVHDX_TUNNEL_VHDSET_FILE_QUERY_INFORMATION_SNAPSHOT_ENTRY_RESPONSE>(
                false,//true for Async operation, false for non-async operation
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_VHDSET_QUERY_INFORMATION,
                requestId,
                payload,
                out header,
                out snapshotEntryResponse);
            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_VHDSET_QUERY_INFORMATION, (uint)RsvdStatus.STATUS_SVHDX_SUCCESS, requestId++);
        }
        private void CheckDiskFormat()
        {
            RsvdClient newClient = new RsvdClient(TestConfig.Timeout);
            ulong newRequestId = 0;
            OpenSharedVHD(TestConfig.NameOfConvertedSharedVHDS, newRequestId++, rsvdClient: newClient);
            SVHDX_TUNNEL_DISK_INFO_RESPONSE? diskInfo = GetVirtualDiskInfo(ref newRequestId, newClient);

            BaseTestSite.Assert.AreEqual(
                DISK_FORMAT.VIRTUAL_STORAGE_TYPE_DEVICE_VHDS,
                diskInfo.Value.DiskFormat,
                "Disk format should have been changed into VIRTUAL_STORAGE_TYPE_DEVICE_VHDS, the actual value is: {0}",
                diskInfo.Value.DiskFormat);
        }
        public void TwoClientsWriteSameSharedVHD()
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1.	The first client opens a shared virtual disk file and expects success.");
            OpenSharedVHD(TestConfig.NameOfSharedVHDX, RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1, 0);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2.	The first client writes file content and expects success.");
            byte[] payload = new byte[512];
            uint status = client.Write(0, payload);
            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Write content of shared virtual disk file from the first client should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "3.	The second client opens a shared virtual disk file and expects success.");
            this.secondClient = new RsvdClient(TestConfig.Timeout);
            OpenSharedVHD(TestConfig.NameOfSharedVHDX, RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1, 0, rsvdClient: secondClient);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "4.	The second client writes file content and expects success.");
            status = secondClient.Write(0, payload);
            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Write content of shared virtual disk file from the second client should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "5.	The first client closes the file.");
            client.CloseSharedVirtualDisk();
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "6.	The second client closes the file.");
            secondClient.CloseSharedVirtualDisk();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Connect to the share VHD file.
        /// </summary>
        private bool TestRsvdVersion(
            string vhdxName,
            string share,
            RSVD_PROTOCOL_VERSION version)
        {
            using (RsvdClient client = new RsvdClient(new TimeSpan(0, 0, defaultTimeoutInSeconds)))
            {
                CREATE_Response             response;
                Smb2CreateContextResponse[] serverContexts;
                client.Connect(SUTName, SUTIpAddress, Credential.DomainName, Credential.AccountName, Credential.Password, SecurityPackageType, true, share);

                Smb2CreateContextRequest[] contexts;
                if (version == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2)
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContextV2
                        {
                            Version                          = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2,
                            OriginatorFlags                  = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName                = initiatorHostName,
                            InitiatorHostNameLength          = (ushort)(initiatorHostName.Length * 2), // InitiatorHostName is a null-terminated Unicode UTF-16 string
                            VirtualDiskPropertiesInitialized = 0,
                            ServerServiceVersion             = 0,
                            VirtualSectorSize                = 0,
                            PhysicalSectorSize               = 0,
                            VirtualSize                      = 0
                        }
                    };
                    foreach (Smb2CreateSvhdxOpenDeviceContextV2 context in contexts)
                    {
                        logWriter.AddLog(DetectLogLevel.Information, @"OpenSharedVirtualDisk request was sent with context: ");
                        logWriter.AddLog(DetectLogLevel.Information, @"Version: " + context.Version.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"OriginatorFlags: " + context.OriginatorFlags.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostName: " + context.InitiatorHostName.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostNameLength: " + context.InitiatorHostNameLength.ToString());
                    }
                }
                else
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContext
                        {
                            Version                 = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1,
                            OriginatorFlags         = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName       = initiatorHostName,
                            InitiatorHostNameLength = (ushort)(initiatorHostName.Length * 2)  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                        }
                    };
                    foreach (Smb2CreateSvhdxOpenDeviceContext context in contexts)
                    {
                        logWriter.AddLog(DetectLogLevel.Information, @"OpenSharedVirtualDisk request was sent with context: ");
                        logWriter.AddLog(DetectLogLevel.Information, @"Version: " + context.Version.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"OriginatorFlags: " + context.OriginatorFlags.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostName: " + context.InitiatorHostName.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostNameLength: " + context.InitiatorHostNameLength.ToString());
                    }
                }

                uint status;
                status = client.OpenSharedVirtualDisk(
                    vhdxName,
                    TestTools.StackSdk.FileAccessService.FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                    contexts,
                    out serverContexts,
                    out response);

                logWriter.AddLog(DetectLogLevel.Information, @"Get OpenSharedVirtualDisk response with status: " + status);

                if (serverContexts == null)
                {
                    logWriter.AddLog(DetectLogLevel.Information, @"The response does not contain any server contexts.");
                }
                else
                {
                    foreach (Smb2CreateContextResponse ctx in serverContexts)
                    {
                        Type type = ctx.GetType();
                        if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponse")
                        {
                            logWriter.AddLog(DetectLogLevel.Information, @"Server response context is Smb2CreateSvhdxOpenDeviceContextResponse. ");

                            Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = ctx as Smb2CreateSvhdxOpenDeviceContextResponse;
                            logWriter.AddLog(DetectLogLevel.Information, @"Version is: " + openDeviceContext.Version.ToString());
                            logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostName is: " + openDeviceContext.InitiatorHostName.ToString());
                            logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostNameLength is: " + openDeviceContext.InitiatorHostNameLength.ToString());
                        }

                        if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2")
                        {
                            logWriter.AddLog(DetectLogLevel.Information, @"Server response context is Smb2CreateSvhdxOpenDeviceContextResponseV2. ");

                            Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = ctx as Smb2CreateSvhdxOpenDeviceContextResponseV2;
                            logWriter.AddLog(DetectLogLevel.Information, @"Version is: " + openDeviceContext.Version.ToString());
                            logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostName is: " + openDeviceContext.InitiatorHostName.ToString());
                            logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostNameLength is: " + openDeviceContext.InitiatorHostNameLength.ToString());
                        }
                    }
                }

                bool result = false;

                if (status != Smb2Status.STATUS_SUCCESS)
                {
                    result = false;
                    logWriter.AddLog(DetectLogLevel.Information, @"Get status " + status + @" from server response.");
                    logWriter.AddLog(DetectLogLevel.Information, @"The RSVD version " + version + @" is found not supported by server.");
                    return(result);
                }

                result = CheckOpenDeviceContext(serverContexts, version);
                client.CloseSharedVirtualDisk();

                return(result);
            }
        }
        public SVHDX_TUNNEL_DISK_INFO_RESPONSE?GetVirtualDiskInfo(ref ulong requestId, RsvdClient rsvdClient = null)
        {
            if (rsvdClient == null)
            {
                rsvdClient = this.client;
            }

            byte[] payload = client.CreateTunnelDiskInfoRequest();
            SVHDX_TUNNEL_OPERATION_HEADER?  header;
            SVHDX_TUNNEL_DISK_INFO_RESPONSE?response;
            uint status = client.TunnelOperation <SVHDX_TUNNEL_DISK_INFO_RESPONSE>(
                false,//true for Async operation, false for non-async operation
                RSVD_TUNNEL_OPERATION_CODE.RSVD_TUNNEL_GET_DISK_INFO_OPERATION,
                requestId,
                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_GET_DISK_INFO_OPERATION, (uint)RsvdStatus.STATUS_SVHDX_SUCCESS, requestId++);

            return(response);
        }
        protected override void TestInitialize()
        {
            base.TestInitialize();

            secondClient = new RsvdClient(TestConfig.Timeout);
        }
        /// <summary>
        /// Open the shared virtual disk file.
        /// </summary>
        /// <param name="fileName">The virtual disk file name to be used</param>
        /// <param name="requestId">OpenRequestId, same with other operations' request id</param>
        /// <param name="hasInitiatorId">If the SVHDX_OPEN_DEVICE_CONTEXT contains InitiatorId</param>
        /// <param name="rsvdClient">The instance of rsvd client. NULL stands for the default client</param>
        public void OpenSharedVHD(string fileName, ulong?requestId = null, bool hasInitiatorId = true, RsvdClient rsvdClient = null)
        {
            if (rsvdClient == null)
            {
                rsvdClient = this.client;
            }

            rsvdClient.Connect(
                TestConfig.FileServerNameContainingSharedVHD,
                TestConfig.FileServerIPContainingSharedVHD,
                TestConfig.DomainName,
                TestConfig.UserName,
                TestConfig.UserPassword,
                TestConfig.DefaultSecurityPackage,
                TestConfig.UseServerGssToken,
                TestConfig.ShareContainingSharedVHD);

            Smb2CreateContextRequest[] contexts = null;
            if (TestConfig.ServerServiceVersion == (uint)0x00000001)
            {
                contexts = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateSvhdxOpenDeviceContext
                    {
                        Version                 = TestConfig.ServerServiceVersion,
                        OriginatorFlags         = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                        InitiatorHostName       = TestConfig.InitiatorHostName,
                        InitiatorHostNameLength = (ushort)(TestConfig.InitiatorHostName.Length * 2),
                        OpenRequestId           = requestId == null ? ((ulong)new System.Random().Next()) : requestId.Value,
                        InitiatorId             = hasInitiatorId ? Guid.NewGuid():Guid.Empty,
                        HasInitiatorId          = hasInitiatorId
                    }
                };
            }
            else if (TestConfig.ServerServiceVersion == (uint)0x00000002)
            {
                contexts = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateSvhdxOpenDeviceContextV2
                    {
                        Version                          = TestConfig.ServerServiceVersion,
                        OriginatorFlags                  = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                        InitiatorHostName                = TestConfig.InitiatorHostName,
                        InitiatorHostNameLength          = (ushort)(TestConfig.InitiatorHostName.Length * 2),
                        OpenRequestId                    = requestId == null ? ((ulong)new System.Random().Next()) : requestId.Value,
                        InitiatorId                      = hasInitiatorId ? Guid.NewGuid():Guid.Empty,
                        HasInitiatorId                   = hasInitiatorId,
                        VirtualDiskPropertiesInitialized = 0,
                        ServerServiceVersion             = 0,
                        VirtualSize                      = 0,
                        PhysicalSectorSize               = 0,
                        VirtualSectorSize                = 0
                    }
                };
            }
            else
            {
                throw new ArgumentException("The ServerServiceVersion {0} is not supported.", "Version");
            }

            CREATE_Response response;

            Smb2CreateContextResponse[] serverContextResponse;
            uint status = rsvdClient.OpenSharedVirtualDisk(
                fileName + fileNameSuffix,
                FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                contexts,
                out serverContextResponse,
                out response);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Open shared virtual disk file should succeed, actual status: {0}",
                GetStatus(status));
        }
        /// <summary>
        /// Connect to the share VHD file.
        /// </summary>
        private bool TestRsvdVersion(
            string vhdxName,
            string share,
            RSVD_PROTOCOL_VERSION version)
        {
            using (RsvdClient client = new RsvdClient(new TimeSpan(0, 0, defaultTimeoutInSeconds)))
            {
                CREATE_Response response;
                Smb2CreateContextResponse[] serverContexts;
                client.Connect(SUTName, SUTIpAddress, Credential.DomainName, Credential.AccountName, Credential.Password, SecurityPackageType, true, share);

                Smb2CreateContextRequest[] contexts;
                if (version == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2)
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContextV2
                        {
                            Version = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2,
                            OriginatorFlags = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName = initiatorHostName,
                            InitiatorHostNameLength = (ushort)(initiatorHostName.Length * 2),  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                            VirtualDiskPropertiesInitialized = 0,
                            ServerServiceVersion = 0,
                            VirtualSectorSize = 0,
                            PhysicalSectorSize = 0,
                            VirtualSize = 0
                        }
                    };
                }
                else
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContext
                        {
                            Version = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1,
                            OriginatorFlags = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName = initiatorHostName,
                            InitiatorHostNameLength = (ushort)(initiatorHostName.Length * 2)  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                        }
                    };
                }

                uint status;
                status = client.OpenSharedVirtualDisk(
                    vhdxName,
                    TestTools.StackSdk.FileAccessService.FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                    contexts,
                    out serverContexts,
                    out response);

                bool result = false;

                if (status != Smb2Status.STATUS_SUCCESS)
                {
                    result = false;
                    logWriter.AddLog(LogLevel.Information, string.Format("{0} is found not supported.", version));
                    return result;
                }

                result = CheckOpenDeviceContext(serverContexts, version);
                client.CloseSharedVirtualDisk();

                return result;
            }
        }