[libvirt] [PATCH v2 4/9] admin: Move remote admin API version to a separate module
Martin Kletzander
mkletzan at redhat.com
Tue Nov 3 18:47:32 UTC 2015
On Fri, Oct 16, 2015 at 08:12:21PM +0200, Erik Skultety wrote:
>By moving the remote version into a separate module, we gain a slightly
>better maintainability in the long run than just by leaving it in one
>place with the existing libvirt-admin library which can start getting
>pretty messy later on.
>---
> src/admin/admin_remote.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++
> src/libvirt-admin.c | 115 +--------------------------------------
> 2 files changed, 137 insertions(+), 114 deletions(-)
> create mode 100644 src/admin/admin_remote.c
>
>diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c
>new file mode 100644
>index 0000000..b8e6607
>--- /dev/null
>+++ b/src/admin/admin_remote.c
>@@ -0,0 +1,136 @@
>+/*
>+ * admin_remote.c
>+ *
>+ * Copyright (C) 2015 Red Hat, Inc.
>+ *
>+ * This library 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; either
>+ * version 2.1 of the License, or (at your option) any later version.
>+ *
>+ * This library 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.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this library. If not, see
>+ * <http://www.gnu.org/licenses/>.
>+ *
>+ * Author: Erik Skultety <eskultet at redhat.com>
>+ */
>+
>+#include <config.h>
>+#include <rpc/rpc.h>
>+#include "admin_protocol.h"
>+
>+typedef struct _remoteAdminPriv remoteAdminPriv;
>+typedef remoteAdminPriv *remoteAdminPrivPtr;
>+
>+struct _remoteAdminPriv {
>+ virObjectLockable parent;
>+
>+ int counter;
>+ virNetClientPtr client;
>+ virNetClientProgramPtr program;
>+};
>+
>+static virClassPtr remoteAdminPrivClass;
>+
>+static void
>+remoteAdminPrivDispose(void *opaque)
>+{
>+ remoteAdminPrivPtr priv = opaque;
>+
>+ virObjectUnref(priv->program);
>+ virObjectUnref(priv->client);
>+}
>+
>+
>+static int
>+callFull(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
>+ remoteAdminPrivPtr priv,
>+ int *fdin,
>+ size_t fdinlen,
>+ int **fdout,
>+ size_t *fdoutlen,
>+ int proc_nr,
>+ xdrproc_t args_filter, char *args,
>+ xdrproc_t ret_filter, char *ret)
>+{
>+ int rv;
>+ virNetClientProgramPtr prog = priv->program;
>+ int counter = priv->counter++;
>+ virNetClientPtr client = priv->client;
>+
>+ /* Unlock, so that if we get any async events/stream data
>+ * while processing the RPC, we don't deadlock when our
>+ * callbacks for those are invoked
>+ */
>+ virObjectRef(priv);
>+ virObjectUnlock(priv);
>+
>+ rv = virNetClientProgramCall(prog,
>+ client,
>+ counter,
>+ proc_nr,
>+ fdinlen, fdin,
>+ fdoutlen, fdout,
>+ args_filter, args,
>+ ret_filter, ret);
>+
>+ virObjectLock(priv);
>+ virObjectUnref(priv);
>+
>+ return rv;
>+}
>+
>+static int
>+call(virAdmConnectPtr conn,
>+ unsigned int flags,
>+ int proc_nr,
>+ xdrproc_t args_filter, char *args,
>+ xdrproc_t ret_filter, char *ret)
>+{
>+ virCheckFlags(0, -1);
>+
>+ return callFull(conn, conn->privateData,
>+ NULL, 0, NULL, NULL, proc_nr,
>+ args_filter, args, ret_filter, ret);
>+}
>+
>+#include "admin_client.h"
>+
>+static void
>+remoteAdminPrivFree(void *opaque)
>+{
>+ virAdmConnectPtr conn = opaque;
>+
>+ remoteAdminConnectClose(conn);
>+ virObjectUnref(conn->privateData);
>+}
>+
>+static remoteAdminPrivPtr
>+remoteAdminPrivNew(const char *sock_path)
>+{
>+ remoteAdminPrivPtr priv = NULL;
>+
>+ if (!(priv = virObjectLockableNew(remoteAdminPrivClass)))
>+ goto error;
>+
>+ if (!(priv->client = virNetClientNewUNIX(sock_path, false, NULL)))
>+ goto error;
>+
>+ if (!(priv->program = virNetClientProgramNew(ADMIN_PROGRAM,
>+ ADMIN_PROTOCOL_VERSION,
>+ NULL, 0, NULL)))
>+ goto error;
>+
>+ if (virNetClientAddProgram(priv->client, priv->program) < 0)
>+ goto error;
>+
>+ return priv;
>+ error:
>+ virObjectUnref(priv);
>+ return NULL;
>+}
>diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
>index f0824dd..cdc712c 100644
>--- a/src/libvirt-admin.c
>+++ b/src/libvirt-admin.c
>@@ -22,8 +22,6 @@
>
> #include <config.h>
>
>-#include <rpc/rpc.h>
>-
> #include "internal.h"
> #include "datatypes.h"
> #include "configmake.h"
>@@ -44,121 +42,10 @@
>
> VIR_LOG_INIT("libvirt-admin");
>
>-
>-typedef struct _remoteAdminPriv remoteAdminPriv;
>-typedef remoteAdminPriv *remoteAdminPrivPtr;
>-
>-struct _remoteAdminPriv {
>- virObjectLockable parent;
>-
>- int counter;
>- virNetClientPtr client;
>- virNetClientProgramPtr program;
>-};
>-
>-static virClassPtr remoteAdminPrivClass;
>-
>-static void
>-remoteAdminPrivDispose(void *opaque)
>-{
>- remoteAdminPrivPtr priv = opaque;
>-
>- virObjectUnref(priv->program);
>- virObjectUnref(priv->client);
>-}
>-
>-
>-static int
>-callFull(virAdmConnectPtr conn ATTRIBUTE_UNUSED,
>- remoteAdminPrivPtr priv,
>- int *fdin,
>- size_t fdinlen,
>- int **fdout,
>- size_t *fdoutlen,
>- int proc_nr,
>- xdrproc_t args_filter, char *args,
>- xdrproc_t ret_filter, char *ret)
>-{
>- int rv;
>- virNetClientProgramPtr prog = priv->program;
>- int counter = priv->counter++;
>- virNetClientPtr client = priv->client;
>-
>- /* Unlock, so that if we get any async events/stream data
>- * while processing the RPC, we don't deadlock when our
>- * callbacks for those are invoked
>- */
>- virObjectRef(priv);
>- virObjectUnlock(priv);
>-
>- rv = virNetClientProgramCall(prog,
>- client,
>- counter,
>- proc_nr,
>- fdinlen, fdin,
>- fdoutlen, fdout,
>- args_filter, args,
>- ret_filter, ret);
>-
>- virObjectLock(priv);
>- virObjectUnref(priv);
>-
>- return rv;
>-}
>-
>-static int
>-call(virAdmConnectPtr conn,
>- unsigned int flags,
>- int proc_nr,
>- xdrproc_t args_filter, char *args,
>- xdrproc_t ret_filter, char *ret)
>-{
>- virCheckFlags(0, -1);
>-
>- return callFull(conn, conn->privateData,
>- NULL, 0, NULL, NULL, proc_nr,
>- args_filter, args, ret_filter, ret);
>-}
>-
>-#include "admin_protocol.h"
>-#include "admin_client.h"
>-
> static bool virAdmGlobalError;
> static virOnceControl virAdmGlobalOnce = VIR_ONCE_CONTROL_INITIALIZER;
>
[...]
many lines
[...]
>+#include "admin_remote.c"
>
Simple code movement, ACK, although I would just move the include so
that the virAdmGlobal* things are together. I have no idea why I had
them so far apart...
Martin
> static void
> virAdmGlobalInit(void)
>--
>2.4.3
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20151103/b895602a/attachment-0001.sig>
More information about the libvir-list
mailing list