From e52040da444ec133aa0f295d2583e2e01fa5db83 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Sat, 22 Oct 2016 16:48:23 +0800 Subject: [PATCH 01/11] Remove CFStringGetCStringPtr() --- Source/User/iSCSI Framework/iSCSIUtils.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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 +} From fb80907f1299996859bb27f388570e1aa6a7b816 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Sat, 22 Oct 2016 18:01:26 +0800 Subject: [PATCH 02/11] Removed redundant close() call --- Source/Kernel/iSCSIHBAUserClient.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/Kernel/iSCSIHBAUserClient.cpp b/Source/Kernel/iSCSIHBAUserClient.cpp index a010a356..2ad6fafe 100644 --- a/Source/Kernel/iSCSIHBAUserClient.cpp +++ b/Source/Kernel/iSCSIHBAUserClient.cpp @@ -319,10 +319,7 @@ 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(); } From 3b045a3ec8beeb6d884db1eda6119100a4014486 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Sat, 22 Oct 2016 21:58:24 +0800 Subject: [PATCH 03/11] Fix: incomplete logout when single portal is logged in and portal is specified during logout --- Source/User/iscsid/iSCSIDaemon.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/User/iscsid/iSCSIDaemon.c b/Source/User/iscsid/iSCSIDaemon.c index 678de72e..f34e001c 100644 --- a/Source/User/iscsid/iSCSIDaemon.c +++ b/Source/User/iscsid/iSCSIDaemon.c @@ -778,7 +778,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 +791,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; } From 3b29ea8b99a9e9a71677703c2f48f41bcd7d2f3a Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Thu, 24 Nov 2016 10:13:18 -0600 Subject: [PATCH 04/11] Fixes issue with START_STOP_UNIT with some target implementations. --- Source/Kernel/iSCSIHBAUserClient.cpp | 2 +- Source/Kernel/iSCSIVirtualHBA.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Kernel/iSCSIHBAUserClient.cpp b/Source/Kernel/iSCSIHBAUserClient.cpp index 2ad6fafe..9ad77579 100644 --- a/Source/Kernel/iSCSIHBAUserClient.cpp +++ b/Source/Kernel/iSCSIHBAUserClient.cpp @@ -319,7 +319,7 @@ IOReturn iSCSIHBAUserClient::clientDied() { // Tell HBA to release any resources that aren't active (e.g., // connections we started to establish but didn't activate) - + 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 From 4aa646c3b3683a879dcf77a98671380f00ae82c2 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Sat, 3 Dec 2016 12:23:56 +0800 Subject: [PATCH 05/11] Notification when iscsid can't connect to kext --- .../User/iSCSI Framework/iSCSIDaemonInterface.c | 3 +-- Source/User/iscsid/iSCSIDaemon.c | 11 ++++++++--- Source/User/iscsid/iSCSIHBAInterface.c | 4 ++-- Source/User/iscsid/iSCSISessionManager.c | 16 +++++++++++----- .../xcshareddata/xcschemes/iscsictl.xcscheme | 6 ++++++ 5 files changed, 28 insertions(+), 12 deletions(-) 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/iscsid/iSCSIDaemon.c b/Source/User/iscsid/iSCSIDaemon.c index f34e001c..8abd6d27 100644 --- a/Source/User/iscsid/iSCSIDaemon.c +++ b/Source/User/iscsid/iSCSIDaemon.c @@ -1388,7 +1388,7 @@ errno_t iSCSIDUpdateDiscovery(int fd, if(discoveryEnabled) { discoveryTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, - CFAbsoluteTimeGetCurrent() + 2.0, + CFAbsoluteTimeGetCurrent(), interval,0,0,callout,NULL); CFRunLoopAddTimer(CFRunLoopGetCurrent(),discoveryTimer,kCFRunLoopDefaultMode); @@ -1400,6 +1400,10 @@ errno_t iSCSIDUpdateDiscovery(int fd, if(send(fd,&rsp,sizeof(rsp),0) != sizeof(rsp)) error = EAGAIN; + + // If discovery was enabled do it now... +// if(discoveryEnabled) +// iSCSIDisco return error; } @@ -1996,9 +2000,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 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/xcshareddata/xcschemes/iscsictl.xcscheme b/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iscsictl.xcscheme index 87c8b827..6183e239 100644 --- a/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iscsictl.xcscheme +++ b/iSCSIInitiator.xcodeproj/xcshareddata/xcschemes/iscsictl.xcscheme @@ -62,6 +62,12 @@ ReferencedContainer = "container:iSCSIInitiator.xcodeproj"> + + + + From f407bee36b6af3eb1a9090c57824b9d48d181ac9 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Sat, 3 Dec 2016 12:35:15 +0800 Subject: [PATCH 06/11] Rename package from OS X to macOS --- Distribution/package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Distribution/package.sh b/Distribution/package.sh index 92825be4..2eaf2ec3 100755 --- a/Distribution/package.sh +++ b/Distribution/package.sh @@ -1,5 +1,5 @@ # 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" From 8adc47aa282f3101eb329607054477ab9618758f Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Sat, 3 Dec 2016 17:38:26 +0800 Subject: [PATCH 07/11] iSCSIDQueueLogin() checks reachability first and attempts to login. Queues login only if unreachable. --- Source/User/iscsid/iSCSIDaemon.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Source/User/iscsid/iSCSIDaemon.c b/Source/User/iscsid/iSCSIDaemon.c index 8abd6d27..ba955b94 100644 --- a/Source/User/iscsid/iSCSIDaemon.c +++ b/Source/User/iscsid/iSCSIDaemon.c @@ -1662,9 +1662,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) From 2f33cb5613a37fececb3597fbb0344769c3df7c9 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Sun, 4 Dec 2016 09:43:02 +0800 Subject: [PATCH 08/11] Fix corner case - inability to change IQN or alias when preferences plist does not exist --- Source/User/iSCSI Framework/iSCSIPreferences.c | 2 ++ 1 file changed, 2 insertions(+) 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 From d1ad33f65f2962c461b7630d8fcb4eec23ca22f5 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Tue, 20 Dec 2016 20:02:46 +0800 Subject: [PATCH 09/11] Update version to beta 5 --- iSCSIInitiator.xcodeproj/project.pbxproj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iSCSIInitiator.xcodeproj/project.pbxproj b/iSCSIInitiator.xcodeproj/project.pbxproj index 8179496f..8bdd7fe8 100644 --- a/iSCSIInitiator.xcodeproj/project.pbxproj +++ b/iSCSIInitiator.xcodeproj/project.pbxproj @@ -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)", @@ -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,6 +1022,7 @@ CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; + CURRENT_PROJECT_VERSION = "1.0.0-beta5"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_CURRENT_VERSION = 1.0.0; ENABLE_NS_ASSERTIONS = NO; @@ -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,6 +1113,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; + CURRENT_PROJECT_VERSION = "1.0.0-beta5"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_CURRENT_VERSION = 1.0.0; ENABLE_NS_ASSERTIONS = NO; From c8df7c697a68e15dafc6cba5c3f06c738d432e04 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Tue, 20 Dec 2016 20:44:42 +0800 Subject: [PATCH 10/11] Fixes delays associated with discovery when adding a new discovery portal or enabling discovery after having added a new portal --- Distribution/package.sh | 2 +- Source/User/iscsictl/iSCSICtl.m | 4 ++++ Source/User/iscsid/iSCSIDaemon.c | 8 ++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Distribution/package.sh b/Distribution/package.sh index 2eaf2ec3..e8d91ecd 100755 --- a/Distribution/package.sh +++ b/Distribution/package.sh @@ -1,7 +1,7 @@ # Package parameters 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/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 ba955b94..cc8f093e 100644 --- a/Source/User/iscsid/iSCSIDaemon.c +++ b/Source/User/iscsid/iSCSIDaemon.c @@ -1387,8 +1387,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(), + CFAbsoluteTimeGetCurrent()+delay, interval,0,0,callout,NULL); CFRunLoopAddTimer(CFRunLoopGetCurrent(),discoveryTimer,kCFRunLoopDefaultMode); @@ -1400,10 +1401,6 @@ errno_t iSCSIDUpdateDiscovery(int fd, if(send(fd,&rsp,sizeof(rsp),0) != sizeof(rsp)) error = EAGAIN; - - // If discovery was enabled do it now... -// if(discoveryEnabled) -// iSCSIDisco return error; } @@ -1843,7 +1840,6 @@ void iSCSIDPrepareForSystemSleep() DASessionScheduleWithRunLoop(diskSession,CFRunLoopGetMain(),kCFRunLoopDefaultMode); iSCSIDAUnmountForTarget(diskSession,kDADiskUnmountOptionWhole,target,&iSCSIDPrepareForSystemSleepComplete,(void*)sessionId); -// iSCSITargetRelease(target); } CFRetain(diskSession); From 3f168f926f1d932c0256a5d5b3abba8cf92da852 Mon Sep 17 00:00:00 2001 From: Nareg Sinenian Date: Wed, 21 Dec 2016 00:52:30 +0800 Subject: [PATCH 11/11] Fixes issue where running discovery may prevent access to preferences, causing iscsid to crash. --- Source/User/iscsid/iSCSIDaemon.c | 39 ++++++++++++++----- iSCSIInitiator.xcodeproj/project.pbxproj | 12 +++--- .../xcschemes/iSCSI.framework.xcscheme | 2 +- .../xcschemes/iSCSI.kext.xcscheme | 2 +- .../xcshareddata/xcschemes/iscsictl.xcscheme | 2 +- .../xcshareddata/xcschemes/iscsid.xcscheme | 2 +- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Source/User/iscsid/iSCSIDaemon.c b/Source/User/iscsid/iSCSIDaemon.c index cc8f093e..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) @@ -1302,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) { @@ -1314,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; } @@ -2112,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/iSCSIInitiator.xcodeproj/project.pbxproj b/iSCSIInitiator.xcodeproj/project.pbxproj index 8bdd7fe8..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; @@ -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; @@ -1023,7 +1023,7 @@ COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; CURRENT_PROJECT_VERSION = "1.0.0-beta5"; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEBUG_INFORMATION_FORMAT = dwarf; DYLIB_CURRENT_VERSION = 1.0.0; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -1114,7 +1114,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; CURRENT_PROJECT_VERSION = "1.0.0-beta5"; - 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"; 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 @@