]>
git.proxmox.com Git - mirror_qemu.git/blob - hw/xen/xen_pvdev.c
2 * Xen para-virtualization device
4 * (c) 2008 Gerd Hoffmann <kraxel@redhat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>
20 #include "qemu/osdep.h"
22 #include "hw/xen/xen_backend.h"
23 #include "hw/xen/xen_pvdev.h"
26 /* ------------------------------------------------------------- */
28 int xenstore_write_str(const char *base
, const char *node
, const char *val
)
30 char abspath
[XEN_BUFSIZE
];
32 snprintf(abspath
, sizeof(abspath
), "%s/%s", base
, node
);
33 if (!xs_write(xenstore
, 0, abspath
, val
, strlen(val
))) {
39 char *xenstore_read_str(const char *base
, const char *node
)
41 char abspath
[XEN_BUFSIZE
];
43 char *str
, *ret
= NULL
;
45 snprintf(abspath
, sizeof(abspath
), "%s/%s", base
, node
);
46 str
= xs_read(xenstore
, 0, abspath
, &len
);
48 /* move to qemu-allocated memory to make sure
49 * callers can savely g_free() stuff. */
56 int xenstore_write_int(const char *base
, const char *node
, int ival
)
60 snprintf(val
, sizeof(val
), "%d", ival
);
61 return xenstore_write_str(base
, node
, val
);
64 int xenstore_write_int64(const char *base
, const char *node
, int64_t ival
)
68 snprintf(val
, sizeof(val
), "%"PRId64
, ival
);
69 return xenstore_write_str(base
, node
, val
);
72 int xenstore_read_int(const char *base
, const char *node
, int *ival
)
77 val
= xenstore_read_str(base
, node
);
78 if (val
&& 1 == sscanf(val
, "%d", ival
)) {
85 int xenstore_read_uint64(const char *base
, const char *node
, uint64_t *uval
)
90 val
= xenstore_read_str(base
, node
);
91 if (val
&& 1 == sscanf(val
, "%"SCNu64
, uval
)) {
98 const char *xenbus_strstate(enum xenbus_state state
)
100 static const char *const name
[] = {
101 [XenbusStateUnknown
] = "Unknown",
102 [XenbusStateInitialising
] = "Initialising",
103 [XenbusStateInitWait
] = "InitWait",
104 [XenbusStateInitialised
] = "Initialised",
105 [XenbusStateConnected
] = "Connected",
106 [XenbusStateClosing
] = "Closing",
107 [XenbusStateClosed
] = "Closed",
109 return (state
< ARRAY_SIZE(name
)) ? name
[state
] : "INVALID";
114 * 0 == errors (stderr + logfile).
115 * 1 == informative debug messages (logfile only).
116 * 2 == noisy debug messages (logfile only).
117 * 3 == will flood your log (logfile only).
119 void xen_be_printf(struct XenDevice
*xendev
, int msg_level
,
120 const char *fmt
, ...)
125 if (msg_level
> xendev
->debug
) {
128 qemu_log("xen be: %s: ", xendev
->name
);
129 if (msg_level
== 0) {
130 fprintf(stderr
, "xen be: %s: ", xendev
->name
);
133 if (msg_level
> debug
) {
136 qemu_log("xen be core: ");
137 if (msg_level
== 0) {
138 fprintf(stderr
, "xen be core: ");
142 qemu_log_vprintf(fmt
, args
);
144 if (msg_level
== 0) {
146 vfprintf(stderr
, fmt
, args
);