diff mbox

[5/5] qmp/hmp: add set-vm-generation-id commands

Message ID d73fe3d84b15c6bda193c709ed11d9335f99d9f8.1482187052.git.ben@skyportsystems.com
State New
Headers show

Commit Message

ben@skyportsystems.com Dec. 19, 2016, 10:46 p.m. UTC
From: Igor Mammedov <imammedo@redhat.com>

Add set-vm-generation-id command to set Virtual Machine
Generation ID counter.

QMP command example:
    { "execute": "set-vm-generation-id",
          "arguments": {
              "changed": true,
              "guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
          }
    }

HMP command example:
    set-vm-generation-id changed=true guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87

Signed-off-by: Ben Warren <ben@skyportsystems.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
---
 hmp-commands.hx  | 13 +++++++++++++
 hmp.c            | 13 +++++++++++++
 hmp.h            |  1 +
 qapi-schema.json | 12 ++++++++++++
 stubs/vmgenid.c  |  6 ++++++
 5 files changed, 45 insertions(+)

Comments

Eric Blake Dec. 20, 2016, 2:36 p.m. UTC | #1
On 12/19/2016 04:46 PM, ben@skyportsystems.com wrote:
> From: Igor Mammedov <imammedo@redhat.com>
> 
> Add set-vm-generation-id command to set Virtual Machine
> Generation ID counter.
> 
> QMP command example:
>     { "execute": "set-vm-generation-id",
>           "arguments": {
>               "changed": true,
>               "guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
>           }
>     }
> 
> HMP command example:
>     set-vm-generation-id changed=true guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87
> 
> Signed-off-by: Ben Warren <ben@skyportsystems.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Cc: Eric Blake <eblake@redhat.com>
> ---

> +++ b/qapi-schema.json
> @@ -4796,3 +4796,15 @@
>  # Since 2.9
>  ##
>  { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
> +
> +##
> +# @set-vm-generation-id
> +#
> +# Set Virtual Machine Generation ID
> +#
> +# @changed: Is the Virtual Machine Generation ID a new value?
> +# @guid: new GUID to set as Virtual Machine Generation ID
> +#
> +# Since 2.9
> +##
> +{ 'command': 'set-vm-generation-id', 'data': { 'changed': 'bool', 'guid': 'str' } }

When should 'changed' ever be set to false?  Should it be an optional
parameter, defaulting to true, if it is even needed?
ben@skyportsystems.com Dec. 20, 2016, 5:23 p.m. UTC | #2
Hi Eric,
> On Dec 20, 2016, at 6:36 AM, Eric Blake <eblake@redhat.com> wrote:
> 
> On 12/19/2016 04:46 PM, ben@skyportsystems.com <mailto:ben@skyportsystems.com> wrote:
>> From: Igor Mammedov <imammedo@redhat.com>
>> 
>> Add set-vm-generation-id command to set Virtual Machine
>> Generation ID counter.
>> 
>> QMP command example:
>>    { "execute": "set-vm-generation-id",
>>          "arguments": {
>>              "changed": true,
>>              "guid": "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
>>          }
>>    }
>> 
>> HMP command example:
>>    set-vm-generation-id changed=true guid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87
>> 
>> Signed-off-by: Ben Warren <ben@skyportsystems.com>
>> Cc: Igor Mammedov <imammedo@redhat.com>
>> Cc: Eric Blake <eblake@redhat.com>
>> ---
> 
>> +++ b/qapi-schema.json
>> @@ -4796,3 +4796,15 @@
>> # Since 2.9
>> ##
>> { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
>> +
>> +##
>> +# @set-vm-generation-id
>> +#
>> +# Set Virtual Machine Generation ID
>> +#
>> +# @changed: Is the Virtual Machine Generation ID a new value?
>> +# @guid: new GUID to set as Virtual Machine Generation ID
>> +#
>> +# Since 2.9
>> +##
>> +{ 'command': 'set-vm-generation-id', 'data': { 'changed': 'bool', 'guid': 'str' } }
> 
> When should 'changed' ever be set to false?  Should it be an optional
> parameter, defaulting to true, if it is even needed?
> 
Let me explain the intent, then we can talk about implementation.  I apologize if this is stuff you already know.  The purpose of VM Generation ID in Windows is to detect time rollbacks.  Active Directory in particular can get out of sync in hard-to-debug ways.  VM Generation ID is supposed to help with this, in that it tells Windows that a time rollback has occurred and therefore its AD data is “dirty” and must be “pull-synced” from its replication partners.  The problem is that this replication can be quite costly in large installations, so I want to only do it if necessary.  So the answer to your question is that “changed” will be false most of the time, and will be set to true only in a couple of situations: new VM instantiation and snapshot rollback.  It’s up to the managing service (libvirt or custom SW, I guess) to manage the lifecycle of a VM and set this flag accordingly.

Now, the VM Generation ID spec identifies an ACPI Notify operation that is bound to the VM Generation ID ACPI object.  I have this GPE only being set if the ‘changed’ variable is true.  I don’t know enough about ACPI to know if this is the right approach, and will be doing as much testing within Windows to see if this does what I want, but as I’m sure you know Windows is pretty opaque and it’s not always obvious how to get the relevant information.

I have both Hyper-V and Xen setups available and am trying to emulate the Hyper-V one since we should probably consider it to be a reference design.  I know Xen just sets this thing blindly and we can do better than that.

> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org <http://libvirt.org/>
—Ben
diff mbox

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 8819281..495fc95 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1775,5 +1775,18 @@  ETEXI
     },
 
 STEXI
+@item set-vm-generation-id @var{changed} @var{uuid}
+Set Virtual Machine Generation ID counter to @var{guid}
+ETEXI
+
+    {
+        .name       = "set-vm-generation-id",
+        .args_type  = "changed:b,guid:s",
+        .params     = "changed guid",
+        .help       = "Set Virtual Machine Generation ID counter",
+        .cmd = hmp_set_vm_generation_id,
+    },
+
+STEXI
 @end table
 ETEXI
diff --git a/hmp.c b/hmp.c
index 9ec27ae..d73af31 100644
--- a/hmp.c
+++ b/hmp.c
@@ -2579,3 +2579,16 @@  void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
     }
     qapi_free_GuidInfo(info);
 }
+
+void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict)
+{
+    Error *errp = NULL;
+    const char *guid = qdict_get_str(qdict, "guid");
+    bool changed = qdict_get_bool(qdict, "changed");
+
+    qmp_set_vm_generation_id(changed, guid, &errp);
+    if (errp) {
+        hmp_handle_error(mon, &errp);
+        return;
+    }
+}
diff --git a/hmp.h b/hmp.h
index 799fd37..e0ac1e8 100644
--- a/hmp.h
+++ b/hmp.h
@@ -138,5 +138,6 @@  void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict);
 void hmp_info_dump(Monitor *mon, const QDict *qdict);
 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict);
+void hmp_set_vm_generation_id(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 2348391..72f3515 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4796,3 +4796,15 @@ 
 # Since 2.9
 ##
 { 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
+
+##
+# @set-vm-generation-id
+#
+# Set Virtual Machine Generation ID
+#
+# @changed: Is the Virtual Machine Generation ID a new value?
+# @guid: new GUID to set as Virtual Machine Generation ID
+#
+# Since 2.9
+##
+{ 'command': 'set-vm-generation-id', 'data': { 'changed': 'bool', 'guid': 'str' } }
diff --git a/stubs/vmgenid.c b/stubs/vmgenid.c
index 8c448ac..588aeb4 100644
--- a/stubs/vmgenid.c
+++ b/stubs/vmgenid.c
@@ -6,3 +6,9 @@  GuidInfo *qmp_query_vm_generation_id(Error **errp)
     error_setg(errp, "this command is not currently supported");
     return NULL;
 }
+
+void qmp_set_vm_generation_id(bool changed, const char *guid, Error **errp)
+{
+    error_setg(errp, "this command is not currently supported");
+    return;
+}