@@ -275,14 +275,17 @@ func hostPathIsEmpty(p string) (bool, error) {
275
275
}
276
276
277
277
// 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 {
279
279
snapshot , ok := hostPathVolumeSnapshots [snapshotId ]
280
280
if ! ok {
281
281
return status .Errorf (codes .NotFound , "cannot find snapshot %v" , snapshotId )
282
282
}
283
283
if snapshot .ReadyToUse != true {
284
284
return status .Errorf (codes .Internal , "snapshot %v is not yet ready to use." , snapshotId )
285
285
}
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
+ }
286
289
snapshotPath := snapshot .Path
287
290
args := []string {"zxvf" , snapshotPath , "-C" , destPath }
288
291
executor := utilexec .New ()
@@ -294,7 +297,7 @@ func loadFromSnapshot(snapshotId, destPath string) error {
294
297
}
295
298
296
299
// 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 {
298
301
hostPathVolume , ok := hostPathVolumes [srcVolumeId ]
299
302
if ! ok {
300
303
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 {
305
308
return status .Errorf (codes .Internal , "failed verification check of source hostpath volume: %s: %v" , srcVolumeId , err )
306
309
}
307
310
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
+
308
315
// 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
309
316
if ! isEmpty {
310
317
args := []string {"-a" , srcPath + "/." , destPath + "/" }
0 commit comments