/// <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); }
/// <summary> /// To reset the detection information. /// </summary> public void ResetDetectResult() { F_CopyOffload = new DetectResult[] { DetectResult.UnSupported, DetectResult.UnSupported }; F_IntegrityInfo = new DetectResult[] { DetectResult.UnSupported, DetectResult.UnSupported }; F_FileLevelTrim = DetectResult.UnSupported; F_ResilientHandle = DetectResult.UnSupported; F_ValidateNegotiateInfo = DetectResult.UnSupported; F_EnumerateSnapShots = DetectResult.UnSupported; F_AppInstanceId = DetectResult.UnSupported; F_HandleV1_BatchOplock = DetectResult.UnSupported; F_HandleV1_LeaseV1 = DetectResult.UnSupported; F_HandleV2_BatchOplock = DetectResult.UnSupported; F_HandleV2_LeaseV1 = DetectResult.UnSupported; F_HandleV2_LeaseV2 = DetectResult.UnSupported; F_Leasing_V1 = DetectResult.UnSupported; F_Leasing_V2 = DetectResult.UnSupported; RsvdVersion = 0; SqosVersion = 0; }
private bool CheckOpenDeviceContext(Smb2CreateContextResponse[] servercreatecontexts, RSVD_PROTOCOL_VERSION expectVersion) { if (servercreatecontexts == null) { if (expectVersion == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1) { // <10> Section 3.2.5.1: Windows Server 2012 R2 without [MSKB-3025091] doesn't return SVHDX_OPEN_DEVICE_CONTEXT_RESPONSE. // So if the open device context returns success, but without SVHDX_OPEN_DEVICE_CONTEXT_RESPONSE, the SUT may still support RSVD version 1. return true; } else { return false; } } foreach (var context in servercreatecontexts) { Type type = context.GetType(); if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponse") { Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponse; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return true; } } if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2") { Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponseV2; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return true; } } } return false; }
/// <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 bool CheckOpenDeviceContext(Smb2CreateContextResponse[] servercreatecontexts, RSVD_PROTOCOL_VERSION expectVersion) { if (servercreatecontexts == null) { if (expectVersion == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1) { // <10> Section 3.2.5.1: Windows Server 2012 R2 without [MSKB-3025091] doesn't return SVHDX_OPEN_DEVICE_CONTEXT_RESPONSE. // So if the open device context returns success, but without SVHDX_OPEN_DEVICE_CONTEXT_RESPONSE, the SUT may still support RSVD version 1. return(true); } else { return(false); } } foreach (var context in servercreatecontexts) { Type type = context.GetType(); if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponse") { Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponse; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return(true); } } if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2") { Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponseV2; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return(true); } } } return(false); }
/// <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> /// <param name="serverContextResponse">The create context response returned by server</param> /// <param name="initiatorHostName">It specifies the computer name on which the initiator resides</param> public void OpenSharedVHD( string fileName, RSVD_PROTOCOL_VERSION version, ulong?openRequestId, bool hasInitiatorId, RsvdClient rsvdClient, out Smb2CreateContextResponse[] serverContextResponse, string initiatorHostName) { 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; string tempInitiatorHostName = initiatorHostName ?? TestConfig.InitiatorHostName; if (version == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1) { contexts = new Smb2CreateContextRequest[] { new Smb2CreateSvhdxOpenDeviceContext { Version = (uint)version, OriginatorFlags = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER, InitiatorHostName = tempInitiatorHostName, InitiatorHostNameLength = (ushort)(tempInitiatorHostName.Length * 2), OpenRequestId = openRequestId == null ? RequestIdentifier : openRequestId.Value, InitiatorId = hasInitiatorId ? Guid.NewGuid():Guid.Empty, HasInitiatorId = hasInitiatorId } }; } else if (version == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2) { contexts = new Smb2CreateContextRequest[] { new Smb2CreateSvhdxOpenDeviceContextV2 { Version = (uint)version, OriginatorFlags = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER, InitiatorHostName = TestConfig.InitiatorHostName, InitiatorHostNameLength = (ushort)(TestConfig.InitiatorHostName.Length * 2), OpenRequestId = openRequestId == null ? RequestIdentifier : openRequestId.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; 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)); }
private bool CheckOpenDeviceContext(Smb2CreateContextResponse[] servercreatecontexts, RSVD_PROTOCOL_VERSION expectVersion) { if (servercreatecontexts == null) { return(false); } foreach (var context in servercreatecontexts) { Type type = context.GetType(); if (type.Name == "Smb2CreateSvhdxOpenDeviceContext") { Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponse; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return(true); } } if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2") { Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponseV2; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return(true); } } } return(false); }
/// <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; } }