From patchwork Thu Jul 10 16:15:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 33442 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6AE6D203F4 for ; Thu, 10 Jul 2014 16:21:29 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id eu11sf61008265pac.10 for ; Thu, 10 Jul 2014 09:21:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=hSChOSFgrU4u8tjun/0QrgM7NvMiirZQt6n6c21tTZo=; b=j7XGeHsOatppWFdCyIKs0ZQyUTTOtmbkPtzuq5vGGHxd9g81ZdTgQv9t4gVKI46jwu wPAItNYvkl/Tq99kMlTaGktiScYWyC89WGV0xYOrZ+gwcfiWWc94u0wlbIbDIvIsFd5J fOnxPRulFFlVZ2Q8DdMmCGVZKPNOMod38bcY6h3O8vwymPB5hSnTh/ikj5W6zNJwfNk3 Xha2dDpBqyYzlmBVe88bfnZwSzuwjpNcpukCu6PwSTRNPYkS4ohoqLvbq6cCAZrJHSvv CoBbAXOJ0nOm8H/TzNZqiSsH7yxKwGxnn8vZ9kj8kr6J7Xh/HFRAKsW/e01ezQZ8t4A3 jMjg== X-Gm-Message-State: ALoCoQnD+b58UptDwlcp91Mqvtp/Yziiyr7eTH4kPL5HZspb6jRaVcJFJHblLMGdA9SobP5FVfjQ X-Received: by 10.66.102.68 with SMTP id fm4mr23523682pab.27.1405009288732; Thu, 10 Jul 2014 09:21:28 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.3 with SMTP id t3ls115723qga.82.gmail; Thu, 10 Jul 2014 09:21:28 -0700 (PDT) X-Received: by 10.221.41.135 with SMTP id tu7mr617158vcb.70.1405009288607; Thu, 10 Jul 2014 09:21:28 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id o14si3082660vdi.42.2014.07.10.09.21.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 10 Jul 2014 09:21:28 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id il7so11298697vcb.27 for ; Thu, 10 Jul 2014 09:21:28 -0700 (PDT) X-Received: by 10.52.144.235 with SMTP id sp11mr22461766vdb.25.1405009288473; Thu, 10 Jul 2014 09:21:28 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp148268vcb; Thu, 10 Jul 2014 09:21:27 -0700 (PDT) X-Received: by 10.50.30.228 with SMTP id v4mr22874610igh.26.1405009287767; Thu, 10 Jul 2014 09:21:27 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id n4si13934000igp.56.2014.07.10.09.21.26 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 10 Jul 2014 09:21:27 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X5H4o-0007os-Kn; Thu, 10 Jul 2014 16:20:06 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X5H4m-0007nn-Q0 for xen-devel@lists.xensource.com; Thu, 10 Jul 2014 16:20:05 +0000 Received: from [85.158.139.211:8406] by server-14.bemta-5.messagelabs.com id ED/78-27057-43DBEB35; Thu, 10 Jul 2014 16:20:04 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1405009200!9514446!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 25396 invoked from network); 10 Jul 2014 16:20:02 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-10.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 10 Jul 2014 16:20:02 -0000 X-IronPort-AV: E=Sophos;i="5.01,638,1400025600"; d="scan'208";a="151722710" Received: from accessns.citrite.net (HELO FTLPEX01CL01.citrite.net) ([10.9.154.239]) by FTLPIPO02.CITRIX.COM with ESMTP; 10 Jul 2014 16:16:56 +0000 Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Thu, 10 Jul 2014 12:16:54 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1X5H1c-0001MU-JG; Thu, 10 Jul 2014 17:16:48 +0100 From: Stefano Stabellini To: Date: Thu, 10 Jul 2014 17:15:59 +0100 Message-ID: <1405008961-17187-1-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian.Jackson@eu.citrix.com, Ian.Campbell@citrix.com, Stefano Stabellini Subject: [Xen-devel] [PATCH 1/3] move xenstore public headers to include subdir X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: Signed-off-by: Stefano Stabellini --- tools/xenstore/Makefile | 9 +- tools/xenstore/compat/xs.h | 2 - tools/xenstore/compat/xs_lib.h | 2 - tools/xenstore/include/compat/xs.h | 2 + tools/xenstore/include/compat/xs_lib.h | 2 + tools/xenstore/include/xenstore.h | 257 ++++++++++++++++++++++++++++++++ tools/xenstore/include/xenstore_lib.h | 85 +++++++++++ tools/xenstore/xenstore.h | 257 -------------------------------- tools/xenstore/xenstore_lib.h | 85 ----------- 9 files changed, 351 insertions(+), 350 deletions(-) delete mode 100644 tools/xenstore/compat/xs.h delete mode 100644 tools/xenstore/compat/xs_lib.h create mode 100644 tools/xenstore/include/compat/xs.h create mode 100644 tools/xenstore/include/compat/xs_lib.h create mode 100644 tools/xenstore/include/xenstore.h create mode 100644 tools/xenstore/include/xenstore_lib.h delete mode 100644 tools/xenstore/xenstore.h delete mode 100644 tools/xenstore/xenstore_lib.h diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile index e34bd41..2947d3e 100644 --- a/tools/xenstore/Makefile +++ b/tools/xenstore/Makefile @@ -6,6 +6,7 @@ MINOR = 3 CFLAGS += -Werror CFLAGS += -I. +CFLAGS += -I./include CFLAGS += $(CFLAGS_libxenctrl) CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod @@ -126,10 +127,10 @@ install: all ln -sf libxenstore.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenstore.so.$(MAJOR) ln -sf libxenstore.so.$(MAJOR) $(DESTDIR)$(LIBDIR)/libxenstore.so $(INSTALL_DATA) libxenstore.a $(DESTDIR)$(LIBDIR) - $(INSTALL_DATA) xenstore.h $(DESTDIR)$(INCLUDEDIR) - $(INSTALL_DATA) xenstore_lib.h $(DESTDIR)$(INCLUDEDIR) - $(INSTALL_DATA) compat/xs.h $(DESTDIR)$(INCLUDEDIR)/xenstore-compat/xs.h - $(INSTALL_DATA) compat/xs_lib.h $(DESTDIR)$(INCLUDEDIR)/xenstore-compat/xs_lib.h + $(INSTALL_DATA) include/xenstore.h $(DESTDIR)$(INCLUDEDIR) + $(INSTALL_DATA) include/xenstore_lib.h $(DESTDIR)$(INCLUDEDIR) + $(INSTALL_DATA) include/compat/xs.h $(DESTDIR)$(INCLUDEDIR)/xenstore-compat/xs.h + $(INSTALL_DATA) include/compat/xs_lib.h $(DESTDIR)$(INCLUDEDIR)/xenstore-compat/xs_lib.h ln -sf xenstore-compat/xs.h $(DESTDIR)$(INCLUDEDIR)/xs.h ln -sf xenstore-compat/xs_lib.h $(DESTDIR)$(INCLUDEDIR)/xs_lib.h diff --git a/tools/xenstore/compat/xs.h b/tools/xenstore/compat/xs.h deleted file mode 100644 index 99cf39b..0000000 --- a/tools/xenstore/compat/xs.h +++ /dev/null @@ -1,2 +0,0 @@ -#warning xs.h is deprecated use xenstore.h instead -#include diff --git a/tools/xenstore/compat/xs_lib.h b/tools/xenstore/compat/xs_lib.h deleted file mode 100644 index ad81b54..0000000 --- a/tools/xenstore/compat/xs_lib.h +++ /dev/null @@ -1,2 +0,0 @@ -#warning xs_lib.h is deprecated use xenstore_lib.h instead -#include diff --git a/tools/xenstore/include/compat/xs.h b/tools/xenstore/include/compat/xs.h new file mode 100644 index 0000000..99cf39b --- /dev/null +++ b/tools/xenstore/include/compat/xs.h @@ -0,0 +1,2 @@ +#warning xs.h is deprecated use xenstore.h instead +#include diff --git a/tools/xenstore/include/compat/xs_lib.h b/tools/xenstore/include/compat/xs_lib.h new file mode 100644 index 0000000..ad81b54 --- /dev/null +++ b/tools/xenstore/include/compat/xs_lib.h @@ -0,0 +1,2 @@ +#warning xs_lib.h is deprecated use xenstore_lib.h instead +#include diff --git a/tools/xenstore/include/xenstore.h b/tools/xenstore/include/xenstore.h new file mode 100644 index 0000000..fdf5e76 --- /dev/null +++ b/tools/xenstore/include/xenstore.h @@ -0,0 +1,257 @@ +/* + Xen Store Daemon providing simple tree-like database. + Copyright (C) 2005 Rusty Russell IBM Corporation + + 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, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef XENSTORE_H +#define XENSTORE_H + +#include + +#define XBT_NULL 0 + +#define XS_OPEN_READONLY 1UL<<0 +#define XS_OPEN_SOCKETONLY 1UL<<1 + +/* + * Setting XS_UNWATCH_FILTER arranges that after xs_unwatch, no + * related watch events will be delivered via xs_read_watch. But + * this relies on the couple token, subpath is unique. + * + * XS_UNWATCH_FILTER clear XS_UNWATCH_FILTER set + * + * Even after xs_unwatch, "stale" After xs_unwatch returns, no + * instances of the watch event watch events with the same + * may be delivered. token and with the same subpath + * will be delivered. + * + * A path and a subpath can be The application must avoid + * register with the same token. registering a path (/foo/) and + * a subpath (/foo/bar) with the + * same path until a successful + * xs_unwatch for the first watch + * has returned. + */ +#define XS_UNWATCH_FILTER 1UL<<2 + +struct xs_handle; +typedef uint32_t xs_transaction_t; + +/* IMPORTANT: For details on xenstore protocol limits, see + * docs/misc/xenstore.txt in the Xen public source repository, and use the + * XENSTORE_*_MAX limit macros defined in xen/io/xs_wire.h. + */ + +/* On failure, these routines set errno. */ + +/* Open a connection to the xs daemon. + * Attempts to make a connection over the socket interface, + * and if it fails, then over the xenbus interface. + * Mode 0 specifies read-write access, XS_OPEN_READONLY for + * read-only access. + * Returns a handle or NULL. + */ +struct xs_handle *xs_open(unsigned long flags); + +/* Close the connection to the xs daemon. */ +void xs_close(struct xs_handle *xsh); + +/* Connect to the xs daemon. + * Returns a handle or NULL. + * Deprecated, please use xs_open(0) instead + */ +struct xs_handle *xs_daemon_open(void); +struct xs_handle *xs_domain_open(void); + +/* Connect to the xs daemon (readonly for non-root clients). + * Returns a handle or NULL. + * Deprecated, please use xs_open(XS_OPEN_READONLY) instead + */ +struct xs_handle *xs_daemon_open_readonly(void); + +/* Close the connection to the xs daemon. + * Deprecated, please use xs_close() instead + */ +void xs_daemon_close(struct xs_handle *); + +/* Throw away the connection to the xs daemon, for use after fork(). */ +void xs_daemon_destroy_postfork(struct xs_handle *); + +/* Get contents of a directory. + * Returns a malloced array: call free() on it after use. + * Num indicates size. + */ +char **xs_directory(struct xs_handle *h, xs_transaction_t t, + const char *path, unsigned int *num); + +/* Get the value of a single file, nul terminated. + * Returns a malloced value: call free() on it after use. + * len indicates length in bytes, not including terminator. + */ +void *xs_read(struct xs_handle *h, xs_transaction_t t, + const char *path, unsigned int *len); + +/* Write the value of a single file. + * Returns false on failure. + */ +bool xs_write(struct xs_handle *h, xs_transaction_t t, + const char *path, const void *data, unsigned int len); + +/* Create a new directory. + * Returns false on failure, or success if it already exists. + */ +bool xs_mkdir(struct xs_handle *h, xs_transaction_t t, + const char *path); + +/* Destroy a file or directory (and children). + * Returns false on failure, or if it doesn't exist. + */ +bool xs_rm(struct xs_handle *h, xs_transaction_t t, + const char *path); + +/* Restrict a xenstore handle so that it acts as if it had the + * permissions of domain @domid. The handle must currently be + * using domain 0's credentials. + * + * Returns false on failure, in which case the handle continues + * to use the old credentials, or true on success. + */ +bool xs_restrict(struct xs_handle *h, unsigned domid); + +/* Get permissions of node (first element is owner, first perms is "other"). + * Returns malloced array, or NULL: call free() after use. + */ +struct xs_permissions *xs_get_permissions(struct xs_handle *h, + xs_transaction_t t, + const char *path, unsigned int *num); + +/* Set permissions of node (must be owner). + * Returns false on failure. + */ +bool xs_set_permissions(struct xs_handle *h, xs_transaction_t t, + const char *path, struct xs_permissions *perms, + unsigned int num_perms); + +/* Watch a node for changes (poll on fd to detect, or call read_watch()). + * When the node (or any child) changes, fd will become readable. + * Token is returned when watch is read, to allow matching. + * Returns false on failure. + */ +bool xs_watch(struct xs_handle *h, const char *path, const char *token); + +/* Return the FD to poll on to see if a watch has fired. */ +int xs_fileno(struct xs_handle *h); + +/* Check for node changes. On success, returns a non-NULL pointer ret + * such that ret[0] and ret[1] are valid C strings, namely the + * triggering path (see docs/misc/xenstore.txt) and the token (from + * xs_watch). On error return value is NULL setting errno. + * + * Callers should, after xs_fileno has become readable, repeatedly + * call xs_check_watch until it returns NULL and sets errno to EAGAIN. + * (If the fd became readable, xs_check_watch is allowed to make it no + * longer show up as readable even if future calls to xs_check_watch + * will return more watch events.) + * + * After the caller is finished with the returned information it + * should be freed all in one go with free(ret). + */ +char **xs_check_watch(struct xs_handle *h); + +/* Find out what node change was on (will block if nothing pending). + * Returns array containing the path and token. Use XS_WATCH_* to access these + * elements. Call free() after use. + */ +char **xs_read_watch(struct xs_handle *h, unsigned int *num); + +/* Remove a watch on a node: implicitly acks any outstanding watch. + * Returns false on failure (no watch on that node). + */ +bool xs_unwatch(struct xs_handle *h, const char *path, const char *token); + +/* Start a transaction: changes by others will not be seen during this + * transaction, and changes will not be visible to others until end. + * Returns NULL on failure. + */ +xs_transaction_t xs_transaction_start(struct xs_handle *h); + +/* End a transaction. + * If abandon is true, transaction is discarded instead of committed. + * Returns false on failure: if errno == EAGAIN, you have to restart + * transaction. + */ +bool xs_transaction_end(struct xs_handle *h, xs_transaction_t t, + bool abort); + +/* Introduce a new domain. + * This tells the store daemon about a shared memory page, event channel and + * store path associated with a domain: the domain uses these to communicate. + */ +bool xs_introduce_domain(struct xs_handle *h, + unsigned int domid, + unsigned long mfn, + unsigned int eventchn); + +/* Set the target of a domain + * This tells the store daemon that a domain is targetting another one, so + * it should let it tinker with it. + */ +bool xs_set_target(struct xs_handle *h, + unsigned int domid, + unsigned int target); + +/* Resume a domain. + * Clear the shutdown flag for this domain in the store. + */ +bool xs_resume_domain(struct xs_handle *h, unsigned int domid); + +/* Release a domain. + * Tells the store domain to release the memory page to the domain. + */ +bool xs_release_domain(struct xs_handle *h, unsigned int domid); + +/* Query the home path of a domain. Call free() after use. + */ +char *xs_get_domain_path(struct xs_handle *h, unsigned int domid); + +/* Returns true if child is either equal to parent, or a node underneath + * parent; or false otherwise. Done by string comparison, so relative and + * absolute pathnames never in a parent/child relationship by this + * definition. Cannot fail. + */ +bool xs_path_is_subpath(const char *parent, const char *child); + +/* Return whether the domain specified has been introduced to xenstored. + */ +bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid); + +/* Only useful for DEBUG versions */ +char *xs_debug_command(struct xs_handle *h, const char *cmd, + void *data, unsigned int len); + +int xs_suspend_evtchn_port(int domid); +#endif /* XENSTORE_H */ + +/* + * Local variables: + * c-file-style: "linux" + * indent-tabs-mode: t + * c-indent-level: 8 + * c-basic-offset: 8 + * tab-width: 8 + * End: + */ diff --git a/tools/xenstore/include/xenstore_lib.h b/tools/xenstore/include/xenstore_lib.h new file mode 100644 index 0000000..5c2baf6 --- /dev/null +++ b/tools/xenstore/include/xenstore_lib.h @@ -0,0 +1,85 @@ +/* + Common routines between Xen store user library and daemon. + Copyright (C) 2005 Rusty Russell IBM Corporation + + 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, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef XENSTORE_LIB_H +#define XENSTORE_LIB_H + +#include +#include +#include +#include +#include + +/* Bitmask of permissions. */ +enum xs_perm_type { + XS_PERM_NONE = 0, + XS_PERM_READ = 1, + XS_PERM_WRITE = 2, + /* Internal use. */ + XS_PERM_ENOENT_OK = 4, + XS_PERM_OWNER = 8, +}; + +struct xs_permissions +{ + unsigned int id; + enum xs_perm_type perms; +}; + +/* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */ +#define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2) + +/* Path for various daemon things: env vars can override. */ +const char *xs_daemon_rootdir(void); +const char *xs_daemon_rundir(void); +const char *xs_daemon_socket(void); +const char *xs_daemon_socket_ro(void); +const char *xs_domain_dev(void); +const char *xs_daemon_tdb(void); + +/* Simple write function: loops for you. */ +bool xs_write_all(int fd, const void *data, unsigned int len); + +/* Convert strings to permissions. False if a problem. */ +bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num, + const char *strings); + +/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */ +bool xs_perm_to_string(const struct xs_permissions *perm, + char *buffer, size_t buf_len); + +/* Given a string and a length, count how many strings (nul terms). */ +unsigned int xs_count_strings(const char *strings, unsigned int len); + +/* Sanitising (quoting) possibly-binary strings. */ +struct expanding_buffer { + char *buf; + int avail; +}; + +/* Ensure that given expanding buffer has at least min_avail characters. */ +char *expanding_buffer_ensure(struct expanding_buffer *, int min_avail); + +/* sanitise_value() may return NULL if malloc fails. */ +char *sanitise_value(struct expanding_buffer *, const char *val, unsigned len); + +/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */ +void unsanitise_value(char *out, unsigned *out_len_r, const char *in); + +#endif /* XENSTORE_LIB_H */ diff --git a/tools/xenstore/xenstore.h b/tools/xenstore/xenstore.h deleted file mode 100644 index fdf5e76..0000000 --- a/tools/xenstore/xenstore.h +++ /dev/null @@ -1,257 +0,0 @@ -/* - Xen Store Daemon providing simple tree-like database. - Copyright (C) 2005 Rusty Russell IBM Corporation - - 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, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef XENSTORE_H -#define XENSTORE_H - -#include - -#define XBT_NULL 0 - -#define XS_OPEN_READONLY 1UL<<0 -#define XS_OPEN_SOCKETONLY 1UL<<1 - -/* - * Setting XS_UNWATCH_FILTER arranges that after xs_unwatch, no - * related watch events will be delivered via xs_read_watch. But - * this relies on the couple token, subpath is unique. - * - * XS_UNWATCH_FILTER clear XS_UNWATCH_FILTER set - * - * Even after xs_unwatch, "stale" After xs_unwatch returns, no - * instances of the watch event watch events with the same - * may be delivered. token and with the same subpath - * will be delivered. - * - * A path and a subpath can be The application must avoid - * register with the same token. registering a path (/foo/) and - * a subpath (/foo/bar) with the - * same path until a successful - * xs_unwatch for the first watch - * has returned. - */ -#define XS_UNWATCH_FILTER 1UL<<2 - -struct xs_handle; -typedef uint32_t xs_transaction_t; - -/* IMPORTANT: For details on xenstore protocol limits, see - * docs/misc/xenstore.txt in the Xen public source repository, and use the - * XENSTORE_*_MAX limit macros defined in xen/io/xs_wire.h. - */ - -/* On failure, these routines set errno. */ - -/* Open a connection to the xs daemon. - * Attempts to make a connection over the socket interface, - * and if it fails, then over the xenbus interface. - * Mode 0 specifies read-write access, XS_OPEN_READONLY for - * read-only access. - * Returns a handle or NULL. - */ -struct xs_handle *xs_open(unsigned long flags); - -/* Close the connection to the xs daemon. */ -void xs_close(struct xs_handle *xsh); - -/* Connect to the xs daemon. - * Returns a handle or NULL. - * Deprecated, please use xs_open(0) instead - */ -struct xs_handle *xs_daemon_open(void); -struct xs_handle *xs_domain_open(void); - -/* Connect to the xs daemon (readonly for non-root clients). - * Returns a handle or NULL. - * Deprecated, please use xs_open(XS_OPEN_READONLY) instead - */ -struct xs_handle *xs_daemon_open_readonly(void); - -/* Close the connection to the xs daemon. - * Deprecated, please use xs_close() instead - */ -void xs_daemon_close(struct xs_handle *); - -/* Throw away the connection to the xs daemon, for use after fork(). */ -void xs_daemon_destroy_postfork(struct xs_handle *); - -/* Get contents of a directory. - * Returns a malloced array: call free() on it after use. - * Num indicates size. - */ -char **xs_directory(struct xs_handle *h, xs_transaction_t t, - const char *path, unsigned int *num); - -/* Get the value of a single file, nul terminated. - * Returns a malloced value: call free() on it after use. - * len indicates length in bytes, not including terminator. - */ -void *xs_read(struct xs_handle *h, xs_transaction_t t, - const char *path, unsigned int *len); - -/* Write the value of a single file. - * Returns false on failure. - */ -bool xs_write(struct xs_handle *h, xs_transaction_t t, - const char *path, const void *data, unsigned int len); - -/* Create a new directory. - * Returns false on failure, or success if it already exists. - */ -bool xs_mkdir(struct xs_handle *h, xs_transaction_t t, - const char *path); - -/* Destroy a file or directory (and children). - * Returns false on failure, or if it doesn't exist. - */ -bool xs_rm(struct xs_handle *h, xs_transaction_t t, - const char *path); - -/* Restrict a xenstore handle so that it acts as if it had the - * permissions of domain @domid. The handle must currently be - * using domain 0's credentials. - * - * Returns false on failure, in which case the handle continues - * to use the old credentials, or true on success. - */ -bool xs_restrict(struct xs_handle *h, unsigned domid); - -/* Get permissions of node (first element is owner, first perms is "other"). - * Returns malloced array, or NULL: call free() after use. - */ -struct xs_permissions *xs_get_permissions(struct xs_handle *h, - xs_transaction_t t, - const char *path, unsigned int *num); - -/* Set permissions of node (must be owner). - * Returns false on failure. - */ -bool xs_set_permissions(struct xs_handle *h, xs_transaction_t t, - const char *path, struct xs_permissions *perms, - unsigned int num_perms); - -/* Watch a node for changes (poll on fd to detect, or call read_watch()). - * When the node (or any child) changes, fd will become readable. - * Token is returned when watch is read, to allow matching. - * Returns false on failure. - */ -bool xs_watch(struct xs_handle *h, const char *path, const char *token); - -/* Return the FD to poll on to see if a watch has fired. */ -int xs_fileno(struct xs_handle *h); - -/* Check for node changes. On success, returns a non-NULL pointer ret - * such that ret[0] and ret[1] are valid C strings, namely the - * triggering path (see docs/misc/xenstore.txt) and the token (from - * xs_watch). On error return value is NULL setting errno. - * - * Callers should, after xs_fileno has become readable, repeatedly - * call xs_check_watch until it returns NULL and sets errno to EAGAIN. - * (If the fd became readable, xs_check_watch is allowed to make it no - * longer show up as readable even if future calls to xs_check_watch - * will return more watch events.) - * - * After the caller is finished with the returned information it - * should be freed all in one go with free(ret). - */ -char **xs_check_watch(struct xs_handle *h); - -/* Find out what node change was on (will block if nothing pending). - * Returns array containing the path and token. Use XS_WATCH_* to access these - * elements. Call free() after use. - */ -char **xs_read_watch(struct xs_handle *h, unsigned int *num); - -/* Remove a watch on a node: implicitly acks any outstanding watch. - * Returns false on failure (no watch on that node). - */ -bool xs_unwatch(struct xs_handle *h, const char *path, const char *token); - -/* Start a transaction: changes by others will not be seen during this - * transaction, and changes will not be visible to others until end. - * Returns NULL on failure. - */ -xs_transaction_t xs_transaction_start(struct xs_handle *h); - -/* End a transaction. - * If abandon is true, transaction is discarded instead of committed. - * Returns false on failure: if errno == EAGAIN, you have to restart - * transaction. - */ -bool xs_transaction_end(struct xs_handle *h, xs_transaction_t t, - bool abort); - -/* Introduce a new domain. - * This tells the store daemon about a shared memory page, event channel and - * store path associated with a domain: the domain uses these to communicate. - */ -bool xs_introduce_domain(struct xs_handle *h, - unsigned int domid, - unsigned long mfn, - unsigned int eventchn); - -/* Set the target of a domain - * This tells the store daemon that a domain is targetting another one, so - * it should let it tinker with it. - */ -bool xs_set_target(struct xs_handle *h, - unsigned int domid, - unsigned int target); - -/* Resume a domain. - * Clear the shutdown flag for this domain in the store. - */ -bool xs_resume_domain(struct xs_handle *h, unsigned int domid); - -/* Release a domain. - * Tells the store domain to release the memory page to the domain. - */ -bool xs_release_domain(struct xs_handle *h, unsigned int domid); - -/* Query the home path of a domain. Call free() after use. - */ -char *xs_get_domain_path(struct xs_handle *h, unsigned int domid); - -/* Returns true if child is either equal to parent, or a node underneath - * parent; or false otherwise. Done by string comparison, so relative and - * absolute pathnames never in a parent/child relationship by this - * definition. Cannot fail. - */ -bool xs_path_is_subpath(const char *parent, const char *child); - -/* Return whether the domain specified has been introduced to xenstored. - */ -bool xs_is_domain_introduced(struct xs_handle *h, unsigned int domid); - -/* Only useful for DEBUG versions */ -char *xs_debug_command(struct xs_handle *h, const char *cmd, - void *data, unsigned int len); - -int xs_suspend_evtchn_port(int domid); -#endif /* XENSTORE_H */ - -/* - * Local variables: - * c-file-style: "linux" - * indent-tabs-mode: t - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * End: - */ diff --git a/tools/xenstore/xenstore_lib.h b/tools/xenstore/xenstore_lib.h deleted file mode 100644 index 5c2baf6..0000000 --- a/tools/xenstore/xenstore_lib.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - Common routines between Xen store user library and daemon. - Copyright (C) 2005 Rusty Russell IBM Corporation - - 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, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef XENSTORE_LIB_H -#define XENSTORE_LIB_H - -#include -#include -#include -#include -#include - -/* Bitmask of permissions. */ -enum xs_perm_type { - XS_PERM_NONE = 0, - XS_PERM_READ = 1, - XS_PERM_WRITE = 2, - /* Internal use. */ - XS_PERM_ENOENT_OK = 4, - XS_PERM_OWNER = 8, -}; - -struct xs_permissions -{ - unsigned int id; - enum xs_perm_type perms; -}; - -/* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */ -#define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2) - -/* Path for various daemon things: env vars can override. */ -const char *xs_daemon_rootdir(void); -const char *xs_daemon_rundir(void); -const char *xs_daemon_socket(void); -const char *xs_daemon_socket_ro(void); -const char *xs_domain_dev(void); -const char *xs_daemon_tdb(void); - -/* Simple write function: loops for you. */ -bool xs_write_all(int fd, const void *data, unsigned int len); - -/* Convert strings to permissions. False if a problem. */ -bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num, - const char *strings); - -/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */ -bool xs_perm_to_string(const struct xs_permissions *perm, - char *buffer, size_t buf_len); - -/* Given a string and a length, count how many strings (nul terms). */ -unsigned int xs_count_strings(const char *strings, unsigned int len); - -/* Sanitising (quoting) possibly-binary strings. */ -struct expanding_buffer { - char *buf; - int avail; -}; - -/* Ensure that given expanding buffer has at least min_avail characters. */ -char *expanding_buffer_ensure(struct expanding_buffer *, int min_avail); - -/* sanitise_value() may return NULL if malloc fails. */ -char *sanitise_value(struct expanding_buffer *, const char *val, unsigned len); - -/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */ -void unsanitise_value(char *out, unsigned *out_len_r, const char *in); - -#endif /* XENSTORE_LIB_H */