@@ -320,3 +320,21 @@ This command is always allowed.
* -KVM_ENOENT - the event specified by ``id`` is unsupported
* -KVM_EPERM - the event specified by ``id`` is disallowed
* -KVM_EINVAL - the padding is not zero
+
+4. KVMI_VM_GET_INFO
+-------------------
+
+:Architectures: all
+:Versions: >= 1
+:Parameters: none
+:Returns:
+
+::
+
+ struct kvmi_error_code;
+ struct kvmi_vm_get_info_reply {
+ __u32 vcpu_count;
+ __u32 padding[3];
+ };
+
+Returns the number of online vCPUs.
@@ -17,6 +17,7 @@ enum {
KVMI_GET_VERSION = 2,
KVMI_VM_CHECK_COMMAND = 3,
KVMI_VM_CHECK_EVENT = 4,
+ KVMI_VM_GET_INFO = 5,
KVMI_NUM_MESSAGES
};
@@ -64,4 +65,9 @@ struct kvmi_vm_check_event {
__u32 padding2;
};
+struct kvmi_vm_get_info_reply {
+ __u32 vcpu_count;
+ __u32 padding[3];
+};
+
#endif /* _UAPI__LINUX_KVMI_H */
@@ -254,6 +254,20 @@ static void test_cmd_check_event(void)
-r, kvm_strerror(-r));
}
+static void test_cmd_get_vm_info(void)
+{
+ struct kvmi_vm_get_info_reply rpl;
+ struct kvmi_msg_hdr req;
+
+ test_vm_command(KVMI_VM_GET_INFO, &req, sizeof(req), &rpl,
+ sizeof(rpl));
+ TEST_ASSERT(rpl.vcpu_count == 1,
+ "Unexpected number of vCPU count %u\n",
+ rpl.vcpu_count);
+
+ DEBUG("vcpu count: %u\n", rpl.vcpu_count);
+}
+
static void test_introspection(struct kvm_vm *vm)
{
setup_socket();
@@ -263,6 +277,7 @@ static void test_introspection(struct kvm_vm *vm)
test_cmd_get_version();
test_cmd_check_command();
test_cmd_check_event();
+ test_cmd_get_vm_info();
unhook_introspection(vm);
}
@@ -159,6 +159,18 @@ static int handle_check_event(struct kvm_introspection *kvmi,
return kvmi_msg_vm_reply(kvmi, msg, ec, NULL, 0);
}
+static int handle_get_info(struct kvm_introspection *kvmi,
+ const struct kvmi_msg_hdr *msg,
+ const void *req)
+{
+ struct kvmi_vm_get_info_reply rpl;
+
+ memset(&rpl, 0, sizeof(rpl));
+ rpl.vcpu_count = atomic_read(&kvmi->kvm->online_vcpus);
+
+ return kvmi_msg_vm_reply(kvmi, msg, 0, &rpl, sizeof(rpl));
+}
+
/*
* These commands are executed by the receiving thread/worker.
*/
@@ -167,6 +179,7 @@ static int(*const msg_vm[])(struct kvm_introspection *,
[KVMI_GET_VERSION] = handle_get_version,
[KVMI_VM_CHECK_COMMAND] = handle_check_command,
[KVMI_VM_CHECK_EVENT] = handle_check_event,
+ [KVMI_VM_GET_INFO] = handle_get_info,
};
static bool is_vm_command(u16 id)