/// <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));
        }
Beispiel #2
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);
            }
        }
        /// <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);
            }
        }
        /// <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;
            }
        }