| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,14 @@ |
| 0 |
+package docker |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "os" |
|
| 4 |
+ "io" |
|
| 5 |
+) |
|
| 6 |
+ |
|
| 7 |
+func CopyFile(dstFile, srcFile *os.File) error {
|
|
| 8 |
+ // No BTRFS reflink suppport, Fall back to normal copy |
|
| 9 |
+ |
|
| 10 |
+ // FIXME: Check the return of Copy and compare with dstFile.Stat().Size |
|
| 11 |
+ _, err := io.Copy(dstFile, srcFile) |
|
| 12 |
+ return err |
|
| 13 |
+} |
| 0 | 14 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,53 @@ |
| 0 |
+package docker |
|
| 1 |
+ |
|
| 2 |
+// FIXME: This could be easily rewritten in pure Go |
|
| 3 |
+ |
|
| 4 |
+/* |
|
| 5 |
+#include <sys/ioctl.h> |
|
| 6 |
+#include <linux/fs.h> |
|
| 7 |
+#include <errno.h> |
|
| 8 |
+ |
|
| 9 |
+// See linux.git/fs/btrfs/ioctl.h |
|
| 10 |
+#define BTRFS_IOCTL_MAGIC 0x94 |
|
| 11 |
+#define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int) |
|
| 12 |
+ |
|
| 13 |
+int |
|
| 14 |
+btrfs_reflink(int fd_out, int fd_in) |
|
| 15 |
+{
|
|
| 16 |
+ int res; |
|
| 17 |
+ res = ioctl(fd_out, BTRFS_IOC_CLONE, fd_in); |
|
| 18 |
+ if (res < 0) |
|
| 19 |
+ return errno; |
|
| 20 |
+ return 0; |
|
| 21 |
+} |
|
| 22 |
+ |
|
| 23 |
+*/ |
|
| 24 |
+import "C" |
|
| 25 |
+ |
|
| 26 |
+import ( |
|
| 27 |
+ "os" |
|
| 28 |
+ "io" |
|
| 29 |
+ "syscall" |
|
| 30 |
+) |
|
| 31 |
+ |
|
| 32 |
+// FIXME: Move this to btrfs package? |
|
| 33 |
+ |
|
| 34 |
+func BtrfsReflink(fd_out, fd_in uintptr) error {
|
|
| 35 |
+ res := C.btrfs_reflink(C.int(fd_out), C.int(fd_in)) |
|
| 36 |
+ if res != 0 {
|
|
| 37 |
+ return syscall.Errno(res) |
|
| 38 |
+ } |
|
| 39 |
+ return nil |
|
| 40 |
+} |
|
| 41 |
+ |
|
| 42 |
+func CopyFile(dstFile, srcFile *os.File) error {
|
|
| 43 |
+ err := BtrfsReflink(dstFile.Fd(), srcFile.Fd()) |
|
| 44 |
+ if err == nil {
|
|
| 45 |
+ return nil |
|
| 46 |
+ } |
|
| 47 |
+ |
|
| 48 |
+ // Fall back to normal copy |
|
| 49 |
+ // FIXME: Check the return of Copy and compare with dstFile.Stat().Size |
|
| 50 |
+ _, err = io.Copy(dstFile, srcFile) |
|
| 51 |
+ return err |
|
| 52 |
+} |
| ... | ... |
@@ -1,37 +1,13 @@ |
| 1 | 1 |
package docker |
| 2 | 2 |
|
| 3 |
-/* |
|
| 4 |
-#include <sys/ioctl.h> |
|
| 5 |
-#include <linux/fs.h> |
|
| 6 |
-#include <errno.h> |
|
| 7 |
- |
|
| 8 |
-// See linux.git/fs/btrfs/ioctl.h |
|
| 9 |
-#define BTRFS_IOCTL_MAGIC 0x94 |
|
| 10 |
-#define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int) |
|
| 11 |
- |
|
| 12 |
-int |
|
| 13 |
-btrfs_reflink(int fd_out, int fd_in) |
|
| 14 |
-{
|
|
| 15 |
- int res; |
|
| 16 |
- res = ioctl(fd_out, BTRFS_IOC_CLONE, fd_in); |
|
| 17 |
- if (res < 0) |
|
| 18 |
- return errno; |
|
| 19 |
- return 0; |
|
| 20 |
-} |
|
| 21 |
- |
|
| 22 |
-*/ |
|
| 23 |
-import "C" |
|
| 24 | 3 |
import ( |
| 25 | 4 |
"fmt" |
| 26 | 5 |
"github.com/dotcloud/docker/archive" |
| 27 | 6 |
"github.com/dotcloud/docker/namesgenerator" |
| 28 | 7 |
"github.com/dotcloud/docker/utils" |
| 29 |
- "io" |
|
| 30 | 8 |
"io/ioutil" |
| 31 |
- "os" |
|
| 32 | 9 |
"strconv" |
| 33 | 10 |
"strings" |
| 34 |
- "syscall" |
|
| 35 | 11 |
) |
| 36 | 12 |
|
| 37 | 13 |
type Change struct {
|
| ... | ... |
@@ -346,13 +322,6 @@ func migratePortMappings(config *Config, hostConfig *HostConfig) error {
|
| 346 | 346 |
return nil |
| 347 | 347 |
} |
| 348 | 348 |
|
| 349 |
-func BtrfsReflink(fd_out, fd_in uintptr) error {
|
|
| 350 |
- res := C.btrfs_reflink(C.int(fd_out), C.int(fd_in)) |
|
| 351 |
- if res != 0 {
|
|
| 352 |
- return syscall.Errno(res) |
|
| 353 |
- } |
|
| 354 |
- return nil |
|
| 355 |
-} |
|
| 356 | 349 |
|
| 357 | 350 |
// Links come in the format of |
| 358 | 351 |
// name:alias |
| ... | ... |
@@ -386,14 +355,3 @@ func (c *checker) Exists(name string) bool {
|
| 386 | 386 |
func generateRandomName(runtime *Runtime) (string, error) {
|
| 387 | 387 |
return namesgenerator.GenerateRandomName(&checker{runtime})
|
| 388 | 388 |
} |
| 389 |
- |
|
| 390 |
-func CopyFile(dstFile, srcFile *os.File) error {
|
|
| 391 |
- err := BtrfsReflink(dstFile.Fd(), srcFile.Fd()) |
|
| 392 |
- if err == nil {
|
|
| 393 |
- return nil |
|
| 394 |
- } |
|
| 395 |
- |
|
| 396 |
- // Fall back to normal copy |
|
| 397 |
- _, err = io.Copy(dstFile, srcFile) |
|
| 398 |
- return err |
|
| 399 |
-} |