VMware Cloud Community
Wolfee
Contributor
Contributor

FileStream Error

We’re using a a script that adds RDM disks to a VM by reading in a csv file to match the array serial numbers to the naa IDs presented to the hosts. The script is run using an enterprise job scheduler. The script works fine when run manually (either directly from Powershell or through the job scheduler app but when run automatically, the job will fail with the following error:

The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 code or another FileStream. This may cause data loss.

    + CategoryInfo          : NotSpecified: (:) [out-lineoutput], IOException

    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.OutLineOutputCommand

Most of the time, it will map some of the RDMs before it throws the error.

I was just wondering if anyone has seen this before.

I've contacted MS Support, VMware Support & the Job Scheduler support. No luck there yet.

Lee Holmes discusses this error on his site here which many other sites refer back to.

http://www.leeholmes.com/blog/2008/07/30/workaround-the-os-handles-position-is-not-what-filestream-e...

0 Kudos
6 Replies
LucD
Leadership
Leadership

A wild guess, did you try if the PowerShell v3 RC demonstrates the same behaviour ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Wolfee
Contributor
Contributor

Hi Luc,

No - I haven't tried that since this is production and I can't install a RC on a prod system. (although the thought did cross my mind).

However, while continuing my search, I ran across the following 2 postings:

http://communities.vmware.com/thread/279467 describes very closely what I'm doing and references this posting

http://communities.vmware.com/message/1687131#1687131

I'm looking those over now. - The only difference that I can see is I'm doing this on the same array.

The error is troubling though. I"m using the new-harddisk cmdlet and getting the error.

I'm getting the device IDs dumped in a csv file from the SAN team, then reading in the deviceID list, matching it to the naa ID and mapping the RDMs.

This is the code that does the work:

foreach

($rdmID in $rdmIDs){

Write-Host "Adding Replay volume" $rdmID

$deviceName = (Get-ScsiLun -vmhost $esxhost -LunType disk | where {$_.CanonicalName -match $rdmID.DeviceID}).ConsoleDeviceName

New-HardDisk -VM $vmName -DiskType RawPhysical -DeviceName $deviceName | Out-Null

}

0 Kudos
LucD
Leadership
Leadership

From the error message I would say the problem is in the output stream, not from reading the CSV file.

And I don't think the New-Harddisk cmdlet is involved, it must be coming from output that is created by the script in parallel with output coming from the cmd redirection.

Are any of the 3 conditions Lee mentions, met in the way you are running the script ?

Did you try removing the Write-Host cmdlets from the script and using a Start-Transcript instead ?

Is the workaround Lee mentions working for you ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Wolfee
Contributor
Contributor

Sorry for not posting those details..

Yes - I did try the code that Lee posted but the error still persists.

As for the 3 conditions, none really apply. The script is being called from Cisco Tidal - (Enterprise Job Scheduler).

Here's how that's done.

Command: <path to powershell.exe>

Command Parameters: <path to script>

As for the "write-host" cmdlets - yes - they were added to echo what is happening withing the script to the Tidal console output to help figure out what's going on with this error. (The error was happening before we added write-host)

I noticed when the error occurs, some of the RDMs are mapped, but based on the error output from Tidal, the  $DeviceID variable is coming back empty in the output from the logging.

New-HardDisk : Cannot validate argument on parameter 'DeviceName'. The argument  is null. Supply a non-null argument and try the command again.

At <path to script>:54 char:60

+     New-HardDisk -VM $vmName -DiskType RawPhysical -DeviceName <<<<

+ $deviceName | Out-Null  

    + CategoryInfo          : InvalidData: (:) [New-HardDisk], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.NewHardDisk

Write-Host : The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one FileStream and in Win32 code or another FileS tream. This may cause data loss.

At <path to script>:52 char:12

+     Write-Host <<<<  "Adding Replay volume" $rdmID

    + CategoryInfo          : NotSpecified: (:) [Write-Host], IOException

    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.WriteHostCommand

0 Kudos
Wolfee
Contributor
Contributor

It looks like it may have been a result of the cluster HBA scan which runs in a seperate job directly before this. After the replay volume is presented to the cluster, we ran a job that scanned each hosts HBAs for the newly added storage. The re-scan job was across all hosts in the cluster. I believe this was causing a "disconnect or timeout" of the PowerCLI session which would ultimately cause the FileStream error. Although not confirmed, I suspect this may have been the cause. Thanks for your help.

0 Kudos