From 4ef8f6d323421b50891d8e63503bf3ee41dfe6cb Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sun, 2 Jun 2019 12:19:22 -0700 Subject: [PATCH] copy: allow non-cgo build Signed-off-by: Tonis Tiigi (cherry picked from commit 230a55d337f67a2850fd3206500c5c2a89f9e2e7) Signed-off-by: Kir Kolyshkin --- daemon/graphdriver/copy/copy.go | 10 +--------- daemon/graphdriver/copy/copy_cgo.go | 22 ++++++++++++++++++++++ daemon/graphdriver/copy/copy_nocgo.go | 13 +++++++++++++ 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 daemon/graphdriver/copy/copy_cgo.go create mode 100644 daemon/graphdriver/copy/copy_nocgo.go diff --git a/daemon/graphdriver/copy/copy.go b/daemon/graphdriver/copy/copy.go index 70ae9ce230..f8125403c4 100644 --- a/daemon/graphdriver/copy/copy.go +++ b/daemon/graphdriver/copy/copy.go @@ -2,14 +2,6 @@ package copy // import "github.com/docker/docker/daemon/graphdriver/copy" -/* -#include - -#ifndef FICLONE -#define FICLONE _IOW(0x94, 9, int) -#endif -*/ -import "C" import ( "container/list" "fmt" @@ -50,7 +42,7 @@ func copyRegular(srcPath, dstPath string, fileinfo os.FileInfo, copyWithFileRang defer dstFile.Close() if *copyWithFileClone { - _, _, err = unix.Syscall(unix.SYS_IOCTL, dstFile.Fd(), C.FICLONE, srcFile.Fd()) + err = fiClone(srcFile, dstFile) if err == nil { return nil } diff --git a/daemon/graphdriver/copy/copy_cgo.go b/daemon/graphdriver/copy/copy_cgo.go new file mode 100644 index 0000000000..6bd34864fb --- /dev/null +++ b/daemon/graphdriver/copy/copy_cgo.go @@ -0,0 +1,22 @@ +// +build linux,cgo + +package copy // import "github.com/docker/docker/daemon/graphdriver/copy" + +/* +#include + +#ifndef FICLONE +#define FICLONE _IOW(0x94, 9, int) +#endif +*/ +import "C" +import ( + "os" + + "golang.org/x/sys/unix" +) + +func fiClone(srcFile, dstFile *os.File) error { + _, _, err := unix.Syscall(unix.SYS_IOCTL, dstFile.Fd(), C.FICLONE, srcFile.Fd()) + return err +} diff --git a/daemon/graphdriver/copy/copy_nocgo.go b/daemon/graphdriver/copy/copy_nocgo.go new file mode 100644 index 0000000000..89e3c7f51e --- /dev/null +++ b/daemon/graphdriver/copy/copy_nocgo.go @@ -0,0 +1,13 @@ +// +build linux,!cgo + +package copy // import "github.com/docker/docker/daemon/graphdriver/copy" + +import ( + "os" + + "golang.org/x/sys/unix" +) + +func fiClone(srcFile, dstFile *os.File) error { + return unix.ENOSYS +}