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>,
	wei.liu2@citrix.com, ian.jackson@eu.citrix.com
Subject: [PATCH v4 2/6] xenstore: Split out XS_CONTROL action to dedicated source file
Date: Fri, 24 Feb 2017 07:21:41 +0100	[thread overview]
Message-ID: <20170224062145.2041-3-jgross@suse.com> (raw)
In-Reply-To: <20170224062145.2041-1-jgross@suse.com>

Move the XS_CONTROL handling of xenstored to a new source file
xenstored_control.c.

In order to avoid making get_string() in xenstored_core.c globally
visible use strlen() instead, which is save in this context due to
xs_count_strings() before returned a value > 1.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
---
 tools/xenstore/Makefile            |  4 +++-
 tools/xenstore/xenstored_control.c | 46 ++++++++++++++++++++++++++++++++++++++
 tools/xenstore/xenstored_control.h | 19 ++++++++++++++++
 tools/xenstore/xenstored_core.c    | 27 ++--------------------
 tools/xenstore/xenstored_core.h    |  2 +-
 5 files changed, 71 insertions(+), 27 deletions(-)
 create mode 100644 tools/xenstore/xenstored_control.c
 create mode 100644 tools/xenstore/xenstored_control.h

diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 36b6fd4..bdca108 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -23,7 +23,9 @@ LDFLAGS += $(LDFLAGS-y)
 CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod
 CLIENTS += xenstore-write xenstore-ls xenstore-watch
 
-XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o
+XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o
+XENSTORED_OBJS += xenstored_transaction.o xenstored_control.o
+XENSTORED_OBJS += xs_lib.o talloc.o utils.o tdb.o hashtable.o
 
 XENSTORED_OBJS_$(CONFIG_Linux) = xenstored_posix.o
 XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o xenstored_posix.o xenstored_probes.o
diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c
new file mode 100644
index 0000000..f169d23
--- /dev/null
+++ b/tools/xenstore/xenstored_control.c
@@ -0,0 +1,46 @@
+/*
+    Interactive commands for Xen Store Daemon.
+    Copyright (C) 2017 Juergen Gross, SUSE Linux GmbH
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <errno.h>
+
+#include "utils.h"
+#include "xenstored_core.h"
+#include "xenstored_control.h"
+
+int do_control(struct connection *conn, struct buffered_data *in)
+{
+	int num;
+
+	if (conn->id != 0)
+		return EACCES;
+
+	num = xs_count_strings(in->buffer, in->used);
+
+	if (streq(in->buffer, "print")) {
+		if (num < 2)
+			return EINVAL;
+		xprintf("control: %s", in->buffer + strlen(in->buffer) + 1);
+	}
+
+	if (streq(in->buffer, "check"))
+		check_store();
+
+	send_ack(conn, XS_CONTROL);
+
+	return 0;
+}
diff --git a/tools/xenstore/xenstored_control.h b/tools/xenstore/xenstored_control.h
new file mode 100644
index 0000000..207e0a6
--- /dev/null
+++ b/tools/xenstore/xenstored_control.h
@@ -0,0 +1,19 @@
+/*
+    Interactive commands for Xen Store Daemon.
+    Copyright (C) 2017 Juergen Gross, SUSE Linux GmbH
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; If not, see <http://www.gnu.org/licenses/>.
+*/
+
+int do_control(struct connection *conn, struct buffered_data *in);
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 97e7e31..94c0a1d 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -51,6 +51,7 @@
 #include "xenstored_watch.h"
 #include "xenstored_transaction.h"
 #include "xenstored_domain.h"
+#include "xenstored_control.h"
 #include "tdb.h"
 
 #include "hashtable.h"
@@ -84,7 +85,6 @@ static TDB_CONTEXT *tdb_ctx = NULL;
 static bool trigger_talloc_report = false;
 
 static void corrupt(struct connection *conn, const char *fmt, ...);
-static void check_store(void);
 static const char *sockmsg_string(enum xsd_sockmsg_type type);
 
 #define log(...)							\
@@ -1261,29 +1261,6 @@ static int do_set_perms(struct connection *conn, struct buffered_data *in)
 	return 0;
 }
 
-static int do_control(struct connection *conn, struct buffered_data *in)
-{
-	int num;
-
-	if (conn->id != 0)
-		return EACCES;
-
-	num = xs_count_strings(in->buffer, in->used);
-
-	if (streq(in->buffer, "print")) {
-		if (num < 2)
-			return EINVAL;
-		xprintf("control: %s", in->buffer + get_string(in, 0));
-	}
-
-	if (streq(in->buffer, "check"))
-		check_store();
-
-	send_ack(conn, XS_CONTROL);
-
-	return 0;
-}
-
 static struct {
 	const char *str;
 	int (*func)(struct connection *conn, struct buffered_data *in);
@@ -1764,7 +1741,7 @@ static void clean_store(struct hashtable *reachable)
 }
 
 
-static void check_store(void)
+void check_store(void)
 {
 	char * root = talloc_strdup(NULL, "/");
 	struct hashtable * reachable =
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index f6a56f7..89c1d75 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -158,7 +158,7 @@ TDB_CONTEXT *tdb_context(struct connection *conn);
 bool replace_tdb(const char *newname, TDB_CONTEXT *newtdb);
 
 struct connection *new_connection(connwritefn_t *write, connreadfn_t *read);
-
+void check_store(void);
 
 /* Is this a valid node name? */
 bool is_valid_nodename(const char *node);
-- 
2.10.2


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

  parent reply	other threads:[~2017-02-24  6:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24  6:21 [PATCH v4 0/6] xenstore: enhance runtime debug capabilities Juergen Gross
2017-02-24  6:21 ` [PATCH v4 1/6] xenstore: rename XS_DEBUG wire command Juergen Gross
2017-02-24  6:21 ` Juergen Gross [this message]
2017-02-24  6:21 ` [PATCH v4 3/6] xenstore: enhance control command support Juergen Gross
2017-02-24 10:02   ` Wei Liu
2017-02-24  6:21 ` [PATCH v4 4/6] xenstore: add support for changing log functionality dynamically Juergen Gross
2017-02-24  6:21 ` [PATCH v4 5/6] xenstore: make memory report available via XS_CONTROL Juergen Gross
2017-02-24  6:21 ` [PATCH v4 6/6] xenstore: remove memory report command line support Juergen Gross

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=20170224062145.2041-3-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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).