[PATCH 0/3] implement a few guest agent based APIs
Roman Bogorodskiy (3): bhyve: implement domain{Get,Set}Time APIs bhyve: implement domainSetUserPassword API bhyve: implement domainAuthorizedSSHKeys{Get,Set} APIs src/bhyve/bhyve_driver.c | 225 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) -- 2.52.0
Implement the domain{Get,Set}Time APIs for getting and setting domain time. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_driver.c | 93 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 2e7a534396..f99ce3bb8b 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -2375,6 +2375,97 @@ bhyveDomainGetFSInfo(virDomainPtr dom, return ret; } +static int +bhyveDomainGetTime(virDomainPtr domain, + long long *seconds, + unsigned int *nseconds, + unsigned int flags) +{ + virDomainObj *vm = NULL; + qemuAgent *agent; + int ret = -1; + int rv; + + virCheckFlags(0, ret); + + if (!(vm = bhyveDomObjFromDomain(domain))) + return ret; + + if (virDomainGetTimeEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjBeginAgentJob(vm, VIR_AGENT_JOB_QUERY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (bhyveDomainEnsureAgent(vm, true) < 0) + goto endjob; + + agent = bhyveDomainObjEnterAgent(vm); + rv = qemuAgentGetTime(agent, seconds, nseconds); + bhyveDomainObjExitAgent(vm, agent); + + if (rv < 0) + goto endjob; + + ret = 0; + + endjob: + virDomainObjEndAgentJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int +bhyveDomainSetTime(virDomainPtr domain, + long long seconds, + unsigned int nseconds, + unsigned int flags) +{ + virDomainObj *vm = NULL; + qemuAgent *agent; + bool rtcSync = flags & VIR_DOMAIN_TIME_SYNC; + int ret = -1; + int rv; + + virCheckFlags(VIR_DOMAIN_TIME_SYNC, ret); + + if (!(vm = bhyveDomObjFromDomain(domain))) + return ret; + + if (virDomainSetTimeEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjBeginAgentJob(vm, VIR_AGENT_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (bhyveDomainEnsureAgent(vm, true) < 0) + goto endjob; + + agent = bhyveDomainObjEnterAgent(vm); + rv = qemuAgentSetTime(agent, seconds, nseconds, rtcSync); + bhyveDomainObjExitAgent(vm, agent); + + if (rv < 0) + goto endjob; + + ret = 0; + + endjob: + virDomainObjEndAgentJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static virHypervisorDriver bhyveHypervisorDriver = { .name = "bhyve", .connectURIProbe = bhyveConnectURIProbe, @@ -2447,6 +2538,8 @@ static virHypervisorDriver bhyveHypervisorDriver = { .domainGetMemoryParameters = bhyveDomainGetMemoryParameters, /* 12.4.0 */ .domainSetMemoryParameters = bhyveDomainSetMemoryParameters, /* 12.4.0 */ .domainGetFSInfo = bhyveDomainGetFSInfo, /* 12.5.0 */ + .domainGetTime = bhyveDomainGetTime, /* 12.6.0 */ + .domainSetTime = bhyveDomainSetTime, /* 12.6.0 */ }; -- 2.52.0
Implement the domainSetUserPassword API for setting user password using the guest agent. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_driver.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index f99ce3bb8b..d5f22b18bd 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -2466,6 +2466,52 @@ bhyveDomainSetTime(virDomainPtr domain, return ret; } +static int +bhyveDomainSetUserPassword(virDomainPtr domain, + const char *user, + const char *password, + unsigned int flags) +{ + virDomainObj *vm = NULL; + qemuAgent *agent; + int ret = -1; + int rv; + + virCheckFlags(VIR_DOMAIN_PASSWORD_ENCRYPTED, -1); + + if (!(vm = bhyveDomObjFromDomain(domain))) + return ret; + + if (virDomainSetUserPasswordEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjBeginAgentJob(vm, VIR_AGENT_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (bhyveDomainEnsureAgent(vm, true) < 0) + goto endjob; + + agent = bhyveDomainObjEnterAgent(vm); + rv = qemuAgentSetUserPassword(agent, user, password, + flags & VIR_DOMAIN_PASSWORD_ENCRYPTED); + bhyveDomainObjExitAgent(vm, agent); + + if (rv < 0) + goto endjob; + + ret = 0; + + endjob: + virDomainObjEndAgentJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static virHypervisorDriver bhyveHypervisorDriver = { .name = "bhyve", .connectURIProbe = bhyveConnectURIProbe, @@ -2540,6 +2586,7 @@ static virHypervisorDriver bhyveHypervisorDriver = { .domainGetFSInfo = bhyveDomainGetFSInfo, /* 12.5.0 */ .domainGetTime = bhyveDomainGetTime, /* 12.6.0 */ .domainSetTime = bhyveDomainSetTime, /* 12.6.0 */ + .domainSetUserPassword = bhyveDomainSetUserPassword, /* 12.6.0 */ }; -- 2.52.0
Implement the domainAuthorizedSSHKeys{Get,Set} APIs using the guest agent. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_driver.c | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index d5f22b18bd..ed03c16ea8 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -2512,6 +2512,89 @@ bhyveDomainSetUserPassword(virDomainPtr domain, return ret; } +static int +bhyveDomainAuthorizedSSHKeysGet(virDomainPtr domain, + const char *user, + char ***keys, + unsigned int flags) +{ + virDomainObj *vm = NULL; + qemuAgent *agent; + int rv = -1; + + virCheckFlags(0, -1); + + if (!(vm = bhyveDomObjFromDomain(domain))) + return -1; + + if (virDomainAuthorizedSshKeysGetEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjBeginAgentJob(vm, VIR_AGENT_JOB_QUERY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (bhyveDomainEnsureAgent(vm, true) < 0) + goto endjob; + + agent = bhyveDomainObjEnterAgent(vm); + rv = qemuAgentSSHGetAuthorizedKeys(agent, user, keys); + bhyveDomainObjExitAgent(vm, agent); + + endjob: + virDomainObjEndAgentJob(vm); + cleanup: + virDomainObjEndAPI(&vm); + return rv; +} + +static int +bhyveDomainAuthorizedSSHKeysSet(virDomainPtr domain, + const char *user, + const char **keys, + unsigned int nkeys, + unsigned int flags) +{ + virDomainObj *vm = NULL; + qemuAgent *agent; + const bool append = flags & VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_APPEND; + const bool remove = flags & VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE; + int rv = -1; + + virCheckFlags(VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_APPEND | + VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE, -1); + + if (!(vm = bhyveDomObjFromDomain(domain))) + return -1; + + if (virDomainAuthorizedSshKeysSetEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjBeginAgentJob(vm, VIR_AGENT_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (bhyveDomainEnsureAgent(vm, true) < 0) + goto endjob; + + agent = bhyveDomainObjEnterAgent(vm); + if (remove) + rv = qemuAgentSSHRemoveAuthorizedKeys(agent, user, keys, nkeys); + else + rv = qemuAgentSSHAddAuthorizedKeys(agent, user, keys, nkeys, !append); + bhyveDomainObjExitAgent(vm, agent); + + endjob: + virDomainObjEndAgentJob(vm); + cleanup: + virDomainObjEndAPI(&vm); + return rv; +} + static virHypervisorDriver bhyveHypervisorDriver = { .name = "bhyve", .connectURIProbe = bhyveConnectURIProbe, @@ -2587,6 +2670,8 @@ static virHypervisorDriver bhyveHypervisorDriver = { .domainGetTime = bhyveDomainGetTime, /* 12.6.0 */ .domainSetTime = bhyveDomainSetTime, /* 12.6.0 */ .domainSetUserPassword = bhyveDomainSetUserPassword, /* 12.6.0 */ + .domainAuthorizedSSHKeysGet = bhyveDomainAuthorizedSSHKeysGet, /* 12.6.0 */ + .domainAuthorizedSSHKeysSet = bhyveDomainAuthorizedSSHKeysSet, /* 12.6.0 */ }; -- 2.52.0
On 6/6/26 11:44, Roman Bogorodskiy wrote:
Roman Bogorodskiy (3): bhyve: implement domain{Get,Set}Time APIs bhyve: implement domainSetUserPassword API bhyve: implement domainAuthorizedSSHKeys{Get,Set} APIs
src/bhyve/bhyve_driver.c | 225 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Michal Prívozník -
Roman Bogorodskiy