/****************************************************************************** * xenbus_comms.c * * Low level code to talks to Xen Store: ringbuffer and event channel. * * Copyright (C) 2005 Rusty Russell, IBM Corporation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation; or, when distributed * separately from the Linux kernel or incorporated into other * software packages, subject to the following license: * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this source file (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE.
*/
src = get_input_chunk(cons, prod, intf->rsp, &avail); if (avail == 0) continue; if (avail > len)
avail = len;
/* Must read data /after/ reading the producer index. */
virt_rmb();
memcpy(data, src, avail);
data += avail;
len -= avail;
bytes += avail;
/* Other side must not see free space until we've copied out */
virt_mb();
intf->rsp_cons += avail;
/* Implies mb(): other side will see the updated consumer. */ if (intf->rsp_prod - cons >= XENSTORE_RING_SIZE)
notify_remote_via_evtchn(xen_store_evtchn);
}
/* * We must disallow save/restore while reading a message. * A partial read across s/r leaves us out of sync with * xenstored. * xs_response_mutex is locked as long as we are processing one * message. state.in_msg will be true as long as we are holding * the lock here.
*/
mutex_lock(&xs_response_mutex);
if (!xb_data_to_read()) { /* We raced with save/restore: pending data 'gone'. */
mutex_unlock(&xs_response_mutex);
state.in_msg = false; return 0;
}
}
if (state.in_hdr) { if (state.read != sizeof(state.msg)) {
err = xb_read((void *)&state.msg + state.read, sizeof(state.msg) - state.read); if (err < 0) goto out;
state.read += err; if (state.read != sizeof(state.msg)) return 0; if (state.msg.len > XENSTORE_PAYLOAD_MAX) {
err = -EINVAL; goto out;
}
}
len = state.msg.len + 1; if (state.msg.type == XS_WATCH_EVENT)
len += sizeof(*state.watch);
state.alloc = kmalloc(len, GFP_NOIO | __GFP_HIGH); if (!state.alloc) return -ENOMEM;
while (!kthread_should_stop()) { if (wait_event_interruptible(xb_waitq, xb_thread_work())) continue;
err = process_msg(); if (err == -ENOMEM)
schedule(); elseif (err)
pr_warn_ratelimited("error %d while reading message\n",
err);
err = process_writes(); if (err)
pr_warn_ratelimited("error %d while writing message\n",
err);
}
xenbus_task = NULL; return 0;
}
/** * xb_init_comms - Set up interrupt handler off store event channel.
*/ int xb_init_comms(void)
{ struct xenstore_domain_interface *intf = xen_store_interface;
if (intf->req_prod != intf->req_cons)
pr_err("request ring is not quiescent (%08x:%08x)!\n",
intf->req_cons, intf->req_prod);
if (intf->rsp_prod != intf->rsp_cons) {
pr_warn("response ring is not quiescent (%08x:%08x): fixing up\n",
intf->rsp_cons, intf->rsp_prod); /* breaks kdump */ if (!reset_devices)
intf->rsp_cons = intf->rsp_prod;
}
if (xenbus_irq) { /* Already have an irq; assume we're resuming */
rebind_evtchn_irq(xen_store_evtchn, xenbus_irq);
} else { int err;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.