Allow callers to specify that all the disks from a domain are added
with a specific discard mode (instead of always having discard
disabled).
---
generator/actions.ml | 4 ++--
src/guestfs-internal-frontend.h | 2 ++
src/libvirt-domain.c | 16 ++++++++++++++++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/generator/actions.ml b/generator/actions.ml
index 597138c..742df6a 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1576,7 +1576,7 @@ not part of the formal API and can be removed or changed at any
time." };
{ defaults with
name = "add_domain";
- style = RInt "nrdisks", [String "dom"], [OString
"libvirturi"; OBool "readonly"; OString "iface"; OBool
"live"; OBool "allowuuid"; OString "readonlydisk"; OString
"cachemode"];
+ style = RInt "nrdisks", [String "dom"], [OString
"libvirturi"; OBool "readonly"; OString "iface"; OBool
"live"; OBool "allowuuid"; OString "readonlydisk"; OString
"cachemode"; OString "discard"];
fish_alias = ["domain"]; config_only = true;
shortdesc = "add the disk(s) from a named libvirt domain";
longdesc = "\
@@ -1668,7 +1668,7 @@ C<guestfs_add_drive_opts>." };
This interface is not quite baked yet. -- RWMJ 2010-11-11
{ defaults with
name = "add_libvirt_dom";
- style = RInt "nrdisks", [Pointer ("virDomainPtr",
"dom")], [Bool "readonly"; String "iface"; Bool
"live"; String "readonlydisk"; OString "cachemode"];
+ style = RInt "nrdisks", [Pointer ("virDomainPtr",
"dom")], [Bool "readonly"; String "iface"; Bool
"live"; String "readonlydisk"; OString "cachemode"; OString
"discard"];
in_fish = false;
shortdesc = "add the disk(s) from a libvirt domain";
longdesc = "\
diff --git a/src/guestfs-internal-frontend.h b/src/guestfs-internal-frontend.h
index 80ebf50..6bf0a94 100644
--- a/src/guestfs-internal-frontend.h
+++ b/src/guestfs-internal-frontend.h
@@ -144,6 +144,8 @@ struct guestfs___add_libvirt_dom_argv {
const char *readonlydisk;
#define GUESTFS___ADD_LIBVIRT_DOM_CACHEMODE_BITMASK (UINT64_C(1)<<4)
const char *cachemode;
+#define GUESTFS___ADD_LIBVIRT_DOM_DISCARD_BITMASK (UINT64_C(1)<<5)
+ const char *discard;
};
extern GUESTFS_DLL_PUBLIC int guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom,
const struct guestfs___add_libvirt_dom_argv *optargs);
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 3a1c691..cadae3e 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -64,6 +64,7 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name,
const char *readonlydisk;
const char *iface;
const char *cachemode;
+ const char *discard;
struct guestfs___add_libvirt_dom_argv optargs2 = { .bitmask = 0 };
libvirturi = optargs->bitmask & GUESTFS_ADD_DOMAIN_LIBVIRTURI_BITMASK
@@ -80,6 +81,8 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name,
? optargs->readonlydisk : NULL;
cachemode = optargs->bitmask & GUESTFS_ADD_DOMAIN_CACHEMODE_BITMASK
? optargs->cachemode : NULL;
+ discard = optargs->bitmask & GUESTFS_ADD_DOMAIN_DISCARD_BITMASK
+ ? optargs->discard : NULL;
if (live && readonly) {
error (g, _("you cannot set both live and readonly flags"));
@@ -136,6 +139,10 @@ guestfs__add_domain (guestfs_h *g, const char *domain_name,
optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_CACHEMODE_BITMASK;
optargs2.cachemode = cachemode;
}
+ if (discard) {
+ optargs2.bitmask |= GUESTFS___ADD_LIBVIRT_DOM_DISCARD_BITMASK;
+ optargs2.discard = discard;
+ }
r = guestfs___add_libvirt_dom (g, dom, &optargs2);
@@ -171,6 +178,7 @@ guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom,
int readonly;
const char *iface;
const char *cachemode;
+ const char *discard;
int live;
/* Default for back-compat reasons: */
enum readonlydisk readonlydisk = readonlydisk_write;
@@ -208,6 +216,10 @@ guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom,
optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_CACHEMODE_BITMASK
? optargs->cachemode : NULL;
+ discard =
+ optargs->bitmask & GUESTFS___ADD_LIBVIRT_DOM_DISCARD_BITMASK
+ ? optargs->discard : NULL;
+
if (live && readonly) {
error (g, _("you cannot set both live and readonly flags"));
return -1;
@@ -272,6 +284,10 @@ guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom,
data.optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_CACHEMODE_BITMASK;
data.optargs.cachemode = cachemode;
}
+ if (discard) {
+ data.optargs.bitmask |= GUESTFS_ADD_DRIVE_OPTS_DISCARD_BITMASK;
+ data.optargs.discard = discard;
+ }
/* Checkpoint the command line around the operation so that either
* all disks are added or none are added.
--
1.8.5.3