Skip to content

Commit

Permalink
Extract regular files as well during clone from filesystem
Browse files Browse the repository at this point in the history
Sometimes the tar entry will not be sparse:
- Preallocated target
- CephFS way of reporting sparse files - https://docs.ceph.com/en/latest/cephfs/posix/

In those cases we still want to grab the disk image.

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
  • Loading branch information
akalenyu committed Jan 4, 2024
1 parent 10bb5e6 commit 30b9a80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pkg/uploadserver/uploadserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,11 @@ func untarToBlockdev(stream io.Reader, dest string) error {
case header == nil:
continue
}
if header.Typeflag == tar.TypeGNUSparse && strings.Contains(header.Name, common.DiskImageName) {
if !strings.Contains(header.Name, common.DiskImageName) {
continue
}
switch header.Typeflag {
case tar.TypeReg, tar.TypeGNUSparse:
klog.Infof("Untaring %d bytes to %s", header.Size, dest)
f, err := os.OpenFile(dest, os.O_APPEND|os.O_WRONLY, os.ModeDevice|os.ModePerm)
if err != nil {
Expand Down
12 changes: 9 additions & 3 deletions tests/cloner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ var _ = Describe("all clone tests", func() {
completeClone(f, f.Namespace, targetPvc, filepath.Join(testBaseDir, testFile), fillDataFSMD5sum, "")
})

It("[test_id:cnv-5569]Should clone data from filesystem to block", func() {
DescribeTable("Should clone data from filesystem to block", func(preallocate bool) {
if !f.IsBlockVolumeStorageClassAvailable() {
Skip("Storage Class for block volume is not available")
}
Expand All @@ -445,6 +445,9 @@ var _ = Describe("all clone tests", func() {
Expect(err).ToNot(HaveOccurred())

targetDV := utils.NewDataVolumeCloneToBlockPV("target-dv", "1Gi", sourcePvc.Namespace, sourcePvc.Name, f.BlockSCName)
if preallocate {
targetDV.Spec.Preallocation = pointer.Bool(true)
}
targetDataVolume, err := utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, targetDV)
Expect(err).ToNot(HaveOccurred())
targetPvc, err := utils.WaitForPVC(f.K8sClient, targetDataVolume.Namespace, targetDataVolume.Name)
Expand Down Expand Up @@ -474,9 +477,12 @@ var _ = Describe("all clone tests", func() {
By("Deleting verifier pod")
err = utils.DeleteVerifierPod(f.K8sClient, f.Namespace.Name)
Expect(err).ToNot(HaveOccurred())
})
},
Entry("[test_id:5569]regular target", false),
Entry("[test_id:XXXX]preallocated target", true),
)

It("[test_id:cnv-5570]Should clone data from block to filesystem", func() {
It("[test_id:5570]Should clone data from block to filesystem", func() {
if !f.IsBlockVolumeStorageClassAvailable() {
Skip("Storage Class for block volume is not available")
}
Expand Down

0 comments on commit 30b9a80

Please sign in to comment.