Microsoft Virtualization Discussions

Close-NcCifsSession won't work due to session id being greater than signed 64bit int can hold

cprivitere
4,002 Views

We're trying to use the Powershell Toolkit to manage file locks. Part of this process includes getting and passing through CIFS Session IDs to tell it exactly what locks to close from which user.

 

What we've noticed however, is that the variable type being used to hold the Session ID is not large enough to hold the actual value that OnTap uses. 

 

For example, a user right now has a file open. His Session ID is "15799753392746039225". That is larger than a signed 64 bit int can hold.

 

When you try to pass it into the Close-NcCifsSession (yes I know to really close it you would want to pass more, but this is just to illustrate the problem) you get an error like this:

 

PS C:\Users\cprivite> Close-NcCifsSession -SessionId $test[1].SessionId
Close-NcCifsSession : Cannot bind parameter 'SessionId'. Cannot convert value "15799753392746137485" to type "System.Int64". Error: "Value was either too large or too small for an Int64."
At line:1 char:32
+ Close-NcCifsSession -SessionId $test[1].SessionId
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Close-NcCifsSession], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,DataONTAP.C.PowerShell.SDK.Cmdlets.Cifs.CloseNcCifsSession

 

 

 

Can we get the Toolkit to be updated to use unsigned ints for values like this? Either ulong or System.uInt64 should both work.

3 REPLIES 3

JGPSHNTAP
3,840 Views

What version of Ontap are you using.

 

My session ID is 4727372233855467525

 

I'm using ontap 9.0P1 and i'm not seeing an issue

 

Your session ID is one character bigger though

 

PS C:\powershell> $d = "15799753392746137485"
PS C:\powershell> $d.length
20
PS C:\powershell> $v = "4727372233855467525"
PS C:\powershell> $v.length
19

cprivitere
3,730 Views

We're using 9.0P1 as well.

 

I just pulled a fresh session id off the filer, and it's "15441154272399424878" which is still 20 characters long.

 

 

MikeC_12
2,811 Views

 

I struggled with this one for a while, but did eventually find a solution (or more correctly, a work-around).

 

Use the Invoke-NcSsh  function (requires PS Toolkit 4.5.1,  and you'll need to enable SSH access as well as ONTAPI for the account you use)

 

Here's a function I use to close CIFS sessions from a specified client IP:

 

Function Close-NtapSessions () {
  Param(
    [Parameter(Mandatory=$True,Position=0,HelpMessage="IP address of client")]
    [string]$ClientIP = ''
  )

Write-Output "`Retrieving CIFS sessions for $ClientIP"
$ClientIP = $ClientIP -replace '\s',''
$sessions = Get-NcCifsSession -Query @{Address=$ClientIP} | select "Address","ConnectionId","SessionId", "Node", "Vserver", "ConnectedTime"
$sessions | Format-List | Write-Output
if ($sessions) {
  $cluster = (Get-NcCluster).ClusterName
  foreach ($session in $sessions ) {
    $Vserver = $session.Vserver
    $SessionId = $session.SessionId
    $ConnectionId = $session.ConnectionId
    $node = $session.Node
    Write-Output "Running: cifs session close -node $node -session-id $SessionId -connection-id $ConnectionId -vserver $Vserver"
    Invoke-NcSsh -Command "cifs session close -node $node -session-id $SessionId -connection-id $ConnectionId -vserver $Vserver"

  }
}
else {
  Write-Output " No connected sessions found."
}
Write-Output "`nAfter close - Retrieving CIFS sessions for $($ClientIP):"
$sessions = Get-NcCifsSession -Query @{Address=$ClientIP} | select "Address","ConnectionId","SessionId", "Node", "Vserver", "ConnectedTime"
if ($sessions) { $sessions | Format-List }
else {Write-Output " No connected sessions found.`n" }

return ($_)
}

 

 

 

   - MIke C

 

Public