本文整理汇总了C++中xs_read函数的典型用法代码示例。如果您正苦于以下问题:C++ xs_read函数的具体用法?C++ xs_read怎么用?C++ xs_read使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xs_read函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: xs_open
char *get_vm_name(int dom, int *target_dom)
{
struct xs_handle *xs;
char buf[64];
char *name;
char *target_dom_str;
unsigned int len = 0;
xs = xs_open(0);
if (!xs) {
perror("xs_daemon_open");
exit(1);
}
snprintf(buf, sizeof(buf), "/local/domain/%d/target", dom);
target_dom_str = xs_read(xs, 0, buf, &len);
if (target_dom_str) {
errno = 0;
*target_dom = strtol(target_dom_str, (char **) NULL, 10);
if (errno != 0) {
perror("strtol");
exit(1);
}
} else
*target_dom = dom;
snprintf(buf, sizeof(buf), "/local/domain/%d/name", *target_dom);
name = xs_read(xs, 0, buf, &len);
if (!name) {
perror("xs_read domainname");
exit(1);
}
xs_close(xs);
return name;
}
示例2: xs_get_domain_path
char *xenstore_vm_read(int domid, char *key, unsigned int *len)
{
char *buf = NULL, *path = NULL, *value = NULL;
if (xsh == NULL)
goto out;
path = xs_get_domain_path(xsh, domid);
if (path == NULL) {
fprintf(logfile, "xs_get_domain_path(%d): error\n", domid);
goto out;
}
pasprintf(&buf, "%s/vm", path);
free(path);
path = xs_read(xsh, XBT_NULL, buf, NULL);
if (path == NULL) {
fprintf(logfile, "xs_read(%s): read error\n", buf);
goto out;
}
pasprintf(&buf, "%s/%s", path, key);
value = xs_read(xsh, XBT_NULL, buf, len);
if (value == NULL) {
fprintf(logfile, "xs_read(%s): read error\n", buf);
goto out;
}
out:
free(path);
free(buf);
return value;
}
示例3: xenStoreDomainGetDiskID
/*
* xenStoreDomainGetDiskID:
* @conn: pointer to the connection.
* @id: the domain id
* @dev: the virtual block device name
*
* Get the reference (i.e. the string number) for the device on that domain
* which uses the given virtual block device name
*
* The caller must hold the lock on the privateData
* associated with the 'conn' parameter.
*
* Returns the new string or NULL in case of error, the string must be
* freed by the caller.
*/
char *
xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev)
{
char dir[80], path[128], **list = NULL, *val = NULL;
unsigned int devlen, len, num;
size_t i;
char *ret = NULL;
xenUnifiedPrivatePtr priv = conn->privateData;
if (id < 0 || priv->xshandle == NULL || dev == NULL)
return NULL;
devlen = strlen(dev);
if (devlen <= 0)
return NULL;
snprintf(dir, sizeof(dir), "/local/domain/0/backend/vbd/%d", id);
list = xs_directory(priv->xshandle, 0, dir, &num);
if (list != NULL) {
for (i = 0; i < num; i++) {
snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev");
val = xs_read(priv->xshandle, 0, path, &len);
if (val == NULL)
break;
if ((devlen != len) || memcmp(val, dev, len)) {
VIR_FREE(val);
} else {
ignore_value(VIR_STRDUP(ret, list[i]));
VIR_FREE(val);
VIR_FREE(list);
return ret;
}
}
VIR_FREE(list);
}
snprintf(dir, sizeof(dir), "/local/domain/0/backend/tap/%d", id);
list = xs_directory(priv->xshandle, 0, dir, &num);
if (list != NULL) {
for (i = 0; i < num; i++) {
snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev");
val = xs_read(priv->xshandle, 0, path, &len);
if (val == NULL)
break;
if ((devlen != len) || memcmp(val, dev, len)) {
VIR_FREE(val);
} else {
ignore_value(VIR_STRDUP(ret, list[i]));
VIR_FREE(val);
VIR_FREE(list);
return ret;
}
}
VIR_FREE(list);
}
return NULL;
}
示例4: read_param
static char* read_param(const char *paramname) {
char keybuf[128];
unsigned int len;
int my_domid;
my_domid = atoi(xs_read(xsh, 0, "domid", &len));
snprintf(keybuf, sizeof(keybuf), "/local/domain/0/backend/audio/%d/%d/%s", my_domid, device_id, paramname);
/* remember to free lvalue! */
return xs_read(xsh, 0, keybuf, &len);
}
示例5: wait_for_backend_state_change
static int wait_for_backend_state_change() {
char keybuf[128];
int my_domid;
unsigned int len;
int backend_state;
int seconds;
char *buf, **vec;
int ret;
int xs_fd;
struct timeval tv;
fd_set watch_fdset;
int start, now;
backend_state = STATE_UNDEFINED;
xs_fd = xs_fileno(xsh);
start = now = time(NULL);
my_domid = atoi(xs_read(xsh, 0, "domid", &len));
snprintf(keybuf, sizeof(keybuf), "/local/domain/0/backend/audio/%d/%d/state", my_domid, device_id);
/*XXX: hardcoded */
seconds = 10;
do {
tv.tv_usec = 0;
tv.tv_sec = (start + seconds) - now;
FD_ZERO(&watch_fdset);
FD_SET(xs_fd, &watch_fdset);
ret=select(xs_fd + 1, &watch_fdset, NULL, NULL, &tv);
if (ret==-1)
/* error */
return -1;
else if (ret) {
/* Read the watch to drain the buffer */
vec = xs_read_watch(xsh, &len);
buf = xs_read(xsh, XBT_NULL, vec[0], &len);
if (buf == 0) {
/* usually means that the backend isn't there yet */
continue;
};
backend_state = atoi(buf);
free(buf);
free(vec);
}
/* else: timeout */
} while (backend_state == STATE_UNDEFINED && \
(now = time(NULL)) < start + seconds);
return backend_state;
}
示例6: getMyDomId
ivc_connection_t *makeConnection(libIVC_t *iface,
char *name,
ivc_contype_t type,
float per)
{
char *key, *val, *rdomstr = NULL, *rrefstr = NULL, *rpstr = NULL;
uint32_t me, other, num_refs, *grants;
struct xs_permissions perms;
ivc_connection_t *res;
evtchn_port_t port;
unsigned int len;
void *buffer;
/* me <- xsGetDomId */
me = getMyDomId(iface);
/* removePath xs targetPath */
ASPRINTF(&key, "/rendezvous/%s", name);
xs_rm(iface->xs, 0, key);
/* xsMakeDirectory xs targetPath */
xs_mkdir(iface->xs, 0, key);
/* xsSetPermissions xs targetPath [ReadWritePerm me] */
perms.id = me;
perms.perms = XS_PERM_READ | XS_PERM_WRITE;
xs_set_permissions(iface->xs, 0, key, &perms, 1);
/* xsWrite xs (targetPath ++ "/LeftDomId") (show me) */
free(key), ASPRINTF(&key, "/rendezvous/%s/LeftDomId", name);
ASPRINTF(&val, "dom%d", me);
xs_write(iface->xs, 0, key, val, strlen(val));
/* other <- read <$> waitForKey xs (targetPAth ++ "/RightDomId") */
free(key), ASPRINTF(&key, "/rendezvous/%s/RightDomId", name);
while(!rdomstr) { rdomstr = xs_read(iface->xs, 0, key, &len); };
sscanf(rdomstr, "dom%d", &other);
/* grants <- read <$> waitForKey xs (targetPAth ++ "/RightGrantRefs") */
free(key), ASPRINTF(&key, "/rendezvous/%s/RightGrantRefs", name);
while(!rrefstr) { rrefstr = xs_read(iface->xs, 0, key, &len); }
grants = parseRefs(rrefstr, &num_refs);
buffer = xc_gnttab_map_domain_grant_refs(iface->gt, num_refs, other, grants,
PROT_READWRITE);
assert(buffer);
/* ports <- read <$> waitForKey xs (targetPAth ++ "/RightPorts") */
free(key), ASPRINTF(&key, "/rendezvous/%s/RightPorts", name);
while(!rpstr) { rpstr = xs_read(iface->xs, 0, key, &len); }
sscanf(rpstr, "[echan:%d]", &port);
port = xc_evtchn_bind_interdomain(iface->ec, other, port);
assert(port >= 0);
/* res <- acceptConnection other grants ports extra */
res = buildChannel(iface, other, type, port, buffer, num_refs * 4096, per, 0);
/* xsWrite xs (targetPath ++ "/LeftConnectionConfirmed") "True" */
free(key), ASPRINTF(&key, "/rendezvous/%s/LeftConnectionConfirmed", name);
free(val), ASPRINTF(&val, "True");
xs_write(iface->xs, 0, key, val, strlen(val));
/* return res */
return res;
}
示例7: xenstore_read_vncpasswd
int xenstore_read_vncpasswd(int domid, char *pwbuf, size_t pwbuflen)
{
char *buf = NULL, *path, *uuid = NULL, *passwd = NULL;
unsigned int i, len, rc = 0;
if (xsh == NULL) {
return -1;
}
path = xs_get_domain_path(xsh, domid);
if (path == NULL) {
fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
return -1;
}
pasprintf(&buf, "%s/vm", path);
uuid = xs_read(xsh, XBT_NULL, buf, &len);
if (uuid == NULL) {
fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
free(path);
return -1;
}
pasprintf(&buf, "%s/vncpasswd", uuid);
passwd = xs_read(xsh, XBT_NULL, buf, &len);
if (passwd == NULL) {
fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
pwbuf[0] = '\0';
free(uuid);
free(path);
return rc;
}
for (i=0; i<len && i<pwbuflen; i++) {
pwbuf[i] = passwd[i];
}
pwbuf[len < (pwbuflen-1) ? len : (pwbuflen-1)] = '\0';
passwd[0] = '\0';
pasprintf(&buf, "%s/vncpasswd", uuid);
if (xs_write(xsh, XBT_NULL, buf, passwd, len) == 0) {
fprintf(logfile, "xs_write() vncpasswd failed.\n");
rc = -1;
}
free(passwd);
free(uuid);
free(path);
return rc;
}
示例8: do_read
/* wrapper around xs_read
*/
static char*
do_read (xs_handle_t *xsh, char* path)
{
char *val = NULL, *san_val = NULL, *tmp = NULL;
static struct expanding_buffer ebuf = { 0, };
unsigned len = 0;
val = xs_read (xsh, 0, path, &len);
if (val == NULL) {
syslog (LOG_WARNING,
"xs_read on %s returned null",
path);
return NULL;
}
san_val = sanitise_value (&ebuf, val, len);
if (san_val == NULL) {
syslog (LOG_CRIT, "sanitise_value returned NULL");
free (val);
return NULL;
}
tmp = strdup (san_val);
/* don't free san_val */
free (val);
return tmp;
}
示例9: xenStoreDomainGetUUID
/*
* The caller must hold the lock on the privateData
* associated with the 'conn' parameter.
*/
int
xenStoreDomainGetUUID(virConnectPtr conn, int id, unsigned char *uuid)
{
char prop[200];
xenUnifiedPrivatePtr priv = conn->privateData;
unsigned int len;
char *uuidstr;
int ret = 0;
if (priv->xshandle == NULL)
return -1;
snprintf(prop, 199, "/local/domain/%d/vm", id);
prop[199] = 0;
/* This will return something like
* /vm/00000000-0000-0000-0000-000000000000[-*] */
uuidstr = xs_read(priv->xshandle, 0, prop, &len);
/* Strip optional version suffix when VM was renamed */
if (len > 40) /* strlen('/vm/') + VIR_UUID_STRING_BUFLEN - sizeof('\0') */
uuidstr[40] = '\0';
/* remove "/vm/" */
ret = virUUIDParse(uuidstr + 4, uuid);
VIR_FREE(uuidstr);
return ret;
}
示例10: xen_battery_init_mode
/* This function initializes the mode of the power management. */
static int32_t xen_battery_init_mode(struct xen_battery_manager *xbm)
{
char dompath[XEN_BUFSIZE];
char *value = NULL;
/* xen_extended_power_mgmt xenstore entry indicates whether or not extended
* power management support is requested for the hvm guest. Extended power
* management support includes power management support beyond S3, S4, S5.
* A value of 1 indicates pass-through pm support where upon pm resources
* are mapped to the guest as appropriate where as a value of 2 as set in
* non pass-through mode, requires qemu to take the onus of responding to
* relevant pm port reads/writes. */
if (0 > snprintf(dompath, sizeof(dompath),
"/local/domain/0/device-model/%d/xen_extended_power_mgmt",
xen_domid)) {
XBM_ERROR_MSG("snprintf failed\n");
return -1;
}
value = xs_read(xenstore, XBT_NULL, dompath, NULL);
if (NULL == value) {
XBM_ERROR_MSG("unable to read the content of \"%s\"\n", dompath);
return -1;
}
xbm->mode = strtoull(value, NULL, 10);
free(value);
return 0;
}
示例11: xenStoreDomainGetPCIID
/*
* xenStoreDomainGetPCIID:
* @conn: pointer to the connection.
* @id: the domain id
* @bdf: the PCI BDF
*
* Get the reference (i.e. the string number) for the device on that domain
* which uses the given PCI address
*
* The caller must hold the lock on the privateData
* associated with the 'conn' parameter.
*
* Returns the new string or NULL in case of error, the string must be
* freed by the caller.
*/
char *
xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf)
{
char dir[80], path[128], **list = NULL, *val = NULL;
unsigned int len, num;
size_t i;
char *ret = NULL;
xenUnifiedPrivatePtr priv = conn->privateData;
if (id < 0 || priv->xshandle == NULL || bdf == NULL)
return NULL;
snprintf(dir, sizeof(dir), "/local/domain/0/backend/pci/%d", id);
list = xs_directory(priv->xshandle, 0, dir, &num);
if (list == NULL)
return NULL;
for (i = 0; i < num; i++) {
snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev-0");
if ((val = xs_read(priv->xshandle, 0, path, &len)) == NULL)
break;
bool match = STREQ(val, bdf);
VIR_FREE(val);
if (match) {
ignore_value(VIR_STRDUP(ret, list[i]));
break;
}
}
VIR_FREE(list);
return ret;
}
示例12: check_bd_connected
/* In Xenstore, /local/domain/0/backend/vbd/<domid>/<device>/state,
* if available, must be XenbusStateConnected (= 4), otherwise there
* is no connected device.
*/
static int
check_bd_connected (xenUnifiedPrivatePtr priv, int device, int domid)
{
char s[256], *rs;
int r;
unsigned len = 0;
/* This code assumes we're connected if we can't get to
* xenstore, etc.
*/
if (!priv->xshandle) return 1;
snprintf (s, sizeof s, "/local/domain/0/backend/vbd/%d/%d/state",
domid, device);
s[sizeof s - 1] = '\0';
rs = xs_read (priv->xshandle, 0, s, &len);
if (!rs) return 1;
if (len == 0) {
/* Hmmm ... we can get to xenstore but it returns an empty
* string instead of an error. Assume it's not connected
* in this case.
*/
VIR_FREE(rs);
return 0;
}
r = STREQ (rs, "4");
VIR_FREE(rs);
return r;
}
示例13: get_pty_fd
static int get_pty_fd(struct xs_handle *xs, char *path, int seconds)
/* Check for a pty in xenstore, open it and return its fd.
* Assumes there is already a watch set in the store for this path. */
{
struct timeval tv;
fd_set watch_fdset;
int xs_fd = xs_fileno(xs), pty_fd = -1;
int start, now;
unsigned int len = 0;
char *pty_path, **watch_paths;;
start = now = time(NULL);
do {
tv.tv_usec = 0;
tv.tv_sec = (start + seconds) - now;
FD_ZERO(&watch_fdset);
FD_SET(xs_fd, &watch_fdset);
if (select(xs_fd + 1, &watch_fdset, NULL, NULL, &tv)) {
/* Read the watch to drain the buffer */
watch_paths = xs_read_watch(xs, &len);
free(watch_paths);
/* We only watch for one thing, so no need to
* disambiguate: just read the pty path */
pty_path = xs_read(xs, XBT_NULL, path, &len);
if (pty_path != NULL) {
pty_fd = open(pty_path, O_RDWR | O_NOCTTY);
if (pty_fd == -1)
err(errno, "Could not open tty `%s'",
pty_path);
free(pty_path);
}
}
} while (pty_fd == -1 && (now = time(NULL)) < start + seconds);
return pty_fd;
}
示例14: get_pty_fd
static int get_pty_fd(struct xs_handle *xs, char *path, int seconds)
/* Check for a pty in xenstore, open it and return its fd.
* Assumes there is already a watch set in the store for this path. */
{
struct timeval tv;
fd_set watch_fdset;
int xs_fd = xs_fileno(xs), pty_fd = -1;
int start, now;
unsigned int len = 0;
char *pty_path, **watch_paths;
start = now = time(NULL);
do {
tv.tv_usec = 0;
tv.tv_sec = (start + seconds) - now;
FD_ZERO(&watch_fdset);
FD_SET(xs_fd, &watch_fdset);
if (select(xs_fd + 1, &watch_fdset, NULL, NULL, &tv)) {
/* Read the watch to drain the buffer */
watch_paths = xs_read_watch(xs, &len);
free(watch_paths);
/* We only watch for one thing, so no need to
* disambiguate: just read the pty path */
pty_path = xs_read(xs, XBT_NULL, path, &len);
if (pty_path != NULL) {
if (access(pty_path, R_OK|W_OK) != 0)
continue;
pty_fd = open(pty_path, O_RDWR | O_NOCTTY);
if (pty_fd == -1)
err(errno, "Could not open tty `%s'",
pty_path);
free(pty_path);
}
}
} while (pty_fd == -1 && (now = time(NULL)) < start + seconds);
#ifdef __sun__
if (pty_fd != -1) {
struct termios term;
/*
* The pty may come from either xend (with pygrub) or
* xenconsoled. It may have tty semantics set up, or not.
* While it isn't strictly necessary to have those
* semantics here, it is good to have a consistent
* state that is the same as under Linux.
*
* If tcgetattr fails, they have not been set up,
* so go ahead and set them up now, by pushing the
* ptem and ldterm streams modules.
*/
if (tcgetattr(pty_fd, &term) < 0) {
ioctl(pty_fd, I_PUSH, "ptem");
ioctl(pty_fd, I_PUSH, "ldterm");
}
}
#endif
return pty_fd;
}
示例15: suspend_qemu
static int suspend_qemu(checkpoint_state *s)
{
char path[128];
fprintf(stderr, "pausing QEMU\n");
sprintf(path, "/local/domain/0/device-model/%d/command", s->domid);
if (!xs_write(s->xsh, XBT_NULL, path, "save", 4)) {
fprintf(stderr, "error signalling QEMU to save\n");
return -1;
}
sprintf(path, "/local/domain/0/device-model/%d/state", s->domid);
do {
char* state;
unsigned int len;
state = xs_read(s->xsh, XBT_NULL, path, &len);
if (!state) {
s->errstr = "error reading QEMU state";
return -1;
}
if (!strcmp(state, "paused")) {
free(state);
return 0;
}
free(state);
usleep(1000);
} while(1);
return -1;
}