I ran into a problem recently where I needed to get the size of a volume from a NetApp filer so I could create a new volume (of the same size) and initialise a snapmirror relationship to it. The problem was that sometimes the snapmirror relationship would fail to start, reporting that the destination volume was too small. The fault was in how I was calculating the size of the source volume. I’m going to look at what I did wrong, and the right way to do it.

Using the Data ONTAP Powershell module, the below code shows the result of getting the properties that start with an “S” for the volume “random_volume”.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
PS C:\> Get-NaVol "random_volume" | fl S* Sis : SizeAvailable : 148084289536 SizeTotal : 154618822656 SizeUsed : 6534447104 SnapAutodelete : DataONTAP.Types.Volume.SnapAutodelete SnaplockType : SnaplockVolumeComplianceClock : SnapshotBlocksReserved : 37748736 SnapshotPercentReserved : 20 SpaceReserve : volume SpaceReserveEnabled : True State : online SnaplockVolumeComplianceClockSpecified : False SpaceReserveEnabledSpecified : True |

I was using the “SizeTotal” property in the output above to calculate the size of volume. When the number above is divided by 1GB it will translate to 144 GB, but this is incorrect, as System Manager reports the volume as 180 GB. So why is this number incorrect ?

The answer is also in the above output, as the “SnapshotBlocksReserved” and “SnapshotPercentReserved” values are not 0. As expected, this means a portion of the volume has been reserved for snapshots – in the above case, 20%. The catch is that “SnapshotBlocksReserved” is not in bytes, but in kilobytes. So to get the total size of the volume in bytes we must do the following:

1 2 |
$volume = Get-NaVol "random_volume"; $size = $volume.TotalSize + ($volume.SnapshotBlocksReserved * 1024) |

If we then use the powershell magic of:

1 |
$size / 1GB |

We get the correct result of 180 GB.

I wouldn’t recommend using the SnapshotPercentReserved property to calculate the correct total size – it is a better practice to use the exact number of blocks reserved for snapshots.