[PATCH v1 2/4] remote: Implement remote{Get,Set}Time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is also adding new ACL permission to check 'set_time'.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 daemon/remote.c              | 35 +++++++++++++++++++++++++++++++++++
 src/access/viraccessperm.c   |  2 +-
 src/access/viraccessperm.h   |  6 ++++++
 src/remote/remote_driver.c   | 32 ++++++++++++++++++++++++++++++++
 src/remote/remote_protocol.x | 31 ++++++++++++++++++++++++++++++-
 src/remote_protocol-structs  | 16 ++++++++++++++++
 6 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 932f65f..8020e60 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -6027,3 +6027,38 @@ error:
     }
     return -1;
 }
+
+static int
+remoteDispatchDomainGetTime(virNetServerPtr server ATTRIBUTE_UNUSED,
+                            virNetServerClientPtr client,
+                            virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                            virNetMessageErrorPtr rerr,
+                            remote_domain_get_time_args *args,
+                            remote_domain_get_time_ret *ret)
+{
+    int rv = -1;
+    virDomainPtr dom = NULL;
+    struct daemonClientPrivate *priv = virNetServerClientGetPrivateData(client);
+    long long time;
+
+    if (!priv->conn) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
+        goto cleanup;
+
+    if (virDomainGetTime(dom, &time, args->flags) < 0)
+        goto cleanup;
+
+    ret->time = time;
+    rv = 0;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (dom)
+        virDomainFree(dom);
+    return rv;
+}
diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c
index d517c66..bbcb6c1 100644
--- a/src/access/viraccessperm.c
+++ b/src/access/viraccessperm.c
@@ -42,7 +42,7 @@ VIR_ENUM_IMPL(virAccessPermDomain,
               "init_control", "inject_nmi", "send_input", "send_signal", "fs_trim",
               "block_read", "block_write", "mem_read",
               "open_graphics", "open_device", "screenshot",
-              "open_namespace");
+              "open_namespace", "set_time");
 
 VIR_ENUM_IMPL(virAccessPermInterface,
               VIR_ACCESS_PERM_INTERFACE_LAST,
diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h
index 6d14f05..6bfd787 100644
--- a/src/access/viraccessperm.h
+++ b/src/access/viraccessperm.h
@@ -289,6 +289,12 @@ typedef enum {
      */
     VIR_ACCESS_PERM_DOMAIN_OPEN_NAMESPACE,
 
+    /**
+     * @desc: Write domain time
+     * @message: Setting the domain time requires authorization
+     */
+    VIR_ACCESS_PERM_DOMAIN_SET_TIME,
+
     VIR_ACCESS_PERM_DOMAIN_LAST,
 } virAccessPermDomain;
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 955465a..4acb745 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -7331,6 +7331,36 @@ done:
 }
 
 
+static int
+remoteDomainGetTime(virDomainPtr dom,
+                    long long *time,
+                    unsigned int flags)
+{
+    int rv = -1;
+    struct private_data *priv = dom->conn->privateData;
+    remote_domain_get_time_args args;
+    remote_domain_get_time_ret ret;
+
+    remoteDriverLock(priv);
+
+    make_nonnull_domain(&args.dom, dom);
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+
+    if (call(dom->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_TIME,
+             (xdrproc_t) xdr_remote_domain_get_time_args, (char *) &args,
+             (xdrproc_t) xdr_remote_domain_get_time_ret, (char *) &ret) == -1)
+        goto cleanup;
+
+    *time = ret.time;
+    rv = ret.ret;
+
+cleanup:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
  * (name, uuid) pair into virDomainPtr or virNetworkPtr object.
  * These can return NULL if underlying memory allocations fail,
@@ -7660,6 +7690,8 @@ static virDriver remote_driver = {
     .domainMigrateFinish3Params = remoteDomainMigrateFinish3Params, /* 1.1.0 */
     .domainMigrateConfirm3Params = remoteDomainMigrateConfirm3Params, /* 1.1.0 */
     .connectGetCPUModelNames = remoteConnectGetCPUModelNames, /* 1.1.3 */
+    .domainGetTime = remoteDomainGetTime, /* 1.2.2 */
+    .domainSetTime = remoteDomainSetTime, /* 1.2.2 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index f1f2359..3fda38c 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2845,6 +2845,23 @@ struct remote_domain_fstrim_args {
     unsigned int flags;
 };
 
+struct remote_domain_get_time_args {
+    remote_nonnull_domain dom;
+    unsigned int flags;
+};
+
+struct remote_domain_get_time_ret {
+    hyper time;
+    int ret;
+};
+
+struct remote_domain_set_time_args {
+    remote_nonnull_domain dom;
+    hyper time;
+    remote_string timezone;
+    unsigned int flags;
+};
+
 struct remote_domain_migrate_begin3_params_args {
     remote_nonnull_domain dom;
     remote_typed_param params<REMOTE_DOMAIN_MIGRATE_PARAM_LIST_MAX>;
@@ -5262,5 +5279,17 @@ enum remote_procedure {
      * @generate: both
      * @acl: none
      */
-    REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333
+    REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333,
+
+    /**
+     * @generate: none
+     * @acl: domain:read
+     */
+    REMOTE_PROC_DOMAIN_GET_TIME = 334,
+
+    /**
+     * @generate: both
+     * @acl: domain:set_time
+     */
+    REMOTE_PROC_DOMAIN_SET_TIME = 335
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 5636d55..0effa27 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2284,6 +2284,20 @@ struct remote_domain_fstrim_args {
         uint64_t                   minimum;
         u_int                      flags;
 };
+struct remote_domain_get_time_args {
+        remote_nonnull_domain      dom;
+        u_int                      flags;
+};
+struct remote_domain_get_time_ret {
+        int64_t                    time;
+        int                        ret;
+};
+struct remote_domain_set_time_args {
+        remote_nonnull_domain      dom;
+        int64_t                    time;
+        remote_string              timezone;
+        u_int                      flags;
+};
 struct remote_domain_migrate_begin3_params_args {
         remote_nonnull_domain      dom;
         struct {
@@ -2755,4 +2769,6 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_EVENT_CALLBACK_BALLOON_CHANGE = 331,
         REMOTE_PROC_DOMAIN_EVENT_CALLBACK_PMSUSPEND_DISK = 332,
         REMOTE_PROC_DOMAIN_EVENT_CALLBACK_DEVICE_REMOVED = 333,
+        REMOTE_PROC_DOMAIN_GET_TIME = 334,
+        REMOTE_PROC_DOMAIN_SET_TIME = 335,
 };
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]