mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-04 15:16:58 +00:00
Block dev for restore (#10013)
Run the E2E test on kind / get-go-version (push) Failing after 1m3s
Run the E2E test on kind / build (push) Has been skipped
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / get-go-version (push) Successful in 13s
Main CI / Build (push) Failing after 22s
Run the E2E test on kind / get-go-version (push) Failing after 1m3s
Run the E2E test on kind / build (push) Has been skipped
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / get-go-version (push) Successful in 13s
Main CI / Build (push) Failing after 22s
* add block dev operations for block uploader restore Signed-off-by: Lyndon-Li <lyonghui@vmware.com> * add block dev operations for block uploader restore Signed-off-by: Lyndon-Li <lyonghui@vmware.com> --------- Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Add block dev restore operations for block data mover
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
)
|
||||
@@ -76,3 +77,29 @@ func resolveSymlink(path string) (string, error) {
|
||||
|
||||
return filepath.EvalSymlinks(path)
|
||||
}
|
||||
|
||||
func blkZeroOut(dest *os.File, start int64, length int64) error {
|
||||
const BLKZEROOUT = 0x127b
|
||||
|
||||
zeroRange := [2]uint64{uint64(start), uint64(length)}
|
||||
|
||||
rawConn, err := dest.SyscallConn()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting raw connection")
|
||||
}
|
||||
|
||||
ioctlErr := syscall.Errno(0)
|
||||
if err := rawConn.Control(func(fd uintptr) {
|
||||
if _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, fd, BLKZEROOUT, uintptr(unsafe.Pointer(&zeroRange[0]))); errno != 0 {
|
||||
ioctlErr = errno
|
||||
}
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "error controlling block dev")
|
||||
}
|
||||
|
||||
if ioctlErr != 0 {
|
||||
return errors.Wrapf(ioctlErr, "error calling ioctl on block dev")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -356,3 +357,30 @@ func TestOpenBlockDevice(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlkZeroOut(t *testing.T) {
|
||||
t.Run("closed file returns error", func(t *testing.T) {
|
||||
f, err := os.CreateTemp(t.TempDir(), "blkzeroout-test-*")
|
||||
require.NoError(t, err)
|
||||
err = f.Close()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = blkZeroOut(f, 0, 1024)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("regular file returns ioctl error", func(t *testing.T) {
|
||||
f, err := os.CreateTemp(t.TempDir(), "blkzeroout-test-*")
|
||||
require.NoError(t, err)
|
||||
defer f.Close()
|
||||
|
||||
err = blkZeroOut(f, 0, 1024)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "error calling ioctl on block dev")
|
||||
|
||||
// On regular files, ioctl with BLKZEROOUT should fail with ENOTTY (inappropriate ioctl for device) or EINVAL
|
||||
isENOTTY := errors.Is(err, syscall.ENOTTY)
|
||||
isEINVAL := errors.Is(err, syscall.EINVAL)
|
||||
assert.True(t, isENOTTY || isEINVAL, "expected error to be ENOTTY or EINVAL, got: %v", err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -27,3 +27,7 @@ import (
|
||||
func openBlockDevice(_ string, _ bool) (*os.File, error) {
|
||||
return nil, fmt.Errorf("block mode is not supported for non-linux platforms")
|
||||
}
|
||||
|
||||
func blkZeroOut(_ *os.File, _ int64, _ int64) error {
|
||||
return fmt.Errorf("block mode is not supported for non-linux platforms")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user