Blob Blame History Raw
From c2f3c3eadc4f130a411c6fc259e65d30291bfd0c Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 23 Jun 2016 13:10:35 +0100
Subject: [PATCH] sparsify: Move statvfs wrapper function to mllib.

We wish to use this function in virt-v2v too, so move it to the common
directory.

No functional change.

(cherry picked from commit 24130d787256dc3d9e37e85b1ba35ac7dbeb86a1)
---
 mllib/Makefile.am    |  3 +++
 mllib/StatVFS.ml     | 21 +++++++++++++++++++++
 mllib/StatVFS.mli    | 23 +++++++++++++++++++++++
 mllib/statvfs-c.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 po/POTFILES          |  2 +-
 po/POTFILES-ml       |  1 +
 sparsify/Makefile.am |  3 ++-
 sparsify/copying.ml  |  5 +----
 sparsify/statvfs-c.c | 50 --------------------------------------------------
 9 files changed, 102 insertions(+), 56 deletions(-)
 create mode 100644 mllib/StatVFS.ml
 create mode 100644 mllib/StatVFS.mli
 create mode 100644 mllib/statvfs-c.c
 delete mode 100644 sparsify/statvfs-c.c

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