diff --git a/Distribution/package.sh b/Distribution/package.sh index 92825be4..e8d91ecd 100755 --- a/Distribution/package.sh +++ b/Distribution/package.sh @@ -1,7 +1,7 @@ # Package parameters -NAME="iSCSI Initiator for OS X" +NAME="iSCSI Initiator for macOS" BUNDLE_ID="com.github.iscsi-osx.iSCSIInitiator" -VERSION="1.0.0-beta4" +VERSION="1.0.0-beta5" # Output of final DMG RELEASE="../Release" diff --git a/Source/Kernel/iSCSIHBAUserClient.cpp b/Source/Kernel/iSCSIHBAUserClient.cpp index a010a356..9ad77579 100644 --- a/Source/Kernel/iSCSIHBAUserClient.cpp +++ b/Source/Kernel/iSCSIHBAUserClient.cpp @@ -320,9 +320,6 @@ IOReturn iSCSIHBAUserClient::clientDied() // Tell HBA to release any resources that aren't active (e.g., // connections we started to establish but didn't activate) - // Close the provider (decrease retain count) - close(); - return super::clientDied(); } diff --git a/Source/Kernel/iSCSIVirtualHBA.cpp b/Source/Kernel/iSCSIVirtualHBA.cpp index c21ef868..dc9235d6 100644 --- a/Source/Kernel/iSCSIVirtualHBA.cpp +++ b/Source/Kernel/iSCSIVirtualHBA.cpp @@ -586,7 +586,7 @@ void iSCSIVirtualHBA::BeginTaskOnWorkloopThread(iSCSIVirtualHBA * owner, if(transferDirection == kSCSIDataTransfer_FromInitiatorToTarget) bhs.flags |= kiSCSIPDUSCSICmdFlagWrite; - else + else if(transferDirection == kSCSIDataTransfer_FromTargetToInitiator) bhs.flags |= kiSCSIPDUSCSICmdFlagRead; // For CDB sizes less than 16 bytes, plug directly into SCSI command PDU diff --git a/Source/User/iSCSI Framework/iSCSIDaemonInterface.c b/Source/User/iSCSI Framework/iSCSIDaemonInterface.c index 23aa0728..a175afc0 100644 --- a/Source/User/iSCSI Framework/iSCSIDaemonInterface.c +++ b/Source/User/iSCSI Framework/iSCSIDaemonInterface.c @@ -121,7 +121,7 @@ iSCSIDaemonHandle iSCSIDaemonConnect() // Set timeout for connect() struct timeval tv; memset(&tv,0,sizeof(tv)); - tv.tv_usec = kiSCSIDaemonConnectTimeoutMilliSec*2000; + tv.tv_usec = kiSCSIDaemonConnectTimeoutMilliSec*1000; fd_set fdset; FD_ZERO(&fdset); @@ -532,7 +532,6 @@ CFDictionaryRef iSCSIDaemonCreateCFPropertiesForSession(iSCSIDaemonHandle handle CFRelease(data); } } - return properties; } diff --git a/Source/User/iSCSI Framework/iSCSIPreferences.c b/Source/User/iSCSI Framework/iSCSIPreferences.c index 021c1463..c756bff8 100644 --- a/Source/User/iSCSI Framework/iSCSIPreferences.c +++ b/Source/User/iSCSI Framework/iSCSIPreferences.c @@ -823,6 +823,7 @@ void iSCSIPreferencesSetInitiatorIQN(iSCSIPreferencesRef preferences,CFStringRef if(!initiatorDict) { initiatorDict = iSCSIPreferencesCreateInitiatorDict(); + CFDictionarySetValue(preferences,kiSCSIPKInitiator,initiatorDict); } // Update keychain if necessary @@ -866,6 +867,7 @@ void iSCSIPreferencesSetInitiatorAlias(iSCSIPreferencesRef preferences,CFStringR if(!initiatorDict) { initiatorDict = iSCSIPreferencesCreateInitiatorDict(); + CFDictionarySetValue(preferences,kiSCSIPKInitiator,initiatorDict); } // Update initiator alias diff --git a/Source/User/iSCSI Framework/iSCSIUtils.c b/Source/User/iSCSI Framework/iSCSIUtils.c index d548e6de..403b8fca 100644 --- a/Source/User/iSCSI Framework/iSCSIUtils.c +++ b/Source/User/iSCSI Framework/iSCSIUtils.c @@ -289,10 +289,15 @@ errno_t iSCSIUtilsGetAddressForPortal(iSCSIPortalRef portal, errno_t error = 0; // Resolve the target node first and get a sockaddr info for it - const char * targetAddr, * targetPort; + CFStringRef targetAddr = iSCSIPortalGetAddress(portal); + CFIndex targetAddrLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(targetAddr),kCFStringEncodingASCII) + sizeof('\0'); + char targetAddrBuffer[targetAddrLength]; + CFStringGetCString(targetAddr,targetAddrBuffer,targetAddrLength,kCFStringEncodingASCII); - targetAddr = CFStringGetCStringPtr(iSCSIPortalGetAddress(portal),kCFStringEncodingUTF8); - targetPort = CFStringGetCStringPtr(iSCSIPortalGetPort(portal),kCFStringEncodingUTF8); + CFStringRef targetPort = iSCSIPortalGetPort(portal); + CFIndex targetPortLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(targetPort),kCFStringEncodingASCII) + sizeof('\0'); + char targetPortBuffer[targetPortLength]; + CFStringGetCString(targetPort,targetPortBuffer,targetPortLength,kCFStringEncodingASCII); struct addrinfo hints = { .ai_family = AF_UNSPEC, @@ -301,7 +306,7 @@ errno_t iSCSIUtilsGetAddressForPortal(iSCSIPortalRef portal, }; struct addrinfo * aiTarget = NULL; - if((error = getaddrinfo(targetAddr,targetPort,&hints,&aiTarget))) + if((error = getaddrinfo(targetAddrBuffer,targetPortBuffer,&hints,&aiTarget))) return error; // Copy the sock_addr structure into a sockaddr_storage structure (this @@ -373,4 +378,4 @@ errno_t iSCSIUtilsGetAddressForPortal(iSCSIPortalRef portal, freeifaddrs(interfaceList); return error; -} \ No newline at end of file +} diff --git a/Source/User/iscsictl/iSCSICtl.m b/Source/User/iscsictl/iSCSICtl.m index 58428e2d..43dd5178 100644 --- a/Source/User/iscsictl/iSCSICtl.m +++ b/Source/User/iscsictl/iSCSICtl.m @@ -1966,6 +1966,10 @@ errno_t iSCSICtlAddDiscoveryPortal(AuthorizationRef authorization,CFDictionaryRe if(portal) iSCSIPortalRelease(portal); + + if(!error) + iSCSIDaemonUpdateDiscovery(handle); + if(preferences) iSCSIPreferencesRelease(preferences); iSCSICtlDisconnectFromDaemon(handle); diff --git a/Source/User/iscsid/iSCSIDaemon.c b/Source/User/iscsid/iSCSIDaemon.c index 678de72e..72e064f8 100644 --- a/Source/User/iscsid/iSCSIDaemon.c +++ b/Source/User/iscsid/iSCSIDaemon.c @@ -75,6 +75,12 @@ IONotificationPortRef powerNotifyPortRef; // Used to fire discovery timer at specified intervals CFRunLoopTimerRef discoveryTimer = NULL; +// Used by discovery to notify the main daemon thread that data is ready +CFRunLoopSourceRef discoverySource = NULL; + +// Used to point to discovery records +CFDictionaryRef discoveryRecords = NULL; + // Mutex lock when discovery is running pthread_mutex_t discoveryMutex = PTHREAD_MUTEX_INITIALIZER; @@ -366,10 +372,8 @@ errno_t iSCSIDLoginCommon(SessionIdentifier sessionId, // Update target alias in preferences (if one was furnished) else { - pthread_mutex_lock(&preferencesMutex); iSCSIPreferencesSetTargetAlias(preferences,targetIQN,iSCSITargetGetAlias(target)); iSCSIPreferencesSynchronzeAppValues(preferences); - pthread_mutex_unlock(&preferencesMutex); } if(sessCfg) @@ -778,7 +782,7 @@ errno_t iSCSIDLogout(int fd,iSCSIDMsgLogoutCmd * cmd) iSCSIDLogoutContext * context; context = (iSCSIDLogoutContext*)malloc(sizeof(iSCSIDLogoutContext)); context->fd = fd; - context->portal = portal; + context->portal = NULL; context->errorCode = errorCode; context->diskSession = NULL; @@ -791,8 +795,10 @@ errno_t iSCSIDLogout(int fd,iSCSIDMsgLogoutCmd * cmd) iSCSIDAUnmountForTarget(context->diskSession,kDADiskUnmountOptionWhole,target,&iSCSIDLogoutComplete,context); } // Portal logout only (or no logout and just a response to client if error) - else + else { + context->portal = portal; iSCSIDLogoutComplete(target,kiSCSIDAOperationSuccess,context); + } return 0; } @@ -1300,8 +1306,21 @@ CFDictionaryRef iSCSIDCreateRecordsWithSendTargets(iSCSISessionManagerRef manage void * iSCSIDRunDiscovery(void * context) { - CFDictionaryRef discoveryRecords = iSCSIDCreateRecordsWithSendTargets(sessionManager,preferences); + if(discoveryRecords != NULL) + CFRelease(discoveryRecords); + + discoveryRecords = iSCSIDCreateRecordsWithSendTargets(sessionManager,preferences); + + // Clear mutex created when discovery was launched + pthread_mutex_unlock(&discoveryMutex); + + CFRunLoopSourceSignal(discoverySource); + return NULL; +} + +void iSCSIDProcessDiscoveryData(void * info) +{ // Process discovery results if any if(discoveryRecords) { @@ -1312,19 +1331,15 @@ void * iSCSIDRunDiscovery(void * context) const void * keys[count]; const void * values[count]; CFDictionaryGetKeysAndValues(discoveryRecords,keys,values); - + for(CFIndex i = 0; i < count; i++) iSCSIDUpdatePreferencesWithDiscoveredTargets(sessionManager,preferences,keys[i],values[i]); - + iSCSIPreferencesSynchronzeAppValues(preferences); pthread_mutex_unlock(&preferencesMutex); CFRelease(discoveryRecords); } - - pthread_mutex_unlock(&discoveryMutex); - - return NULL; } @@ -1385,8 +1400,9 @@ errno_t iSCSIDUpdateDiscovery(int fd, // Add new timer with updated interval, if discovery is enabled if(discoveryEnabled) { + CFTimeInterval delay = 2; discoveryTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, - CFAbsoluteTimeGetCurrent() + 2.0, + CFAbsoluteTimeGetCurrent()+delay, interval,0,0,callout,NULL); CFRunLoopAddTimer(CFRunLoopGetCurrent(),discoveryTimer,kCFRunLoopDefaultMode); @@ -1656,9 +1672,25 @@ void iSCSIDQueueLogin(iSCSITargetRef target,iSCSIPortalRef portal) (const struct sockaddr *)&localAddress, (const struct sockaddr *)&remoteAddress); } - - SCNetworkReachabilitySetCallback(reachabilityTarget,iSCSIDProcessQueuedLogin,&reachabilityContext); - SCNetworkReachabilityScheduleWithRunLoop(reachabilityTarget,CFRunLoopGetMain(),kCFRunLoopDefaultMode); + + // If the target is reachable just login; otherwise queue the login ... + SCNetworkReachabilityFlags reachabilityFlags; + SCNetworkReachabilityGetFlags(reachabilityTarget,&reachabilityFlags); + + if(reachabilityFlags & kSCNetworkReachabilityFlagsReachable) { + enum iSCSILoginStatusCode statusCode; + iSCSIDLoginWithPortal(target,portal,&statusCode); + + iSCSITargetRelease(target); + iSCSIPortalRelease(portal); + CFRelease(reachabilityTarget); + free(loginRef); + + } + else { + SCNetworkReachabilitySetCallback(reachabilityTarget,iSCSIDProcessQueuedLogin,&reachabilityContext); + SCNetworkReachabilityScheduleWithRunLoop(reachabilityTarget,CFRunLoopGetMain(),kCFRunLoopDefaultMode); + } } void iSCSIDSessionTimeoutHandler(iSCSITargetRef target,iSCSIPortalRef portal) @@ -1821,7 +1853,6 @@ void iSCSIDPrepareForSystemSleep() DASessionScheduleWithRunLoop(diskSession,CFRunLoopGetMain(),kCFRunLoopDefaultMode); iSCSIDAUnmountForTarget(diskSession,kDADiskUnmountOptionWhole,target,&iSCSIDPrepareForSystemSleepComplete,(void*)sessionId); -// iSCSITargetRelease(target); } CFRetain(diskSession); @@ -1994,9 +2025,10 @@ int main(void) sessionManager = iSCSISessionManagerCreate(kCFAllocatorDefault,callbacks); // Let launchd call us again once the HBA kext is loaded - if(!sessionManager) + if(!sessionManager) { + asl_log(NULL,NULL,ASL_LEVEL_ALERT,"kernel extension has not been loaded, iSCSI services unavailable"); return EAGAIN; - + } iSCSISessionManagerScheduleWithRunLoop(sessionManager,CFRunLoopGetMain(),kCFRunLoopDefaultMode); // Read configuration parameters from the iSCSI property list @@ -2093,6 +2125,14 @@ int main(void) reqInfo->socket = socket; reqInfo->socketSourceRead = sockSourceRead; reqInfo->fd = 0; + + // Runloop source signal by deamoen when discovery data is ready to be processed + CFRunLoopSourceContext discoveryContext; + bzero(&discoveryContext,sizeof(discoveryContext)); + discoveryContext.info = &discoveryRecords; + discoveryContext.perform = iSCSIDProcessDiscoveryData; + discoverySource = CFRunLoopSourceCreate(kCFAllocatorDefault,1,&discoveryContext); + CFRunLoopAddSource(CFRunLoopGetMain(),sockSourceRead,kCFRunLoopDefaultMode); asl_log(NULL,NULL,ASL_LEVEL_INFO,"daemon started"); diff --git a/Source/User/iscsid/iSCSIHBAInterface.c b/Source/User/iscsid/iSCSIHBAInterface.c index fe8c83ae..80925e10 100644 --- a/Source/User/iscsid/iSCSIHBAInterface.c +++ b/Source/User/iscsid/iSCSIHBAInterface.c @@ -164,7 +164,6 @@ iSCSIHBAInterfaceRef iSCSIHBAInterfaceCreate(CFAllocatorRef allocator,iSCSIHBANo // (this may be NULL in which case we are not responsible) if(interface->notifyContext.retain) interface->notifyContext.retain(interface->notifyContext.info); - } // Cleanup else { @@ -176,6 +175,7 @@ iSCSIHBAInterfaceRef iSCSIHBAInterfaceCreate(CFAllocatorRef allocator,iSCSIHBANo IOObjectRelease(service); CFAllocatorDeallocate(allocator,interface); + interface = NULL; } return interface; } @@ -1065,4 +1065,4 @@ CFStringRef iSCSIHBAInterfaceCreateHostInterfaceForConnectionId(iSCSIHBAInterfac return NULL; return CFStringCreateWithCString(kCFAllocatorDefault,hostInterface,kCFStringEncodingASCII); -} \ No newline at end of file +} diff --git a/Source/User/iscsid/iSCSISessionManager.c b/Source/User/iscsid/iSCSISessionManager.c index 1aa32a6f..8b8f4a81 100644 --- a/Source/User/iscsid/iSCSISessionManager.c +++ b/Source/User/iscsid/iSCSISessionManager.c @@ -135,11 +135,17 @@ iSCSISessionManagerRef iSCSISessionManagerCreate(CFAllocatorRef allocator, iSCSIHBAInterfaceRef interface = iSCSIHBAInterfaceCreate(allocator,iSCSIHBANotificationHandler,¬ifyContext); - managerRef->allocator = allocator; - managerRef->hbaInterface = interface; - managerRef->callbacks = callbacks; - managerRef->initiatorName = kiSCSIInitiatorIQN; - managerRef->initiatorAlias = kiSCSIInitiatorAlias; + if(interface) { + managerRef->allocator = allocator; + managerRef->hbaInterface = interface; + managerRef->callbacks = callbacks; + managerRef->initiatorName = kiSCSIInitiatorIQN; + managerRef->initiatorAlias = kiSCSIInitiatorAlias; + } + else { + CFAllocatorDeallocate(allocator,managerRef); + managerRef = NULL; + } return managerRef; } diff --git a/iSCSIInitiator.xcodeproj/project.pbxproj b/iSCSIInitiator.xcodeproj/project.pbxproj index 8179496f..f9262407 100644 --- a/iSCSIInitiator.xcodeproj/project.pbxproj +++ b/iSCSIInitiator.xcodeproj/project.pbxproj @@ -522,7 +522,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0820; TargetAttributes = { 2B1A490B1D3D40FE00D3ED0D = { CreatedOnToolsVersion = 7.3.1; @@ -709,7 +709,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEBUG_INFORMATION_FORMAT = dwarf; DYLIB_CURRENT_VERSION = 1.0.0; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = "compiler-default"; @@ -789,7 +789,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -811,7 +811,7 @@ buildSettings = { CF_PREFERENCES_APP_ID = "$(NAME_PREFIX_D).iSCSIInitiator"; CODE_SIGN_IDENTITY = ""; - CURRENT_PROJECT_VERSION = "1.0.0-beta4"; + CURRENT_PROJECT_VERSION = "1.0.0-beta5"; ENABLE_TESTABILITY = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "CF_PREFERENCES_APP_ID=\\\"$(NAME_PREFIX_D).iSCSIInitiator\\\"", @@ -833,7 +833,7 @@ buildSettings = { CF_PREFERENCES_APP_ID = "$(NAME_PREFIX_D).iSCSIInitiator"; CODE_SIGN_IDENTITY = ""; - CURRENT_PROJECT_VERSION = "1.0.0-beta4"; + CURRENT_PROJECT_VERSION = "1.0.0-beta5"; GCC_PREPROCESSOR_DEFINITIONS = ( "CF_PREFERENCES_APP_ID=\\\"$(NAME_PREFIX_D).iSCSIInitiator\\\"", "NAME_PREFIX_U=$(NAME_PREFIX_U)", @@ -922,7 +922,7 @@ COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = ""; DYLIB_CURRENT_VERSION = 1.0.0; @@ -968,6 +968,7 @@ CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = "1.0.0-beta5"; DYLIB_CURRENT_VERSION = 1.0.0; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -1021,7 +1022,8 @@ CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + CURRENT_PROJECT_VERSION = "1.0.0-beta5"; + DEBUG_INFORMATION_FORMAT = dwarf; DYLIB_CURRENT_VERSION = 1.0.0; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -1068,6 +1070,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = "1.0.0-beta5"; DYLIB_CURRENT_VERSION = 1.0.0; GCC_C_LANGUAGE_STANDARD = "compiler-default"; GCC_DYNAMIC_NO_PIC = NO; @@ -1110,7 +1113,8 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + CURRENT_PROJECT_VERSION = "1.0.0-beta5"; + DEBUG_INFORMATION_FORMAT = dwarf; DYLIB_CURRENT_VERSION = 1.0.0; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = "compiler-default"; diff --git a/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iSCSI.framework.xcscheme b/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iSCSI.framework.xcscheme index a8ec144c..ce2c1c24 100644 --- a/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iSCSI.framework.xcscheme +++ b/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iSCSI.framework.xcscheme @@ -1,6 +1,6 @@ + + + + diff --git a/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iscsid.xcscheme b/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iscsid.xcscheme index 253ab19b..e177f908 100644 --- a/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iscsid.xcscheme +++ b/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iscsid.xcscheme @@ -1,6 +1,6 @@