Skip to content

Commit

Permalink
Merge pull request #78 from iscsi-osx/develop
Browse files Browse the repository at this point in the history
Beta5
  • Loading branch information
nsinenian authored Dec 20, 2016
2 parents 7310571 + 3f168f9 commit 50d756e
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Distribution/package.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 0 additions & 3 deletions Source/Kernel/iSCSIHBAUserClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Kernel/iSCSIVirtualHBA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Source/User/iSCSI Framework/iSCSIDaemonInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -532,7 +532,6 @@ CFDictionaryRef iSCSIDaemonCreateCFPropertiesForSession(iSCSIDaemonHandle handle
CFRelease(data);
}
}

return properties;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/User/iSCSI Framework/iSCSIPreferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ void iSCSIPreferencesSetInitiatorIQN(iSCSIPreferencesRef preferences,CFStringRef

if(!initiatorDict) {
initiatorDict = iSCSIPreferencesCreateInitiatorDict();
CFDictionarySetValue(preferences,kiSCSIPKInitiator,initiatorDict);
}

// Update keychain if necessary
Expand Down Expand Up @@ -866,6 +867,7 @@ void iSCSIPreferencesSetInitiatorAlias(iSCSIPreferencesRef preferences,CFStringR

if(!initiatorDict) {
initiatorDict = iSCSIPreferencesCreateInitiatorDict();
CFDictionarySetValue(preferences,kiSCSIPKInitiator,initiatorDict);
}

// Update initiator alias
Expand Down
15 changes: 10 additions & 5 deletions Source/User/iSCSI Framework/iSCSIUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -373,4 +378,4 @@ errno_t iSCSIUtilsGetAddressForPortal(iSCSIPortalRef portal,

freeifaddrs(interfaceList);
return error;
}
}
4 changes: 4 additions & 0 deletions Source/User/iscsictl/iSCSICtl.m
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,10 @@ errno_t iSCSICtlAddDiscoveryPortal(AuthorizationRef authorization,CFDictionaryRe

if(portal)
iSCSIPortalRelease(portal);

if(!error)
iSCSIDaemonUpdateDiscovery(handle);

if(preferences)
iSCSIPreferencesRelease(preferences);
iSCSICtlDisconnectFromDaemon(handle);
Expand Down
76 changes: 58 additions & 18 deletions Source/User/iscsid/iSCSIDaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {

Expand All @@ -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;
}


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1821,7 +1853,6 @@ void iSCSIDPrepareForSystemSleep()

DASessionScheduleWithRunLoop(diskSession,CFRunLoopGetMain(),kCFRunLoopDefaultMode);
iSCSIDAUnmountForTarget(diskSession,kDADiskUnmountOptionWhole,target,&iSCSIDPrepareForSystemSleepComplete,(void*)sessionId);
// iSCSITargetRelease(target);
}

CFRetain(diskSession);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions Source/User/iscsid/iSCSIHBAInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -176,6 +175,7 @@ iSCSIHBAInterfaceRef iSCSIHBAInterfaceCreate(CFAllocatorRef allocator,iSCSIHBANo
IOObjectRelease(service);

CFAllocatorDeallocate(allocator,interface);
interface = NULL;
}
return interface;
}
Expand Down Expand Up @@ -1065,4 +1065,4 @@ CFStringRef iSCSIHBAInterfaceCreateHostInterfaceForConnectionId(iSCSIHBAInterfac
return NULL;

return CFStringCreateWithCString(kCFAllocatorDefault,hostInterface,kCFStringEncodingASCII);
}
}
16 changes: 11 additions & 5 deletions Source/User/iscsid/iSCSISessionManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,17 @@ iSCSISessionManagerRef iSCSISessionManagerCreate(CFAllocatorRef allocator,

iSCSIHBAInterfaceRef interface = iSCSIHBAInterfaceCreate(allocator,iSCSIHBANotificationHandler,&notifyContext);

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;
}
Expand Down
Loading

0 comments on commit 50d756e

Please sign in to comment.