Skip to content

Commit

Permalink
sparsify: Move statvfs wrapper function to mllib.
Browse files Browse the repository at this point in the history
We wish to use this function in virt-v2v too, so move it to the common
directory.

No functional change.
  • Loading branch information
rwmjones committed Jun 23, 2016
1 parent 5e794b8 commit 24130d7
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/C_SOURCE_FILES
Expand Up @@ -179,6 +179,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
Expand All @@ -200,7 +201,6 @@ python/guestfs-py-byhand.c
python/guestfs-py.c
rescue/rescue.c
ruby/ext/guestfs/_guestfs.c
sparsify/statvfs-c.c
src/actions-0.c
src/actions-1.c
src/actions-2.c
Expand Down
3 changes: 3 additions & 0 deletions mllib/Makefile.am
Expand Up @@ -35,6 +35,7 @@ SOURCES_MLI = \
planner.mli \
progress.mli \
regedit.mli \
StatVFS.mli \
URI.mli

SOURCES_ML = \
Expand All @@ -50,6 +51,7 @@ SOURCES_ML = \
mkdtemp.ml \
planner.ml \
regedit.ml \
StatVFS.ml \
JSON.ml

SOURCES_C = \
Expand All @@ -59,6 +61,7 @@ SOURCES_C = \
fsync-c.c \
mkdtemp-c.c \
progress-c.c \
statvfs-c.c \
uri-c.c

if HAVE_OCAML
Expand Down
21 changes: 21 additions & 0 deletions 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"
23 changes: 23 additions & 0 deletions 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. *)
8 changes: 4 additions & 4 deletions sparsify/statvfs-c.c → mllib/statvfs-c.c
@@ -1,5 +1,5 @@
/* virt-sparsify - interface to statvfs
* Copyright (C) 2013 Red Hat Inc.
/* 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
Expand Down Expand Up @@ -28,10 +28,10 @@
#include <caml/memory.h>
#include <caml/mlvalues.h>

#pragma GCC diagnostic ignored "-Wmissing-prototypes"
extern value guestfs_int_mllib_statvfs_free_space (value pathv);

value
virt_sparsify_statvfs_free_space (value pathv)
guestfs_int_mllib_statvfs_free_space (value pathv)
{
CAMLparam1 (pathv);
CAMLlocal1 (rv);
Expand Down
3 changes: 2 additions & 1 deletion sparsify/Makefile.am
Expand Up @@ -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

Expand All @@ -62,6 +62,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)

Expand Down
5 changes: 1 addition & 4 deletions sparsify/copying.ml
Expand Up @@ -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

Expand Down Expand Up @@ -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_"\
Expand Down

0 comments on commit 24130d7

Please sign in to comment.