本文整理汇总了C++中xenbus_read函数的典型用法代码示例。如果您正苦于以下问题:C++ xenbus_read函数的具体用法?C++ xenbus_read怎么用?C++ xenbus_read使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xenbus_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pcifront_physical_to_virtual
int pcifront_physical_to_virtual (struct pcifront_dev *dev,
unsigned int *dom,
unsigned int *bus,
unsigned int *slot,
unsigned long *fun)
{
/* FIXME: the buffer sizing is a little lazy here. 10 extra bytes
should be enough to hold the paths we need to construct, even
if the number of devices is large */
char path[strlen(dev->backend) + strlen("/num_devs") + 10 + 1];
int i, n;
char *s, *msg = NULL;
unsigned int dom1, bus1, slot1, fun1;
if (!dev)
dev = pcidev;
snprintf(path, sizeof(path), "%s/num_devs", dev->backend);
n = xenbus_read_integer(path);
for (i = 0; i < n; i++) {
snprintf(path, sizeof(path), "%s/dev-%d", dev->backend, i);
msg = xenbus_read(XBT_NIL, path, &s);
if (msg) {
printk("Error %s when reading the PCI root name at %s\n", msg, path);
free(msg);
continue;
}
if (sscanf(s, "%x:%x:%x.%x", &dom1, &bus1, &slot1, &fun1) != 4) {
printk("\"%s\" does not look like a PCI device address\n", s);
free(s);
continue;
}
free(s);
if (dom1 == *dom && bus1 == *bus && slot1 == *slot && fun1 == *fun) {
snprintf(path, sizeof(path), "%s/vdev-%d", dev->backend, i);
msg = xenbus_read(XBT_NIL, path, &s);
if (msg) {
printk("Error %s when reading the PCI root name at %s\n", msg, path);
continue;
}
if (sscanf(s, "%x:%x:%x.%x", dom, bus, slot, fun) != 4) {
printk("\"%s\" does not look like a PCI device address\n", s);
free(s);
continue;
}
free(s);
return 0;
}
}
return -1;
}
示例2: xen_net_read_rate
static void xen_net_read_rate(struct xenbus_device *dev,
unsigned long *bytes, unsigned long *usec)
{
char *s, *e;
unsigned long b, u;
char *ratestr;
/* Default to unlimited bandwidth. */
*bytes = ~0UL;
*usec = 0;
ratestr = xenbus_read(XBT_NIL, dev->nodename, "rate", NULL);
if (IS_ERR(ratestr))
return;
s = ratestr;
b = simple_strtoul(s, &e, 10);
if ((s == e) || (*e != ','))
goto fail;
s = e + 1;
u = simple_strtoul(s, &e, 10);
if ((s == e) || (*e != '\0'))
goto fail;
*bytes = b;
*usec = u;
kfree(ratestr);
return;
fail:
pr_warn("Failed to parse network rate limit. Traffic unlimited.\n");
kfree(ratestr);
}
示例3: GrantAndEventChannelInATransaction
/* Write a grant ref and ec port to xenstore in a transaction for whatever
* your pThing is. Also some non-transaction read/write stuff.
*/
static NTSTATUS
GrantAndEventChannelInATransaction(CHAR *pFrontendPath, struct THING *pThing)
{
NTSTATUS Status;
CHAR *pMyData;
xenbus_transaction_t Xbt;
do {
xenbus_transaction_start(&Xbt);
xenbus_write_grant_ref(Xbt, pFrontendPath, "ring-ref",
pThing->RingGrantRef);
xenbus_write_evtchn_port(Xbt, pFrontendPath, "event-channel",
pThing->EvtchnPort);
Status = xenbus_transaction_end(Xbt, 0);
} while (Status == STATUS_RETRY);
if (Status != STATUS_SUCCESS) {
DbgPrint("Failed to end transaction, 0x%08x.\n", Status);
/* Handle failure */
}
/* A write and read w/o a transaction */
xenbus_write(XBT_NIL, "drivers/mydriver", "1.2.3.4");
Status = xenbus_read(XBT_NIL, "drivers/mydriver/mydata", &pMyData);
if (NT_SUCCESS(Status)) {
DbgPrint("Read MyData: %s\n", pMyData);
XmFreeMemory(pMyData);
}
/* ... */
}
示例4: shutdown_thread
static void shutdown_thread(void *p)
{
const char *path = "control/shutdown";
const char *token = path;
xenbus_event_queue events = NULL;
char *shutdown = NULL, *err;
unsigned int shutdown_reason;
xenbus_watch_path_token(XBT_NIL, path, token, &events);
while ((err = xenbus_read(XBT_NIL, path, &shutdown)) != NULL || !strcmp(shutdown, ""))
{
free(err);
free(shutdown);
shutdown = NULL;
xenbus_wait_for_watch(&events);
}
err = xenbus_unwatch_path_token(XBT_NIL, path, token);
free(err);
err = xenbus_write(XBT_NIL, path, "");
free(err);
printk("Shutting down (%s)\n", shutdown);
if (!strcmp(shutdown, "poweroff"))
shutdown_reason = SHUTDOWN_poweroff;
else if (!strcmp(shutdown, "reboot"))
shutdown_reason = SHUTDOWN_reboot;
else
/* Unknown */
shutdown_reason = SHUTDOWN_crash;
app_shutdown(shutdown_reason);
free(shutdown);
}
示例5: fork_xenbus
int fork_xenbus(void)
{
char path[50];
char *flag = "fork", *err;
xenbus_event_queue events = NULL;
sprintf(path,"fork/requests");
xenbus_watch_path_token(XBT_NIL, path, path, &events);
xenbus_write(XBT_NIL, path, "fork");
while(1){
xenbus_wait_for_watch(&events);
if ((err = xenbus_read(XBT_NIL, path, &flag))) {
free(err);
continue;
}
if (!strcmp(flag, "") || !strcmp(flag, "fork")) {
free(flag);
flag = NULL;
continue;
}else if (!strcmp(flag, "0"))
return 0;
else if (!strcmp(flag, "1"))
return 1;
err = xenbus_write(XBT_NIL, path, "");
free(err);
free(flag);
flag = NULL;
}
return -1;
}
示例6: netback_uevent
/**
* Handle the creation of the hotplug script environment. We add the script
* and vif variables to the environment, for the benefit of the vif-* hotplug
* scripts.
*/
static int netback_uevent(struct xenbus_device *xdev, char **envp,
int num_envp, char *buffer, int buffer_size)
{
struct backend_info *be = xdev->dev.driver_data;
netif_t *netif = be->netif;
int i = 0, length = 0;
char *val;
DPRINTK("netback_uevent");
val = xenbus_read(XBT_NIL, xdev->nodename, "script", NULL);
if (IS_ERR(val)) {
int err = PTR_ERR(val);
xenbus_dev_fatal(xdev, err, "reading script");
return err;
}
else {
add_uevent_var(envp, num_envp, &i, buffer, buffer_size,
&length, "script=%s", val);
kfree(val);
}
add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
"vif=%s", netif->dev->name);
envp[i] = NULL;
return 0;
}
示例7: pcifront_scan
void pcifront_scan(struct pcifront_dev *dev, void (*func)(unsigned int domain, unsigned int bus, unsigned slot, unsigned int fun))
{
char path[strlen(dev->backend) + 1 + 5 + 10 + 1];
int i, n;
char *s, *msg;
unsigned int domain, bus, slot, fun;
snprintf(path, sizeof(path), "%s/num_devs", dev->backend);
n = xenbus_read_integer(path);
for (i = 0; i < n; i++) {
snprintf(path, sizeof(path), "%s/vdev-%d", dev->backend, i);
msg = xenbus_read(XBT_NIL, path, &s);
if (msg) {
printk("Error %s when reading the PCI root name at %s\n", path);
continue;
}
if (sscanf(s, "%x:%x:%x.%x", &domain, &bus, &slot, &fun) != 4) {
printk("\"%s\" does not look like a PCI device address\n", s);
free(s);
continue;
}
free(s);
func(domain, bus, slot, fun);
}
}
示例8: XenLowerReadXenstoreValue
static PCHAR
XenLowerReadXenstoreValue(
PCHAR Path,
PCHAR Value)
{
ULONG plen, vlen;
PCHAR path;
PCHAR res = NULL;
NTSTATUS status;
plen = (ULONG)strlen(Path);
vlen = (ULONG)strlen(Value);
path = (PCHAR)XmAllocateMemory(plen + vlen + 2);
if (path == NULL)
{
return NULL;
}
memcpy(path, Path, plen);
path[plen] = '/';
memcpy(path + plen + 1, Value, vlen + 1);
status = xenbus_read(XBT_NIL, path, &res);
XmFreeMemory(path);
if (!NT_SUCCESS(status))
{
return NULL;
}
return res;
}
示例9: xenbus_read_uuid
int xenbus_read_uuid(const char* path, unsigned char uuid[16]) {
char * res, *buf;
res = xenbus_read(XBT_NIL, path, &buf);
if(res) {
printk("Failed to read %s.\n", path);
free(res);
return 0;
}
if(strlen(buf) != ((2*16)+4) /* 16 hex bytes and 4 hyphens */
|| sscanf(buf,
"%2hhx%2hhx%2hhx%2hhx-"
"%2hhx%2hhx-"
"%2hhx%2hhx-"
"%2hhx%2hhx-"
"%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
uuid, uuid + 1, uuid + 2, uuid + 3,
uuid + 4, uuid + 5, uuid + 6, uuid + 7,
uuid + 8, uuid + 9, uuid + 10, uuid + 11,
uuid + 12, uuid + 13, uuid + 14, uuid + 15) != 16) {
printk("Xenbus path %s value %s is not a uuid!\n", path, buf);
free(buf);
return 0;
}
free(buf);
return 1;
}
示例10: xen_shutdown_handler
/*ARGSUSED*/
static void
xen_shutdown_handler(struct xenbus_watch *watch, const char **vec,
unsigned int len)
{
char *str;
xenbus_transaction_t xbt;
int err, shutdown_code = SHUTDOWN_INVALID;
unsigned int slen;
again:
err = xenbus_transaction_start(&xbt);
if (err)
return;
if (xenbus_read(xbt, "control", "shutdown", (void *)&str, &slen)) {
(void) xenbus_transaction_end(xbt, 1);
return;
}
SUSPEND_DEBUG("%d: xen_shutdown_handler: \"%s\"\n", CPU->cpu_id, str);
/*
* If this is a watch fired from our write below, check out early to
* avoid an infinite loop.
*/
if (strcmp(str, "") == 0) {
(void) xenbus_transaction_end(xbt, 0);
kmem_free(str, slen);
return;
} else if (strcmp(str, "poweroff") == 0) {
shutdown_code = SHUTDOWN_POWEROFF;
} else if (strcmp(str, "reboot") == 0) {
shutdown_code = SHUTDOWN_REBOOT;
} else if (strcmp(str, "suspend") == 0) {
shutdown_code = SHUTDOWN_SUSPEND;
} else if (strcmp(str, "halt") == 0) {
shutdown_code = SHUTDOWN_HALT;
} else {
printf("Ignoring shutdown request: %s\n", str);
}
/*
* XXPV Should we check the value of xenbus_write() too, or are all
* errors automatically folded into xenbus_transaction_end() ??
*/
(void) xenbus_write(xbt, "control", "shutdown", "");
err = xenbus_transaction_end(xbt, 0);
if (err == EAGAIN) {
SUSPEND_DEBUG("%d: trying again\n", CPU->cpu_id);
kmem_free(str, slen);
goto again;
}
kmem_free(str, slen);
if (shutdown_code != SHUTDOWN_INVALID) {
(void) taskq_dispatch(xen_shutdown_tq, xen_shutdown,
(void *)(intptr_t)shutdown_code, 0);
}
}
示例11: shutdown_handler
static void shutdown_handler(struct xenbus_watch *watch,
const char **vec, unsigned int len)
{
char *str;
struct xenbus_transaction xbt;
int err;
static struct shutdown_handler handlers[] = {
{ "poweroff", do_poweroff },
{ "halt", do_poweroff },
{ "reboot", do_reboot },
#ifdef CONFIG_HIBERNATE_CALLBACKS
{ "suspend", do_suspend },
#endif
{NULL, NULL},
};
static struct shutdown_handler *handler;
if (shutting_down != SHUTDOWN_INVALID)
return;
again:
err = xenbus_transaction_start(&xbt);
if (err)
return;
str = (char *)xenbus_read(xbt, "control", "shutdown", NULL);
/* Ignore read errors and empty reads. */
if (XENBUS_IS_ERR_READ(str)) {
xenbus_transaction_end(xbt, 1);
return;
}
for (handler = &handlers[0]; handler->command; handler++) {
if (strcmp(str, handler->command) == 0)
break;
}
/* Only acknowledge commands which we are prepared to handle. */
if (handler->cb)
xenbus_write(xbt, "control", "shutdown", "");
err = xenbus_transaction_end(xbt, 0);
if (err == -EAGAIN) {
kfree(str);
goto again;
}
if (handler->cb) {
handler->cb();
} else {
pr_info("Ignoring shutdown request: %s\n", str);
shutting_down = SHUTDOWN_INVALID;
}
kfree(str);
}
示例12: xenbus_get_self_id
domid_t xenbus_get_self_id(void)
{
char *dom_id;
domid_t ret;
BUG_ON(xenbus_read(XBT_NIL, "domid", &dom_id));
sscanf(dom_id, "%u", (unsigned int*)&ret);
return ret;
}
示例13: uuid_show
static ssize_t uuid_show(struct hyp_sysfs_attr *attr, char *buffer)
{
char *vm, *val;
int ret;
if (!is_xenstored_ready())
return -EBUSY;
vm = xenbus_read(XBT_NIL, "vm", "", NULL);
if (IS_ERR(vm))
return PTR_ERR(vm);
val = xenbus_read(XBT_NIL, vm, "uuid", NULL);
kfree(vm);
if (IS_ERR(val))
return PTR_ERR(val);
ret = sprintf(buffer, "%s\n", val);
kfree(val);
return ret;
}
示例14: read_nicname
static int read_nicname(struct xenbus_device *dev, struct netback_accel *bend)
{
int len;
/* nic name used to select interface used for acceleration */
bend->nicname = xenbus_read(XBT_NIL, dev->nodename, "accel", &len);
if (IS_ERR(bend->nicname))
return PTR_ERR(bend->nicname);
return 0;
}
示例15: do_read_test
static void do_read_test(const char *path)
{
char *res, *msg;
printk("Read %s...\n", path);
msg = xenbus_read(XBT_NIL, path, &res);
if (msg) {
printk("Error in xenbus read: %s\n", msg);
free(msg);
return;
}
printk("Read %s -> %s.\n", path, res);
free(res);
}