Skip to content

Commit

Permalink
Use scratch space for non-archive uploads (with host assisted from bl…
Browse files Browse the repository at this point in the history
…ock exception)

Basically a follow up to 3219 for upload sources,
which suffer from the same issue of losing sparseness.

Signed-off-by: Alex Kalenyuk <[email protected]>
  • Loading branch information
akalenyu committed May 1, 2024
1 parent 50bcbb5 commit 85903b9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
9 changes: 5 additions & 4 deletions cmd/cdi-cloner/clone-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/x509"
"errors"
"flag"
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (er *execReader) Close() error {
}

func init() {
flag.StringVar(&contentType, "content-type", "", "filesystem-clone|blockdevice-clone")
flag.StringVar(&contentType, "content-type", "", fmt.Sprintf("%s|%s", common.FilesystemCloneContentType, common.BlockdeviceClone))
flag.StringVar(&mountPoint, "mount", "", "pvc mount point")
flag.Uint64Var(&uploadBytes, "upload-bytes", 0, "approx number of bytes in input")
klog.InitFlags(nil)
Expand Down Expand Up @@ -138,7 +139,7 @@ func pipeToSnappy(reader io.ReadCloser) io.ReadCloser {

func validateContentType() {
switch contentType {
case "filesystem-clone", "blockdevice-clone":
case common.FilesystemCloneContentType, common.BlockdeviceClone:
default:
klog.Fatalf("Invalid content-type %q", contentType)
}
Expand Down Expand Up @@ -202,13 +203,13 @@ func newTarReader(preallocation bool) (io.ReadCloser, error) {

func getInputStream(preallocation bool) io.ReadCloser {
switch contentType {
case "filesystem-clone":
case common.FilesystemCloneContentType:
rc, err := newTarReader(preallocation)
if err != nil {
klog.Fatalf("Error creating tar reader for %q: %+v", mountPoint, err)
}
return rc
case "blockdevice-clone":
case common.BlockdeviceClone:
rc, err := os.Open(mountPoint)
if err != nil {
klog.Fatalf("Error opening block device %q: %+v", mountPoint, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/importer/upload-datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func (ud *UploadDataSource) Info() (ProcessingPhase, error) {
if ud.contentType == cdiv1.DataVolumeArchive {
return ProcessingPhaseTransferDataDir, nil
}
if !ud.readers.Convert {
// Uploading a raw file, we can write that directly to the target.
if ud.contentType == common.BlockdeviceClone {
// The only exception to write directly is host assisted clone from block
return ProcessingPhaseTransferDataFile, nil
}
return ProcessingPhaseTransferScratch, nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/importer/upload-datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var _ = Describe("Upload data source", func() {
ud = NewUploadDataSource(file, dvKubevirt)
result, err := ud.Info()
Expect(err).NotTo(HaveOccurred())
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
})

DescribeTable("calling transfer should", func(fileName string, dvContentType cdiv1.DataVolumeContentType, expectedPhase ProcessingPhase, scratchPath string, want []byte, wantErr bool) {
Expand Down Expand Up @@ -136,7 +136,7 @@ var _ = Describe("Upload data source", func() {
ud = NewUploadDataSource(sourceFile, dvKubevirt)
result, err := ud.Info()
Expect(err).NotTo(HaveOccurred())
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
result, err = ud.TransferFile(filepath.Join(tmpDir, "file"))
Expect(err).ToNot(HaveOccurred())
Expect(ProcessingPhaseResize).To(Equal(result))
Expand All @@ -149,7 +149,7 @@ var _ = Describe("Upload data source", func() {
ud = NewUploadDataSource(sourceFile, dvKubevirt)
result, err := ud.Info()
Expect(err).NotTo(HaveOccurred())
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
result, err = ud.TransferFile("/invalidpath/invalidfile")
Expect(err).To(HaveOccurred())
Expect(ProcessingPhaseError).To(Equal(result))
Expand Down Expand Up @@ -211,7 +211,7 @@ var _ = Describe("Async Upload data source", func() {
aud = NewAsyncUploadDataSource(file)
result, err := aud.Info()
Expect(err).NotTo(HaveOccurred())
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
})

DescribeTable("calling transfer should", func(fileName, scratchPath string, want []byte, wantErr bool) {
Expand Down Expand Up @@ -260,7 +260,7 @@ var _ = Describe("Async Upload data source", func() {
aud = NewAsyncUploadDataSource(sourceFile)
result, err := aud.Info()
Expect(err).NotTo(HaveOccurred())
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
result, err = aud.TransferFile(filepath.Join(tmpDir, "file"))
Expect(err).ToNot(HaveOccurred())
Expect(ProcessingPhaseValidatePause).To(Equal(result))
Expand All @@ -274,7 +274,7 @@ var _ = Describe("Async Upload data source", func() {
aud = NewAsyncUploadDataSource(sourceFile)
result, err := aud.Info()
Expect(err).NotTo(HaveOccurred())
Expect(ProcessingPhaseTransferDataFile).To(Equal(result))
Expect(ProcessingPhaseTransferScratch).To(Equal(result))
result, err = aud.TransferFile("/invalidpath/invalidfile")
Expect(err).To(HaveOccurred())
Expect(ProcessingPhaseError).To(Equal(result))
Expand Down
4 changes: 0 additions & 4 deletions tests/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:[email protected]][level:compon
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, archivePVC, pathInPvc, expectedMd5)
Expect(err).ToNot(HaveOccurred())
Expect(same).To(BeTrue())
By("Verifying the image is sparse")
Expect(f.VerifySparse(f.Namespace, archivePVC, pathInPvc, utils.UploadFileSize)).To(BeTrue())
}
} else {
checkFailureNoValidToken(archivePVC)
Expand Down Expand Up @@ -729,8 +727,6 @@ var _ = Describe("[rfe_id:138][crit:high][vendor:[email protected]][level:compon
same, err := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, pathInPvc, expectedMd5)
Expect(err).ToNot(HaveOccurred())
Expect(same).To(BeTrue())
By("Verifying the image is sparse")
Expect(f.VerifySparse(f.Namespace, pvc, pathInPvc, utils.UploadFileSize)).To(BeTrue())
}
} else {
checkFailureNoValidToken(pvcPrime)
Expand Down

0 comments on commit 85903b9

Please sign in to comment.