[Pkg-libvirt-commits] [libguestfs] 22/59: New API: blkdiscardzeroes - do discarded blocks read back as zeroes?

Hilko Bengen bengen at moszumanska.debian.org
Thu Mar 20 23:05:35 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit b408419791c2fc895f6d1168f53cd92729c037fd
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Tue Mar 11 19:01:35 2014 +0000

    New API: blkdiscardzeroes - do discarded blocks read back as zeroes?
---
 daemon/blkdiscard.c  | 35 +++++++++++++++++++++++++++++++++++
 generator/actions.ml | 14 ++++++++++++++
 src/MAX_PROC_NR      |  2 +-
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/daemon/blkdiscard.c b/daemon/blkdiscard.c
index 1d507a3..7b63b99 100644
--- a/daemon/blkdiscard.c
+++ b/daemon/blkdiscard.c
@@ -88,3 +88,38 @@ do_blkdiscard (const char *device)
 #else /* !BLKDISCARD */
 OPTGROUP_BLKDISCARD_NOT_AVAILABLE
 #endif
+
+#ifdef BLKDISCARDZEROES
+
+int
+optgroup_blkdiscardzeroes_available (void)
+{
+  return 1;
+}
+
+int
+do_blkdiscardzeroes (const char *device)
+{
+  int fd;
+  unsigned int arg;
+
+  fd = open (device, O_RDONLY|O_CLOEXEC);
+  if (fd == -1) {
+    reply_with_perror ("open: %s", device);
+    return -1;
+  }
+
+  if (ioctl (fd, BLKDISCARDZEROES, &arg) == -1) {
+    reply_with_perror ("ioctl: %s: BLKDISCARDZEROES", device);
+    close (fd);
+    return -1;
+  }
+
+  close (fd);
+
+  return arg != 0;
+}
+
+#else /* !BLKDISCARDZEROES */
+OPTGROUP_BLKDISCARDZEROES_NOT_AVAILABLE
+#endif
diff --git a/generator/actions.ml b/generator/actions.ml
index 5c4adbc..df912f6 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -11834,6 +11834,20 @@ an error or even appear to run but do nothing.  You must also
 set the C<discard> attribute on the underlying drive (see
 C<guestfs_add_drive_opts>)." };
 
+  { defaults with
+    name = "blkdiscardzeroes";
+    style = RBool "zeroes", [Device "device"], [];
+    proc_nr = Some 418;
+    optional = Some "blkdiscardzeroes";
+    shortdesc = "return true if discarded blocks are read as zeroes";
+    longdesc = "\
+This call returns true if blocks on C<device> that have been
+discarded by a call to C<guestfs_blkdiscard> are returned as
+blocks of zero bytes when read the next time.
+
+If it returns false, then it may be that discarded blocks are
+read as stale or random data." };
+
 ]
 
 (* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 53c86ff..29aae8e 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-417
+418

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list