xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
	haozhong.zhang@intel.com, wei.liu2@citrix.com,
	zhangchen.fnst@cn.fujitsu.com, ian.jackson@eu.citrix.com,
	yi.y.sun@linux.intel.com
Subject: [PATCH v2 10/12] libxl: carve out tmem specific functions from libxl.c
Date: Thu,  9 Feb 2017 10:30:23 +0100	[thread overview]
Message-ID: <20170209093025.20849-11-jgross@suse.com> (raw)
In-Reply-To: <20170209093025.20849-1-jgross@suse.com>

libxl.c has grown to an uncomfortable size. Carve out the tmem
related functions to libxl_tmem.c.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/libxl/Makefile     |   2 +-
 tools/libxl/libxl.c      | 142 ----------------------------------------
 tools/libxl/libxl_tmem.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 168 insertions(+), 143 deletions(-)
 create mode 100644 tools/libxl/libxl_tmem.c

diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 4b05e34..99ddae1 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -137,7 +137,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
 			libxl_qmp.o libxl_event.o libxl_fork.o \
 			libxl_dom_suspend.o libxl_dom_save.o libxl_usb.o \
 			libxl_vtpm.o libxl_nic.o libxl_disk.o libxl_console.o \
-			libxl_cpupool.o libxl_mem.o libxl_sched.o \
+			libxl_cpupool.o libxl_mem.o libxl_sched.o libxl_tmem.o \
                         $(LIBXL_OBJS-y)
 LIBXL_OBJS += libxl_genid.o
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 3cf4a56..67c0a13 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2105,148 +2105,6 @@ uint32_t libxl_vm_get_start_time(libxl_ctx *ctx, uint32_t domid)
     return ret;
 }
 
-char *libxl_tmem_list(libxl_ctx *ctx, uint32_t domid, int use_long)
-{
-    int r;
-    char _buf[32768];
-    GC_INIT(ctx);
-
-    r = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_LIST, domid, 32768,
-                        use_long, _buf);
-    if (r < 0) {
-        LOGED(ERROR, domid, "Can not get tmem list");
-        GC_FREE;
-        return NULL;
-    }
-
-    GC_FREE;
-    return strdup(_buf);
-}
-
-int libxl_tmem_freeze(libxl_ctx *ctx, uint32_t domid)
-{
-    int r, rc;
-    GC_INIT(ctx);
-
-    r = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_FREEZE, domid, 0, 0,
-                        NULL);
-    if (r < 0) {
-        LOGED(ERROR, domid, "Can not freeze tmem pools");
-        rc = ERROR_FAIL;
-        goto out;
-    }
-
-    rc = 0;
-out:
-    GC_FREE;
-    return rc;
-}
-
-int libxl_tmem_thaw(libxl_ctx *ctx, uint32_t domid)
-{
-    int r, rc;
-    GC_INIT(ctx);
-
-    r = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_THAW, domid, 0, 0,
-                        NULL);
-    if (r < 0) {
-        LOGED(ERROR, domid, "Can not thaw tmem pools");
-        rc = ERROR_FAIL;
-        goto out;
-    }
-
-    rc = 0;
-out:
-    GC_FREE;
-    return rc;
-}
-
-static int32_t tmem_setop_from_string(char *set_name, uint32_t val,
-                                      xen_tmem_client_t *info)
-{
-    if (!strcmp(set_name, "weight"))
-        info->weight = val;
-    else if (!strcmp(set_name, "compress"))
-        info->flags.u.compress = val;
-    else
-        return -1;
-
-    return 0;
-}
-
-int libxl_tmem_set(libxl_ctx *ctx, uint32_t domid, char* name, uint32_t set)
-{
-    int r, rc;
-    xen_tmem_client_t info;
-    GC_INIT(ctx);
-
-    r = xc_tmem_control(ctx->xch, -1 /* pool_id */,
-                        XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO,
-                        domid, sizeof(info), 0 /* arg */, &info);
-    if (r < 0) {
-        LOGED(ERROR, domid, "Can not get tmem data!");
-        rc = ERROR_FAIL;
-        goto out;
-    }
-    rc = tmem_setop_from_string(name, set, &info);
-    if (rc == -1) {
-        LOGEVD(ERROR, -1, domid, "Invalid set, valid sets are <weight|compress>");
-        rc = ERROR_INVAL;
-        goto out;
-    }
-    r = xc_tmem_control(ctx->xch, -1 /* pool_id */,
-                        XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO,
-                        domid, sizeof(info), 0 /* arg */, &info);
-    if (r < 0) {
-        LOGED(ERROR, domid, "Can not set tmem %s", name);
-        rc = ERROR_FAIL;
-        goto out;
-    }
-
-    rc = 0;
-out:
-    GC_FREE;
-    return rc;
-}
-
-int libxl_tmem_shared_auth(libxl_ctx *ctx, uint32_t domid,
-                           char* uuid, int auth)
-{
-    int r, rc;
-    GC_INIT(ctx);
-
-    r = xc_tmem_auth(ctx->xch, domid, uuid, auth);
-    if (r < 0) {
-        LOGED(ERROR, domid, "Can not set tmem shared auth");
-        rc = ERROR_FAIL;
-        goto out;
-    }
-
-    rc = 0;
-out:
-    GC_FREE;
-    return rc;
-}
-
-int libxl_tmem_freeable(libxl_ctx *ctx)
-{
-    int r, rc;
-    GC_INIT(ctx);
-
-    r = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB,
-                        -1, 0, 0, 0);
-    if (r < 0) {
-        LOGE(ERROR, "Can not get tmem freeable memory");
-        rc = ERROR_FAIL;
-        goto out;
-    }
-
-    rc = 0;
-out:
-    GC_FREE;
-    return rc;
-}
-
 static int fd_set_flags(libxl_ctx *ctx, int fd,
                         int fcntlgetop, int fcntlsetop, const char *fl,
                         int flagmask, int set_p)
diff --git a/tools/libxl/libxl_tmem.c b/tools/libxl/libxl_tmem.c
new file mode 100644
index 0000000..2bee8d1
--- /dev/null
+++ b/tools/libxl/libxl_tmem.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2009-2017 Citrix Ltd and other contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h"
+
+#include "libxl_internal.h"
+
+char *libxl_tmem_list(libxl_ctx *ctx, uint32_t domid, int use_long)
+{
+    int r;
+    char _buf[32768];
+    GC_INIT(ctx);
+
+    r = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_LIST, domid, 32768,
+                        use_long, _buf);
+    if (r < 0) {
+        LOGED(ERROR, domid, "Can not get tmem list");
+        GC_FREE;
+        return NULL;
+    }
+
+    GC_FREE;
+    return strdup(_buf);
+}
+
+int libxl_tmem_freeze(libxl_ctx *ctx, uint32_t domid)
+{
+    int r, rc;
+    GC_INIT(ctx);
+
+    r = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_FREEZE, domid, 0, 0,
+                        NULL);
+    if (r < 0) {
+        LOGED(ERROR, domid, "Can not freeze tmem pools");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    rc = 0;
+out:
+    GC_FREE;
+    return rc;
+}
+
+int libxl_tmem_thaw(libxl_ctx *ctx, uint32_t domid)
+{
+    int r, rc;
+    GC_INIT(ctx);
+
+    r = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_THAW, domid, 0, 0,
+                        NULL);
+    if (r < 0) {
+        LOGED(ERROR, domid, "Can not thaw tmem pools");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    rc = 0;
+out:
+    GC_FREE;
+    return rc;
+}
+
+static int32_t tmem_setop_from_string(char *set_name, uint32_t val,
+                                      xen_tmem_client_t *info)
+{
+    if (!strcmp(set_name, "weight"))
+        info->weight = val;
+    else if (!strcmp(set_name, "compress"))
+        info->flags.u.compress = val;
+    else
+        return -1;
+
+    return 0;
+}
+
+int libxl_tmem_set(libxl_ctx *ctx, uint32_t domid, char* name, uint32_t set)
+{
+    int r, rc;
+    xen_tmem_client_t info;
+    GC_INIT(ctx);
+
+    r = xc_tmem_control(ctx->xch, -1 /* pool_id */,
+                        XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO,
+                        domid, sizeof(info), 0 /* arg */, &info);
+    if (r < 0) {
+        LOGED(ERROR, domid, "Can not get tmem data!");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    rc = tmem_setop_from_string(name, set, &info);
+    if (rc == -1) {
+        LOGEVD(ERROR, -1, domid, "Invalid set, valid sets are <weight|compress>");
+        rc = ERROR_INVAL;
+        goto out;
+    }
+    r = xc_tmem_control(ctx->xch, -1 /* pool_id */,
+                        XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO,
+                        domid, sizeof(info), 0 /* arg */, &info);
+    if (r < 0) {
+        LOGED(ERROR, domid, "Can not set tmem %s", name);
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    rc = 0;
+out:
+    GC_FREE;
+    return rc;
+}
+
+int libxl_tmem_shared_auth(libxl_ctx *ctx, uint32_t domid,
+                           char* uuid, int auth)
+{
+    int r, rc;
+    GC_INIT(ctx);
+
+    r = xc_tmem_auth(ctx->xch, domid, uuid, auth);
+    if (r < 0) {
+        LOGED(ERROR, domid, "Can not set tmem shared auth");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    rc = 0;
+out:
+    GC_FREE;
+    return rc;
+}
+
+int libxl_tmem_freeable(libxl_ctx *ctx)
+{
+    int r, rc;
+    GC_INIT(ctx);
+
+    r = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB,
+                        -1, 0, 0, 0);
+    if (r < 0) {
+        LOGE(ERROR, "Can not get tmem freeable memory");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    rc = 0;
+out:
+    GC_FREE;
+    return rc;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.10.2


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

  parent reply	other threads:[~2017-02-09  9:30 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09  9:30 [PATCH v2 00/12] libxl: split up libxl.c Juergen Gross
2017-02-09  9:30 ` [PATCH v2 01/12] libxl: adjust copyright comment of libxl.c Juergen Gross
2017-02-09 10:18   ` Wei Liu
2017-02-09 11:37   ` Ian Jackson
2017-02-09  9:30 ` [PATCH v2 02/12] libxl: make some functions global to prepare splitting up libxl.c Juergen Gross
2017-02-09 11:36   ` Ian Jackson
2017-02-09 11:42     ` Juergen Gross
2017-02-09 15:44       ` Wei Liu
2017-02-09 16:06         ` Juergen Gross
2017-02-09  9:30 ` [PATCH v2 03/12] libxl: white space cleanup Juergen Gross
2017-02-09 11:37   ` Ian Jackson
2017-02-09  9:30 ` [PATCH v2 04/12] libxl: carve out cpupool specific functions from libxl.c Juergen Gross
2017-02-09  9:30 ` [PATCH v2 05/12] libxl: carve out scheduler " Juergen Gross
2017-02-09  9:30 ` [PATCH v2 06/12] libxl: carve out disk " Juergen Gross
2017-02-09  9:30 ` [PATCH v2 07/12] libxl: carve out console " Juergen Gross
2017-02-09  9:30 ` [PATCH v2 08/12] libxl: carve out memory " Juergen Gross
2017-02-09  9:30 ` [PATCH v2 09/12] libxl: move device specific functions out of libxl.c Juergen Gross
2017-02-09  9:30 ` Juergen Gross [this message]
2017-02-09  9:30 ` [PATCH v2 11/12] libxl: carve out domain specific functions from libxl.c Juergen Gross
2017-02-09  9:30 ` [PATCH v2 12/12] libxl: make one function static Juergen Gross
2017-02-09 11:42   ` Ian Jackson
2017-02-09 10:22 ` [PATCH v2 00/12] libxl: split up libxl.c Wei Liu
2017-02-09 11:41 ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170209093025.20849-11-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=haozhong.zhang@intel.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    --cc=yi.y.sun@linux.intel.com \
    --cc=zhangchen.fnst@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).