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

[Xen-devel] [PATCH v2 3/5] libxc: wrapper for log level sysctl



Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Jan Beulich <JBeulich@xxxxxxxx>
---
 tools/libxc/include/xenctrl.h |   6 ++
 tools/libxc/xc_misc.c         | 143 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 4a85b4a..059c7b4 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1179,6 +1179,12 @@ int xc_readconsolering(xc_interface *xch,
 
 int xc_send_debug_keys(xc_interface *xch, char *keys);
 
+int xc_get_log_level(xc_interface *xch, bool guest,
+                     char *lower_thresh, unsigned int *lower_thresh_len,
+                     char *upper_thresh, unsigned int *upper_thresh_len);
+int xc_set_log_level(xc_interface *xch, bool guest,
+                     char *lower_thresh, char *upper_thresh);
+
 typedef xen_sysctl_physinfo_t xc_physinfo_t;
 typedef xen_sysctl_cputopo_t xc_cputopo_t;
 typedef xen_sysctl_numainfo_t xc_numainfo_t;
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index 06e90de..1dbbe9c 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -187,6 +187,149 @@ int xc_send_debug_keys(xc_interface *xch, char *keys)
     return ret;
 }
 
+int xc_get_log_level(xc_interface *xch, bool guest,
+                     char *lower_thresh, unsigned int *lower_thresh_len,
+                     char *upper_thresh, unsigned int *upper_thresh_len)
+{
+    int ret;
+    DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(lower_thresh, *lower_thresh_len,
+                             XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+    DECLARE_HYPERCALL_BOUNCE(upper_thresh, *upper_thresh_len,
+                             XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
+
+    if ( (ret = xc_hypercall_bounce_pre(xch, lower_thresh)) )
+        goto out;
+    if ( (ret = xc_hypercall_bounce_pre(xch, upper_thresh)) )
+        goto out;
+
+    sysctl.cmd = XEN_SYSCTL_loglvl_op;
+    sysctl.u.loglvl.cmd = XEN_SYSCTL_LOGLVL_get;
+
+    if ( guest )
+    {
+        set_xen_guest_handle(sysctl.u.loglvl.host.lower_thresh,
+                             HYPERCALL_BUFFER_NULL);
+        sysctl.u.loglvl.host.lower_thresh_len = 0;
+        set_xen_guest_handle(sysctl.u.loglvl.host.upper_thresh,
+                             HYPERCALL_BUFFER_NULL);
+        sysctl.u.loglvl.host.upper_thresh_len = 0;
+
+        set_xen_guest_handle(sysctl.u.loglvl.guest.lower_thresh,
+                             lower_thresh);
+        sysctl.u.loglvl.guest.lower_thresh_len = *lower_thresh_len;
+        set_xen_guest_handle(sysctl.u.loglvl.guest.upper_thresh,
+                             upper_thresh);
+        sysctl.u.loglvl.guest.upper_thresh_len = *upper_thresh_len;
+    }
+    else
+    {
+        set_xen_guest_handle(sysctl.u.loglvl.host.lower_thresh,
+                             lower_thresh);
+        sysctl.u.loglvl.host.lower_thresh_len = *lower_thresh_len;
+        set_xen_guest_handle(sysctl.u.loglvl.host.upper_thresh,
+                             upper_thresh);
+        sysctl.u.loglvl.host.upper_thresh_len = *upper_thresh_len;
+
+        set_xen_guest_handle(sysctl.u.loglvl.guest.lower_thresh,
+                             HYPERCALL_BUFFER_NULL);
+        sysctl.u.loglvl.guest.lower_thresh_len = 0;
+        set_xen_guest_handle(sysctl.u.loglvl.guest.upper_thresh,
+                             HYPERCALL_BUFFER_NULL);
+        sysctl.u.loglvl.guest.upper_thresh_len = 0;
+    }
+
+    ret = do_sysctl(xch, &sysctl);
+
+    if ( guest )
+    {
+        *lower_thresh_len = sysctl.u.loglvl.guest.lower_thresh_len;
+        *upper_thresh_len = sysctl.u.loglvl.guest.upper_thresh_len;
+    }
+    else
+    {
+        *lower_thresh_len = sysctl.u.loglvl.host.lower_thresh_len;
+        *upper_thresh_len = sysctl.u.loglvl.host.upper_thresh_len;
+    }
+
+out:
+    xc_hypercall_bounce_post(xch, lower_thresh);
+    xc_hypercall_bounce_post(xch, upper_thresh);
+    return ret;
+}
+
+int xc_set_log_level(xc_interface *xch, bool guest,
+                     char *lower_thresh, char *upper_thresh)
+{
+    int ret;
+    unsigned int lower_thresh_len = 0, upper_thresh_len = 0;
+    DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(lower_thresh, 0 /* later */,
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    DECLARE_HYPERCALL_BOUNCE(upper_thresh, 0 /* later */,
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+
+    if (!lower_thresh && !upper_thresh)
+        return 0;
+
+    sysctl.cmd = XEN_SYSCTL_loglvl_op;
+    sysctl.u.loglvl.cmd = XEN_SYSCTL_LOGLVL_set;
+
+    if (lower_thresh) {
+        lower_thresh_len = strlen(lower_thresh) + 1;
+        HYPERCALL_BOUNCE_SET_SIZE(lower_thresh, lower_thresh_len);
+    }
+
+    if (upper_thresh) {
+        upper_thresh_len = strlen(upper_thresh) + 1;
+        HYPERCALL_BOUNCE_SET_SIZE(upper_thresh, upper_thresh_len);
+    }
+
+    if ( (ret = xc_hypercall_bounce_pre(xch, lower_thresh)) )
+        goto out;
+    if ( (ret = xc_hypercall_bounce_pre(xch, upper_thresh)) )
+        goto out;
+
+    if ( guest )
+    {
+        set_xen_guest_handle(sysctl.u.loglvl.host.lower_thresh,
+                             HYPERCALL_BUFFER_NULL);
+        sysctl.u.loglvl.host.lower_thresh_len = 0;
+        set_xen_guest_handle(sysctl.u.loglvl.host.upper_thresh,
+                             HYPERCALL_BUFFER_NULL);
+        sysctl.u.loglvl.host.upper_thresh_len = 0;
+        set_xen_guest_handle(sysctl.u.loglvl.guest.lower_thresh,
+                             lower_thresh);
+        sysctl.u.loglvl.guest.lower_thresh_len = lower_thresh_len;
+        set_xen_guest_handle(sysctl.u.loglvl.guest.upper_thresh,
+                             upper_thresh);
+        sysctl.u.loglvl.guest.upper_thresh_len = upper_thresh_len;
+    }
+    else
+    {
+        set_xen_guest_handle(sysctl.u.loglvl.host.lower_thresh,
+                             lower_thresh);
+        sysctl.u.loglvl.host.lower_thresh_len = lower_thresh_len;
+        set_xen_guest_handle(sysctl.u.loglvl.host.upper_thresh,
+                             upper_thresh);
+        sysctl.u.loglvl.host.upper_thresh_len = upper_thresh_len;
+
+        set_xen_guest_handle(sysctl.u.loglvl.guest.lower_thresh,
+                             HYPERCALL_BUFFER_NULL);
+        sysctl.u.loglvl.guest.lower_thresh_len = 0;
+        set_xen_guest_handle(sysctl.u.loglvl.guest.upper_thresh,
+                             HYPERCALL_BUFFER_NULL);
+        sysctl.u.loglvl.guest.upper_thresh_len = 0;
+    }
+
+    ret = do_sysctl(xch, &sysctl);
+
+out:
+    xc_hypercall_bounce_post(xch, lower_thresh);
+    xc_hypercall_bounce_post(xch, upper_thresh);
+    return ret;
+}
+
 int xc_physinfo(xc_interface *xch,
                 xc_physinfo_t *put_info)
 {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.