]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: introduce btrfsCloneFile() for COW copy
authorChen Hanxiao <chenhanxiao@cn.fujitsu.com>
Fri, 23 Jan 2015 10:22:34 +0000 (18:22 +0800)
committerJán Tomko <jtomko@redhat.com>
Tue, 27 Jan 2015 12:24:10 +0000 (13:24 +0100)
Add a wrapper for BTRFS_IOC_CLONE ioctl.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
configure.ac
src/storage/storage_backend.c

index ddbdba56c9b48144174f9e9e4c7549a9bfcf3361..2c406520b7593edd3767e66088cd79ade5846a39 100644 (file)
@@ -2175,6 +2175,13 @@ fi
 AM_CONDITIONAL([WITH_HYPERV], [test "$with_hyperv" = "yes"])
 
 
+dnl
+dnl check for kernel headers required by btrfs ioctl
+dnl
+if test "$with_linux" = "yes"; then
+    AC_CHECK_HEADERS([linux/btrfs.h])
+fi
+
 dnl Allow perl/python overrides
 AC_PATH_PROGS([PYTHON], [python2 python])
 AC_PATH_PROG([PERL], [perl])
index b990a82957dbf32e87afe00d0cb5117d0b3084e6..841508e381e6b1e3cde82364212683bc29e134bc 100644 (file)
 # include <selinux/selinux.h>
 #endif
 
+#if HAVE_LINUX_BTRFS_H
+# include <linux/btrfs.h>
+#endif
+
 #include "datatypes.h"
 #include "virerror.h"
 #include "viralloc.h"
@@ -156,6 +160,26 @@ enum {
 #define READ_BLOCK_SIZE_DEFAULT  (1024 * 1024)
 #define WRITE_BLOCK_SIZE_DEFAULT (4 * 1024)
 
+/*
+ * Perform the O(1) btrfs clone operation, if possible.
+ * Upon success, return 0.  Otherwise, return -1 and set errno.
+ */
+#if HAVE_LINUX_BTRFS_H
+static inline int
+btrfsCloneFile(int dest_fd, int src_fd)
+{
+    return ioctl(dest_fd, BTRFS_IOC_CLONE, src_fd);
+}
+#else
+static inline int
+btrfsCloneFile(int dest_fd ATTRIBUTE_UNUSED,
+               int src_fd ATTRIBUTE_UNUSED)
+{
+    errno = ENOTSUP;
+    return -1;
+}
+#endif
+
 static int ATTRIBUTE_NONNULL(2)
 virStorageBackendCopyToFD(virStorageVolDefPtr vol,
                           virStorageVolDefPtr inputvol,