See:
https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg03747.html
Related do RHBZ#1130506.
---
generator/actions.ml | 2 +-
src/drives.c | 11 +++++++++--
src/guestfs-internal.h | 1 +
src/launch-direct.c | 8 +++++---
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/generator/actions.ml b/generator/actions.ml
index fb971d3..4bdd913 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1318,7 +1318,7 @@ not all belong to a single logical operating system
{ defaults with
name = "add_drive";
- style = RErr, [String "filename"], [OBool "readonly"; OString
"format"; OString "iface"; OString "name"; OString
"label"; OString "protocol"; OStringList "server"; OString
"username"; OString "secret"; OString "cachemode"; OString
"discard"; OBool "copyonread"];
+ style = RErr, [String "filename"], [OBool "readonly"; OString
"format"; OString "iface"; OString "name"; OString
"label"; OString "protocol"; OStringList "server"; OString
"username"; OString "secret"; OString "cachemode"; OString
"discard"; OBool "copyonread"; OBool "detectzeros"];
once_had_no_optargs = true;
blocking = false;
fish_alias = ["add"];
diff --git a/src/drives.c b/src/drives.c
index ad747ab..d1e680a 100644
--- a/src/drives.c
+++ b/src/drives.c
@@ -63,6 +63,7 @@ struct drive_create_data {
const char *cachemode;
enum discard discard;
bool copyonread;
+ bool detectzeros;
};
COMPILE_REGEXP (re_hostname_port, "(.*):(\\d+)$", 0)
@@ -116,6 +117,7 @@ create_drive_file (guestfs_h *g,
drv->cachemode = data->cachemode ? safe_strdup (g, data->cachemode) : NULL;
drv->discard = data->discard;
drv->copyonread = data->copyonread;
+ drv->detectzeros = data->detectzeros;
if (data->readonly) {
if (create_overlay (g, drv) == -1) {
@@ -152,6 +154,7 @@ create_drive_non_file (guestfs_h *g,
drv->cachemode = data->cachemode ? safe_strdup (g, data->cachemode) : NULL;
drv->discard = data->discard;
drv->copyonread = data->copyonread;
+ drv->detectzeros = data->detectzeros;
if (data->readonly) {
if (create_overlay (g, drv) == -1) {
@@ -504,7 +507,7 @@ static char *
drive_to_string (guestfs_h *g, const struct drive *drv)
{
return safe_asprintf
- (g, "%s%s%s%s protocol=%s%s%s%s%s%s%s%s%s%s%s",
+ (g, "%s%s%s%s protocol=%s%s%s%s%s%s%s%s%s%s%s%s",
drv->src.u.path,
drv->readonly ? " readonly" : "",
drv->src.format ? " format=" : "",
@@ -520,7 +523,8 @@ drive_to_string (guestfs_h *g, const struct drive *drv)
drv->cachemode ? : "",
drv->discard == discard_disable ? "" :
drv->discard == discard_enable ? " discard=enable" : "
discard=besteffort",
- drv->copyonread ? " copyonread" : "");
+ drv->copyonread ? " copyonread" : "",
+ drv->detectzeros ? " detect-zeroes=on" : "");
}
/* Add struct drive to the g->drives vector at the given index. */
@@ -746,6 +750,9 @@ guestfs_impl_add_drive_opts (guestfs_h *g, const char *filename,
data.servers = NULL;
data.exportname = filename;
+ data.detectzeros = optargs->bitmask &
GUESTFS_ADD_DRIVE_OPTS_DETECTZEROS_BITMASK
+ ? optargs->detectzeros : false;
+
data.readonly = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK
? optargs->readonly : false;
data.format = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_FORMAT_BITMASK
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 43cdd4d..456ac6a 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -269,6 +269,7 @@ struct drive {
char *cachemode;
enum discard discard;
bool copyonread;
+ bool detectzeros;
};
/* Extra hv parameters (from guestfs_config). */
diff --git a/src/launch-direct.c b/src/launch-direct.c
index 5753236..f208f11 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -512,7 +512,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
* the if=... at the end.
*/
param = safe_asprintf
- (g, "file=%s%s,cache=%s%s%s%s%s%s%s,id=hd%zu",
+ (g, "file=%s%s,cache=%s%s%s%s%s%s%s%s,id=hd%zu",
escaped_file,
drv->readonly ? ",snapshot=on" : "",
drv->cachemode ? drv->cachemode : "writeback",
@@ -521,6 +521,7 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
drv->src.format ? drv->src.format : "",
drv->disk_label ? ",serial=" : "",
drv->disk_label ? drv->disk_label : "",
+ drv->detectzeros ? ",detect-zeroes=on" : "",
drv->copyonread ? ",copy-on-read=on" : "",
i);
}
@@ -528,11 +529,12 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
/* Writable qcow2 overlay on top of read-only drive. */
escaped_file = qemu_escape_param (g, drv->overlay);
param = safe_asprintf
- (g, "file=%s,cache=unsafe,format=qcow2%s%s,id=hd%zu",
+ (g,
"file=%s,cache=unsafe,format=qcow2%s%s,id=hd%zu,detect-zeroes=%s",
escaped_file,
drv->disk_label ? ",serial=" : "",
drv->disk_label ? drv->disk_label : "",
- i);
+ i,
+ drv->detectzeros ? "on" : "off");
}
/* If there's an explicit 'iface', use it. Otherwise default to
When the detect-zeros parameter has been added to qemu? When requesting
to enable it, there should be a qemu version check like it has been
done for the discard mode.
Also, this should be added in the libvirt backend too.
--
Pino Toscano