843e19887f64dde75055cf8842fc4db2171eff45johnlev * CDDL HEADER START
843e19887f64dde75055cf8842fc4db2171eff45johnlev * The contents of this file are subject to the terms of the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Common Development and Distribution License (the "License").
843e19887f64dde75055cf8842fc4db2171eff45johnlev * You may not use this file except in compliance with the License.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
843e19887f64dde75055cf8842fc4db2171eff45johnlev * See the License for the specific language governing permissions
843e19887f64dde75055cf8842fc4db2171eff45johnlev * and limitations under the License.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * When distributing Covered Code, include this CDDL HEADER in each
843e19887f64dde75055cf8842fc4db2171eff45johnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * If applicable, add the following below this CDDL HEADER, with the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * fields enclosed by brackets "[]" replaced with your own identifying
843e19887f64dde75055cf8842fc4db2171eff45johnlev * information: Portions Copyright [yyyy] [name of copyright owner]
843e19887f64dde75055cf8842fc4db2171eff45johnlev * CDDL HEADER END
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Use is subject to license terms.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Client-facing interface for the Xenbus driver. In other words, the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * interface between the Xenbus and the device-specific code, be it the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * frontend or the backend of that driver.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Copyright (C) 2005 XenSource Ltd
843e19887f64dde75055cf8842fc4db2171eff45johnlev * This file may be distributed separately from the Linux kernel, or
843e19887f64dde75055cf8842fc4db2171eff45johnlev * incorporated into other software packages, subject to the following license:
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Permission is hereby granted, free of charge, to any person obtaining a copy
843e19887f64dde75055cf8842fc4db2171eff45johnlev * of this source file (the "Software"), to deal in the Software without
843e19887f64dde75055cf8842fc4db2171eff45johnlev * restriction, including without limitation the rights to use, copy, modify,
843e19887f64dde75055cf8842fc4db2171eff45johnlev * merge, publish, distribute, sublicense, and/or sell copies of the Software,
843e19887f64dde75055cf8842fc4db2171eff45johnlev * and to permit persons to whom the Software is furnished to do so, subject to
843e19887f64dde75055cf8842fc4db2171eff45johnlev * the following conditions:
843e19887f64dde75055cf8842fc4db2171eff45johnlev * The above copyright notice and this permission notice shall be included in
843e19887f64dde75055cf8842fc4db2171eff45johnlev * all copies or substantial portions of the Software.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
843e19887f64dde75055cf8842fc4db2171eff45johnlev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
843e19887f64dde75055cf8842fc4db2171eff45johnlev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
843e19887f64dde75055cf8842fc4db2171eff45johnlev * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
843e19887f64dde75055cf8842fc4db2171eff45johnlev * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
843e19887f64dde75055cf8842fc4db2171eff45johnlev * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
843e19887f64dde75055cf8842fc4db2171eff45johnlev * IN THE SOFTWARE.
843e19887f64dde75055cf8842fc4db2171eff45johnlev#pragma ident "%Z%%M% %I% %E% SMI"
843e19887f64dde75055cf8842fc4db2171eff45johnlevxenbus_watch_path(struct xenbus_device *dev, const char *path,
843e19887f64dde75055cf8842fc4db2171eff45johnlev const char **, unsigned int))
843e19887f64dde75055cf8842fc4db2171eff45johnlev xenbus_dev_fatal(dev, err, "adding watch on %s", path);
843e19887f64dde75055cf8842fc4db2171eff45johnlevxenbus_watch_path2(struct xenbus_device *dev, const char *path,
843e19887f64dde75055cf8842fc4db2171eff45johnlev const char **, unsigned int))
843e19887f64dde75055cf8842fc4db2171eff45johnlev state = kmem_alloc(strlen(path) + 1 + strlen(path2) + 1, KM_SLEEP);
843e19887f64dde75055cf8842fc4db2171eff45johnlev err = xenbus_watch_path(dev, state, watch, callback);
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Returns 0 on success, -1 if no change was made, or an errno on failure. We
843e19887f64dde75055cf8842fc4db2171eff45johnlev * check whether the state is currently set to the given value, and if not,
843e19887f64dde75055cf8842fc4db2171eff45johnlev * then the state is set. We don't want to unconditionally write the given
843e19887f64dde75055cf8842fc4db2171eff45johnlev * state, because we don't want to fire watches unnecessarily. Furthermore, if
843e19887f64dde75055cf8842fc4db2171eff45johnlev * the node has gone, we don't write to it, as the device will be tearing down,
843e19887f64dde75055cf8842fc4db2171eff45johnlev * and we don't want to resurrect that directory.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * XXPV: not clear that this is still safe if two threads are racing to update
843e19887f64dde75055cf8842fc4db2171eff45johnlev * the state?
843e19887f64dde75055cf8842fc4db2171eff45johnlevxenbus_switch_state(struct xenbus_device *dev, xenbus_transaction_t xbt,
843e19887f64dde75055cf8842fc4db2171eff45johnlev err = xenbus_scanf(xbt, dev->nodename, "state", "%d", ¤t_state);
843e19887f64dde75055cf8842fc4db2171eff45johnlev /* XXPV: is this really the right thing to do? */
843e19887f64dde75055cf8842fc4db2171eff45johnlev return (0);
843e19887f64dde75055cf8842fc4db2171eff45johnlev err = xenbus_printf(xbt, dev->nodename, "state", "%d", state);
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Return the path to the error node for the given device, or NULL on failure.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * If the value returned is non-NULL, then it is the caller's to kmem_free.
843e19887f64dde75055cf8842fc4db2171eff45johnlevstatic char *
843e19887f64dde75055cf8842fc4db2171eff45johnlev path_buffer = kmem_alloc(strlen("error/") + strlen(dev->nodename) +
843e19887f64dde75055cf8842fc4db2171eff45johnlev (void) strcpy(path_buffer + strlen("error/"), dev->nodename);
843e19887f64dde75055cf8842fc4db2171eff45johnlevcommon_dev_error(struct xenbus_device *dev, int err, const char *fmt,
843e19887f64dde75055cf8842fc4db2171eff45johnlev printf_buffer = kmem_alloc(PRINTF_BUFFER_SIZE, KM_SLEEP);
843e19887f64dde75055cf8842fc4db2171eff45johnlev (void) snprintf(printf_buffer, PRINTF_BUFFER_SIZE, "%d ", err);
843e19887f64dde75055cf8842fc4db2171eff45johnlev ret = vsnprintf(printf_buffer+len, PRINTF_BUFFER_SIZE-len, fmt, ap);
843e19887f64dde75055cf8842fc4db2171eff45johnlev printf("xenbus: failed to write error node for %s (%s)\n",
843e19887f64dde75055cf8842fc4db2171eff45johnlev if (xenbus_write(NULL, path_buffer, "error", printf_buffer) != 0) {
843e19887f64dde75055cf8842fc4db2171eff45johnlev printf("xenbus: failed to write error node for %s (%s)\n",
843e19887f64dde75055cf8842fc4db2171eff45johnlevxenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...)
843e19887f64dde75055cf8842fc4db2171eff45johnlevxenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt, ...)
843e19887f64dde75055cf8842fc4db2171eff45johnlev (void) xenbus_switch_state(dev, XBT_NULL, XenbusStateClosing);
843e19887f64dde75055cf8842fc4db2171eff45johnlev/* Clear any error. */
843e19887f64dde75055cf8842fc4db2171eff45johnlev printf("xenbus: failed to clear error node for %s\n",
843e19887f64dde75055cf8842fc4db2171eff45johnlevxenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn)
843e19887f64dde75055cf8842fc4db2171eff45johnlev int err = gnttab_grant_foreign_access(dev->otherend_id, ring_mfn, 0);
843e19887f64dde75055cf8842fc4db2171eff45johnlev xenbus_dev_fatal(dev, err, "granting access to ring page");
843e19887f64dde75055cf8842fc4db2171eff45johnlevxenbus_alloc_evtchn(struct xenbus_device *dev, int *port)
843e19887f64dde75055cf8842fc4db2171eff45johnlev err = xen_alloc_unbound_evtchn(dev->otherend_id, port);
843e19887f64dde75055cf8842fc4db2171eff45johnlev xenbus_dev_fatal(dev, err, "allocating event channel");
843e19887f64dde75055cf8842fc4db2171eff45johnlev int err = xenbus_gather(XBT_NULL, path, "state", "%d", &result, NULL);
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Local variables:
843e19887f64dde75055cf8842fc4db2171eff45johnlev * c-file-style: "solaris"
843e19887f64dde75055cf8842fc4db2171eff45johnlev * indent-tabs-mode: t
843e19887f64dde75055cf8842fc4db2171eff45johnlev * c-indent-level: 8
843e19887f64dde75055cf8842fc4db2171eff45johnlev * c-basic-offset: 8
843e19887f64dde75055cf8842fc4db2171eff45johnlev * tab-width: 8