Blame SOURCES/0126-sparsify-Move-statvfs-wrapper-function-to-mllib.patch

e76f14
From c2f3c3eadc4f130a411c6fc259e65d30291bfd0c Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Thu, 23 Jun 2016 13:10:35 +0100
e76f14
Subject: [PATCH] sparsify: Move statvfs wrapper function to mllib.
e76f14
e76f14
We wish to use this function in virt-v2v too, so move it to the common
e76f14
directory.
e76f14
e76f14
No functional change.
e76f14
e76f14
(cherry picked from commit 24130d787256dc3d9e37e85b1ba35ac7dbeb86a1)
e76f14
---
e76f14
 mllib/Makefile.am    |  3 +++
e76f14
 mllib/StatVFS.ml     | 21 +++++++++++++++++++++
e76f14
 mllib/StatVFS.mli    | 23 +++++++++++++++++++++++
e76f14
 mllib/statvfs-c.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
e76f14
 po/POTFILES          |  2 +-
e76f14
 po/POTFILES-ml       |  1 +
e76f14
 sparsify/Makefile.am |  3 ++-
e76f14
 sparsify/copying.ml  |  5 +----
e76f14
 sparsify/statvfs-c.c | 50 --------------------------------------------------
e76f14
 9 files changed, 102 insertions(+), 56 deletions(-)
e76f14
 create mode 100644 mllib/StatVFS.ml
e76f14
 create mode 100644 mllib/StatVFS.mli
e76f14
 create mode 100644 mllib/statvfs-c.c
e76f14
 delete mode 100644 sparsify/statvfs-c.c
e76f14
e76f14
diff --git a/mllib/Makefile.am b/mllib/Makefile.am
e76f14
index e0f1987..0a6dd93 100644
e76f14
--- a/mllib/Makefile.am
e76f14
+++ b/mllib/Makefile.am
e76f14
@@ -36,6 +36,7 @@ SOURCES_MLI = \
e76f14
 	planner.mli \
e76f14
 	progress.mli \
e76f14
 	regedit.mli \
e76f14
+	StatVFS.mli \
e76f14
 	URI.mli
e76f14
 
e76f14
 SOURCES_ML = \
e76f14
@@ -50,6 +51,7 @@ SOURCES_ML = \
e76f14
 	mkdtemp.ml \
e76f14
 	planner.ml \
e76f14
 	regedit.ml \
e76f14
+	StatVFS.ml \
e76f14
 	JSON.ml \
e76f14
 	curl.ml
e76f14
 
e76f14
@@ -60,6 +62,7 @@ SOURCES_C = \
e76f14
 	fsync-c.c \
e76f14
 	mkdtemp-c.c \
e76f14
 	progress-c.c \
e76f14
+	statvfs-c.c \
e76f14
 	uri-c.c
e76f14
 
e76f14
 if HAVE_OCAML
e76f14
diff --git a/mllib/StatVFS.ml b/mllib/StatVFS.ml
e76f14
new file mode 100644
e76f14
index 0000000..98e6d22
e76f14
--- /dev/null
e76f14
+++ b/mllib/StatVFS.ml
e76f14
@@ -0,0 +1,21 @@
e76f14
+(* virt tools interface to statvfs
e76f14
+ * Copyright (C) 2016 Red Hat Inc.
e76f14
+ *
e76f14
+ * This program is free software; you can redistribute it and/or modify
e76f14
+ * it under the terms of the GNU General Public License as published by
e76f14
+ * the Free Software Foundation; either version 2 of the License, or
e76f14
+ * (at your option) any later version.
e76f14
+ *
e76f14
+ * This program is distributed in the hope that it will be useful,
e76f14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
e76f14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e76f14
+ * GNU General Public License for more details.
e76f14
+ *
e76f14
+ * You should have received a copy of the GNU General Public License along
e76f14
+ * with this program; if not, write to the Free Software Foundation, Inc.,
e76f14
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
e76f14
+ *)
e76f14
+
e76f14
+(** Binding for [statvfs], but just for getting disk free space. *)
e76f14
+
e76f14
+external free_space : string -> int64 = "guestfs_int_mllib_statvfs_free_space"
e76f14
diff --git a/mllib/StatVFS.mli b/mllib/StatVFS.mli
e76f14
new file mode 100644
e76f14
index 0000000..b1b8834
e76f14
--- /dev/null
e76f14
+++ b/mllib/StatVFS.mli
e76f14
@@ -0,0 +1,23 @@
e76f14
+(* virt tools interface to statvfs
e76f14
+ * Copyright (C) 2016 Red Hat Inc.
e76f14
+ *
e76f14
+ * This program is free software; you can redistribute it and/or modify
e76f14
+ * it under the terms of the GNU General Public License as published by
e76f14
+ * the Free Software Foundation; either version 2 of the License, or
e76f14
+ * (at your option) any later version.
e76f14
+ *
e76f14
+ * This program is distributed in the hope that it will be useful,
e76f14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
e76f14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e76f14
+ * GNU General Public License for more details.
e76f14
+ *
e76f14
+ * You should have received a copy of the GNU General Public License along
e76f14
+ * with this program; if not, write to the Free Software Foundation, Inc.,
e76f14
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
e76f14
+ *)
e76f14
+
e76f14
+(** Binding for [statvfs], but just for getting disk free space. *)
e76f14
+
e76f14
+val free_space : string -> int64
e76f14
+(** [free_space path] returns the free space available on the
e76f14
+    filesystem that contains [path], in bytes. *)
e76f14
diff --git a/mllib/statvfs-c.c b/mllib/statvfs-c.c
e76f14
new file mode 100644
e76f14
index 0000000..5c10531
e76f14
--- /dev/null
e76f14
+++ b/mllib/statvfs-c.c
e76f14
@@ -0,0 +1,50 @@
e76f14
+/* virt tools interface to statvfs
e76f14
+ * Copyright (C) 2013-2016 Red Hat Inc.
e76f14
+ *
e76f14
+ * This program is free software; you can redistribute it and/or modify
e76f14
+ * it under the terms of the GNU General Public License as published by
e76f14
+ * the Free Software Foundation; either version 2 of the License, or
e76f14
+ * (at your option) any later version.
e76f14
+ *
e76f14
+ * This program is distributed in the hope that it will be useful,
e76f14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
e76f14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e76f14
+ * GNU General Public License for more details.
e76f14
+ *
e76f14
+ * You should have received a copy of the GNU General Public License
e76f14
+ * along with this program; if not, write to the Free Software
e76f14
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
e76f14
+ */
e76f14
+
e76f14
+#include <config.h>
e76f14
+
e76f14
+#include <stdio.h>
e76f14
+#include <stdlib.h>
e76f14
+#include <sys/statvfs.h>
e76f14
+#include <stdint.h>
e76f14
+
e76f14
+#include <caml/alloc.h>
e76f14
+#include <caml/fail.h>
e76f14
+#include <caml/memory.h>
e76f14
+#include <caml/mlvalues.h>
e76f14
+
e76f14
+extern value guestfs_int_mllib_statvfs_free_space (value pathv);
e76f14
+
e76f14
+value
e76f14
+guestfs_int_mllib_statvfs_free_space (value pathv)
e76f14
+{
e76f14
+  CAMLparam1 (pathv);
e76f14
+  CAMLlocal1 (rv);
e76f14
+  struct statvfs buf;
e76f14
+  int64_t free_space;
e76f14
+
e76f14
+  if (statvfs (String_val (pathv), &buf) == -1) {
e76f14
+    perror ("statvfs");
e76f14
+    caml_failwith ("statvfs");
e76f14
+  }
e76f14
+
e76f14
+  free_space = (int64_t) buf.f_bsize * buf.f_bavail;
e76f14
+  rv = caml_copy_int64 (free_space);
e76f14
+
e76f14
+  CAMLreturn (rv);
e76f14
+}
e76f14
diff --git a/po/POTFILES b/po/POTFILES
e76f14
index 1252d8b..bef6540 100644
e76f14
--- a/po/POTFILES
e76f14
+++ b/po/POTFILES
e76f14
@@ -266,6 +266,7 @@ mllib/dummy.c
e76f14
 mllib/fsync-c.c
e76f14
 mllib/mkdtemp-c.c
e76f14
 mllib/progress-c.c
e76f14
+mllib/statvfs-c.c
e76f14
 mllib/uri-c.c
e76f14
 ocaml/guestfs-c-actions.c
e76f14
 ocaml/guestfs-c-errnos.c
e76f14
@@ -292,7 +293,6 @@ rescue/rescue.c
e76f14
 rescue/test-virt-rescue.pl
e76f14
 resize/test-virt-resize.pl
e76f14
 ruby/ext/guestfs/_guestfs.c
e76f14
-sparsify/statvfs-c.c
e76f14
 src/actions-0.c
e76f14
 src/actions-1.c
e76f14
 src/actions-2.c
e76f14
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
e76f14
index 2b9bba1..5937ff5 100644
e76f14
--- a/po/POTFILES-ml
e76f14
+++ b/po/POTFILES-ml
e76f14
@@ -38,6 +38,7 @@ dib/utils.ml
e76f14
 get-kernel/get_kernel.ml
e76f14
 mllib/JSON.ml
e76f14
 mllib/JSON_tests.ml
e76f14
+mllib/StatVFS.ml
e76f14
 mllib/URI.ml
e76f14
 mllib/common_gettext.ml
e76f14
 mllib/common_utils.ml
e76f14
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
e76f14
index 9df3e1f..9dd9179 100644
e76f14
--- a/sparsify/Makefile.am
e76f14
+++ b/sparsify/Makefile.am
e76f14
@@ -39,7 +39,7 @@ SOURCES_C = \
e76f14
 	../fish/progress.c \
e76f14
 	../mllib/dev_t-c.c \
e76f14
 	../mllib/progress-c.c \
e76f14
-	statvfs-c.c
e76f14
+	../mllib/statvfs-c.c
e76f14
 
e76f14
 if HAVE_OCAML
e76f14
 
e76f14
@@ -61,6 +61,7 @@ BOBJECTS = \
e76f14
 	$(top_builddir)/mllib/dev_t.cmo \
e76f14
 	$(top_builddir)/mllib/common_utils.cmo \
e76f14
 	$(top_builddir)/mllib/progress.cmo \
e76f14
+	$(top_builddir)/mllib/StatVFS.cmo \
e76f14
 	$(SOURCES_ML:.ml=.cmo)
e76f14
 XOBJECTS = $(BOBJECTS:.cmo=.cmx)
e76f14
 
e76f14
diff --git a/sparsify/copying.ml b/sparsify/copying.ml
e76f14
index 83cbec7..003dbf8 100644
e76f14
--- a/sparsify/copying.ml
e76f14
+++ b/sparsify/copying.ml
e76f14
@@ -31,9 +31,6 @@ open Cmdline
e76f14
 
e76f14
 module G = Guestfs
e76f14
 
e76f14
-external statvfs_free_space : string -> int64 =
e76f14
-  "virt_sparsify_statvfs_free_space"
e76f14
-
e76f14
 type tmp_place =
e76f14
 | Directory of string | Block_device of string | Prebuilt_file of string
e76f14
 
e76f14
@@ -100,7 +97,7 @@ let run indisk outdisk check_tmpdir compress convert
e76f14
           virtual_size (human_size virtual_size);
e76f14
 
e76f14
     let print_warning () =
e76f14
-      let free_space = statvfs_free_space tmpdir in
e76f14
+      let free_space = StatVFS.free_space tmpdir in
e76f14
       let extra_needed = virtual_size -^ free_space in
e76f14
       if extra_needed > 0L then (
e76f14
         warning (f_"\
e76f14
diff --git a/sparsify/statvfs-c.c b/sparsify/statvfs-c.c
e76f14
deleted file mode 100644
e76f14
index 76bff0b..0000000
e76f14
--- a/sparsify/statvfs-c.c
e76f14
+++ /dev/null
e76f14
@@ -1,50 +0,0 @@
e76f14
-/* virt-sparsify - interface to statvfs
e76f14
- * Copyright (C) 2013 Red Hat Inc.
e76f14
- *
e76f14
- * This program is free software; you can redistribute it and/or modify
e76f14
- * it under the terms of the GNU General Public License as published by
e76f14
- * the Free Software Foundation; either version 2 of the License, or
e76f14
- * (at your option) any later version.
e76f14
- *
e76f14
- * This program is distributed in the hope that it will be useful,
e76f14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
e76f14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e76f14
- * GNU General Public License for more details.
e76f14
- *
e76f14
- * You should have received a copy of the GNU General Public License
e76f14
- * along with this program; if not, write to the Free Software
e76f14
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
e76f14
- */
e76f14
-
e76f14
-#include <config.h>
e76f14
-
e76f14
-#include <stdio.h>
e76f14
-#include <stdlib.h>
e76f14
-#include <sys/statvfs.h>
e76f14
-#include <stdint.h>
e76f14
-
e76f14
-#include <caml/alloc.h>
e76f14
-#include <caml/fail.h>
e76f14
-#include <caml/memory.h>
e76f14
-#include <caml/mlvalues.h>
e76f14
-
e76f14
-#pragma GCC diagnostic ignored "-Wmissing-prototypes"
e76f14
-
e76f14
-value
e76f14
-virt_sparsify_statvfs_free_space (value pathv)
e76f14
-{
e76f14
-  CAMLparam1 (pathv);
e76f14
-  CAMLlocal1 (rv);
e76f14
-  struct statvfs buf;
e76f14
-  int64_t free_space;
e76f14
-
e76f14
-  if (statvfs (String_val (pathv), &buf) == -1) {
e76f14
-    perror ("statvfs");
e76f14
-    caml_failwith ("statvfs");
e76f14
-  }
e76f14
-
e76f14
-  free_space = (int64_t) buf.f_bsize * buf.f_bavail;
e76f14
-  rv = caml_copy_int64 (free_space);
e76f14
-
e76f14
-  CAMLreturn (rv);
e76f14
-}
e76f14
-- 
e76f14
1.8.3.1
e76f14