@@ -275,14 +275,17 @@ func hostPathIsEmpty(p string) (bool, error) {
275275}
276276
277277// loadFromSnapshot populates the given destPath with data from the snapshotID
278- func loadFromSnapshot (snapshotId , destPath string ) error {
278+ func loadFromSnapshot (size int64 , snapshotId , destPath string ) error {
279279 snapshot , ok := hostPathVolumeSnapshots [snapshotId ]
280280 if ! ok {
281281 return status .Errorf (codes .NotFound , "cannot find snapshot %v" , snapshotId )
282282 }
283283 if snapshot .ReadyToUse != true {
284284 return status .Errorf (codes .Internal , "snapshot %v is not yet ready to use." , snapshotId )
285285 }
286+ if snapshot .SizeBytes > size {
287+ return status .Errorf (codes .InvalidArgument , "snapshot %v size %v is greater than requested volume size %v" , snapshotId , snapshot .SizeBytes , size )
288+ }
286289 snapshotPath := snapshot .Path
287290 args := []string {"zxvf" , snapshotPath , "-C" , destPath }
288291 executor := utilexec .New ()
@@ -294,7 +297,7 @@ func loadFromSnapshot(snapshotId, destPath string) error {
294297}
295298
296299// loadfromVolume populates the given destPath with data from the srcVolumeID
297- func loadFromVolume (srcVolumeId , destPath string ) error {
300+ func loadFromVolume (size int64 , srcVolumeId , destPath string ) error {
298301 hostPathVolume , ok := hostPathVolumes [srcVolumeId ]
299302 if ! ok {
300303 return status .Error (codes .NotFound , "source volumeId does not exist, are source/destination in the same storage class?" )
@@ -305,6 +308,10 @@ func loadFromVolume(srcVolumeId, destPath string) error {
305308 return status .Errorf (codes .Internal , "failed verification check of source hostpath volume: %s: %v" , srcVolumeId , err )
306309 }
307310
311+ if hostPathVolume .VolSize > size {
312+ return status .Errorf (codes .InvalidArgument , "volume %v size %v is greater than requested volume size %v" , srcVolumeId , hostPathVolume .VolSize , size )
313+ }
314+
308315 // If the source hostpath volume is empty it's a noop and we just move along, otherwise the cp call will fail with a a file stat error DNE
309316 if ! isEmpty {
310317 args := []string {"-a" , srcPath + "/." , destPath + "/" }
0 commit comments