Skip to content

Commit

Permalink
Merge pull request #53 from iscsi-osx/develop
Browse files Browse the repository at this point in the history
Beta-3
  • Loading branch information
nsinenian committed Jun 20, 2016
2 parents 01bb77d + 7c722d6 commit e87c77e
Show file tree
Hide file tree
Showing 31 changed files with 1,454 additions and 2,227 deletions.
6 changes: 5 additions & 1 deletion Distribution/Scripts/Installer/postinstall
Expand Up @@ -25,18 +25,20 @@ OSX_MINOR_VER=$(sw_vers -productVersion | awk -F '.' '{print $2}')
# Minor version of OS X Mavericks
OSX_MAVERICKS_MINOR_VER="9"

if [ "$OSX_MINOR_VER" -ge "$OSX_MAVERICKS_MINOR_VER" ]; then
if [ "$OSX_MINOR_VER" -gt "$OSX_MAVERICKS_MINOR_VER" ]; then
KEXT_DST=/Library/Extensions
else
KEXT_DST=/System/Library/Extensions
fi

# Copy kernel extensions & load it
sudo mkdir -p $KEXT_DST
sudo cp -R $TMP/$KEXT $KEXT_DST/$KEXT
sudo chmod -R 755 $KEXT_DST/$KEXT
sudo chown -R root:wheel $KEXT_DST/$KEXT

# Copy framework
sudo mkdir -p $FRAMEWORK_DST
sudo cp -R $TMP/$FRAMEWORK $FRAMEWORK_DST/$FRAMEWORK
sudo chown -R root:wheel $FRAMEWORK_DST/$FRAMEWORK
sudo chmod -R 755 $FRAMEWORK_DST/$FRAMEWORK
Expand All @@ -50,10 +52,12 @@ sudo chmod 644 $DAEMON_PLIST_DST/$DAEMON_PLIST
sudo chown root:wheel $DAEMON_PLIST_DST/$DAEMON_PLIST

# Copy user tool
sudo mkdir -p $TOOL_DST
sudo cp $TMP/$TOOL $TOOL_DST/$TOOL
sudo chmod +x $TOOL_DST/$TOOL

# Copy man pages
sudo mkdir -p $MAN_DST
sudo cp $TMP/$MAN_TOOL $MAN_DST
sudo cp $TMP/$MAN_DAEMON $MAN_DST

Expand Down
2 changes: 1 addition & 1 deletion Distribution/Scripts/Installer/preinstall
Expand Up @@ -23,7 +23,7 @@ OSX_MINOR_VER=$(sw_vers -productVersion | awk -F '.' '{print $2}')
# Minor version of OS X Mavericks
OSX_MAVERICKS_MINOR_VER="9"

if [ "$OSX_MINOR_VER" -ge "$OSX_MAVERICKS_MINOR_VER" ]; then
if [ "$OSX_MINOR_VER" -gt "$OSX_MAVERICKS_MINOR_VER" ]; then
KEXT_DST=/Library/Extensions
else
KEXT_DST=/System/Library/Extensions
Expand Down
2 changes: 1 addition & 1 deletion Distribution/Scripts/Uninstaller/postinstall
Expand Up @@ -23,7 +23,7 @@ OSX_MINOR_VER=$(sw_vers -productVersion | awk -F '.' '{print $2}')
# Minor version of OS X Mavericks
OSX_MAVERICKS_MINOR_VER="9"

if [ "$OSX_MINOR_VER" -ge "$OSX_MAVERICKS_MINOR_VER" ]; then
if [ "$OSX_MINOR_VER" -gt "$OSX_MAVERICKS_MINOR_VER" ]; then
KEXT_DST=/Library/Extensions
else
KEXT_DST=/System/Library/Extensions
Expand Down
4 changes: 3 additions & 1 deletion Distribution/package.sh
@@ -1,7 +1,7 @@
# Package parameters
NAME="iSCSI Initiator for OS X"
BUNDLE_ID="com.github.iscsi-osx.iSCSIInitiator"
VERSION="1.0.0-beta2"
VERSION="1.0.0-beta3"

# Output of final DMG
RELEASE="../Release"
Expand Down Expand Up @@ -42,6 +42,8 @@ UNINSTALLER_DIST_XML="Resources/Uninstaller.xml"
REQUIREMENTS_PATH="Resources/Requirements.plist"

# Relelase build of all three components
xcodebuild -workspace ../iSCSIInitiator.xcodeproj/project.xcworkspace \
-scheme iSCSI.framework -configuration release BUILD_DIR=$XCODE_RELEASE_BUILD_DIR
xcodebuild -workspace ../iSCSIInitiator.xcodeproj/project.xcworkspace \
-scheme iSCSI.kext -configuration release BUILD_DIR=$XCODE_RELEASE_BUILD_DIR
xcodebuild -workspace ../iSCSIInitiator.xcodeproj/project.xcworkspace \
Expand Down
1 change: 1 addition & 0 deletions Scripts/build.sh
@@ -1,3 +1,4 @@
xcodebuild -workspace ../iSCSIInitiator.xcodeproj/project.xcworkspace -scheme iSCSI.framework
xcodebuild -workspace ../iSCSIInitiator.xcodeproj/project.xcworkspace -scheme iscsid build
xcodebuild -workspace ../iSCSIInitiator.xcodeproj/project.xcworkspace -scheme iscsictl build
xcodebuild -workspace ../iSCSIInitiator.xcodeproj/project.xcworkspace -scheme iSCSI.kext build
7 changes: 5 additions & 2 deletions Scripts/install.sh
Expand Up @@ -22,7 +22,7 @@ OSX_MINOR_VER=$(sw_vers -productVersion | awk -F '.' '{print $2}')
# Minor version of OS X Mavericks
OSX_MAVERICKS_MINOR_VER="9"

if [ "$OSX_MINOR_VER" -ge "$OSX_MAVERICKS_MINOR_VER" ]; then
if [ "$OSX_MINOR_VER" -gt "$OSX_MAVERICKS_MINOR_VER" ]; then
KEXT_DST=/Library/Extensions
else
KEXT_DST=/System/Library/Extensions
Expand All @@ -46,16 +46,17 @@ if [ X"" == X"${SOURCE_PATH}" ]; then
fi

# Copy kernel extension & load it
sudo mkdir -p $KEXT_DST
sudo cp -R $SOURCE_PATH/$KEXT $KEXT_DST/$KEXT
sudo chmod -R 755 $KEXT_DST/$KEXT
sudo chown -R root:wheel $KEXT_DST/$KEXT

# Copy framework
sudo mkdir -p $FRAMEWORK_DST
sudo cp -R $SOURCE_PATH/$FRAMEWORK $FRAMEWORK_DST/$FRAMEWORK
sudo chown -R root:wheel $FRAMEWORK_DST/$FRAMEWORK
sudo chmod -R 755 $FRAMEWORK_DST/$FRAMEWORK


# Copy daemon & set permissions
sudo rm -f /var/logs/iscsid.log
sudo mkdir -p $DAEMON_DST
Expand All @@ -67,10 +68,12 @@ sudo chmod 644 $DAEMON_PLIST_DST/$DAEMON_PLIST
sudo chown root:wheel $DAEMON_PLIST_DST/$DAEMON_PLIST

# Copy user tool
sudo mkdir -p $TOOL_DST
sudo cp $SOURCE_PATH/$TOOL $TOOL_DST/$TOOL
sudo chmod +x $TOOL_DST/$TOOL

# Copy man page
sudo mkdir -p $MAN_DST
sudo cp $SOURCE_PATH/$MAN_TOOL $MAN_DST
sudo cp $SOURCE_PATH/$MAN_DAEMON $MAN_DST

Expand Down
2 changes: 1 addition & 1 deletion Scripts/uninstall.sh
Expand Up @@ -22,7 +22,7 @@ OSX_MINOR_VER=$(sw_vers -productVersion | awk -F '.' '{print $2}')
# Minor version of OS X Mavericks
OSX_MAVERICKS_MINOR_VER="9"

if [ "$OSX_MINOR_VER" -ge "$OSX_MAVERICKS_MINOR_VER" ]; then
if [ "$OSX_MINOR_VER" -gt "$OSX_MAVERICKS_MINOR_VER" ]; then
KEXT_DST=/Library/Extensions
else
KEXT_DST=/System/Library/Extensions
Expand Down
3 changes: 3 additions & 0 deletions Source/Kernel/iSCSITypesKernel.h
Expand Up @@ -105,6 +105,9 @@ typedef struct iSCSIConnection {
/*! Keeps track of the index in the above array should be populated next. */
UInt8 bytesPerSecHistoryIdx;

/*! Keeps track of the connection latency (ms). */
UInt32 latency_ms;

//////////////////// Configured Connection Parameters /////////////////////

/*! Flag that indicates if this connection uses header digests. */
Expand Down
4 changes: 2 additions & 2 deletions Source/Kernel/iSCSIVirtualHBA.cpp
Expand Up @@ -862,10 +862,10 @@ void iSCSIVirtualHBA::ProcessNOPIn(iSCSISession * session,
// Grab current system uptime
clock_get_system_microtime(&secs,&usecs);

UInt32 latency_ms = (secs - secs_stamp)*1e3 + (usecs - usecs_stamp)/1e3;
connection->latency_ms = (secs - secs_stamp)*1e3 + (usecs - usecs_stamp)/1e3;

DBLog("iscsi: Connection latency: %d ms (sid: %d, cid: %d)\n",
latency_ms,session->sessionId,connection->cid);
connection->latency_ms,session->sessionId,connection->cid);

// Remove latency measurement task from queue
connection->taskQueue->completeCurrentTask();
Expand Down
2 changes: 2 additions & 0 deletions Source/User/iSCSI Framework/iSCSIDA.c
Expand Up @@ -97,6 +97,7 @@ void iSCSIDAUnmountApplierFunc(io_object_t entry, void * context)

DADiskRef disk = DADiskCreateFromIOMedia(kCFAllocatorDefault,opContext->session,entry);
DADiskUnmount(disk,opContext->options,iSCSIDADiskUnmountComplete,context);
CFRelease(disk);
}


Expand Down Expand Up @@ -137,6 +138,7 @@ void iSCSIDAMountApplierFunc(io_object_t entry, void * context)

DADiskRef disk = DADiskCreateFromIOMedia(kCFAllocatorDefault,opContext->session,entry);
DADiskMount(disk,NULL,opContext->options,iSCSIDADiskMountComplete,context);
CFRelease(disk);
}

/*! Mounts all IOMedia associated with a particular iSCSI session, and
Expand Down
130 changes: 114 additions & 16 deletions Source/User/iSCSI Framework/iSCSIDaemonInterface.c
Expand Up @@ -35,7 +35,7 @@ static const int kiSCSIDaemonConnectTimeoutMilliSec = 100;
/*! Timeout to use for normal communication with daemon. This is the time
* that the client will have to wait for the deamon to perform the desired
* operation (potentially over the network). */
static const int kiSCSIDaemonDefaultTimeoutSec = 30;
static const int kiSCSIDaemonDefaultTimeoutSec = 10;


const iSCSIDMsgLoginCmd iSCSIDMsgLoginCmdInit = {
Expand Down Expand Up @@ -95,6 +95,14 @@ const iSCSIDMsgPreferencesIOUnlockAndSyncCmd iSCSIDMsgPreferencesIOUnlockAndSync
.funcCode = kiSCSIDPreferencesIOUnlockAndSync
};

const iSCSIDMsgSetSharedSecretCmd iSCSIDMsgSetSharedSecretCmdInit = {
.funcCode = kiSCSIDSetSharedSecret
};

const iSCSIDMsgRemoveSharedSecretCmd iSCSIDMsgRemoveSharedSecretCmdInit = {
.funcCode = kiSCSIDRemoveSharedSecret
};

iSCSIDaemonHandle iSCSIDaemonConnect()
{
iSCSIDaemonHandle handle = socket(PF_LOCAL,SOCK_STREAM,0);
Expand Down Expand Up @@ -654,27 +662,17 @@ errno_t iSCSIDaemonPreferencesIOLockAndSync(iSCSIDaemonHandle handle,
* parameter is NULL, then no changes are made to disk and the semaphore is
* unlocked.
* @param handle a handle to a daemon connection.
* @param authorization an authorization for the right kiSCSIAuthModifyRights
* @param preferences the preferences to be synchronized
* @return an error code indicating whether the operating was successful. */
errno_t iSCSIDaemonPreferencesIOUnlockAndSync(iSCSIDaemonHandle handle,
AuthorizationRef authorization,
iSCSIPreferencesRef preferences)
{
// Validate inputs
if(handle < 0 || !authorization)
if(handle < 0)
return EINVAL;

CFDataRef preferencesData = NULL;

AuthorizationExternalForm authExtForm;
AuthorizationMakeExternalForm(authorization,&authExtForm);

CFDataRef authData = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
(UInt8*)&authExtForm.bytes,
kAuthorizationExternalFormLength,
kCFAllocatorDefault);

iSCSIDMsgPreferencesIOUnlockAndSyncCmd cmd = iSCSIDMsgPreferencesIOUnlockAndSyncCmdInit;

if(preferences) {
Expand All @@ -684,10 +682,7 @@ errno_t iSCSIDaemonPreferencesIOUnlockAndSync(iSCSIDaemonHandle handle,
else
cmd.preferencesLength = 0;

cmd.authorizationLength = cmd.authorizationLength = (UInt32)CFDataGetLength(authData);

errno_t error = iSCSIDaemonSendMsg(handle,(iSCSIDMsgGeneric *)&cmd,
authData,preferencesData,NULL);
errno_t error = iSCSIDaemonSendMsg(handle,(iSCSIDMsgGeneric *)&cmd,preferencesData,NULL);

if(preferencesData)
CFRelease(preferencesData);
Expand All @@ -706,3 +701,106 @@ errno_t iSCSIDaemonPreferencesIOUnlockAndSync(iSCSIDaemonHandle handle,
return rsp.errorCode;
}

/*! Sets or updates a shared secret.
* @param handle a handle to a daemon connection.
* @param authorization an authorization for the right kiSCSIAuthModifyRights.
* @param nodeIQN the node iSCSI qualified name.
* @param sharedSecret the secret to set.
* @return an error code indicating whether the operating was successful. */
errno_t iSCSIDaemonSetSharedSecret(iSCSIDaemonHandle handle,
AuthorizationRef authorization,
CFStringRef nodeIQN,
CFStringRef sharedSecret)
{
// Validate inputs
if(handle < 0 || !authorization || !nodeIQN || !sharedSecret)
return EINVAL;

AuthorizationExternalForm authExtForm;
AuthorizationMakeExternalForm(authorization,&authExtForm);

CFDataRef authData = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
(UInt8*)&authExtForm.bytes,
kAuthorizationExternalFormLength,
kCFAllocatorDefault);

CFDataRef nodeIQNData = CFStringCreateExternalRepresentation(kCFAllocatorDefault,nodeIQN,kCFStringEncodingASCII,NULL);
CFDataRef sharedSecretData = CFStringCreateExternalRepresentation(kCFAllocatorDefault,sharedSecret,kCFStringEncodingASCII,NULL);

iSCSIDMsgSetSharedSecretCmd cmd = iSCSIDMsgSetSharedSecretCmdInit;
cmd.authorizationLength = (UInt32)CFDataGetLength(authData);
cmd.nodeIQNLength = CFDataGetLength(nodeIQNData);
cmd.secretLength = CFDataGetLength(sharedSecretData);

errno_t error = iSCSIDaemonSendMsg(handle,(iSCSIDMsgGeneric *)&cmd,
authData,nodeIQNData,sharedSecretData,NULL);

if(nodeIQNData)
CFRelease(nodeIQNData);

if(sharedSecretData)
CFRelease(sharedSecretData);

if(error)
return error;

iSCSIDMsgSetSharedSecretRsp rsp;

if(recv(handle,&rsp,sizeof(rsp),0) != sizeof(rsp))
return EIO;

if(rsp.funcCode != kiSCSIDSetSharedSecret)
return EIO;

return rsp.errorCode;
}

/*! Sets or updates a shared secret.
* @param handle a handle to a daemon connection.
* @param authorization an authorization for the right kiSCSIAuthModifyRights.
* @param nodeIQN the node iSCSI qualified name.
* @return an error code indicating whether the operating was successful. */
errno_t iSCSIDaemonRemoveSharedSecret(iSCSIDaemonHandle handle,
AuthorizationRef authorization,
CFStringRef nodeIQN)
{
// Validate inputs
if(handle < 0 || !authorization || !nodeIQN)
return EINVAL;

AuthorizationExternalForm authExtForm;
AuthorizationMakeExternalForm(authorization,&authExtForm);

CFDataRef authData = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
(UInt8*)&authExtForm.bytes,
kAuthorizationExternalFormLength,
kCFAllocatorDefault);

CFDataRef nodeIQNData = CFStringCreateExternalRepresentation(kCFAllocatorDefault,nodeIQN,kCFStringEncodingASCII,'0');

iSCSIDMsgRemoveSharedSecretCmd cmd = iSCSIDMsgRemoveSharedSecretCmdInit;
cmd.authorizationLength = (UInt32)CFDataGetLength(authData);
cmd.nodeIQNLength = CFDataGetLength(nodeIQNData);

errno_t error = iSCSIDaemonSendMsg(handle,(iSCSIDMsgGeneric *)&cmd,
authData,nodeIQNData,NULL);

if(nodeIQNData)
CFRelease(nodeIQNData);

if(error)
return error;

iSCSIDMsgRemoveSharedSecretRsp rsp;

if(recv(handle,&rsp,sizeof(rsp),0) != sizeof(rsp))
return EIO;

if(rsp.funcCode != kiSCSIDRemoveSharedSecret)
return EIO;


return rsp.errorCode;
}


23 changes: 20 additions & 3 deletions Source/User/iSCSI Framework/iSCSIDaemonInterface.h
Expand Up @@ -159,12 +159,29 @@ errno_t iSCSIDaemonPreferencesIOLockAndSync(iSCSIDaemonHandle handle,
* parameter is NULL, then no changes are made to disk and the semaphore is
* unlocked.
* @param handle a handle to a daemon connection.
* @param authorization an authorization for the right kiSCSIAuthModifyRights
* @param preferences the preferences to be synchronized
* @return an error code indicating whether the operating was successful. */
errno_t iSCSIDaemonPreferencesIOUnlockAndSync(iSCSIDaemonHandle handle,
AuthorizationRef authorization,
iSCSIPreferencesRef preferences);
iSCSIPreferencesRef preferences);

/*! Sets or updates a shared secret.
* @param handle a handle to a daemon connection.
* @param authorization an authorization for the right kiSCSIAuthModifyRights.
* @param nodeIQN the node iSCSI qualified name.
* @param sharedSecret the secret to set.
* @return an error code indicating whether the operating was successful. */
errno_t iSCSIDaemonSetSharedSecret(iSCSIDaemonHandle handle,
AuthorizationRef authorization,
CFStringRef nodeIQN,
CFStringRef sharedSecret);

/*! Sets or updates a shared secret.
* @param handle a handle to a daemon connection.
* @param authorization an authorization for the right kiSCSIAuthModifyRights.
* @param nodeIQN the node iSCSI qualified name.
* @return an error code indicating whether the operating was successful. */
errno_t iSCSIDaemonRemoveSharedSecret(iSCSIDaemonHandle handle,
AuthorizationRef authorization,
CFStringRef nodeIQN);

#endif /* defined(__ISCSI_DAEMON_INTERFACE__) */

0 comments on commit e87c77e

Please sign in to comment.