Gerd Hoffmann
2009-Apr-21 16:38 UTC
[Xen-devel] [PATCH 0/7] qemu-xen patches: upstream review changes.
Hi, Here comes a series of patches for qemu-xen, making the code identical to the xen support patches being submitted to upstream qemu. The review process on qemu-devel resulted in a number of fixes and cleanups in the backend code, this is where most of the changes come from. There are also some xenfb changes due to displaystate reorganization and xenfb being merged in steps due to that. Changes are also available for pull from from git://git.et.redhat.com/qemu-kraxel.git, branch qx.misc.v6 cheers, Gerd _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/xen_backend.h | 2 +- hw/xen_machine_pv.c | 2 +- hw/xenfb.c | 195 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 116 insertions(+), 83 deletions(-) diff --git a/hw/xen_backend.h b/hw/xen_backend.h index 9aa8d13..8c93c9f 100644 --- a/hw/xen_backend.h +++ b/hw/xen_backend.h @@ -89,6 +89,6 @@ extern struct XenDevOps xen_console_ops; /* xen_console.c */ extern struct XenDevOps xen_kbdmouse_ops; /* xen_framebuffer.c */ extern struct XenDevOps xen_framebuffer_ops; /* xen_framebuffer.c */ -void xen_set_display(int domid); +void xen_init_display(int domid); #endif /* QEMU_HW_XEN_BACKEND_H */ diff --git a/hw/xen_machine_pv.c b/hw/xen_machine_pv.c index 6bfafbb..5536842 100644 --- a/hw/xen_machine_pv.c +++ b/hw/xen_machine_pv.c @@ -71,7 +71,7 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size, xen_be_register("vfb", &xen_framebuffer_ops); /* setup framebuffer */ - xen_set_display(xen_domid); + xen_init_display(xen_domid); } QEMUMachine xenpv_machine = { diff --git a/hw/xenfb.c b/hw/xenfb.c index 4b71bf2..135764d 100644 --- a/hw/xenfb.c +++ b/hw/xenfb.c @@ -86,6 +86,8 @@ struct XenFB { int feature_update; int refresh_period; int bug_trigger; + int have_console; + int do_resize; struct { int x,y,w,h; @@ -129,10 +131,11 @@ static void common_unbind(struct common *c) /* -------------------------------------------------------------------- */ +#ifdef CONFIG_STUBDOM /* - * These two tables are not needed any more here, but left in here - * intentionally as documentation, to show how scancode2linux[] was - * generated, and also because xenfbfront needs them. + * These two tables are not needed any more, but left in here + * intentionally as documentation, to show how scancode2linux[] + * was generated. * * Tables to map from scancode to Linux input layer keycode. * Scancodes are hardware-specific. These maps assumes a @@ -172,6 +175,7 @@ const unsigned char atkbd_unxlate_table[128] = { 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110 }; +#endif /* * for (i = 0; i < 128; i++) { @@ -320,12 +324,14 @@ static void xenfb_mouse_event(void *opaque, int dx, int dy, int dz, int button_state) { struct XenInput *xenfb = opaque; + int dw = ds_get_width(xenfb->c.ds); + int dh = ds_get_height(xenfb->c.ds); int i; if (xenfb->abs_pointer_wanted) xenfb_send_position(xenfb, - dx * (ds_get_width(xenfb->c.ds) - 1) / 0x7fff, - dy * (ds_get_height(xenfb->c.ds) - 1) / 0x7fff, + dx * (dw - 1) / 0x7fff, + dy * (dh - 1) / 0x7fff, dz); else xenfb_send_motion(xenfb, dx, dy, dz); @@ -346,6 +352,11 @@ static int input_init(struct XenDevice *xendev) { struct XenInput *in = container_of(xendev, struct XenInput, c.xendev); + if (!in->c.ds) { + xen_be_printf(xendev, 1, "ds not set (yet)\n"); + return -1; + } + xenstore_write_be_int(xendev, "feature-abs-pointer", 1); return 0; } @@ -547,6 +558,8 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, xenfb->width = width; xenfb->height = height; xenfb->offset = offset; + xenfb->up_fullscreen = 1; + xenfb->do_resize = 1; xen_be_printf(&xenfb->c.xendev, 1, "framebuffer %dx%dx%d offset %d stride %d\n", width, height, depth, offset, row_stride); return 0; @@ -559,9 +572,9 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, + xenfb->offset \ + (line * xenfb->row_stride) \ + (x * xenfb->depth / 8)); \ - DST_T *dst = (DST_T *)(ds_get_data(xenfb->c.ds) \ - + (line * ds_get_linesize(xenfb->c.ds)) \ - + (x * ds_get_bytes_per_pixel(xenfb->c.ds))); \ + DST_T *dst = (DST_T *)(data \ + + (line * linesize) \ + + (x * bpp / 8)); \ int col; \ const int RSS = 32 - (RSB + GSB + BSB); \ const int GSS = 32 - (GSB + BSB); \ @@ -581,55 +594,52 @@ static int xenfb_configure_fb(struct XenFB *xenfb, size_t fb_len_lim, (((spix << GSS) & GSM & GDM) >> GDS) | \ (((spix << BSS) & BSM & BDM) >> BDS); \ src = (SRC_T *) ((unsigned long) src + xenfb->depth / 8); \ - dst = (DST_T *) ((unsigned long) dst + ds_get_bytes_per_pixel(xenfb->c.ds)); \ + dst = (DST_T *) ((unsigned long) dst + bpp / 8); \ } \ } -/* This copies data from the guest framebuffer region, into QEMU''s copy - * NB. QEMU''s copy is stored in the pixel format of a) the local X - * server (SDL case) or b) the current VNC client pixel format. - * When shifting between colour depths we preserve the MSB. +/* + * This copies data from the guest framebuffer region, into QEMU''s + * displaysurface. qemu uses 16 or 32 bpp. In case the pv framebuffer + * uses something else we must convert and copy, otherwise we can + * supply the buffer directly and no thing here. */ static void xenfb_guest_copy(struct XenFB *xenfb, int x, int y, int w, int h) { - int line; + int line, oops = 0; + int bpp = ds_get_bits_per_pixel(xenfb->c.ds); + int linesize = ds_get_linesize(xenfb->c.ds); + uint8_t *data = ds_get_data(xenfb->c.ds); if (!is_buffer_shared(xenfb->c.ds->surface)) { - if (xenfb->depth == ds_get_bits_per_pixel(xenfb->c.ds)) { /* Perfect match can use fast path */ - for (line = y ; line < (y+h) ; line++) { - memcpy(ds_get_data(xenfb->c.ds) + (line * ds_get_linesize(xenfb->c.ds)) + (x * ds_get_bytes_per_pixel(xenfb->c.ds)), - xenfb->pixels + xenfb->offset + (line * xenfb->row_stride) + (x * xenfb->depth / 8), - w * xenfb->depth / 8); - } - } else { /* Mismatch requires slow pixel munging */ - /* 8 bit == r:3 g:3 b:2 */ - /* 16 bit == r:5 g:6 b:5 */ - /* 24 bit == r:8 g:8 b:8 */ - /* 32 bit == r:8 g:8 b:8 (padding:8) */ - if (xenfb->depth == 8) { - if (ds_get_bits_per_pixel(xenfb->c.ds) == 16) { - BLT(uint8_t, uint16_t, 3, 3, 2, 5, 6, 5); - } else if (ds_get_bits_per_pixel(xenfb->c.ds) == 32) { - BLT(uint8_t, uint32_t, 3, 3, 2, 8, 8, 8); - } - } else if (xenfb->depth == 16) { - if (ds_get_bits_per_pixel(xenfb->c.ds) == 8) { - BLT(uint16_t, uint8_t, 5, 6, 5, 3, 3, 2); - } else if (ds_get_bits_per_pixel(xenfb->c.ds) == 32) { - BLT(uint16_t, uint32_t, 5, 6, 5, 8, 8, 8); - } - } else if (xenfb->depth == 24 || xenfb->depth == 32) { - if (ds_get_bits_per_pixel(xenfb->c.ds) == 8) { - BLT(uint32_t, uint8_t, 8, 8, 8, 3, 3, 2); - } else if (ds_get_bits_per_pixel(xenfb->c.ds) == 16) { - BLT(uint32_t, uint16_t, 8, 8, 8, 5, 6, 5); - } else if (ds_get_bits_per_pixel(xenfb->c.ds) == 32) { - BLT(uint32_t, uint32_t, 8, 8, 8, 8, 8, 8); - } - } + switch (xenfb->depth) { + case 8: + if (bpp == 16) { + BLT(uint8_t, uint16_t, 3, 3, 2, 5, 6, 5); + } else if (bpp == 32) { + BLT(uint8_t, uint32_t, 3, 3, 2, 8, 8, 8); + } else { + oops = 1; + } + break; + case 24: + if (bpp == 16) { + BLT(uint32_t, uint16_t, 8, 8, 8, 5, 6, 5); + } else if (bpp == 32) { + BLT(uint32_t, uint32_t, 8, 8, 8, 8, 8, 8); + } else { + oops = 1; + } + break; + default: + oops = 1; } } + if (oops) /* should not happen */ + xen_be_printf(&xenfb->c.xendev, 0, "%s: oops: convert %d -> %d bpp?\n", + __FUNCTION__, xenfb->depth, bpp); + dpy_update(xenfb->c.ds, x, y, w, h); } @@ -685,10 +695,12 @@ static void xenfb_send_refresh_period(struct XenFB *xenfb, int period) static void xenfb_update(void *opaque) { struct XenFB *xenfb = opaque; - int i; struct DisplayChangeListener *l; + int dw = ds_get_width(xenfb->c.ds); + int dh = ds_get_height(xenfb->c.ds); + int i; - if (!xenfb->width || !xenfb->height) + if (xenfb->c.xendev.be_state != XenbusStateConnected) return; if (xenfb->feature_update) { @@ -712,11 +724,12 @@ static void xenfb_update(void *opaque) } } if (idle) - period = XENFB_NO_REFRESH; + period = XENFB_NO_REFRESH; if (xenfb->refresh_period != period) { xenfb_send_refresh_period(xenfb, period); xenfb->refresh_period = period; + xen_be_printf(&xenfb->c.xendev, 1, "refresh period: %d\n", period); } #else ; /* nothing */ @@ -728,11 +741,8 @@ static void xenfb_update(void *opaque) } /* resize if needed */ - if (xenfb->width != ds_get_width(xenfb->c.ds) || - xenfb->height != ds_get_height(xenfb->c.ds) || - xenfb->depth != ds_get_bits_per_pixel(xenfb->c.ds) || - xenfb->row_stride != ds_get_linesize(xenfb->c.ds) || - xenfb->pixels + xenfb->offset != ds_get_data(xenfb->c.ds)) { + if (xenfb->do_resize) { + xenfb->do_resize = 0; switch (xenfb->depth) { case 16: case 32: @@ -747,9 +757,10 @@ static void xenfb_update(void *opaque) qemu_resize_displaysurface(xenfb->c.ds, xenfb->width, xenfb->height); break; } + xen_be_printf(&xenfb->c.xendev, 1, "update: resizing: %dx%d @ %d bpp%s\n", + xenfb->width, xenfb->height, xenfb->depth, + is_buffer_shared(xenfb->c.ds->surface) ? " (shared)" : ""); dpy_resize(xenfb->c.ds); - xen_be_printf(&xenfb->c.xendev, 1, "update: resizing: %dx%d\n", - xenfb->width, xenfb->height); xenfb->up_fullscreen = 1; } @@ -881,6 +892,17 @@ static int fb_connect(struct XenDevice *xendev) if (0 != rc) return rc; +#if 0 /* handled in xen_init_display() for now */ + if (!fb->have_console) { + fb->c.ds = graphic_console_init(xenfb_update, + xenfb_invalidate, + NULL, + NULL, + fb); + fb->have_console = 1; + } +#endif + if (-1 == xenstore_read_fe_int(xendev, "feature-update", &fb->feature_update)) fb->feature_update = 0; if (fb->feature_update) @@ -888,7 +910,6 @@ static int fb_connect(struct XenDevice *xendev) xen_be_printf(xendev, 1, "feature-update=%d, videoram=%d\n", fb->feature_update, videoram); - return 0; } @@ -954,31 +975,43 @@ struct XenDevOps xen_framebuffer_ops = { .frontend_changed = fb_frontend_changed, }; -static void xen_set_display_type(int domid, const char *type, DisplayState *ds) +/* + * FIXME/TODO: Kill this. + * Temporary needed while DisplayState reorganization is in flight. + */ +void xen_init_display(int domid) { - struct XenDevice *xendev; - struct common *c; + struct XenDevice *xfb, *xin; + struct XenFB *fb; + struct XenInput *in; + int i = 0; + +wait_more: + i++; + main_loop_wait(10); /* miliseconds */ + xfb = xen_be_find_xendev("vfb", domid, 0); + xin = xen_be_find_xendev("vkbd", domid, 0); + if (!xfb || !xin) { + if (i < 256) + goto wait_more; + fprintf(stderr, "%s: displaystate setup failed\n", __FUNCTION__); + return; + } - xendev = xen_be_find_xendev(type, domid, 0); - if (!xendev) - return; - c = container_of(xendev, struct common, xendev); - c->ds = ds; - xen_be_printf(xendev, 1, "ds is %p\n", ds); - /* retry ->init() */ - xen_be_check_state(xendev); -} + /* vfb */ + fb = container_of(xfb, struct XenFB, c.xendev); + fb->c.ds = graphic_console_init(xenfb_update, + xenfb_invalidate, + NULL, + NULL, + fb); + fb->have_console = 1; -void xen_set_display(int domid) -{ - struct XenDevice *xendev = xen_be_find_xendev("vfb", domid, 0); - struct XenFB *fb = container_of(xendev, struct XenFB, c.xendev); - DisplayState *ds = graphic_console_init(xenfb_update, - xenfb_invalidate, - NULL, - NULL, - fb); - - xen_set_display_type(domid, "vkbd", ds); - xen_set_display_type(domid, "vfb", ds); + /* vkbd */ + in = container_of(xin, struct XenInput, c.xendev); + in->c.ds = fb->c.ds; + + /* retry ->init() */ + xen_be_check_state(xin); + xen_be_check_state(xfb); } -- 1.6.2.2 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/xen_machine_pv.c | 9 --------- 1 files changed, 0 insertions(+), 9 deletions(-) diff --git a/hw/xen_machine_pv.c b/hw/xen_machine_pv.c index 5536842..4c0ee92 100644 --- a/hw/xen_machine_pv.c +++ b/hw/xen_machine_pv.c @@ -82,12 +82,3 @@ QEMUMachine xenpv_machine = { .max_cpus = 1, .nodisk_ok = 1, }; - -/* - * Local variables: - * indent-tabs-mode: nil - * c-indent-level: 4 - * c-basic-offset: 4 - * tab-width: 4 - * End: - */ -- 1.6.2.2 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Gerd Hoffmann
2009-Apr-21 16:38 UTC
[Xen-devel] [PATCH 3/7] merge review: fix fsf address & compare style
changes coming from upstream merge review (style only, no code changes). - Update FSF address. - Fix strage compare style. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/xen_backend.c | 54 +++++++++++++++++++++++++------------------------- hw/xen_console.c | 12 +++++----- hw/xen_machine_pv.c | 2 +- hw/xenfb.c | 35 +++++++++++++++++---------------- 4 files changed, 52 insertions(+), 51 deletions(-) diff --git a/hw/xen_backend.c b/hw/xen_backend.c index 2bd4433..56b001f 100644 --- a/hw/xen_backend.c +++ b/hw/xen_backend.c @@ -11,9 +11,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* @@ -162,7 +162,7 @@ struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev) continue; if (xendev->dev != dev) continue; - if (0 != strcmp(xendev->type, type)) + if (strcmp(xendev->type, type) != 0) continue; return xendev; } @@ -278,8 +278,8 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev) */ static void xen_be_backend_changed(struct XenDevice *xendev, const char *node) { - if (NULL == node || 0 == strcmp(node, "online")) { - if (-1 == xenstore_read_be_int(xendev, "online", &xendev->online)) + if (node == NULL || strcmp(node, "online") == 0) { + if (xenstore_read_be_int(xendev, "online", &xendev->online) == -1) xendev->online = 0; } @@ -294,8 +294,8 @@ static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) { int fe_state; - if (NULL == node || 0 == strcmp(node, "state")) { - if (-1 == xenstore_read_fe_int(xendev, "state", &fe_state)) + if (node == NULL || strcmp(node, "state") == 0) { + if (xenstore_read_fe_int(xendev, "state", &fe_state) == -1) fe_state = XenbusStateUnknown; if (xendev->fe_state != fe_state) xen_be_printf(xendev, 1, "frontend state: %s -> %s\n", @@ -303,7 +303,7 @@ static void xen_be_frontend_changed(struct XenDevice *xendev, const char *node) xenbus_strstate(fe_state)); xendev->fe_state = fe_state; } - if (NULL == node || 0 == strcmp(node, "protocol")) { + if (node == NULL || strcmp(node, "protocol") == 0) { qemu_free(xendev->protocol); xendev->protocol = xenstore_read_fe_str(xendev, "protocol"); if (xendev->protocol) @@ -333,7 +333,7 @@ static int xen_be_try_setup(struct XenDevice *xendev) char token[XEN_BUFSIZE]; int be_state; - if (-1 == xenstore_read_be_int(xendev, "state", &be_state)) { + if (xenstore_read_be_int(xendev, "state", &be_state) == -1) { xen_be_printf(xendev, 0, "reading backend state failed\n"); return -1; } @@ -345,7 +345,7 @@ static int xen_be_try_setup(struct XenDevice *xendev) } xendev->fe = xenstore_read_be_str(xendev, "frontend"); - if (NULL == xendev->fe) { + if (xendev->fe == NULL) { xen_be_printf(xendev, 0, "reading frontend path failed\n"); return -1; } @@ -383,7 +383,7 @@ static int xen_be_try_init(struct XenDevice *xendev) if (xendev->ops->init) rc = xendev->ops->init(xendev); - if (0 != rc) { + if (rc != 0) { xen_be_printf(xendev, 1, "init() failed\n"); return rc; } @@ -416,7 +416,7 @@ static int xen_be_try_connect(struct XenDevice *xendev) if (xendev->ops->connect) rc = xendev->ops->connect(xendev); - if (0 != rc) { + if (rc != 0) { xen_be_printf(xendev, 0, "connect() failed\n"); return rc; } @@ -485,7 +485,7 @@ void xen_be_check_state(struct XenDevice *xendev) default: rc = -1; } - if (0 != rc) + if (rc != 0) break; } } @@ -515,7 +515,7 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops) return 0; for (j = 0; j < cdev; j++) { xendev = xen_be_get_xendev(type, dom, atoi(dev[j]), ops); - if (NULL == xendev) + if (xendev == NULL) continue; xen_be_check_state(xendev); } @@ -533,14 +533,14 @@ static void xenstore_update_be(char *watch, char *type, int dom, dom0 = xs_get_domain_path(xenstore, 0); len = snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom); free(dom0); - if (0 != strncmp(path, watch, len)) + if (strncmp(path, watch, len) != 0) return; - if (2 != sscanf(watch+len, "/%u/%255s", &dev, path)) { + if (sscanf(watch+len, "/%u/%255s", &dev, path) != 2) { strcpy(path, ""); - if (1 != sscanf(watch+len, "/%u", &dev)) + if (sscanf(watch+len, "/%u", &dev) != 1) dev = -1; } - if (-1 == dev) + if (dev == -1) return; if (0) { @@ -549,7 +549,7 @@ static void xenstore_update_be(char *watch, char *type, int dom, } xendev = xen_be_get_xendev(type, dom, dev, ops); - if (NULL != xendev) { + if (xendev != NULL) { xen_be_backend_changed(xendev, path); xen_be_check_state(xendev); } @@ -561,7 +561,7 @@ static void xenstore_update_fe(char *watch, struct XenDevice *xendev) unsigned int len; len = strlen(xendev->fe); - if (0 != strncmp(xendev->fe, watch, len)) + if (strncmp(xendev->fe, watch, len) != 0) return; if (watch[len] != ''/'') return; @@ -578,13 +578,13 @@ static void xenstore_update(void *unused) unsigned int dom, count; vec = xs_read_watch(xenstore, &count); - if (NULL == vec) + if (vec == NULL) goto cleanup; - if (3 == sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, - &type, &dom, &ops)) + if (sscanf(vec[XS_WATCH_TOKEN], "be:%" PRIxPTR ":%d:%" PRIxPTR, + &type, &dom, &ops) == 3) xenstore_update_be(vec[XS_WATCH_PATH], (void*)type, dom, (void*)ops); - if (1 == sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr)) + if (sscanf(vec[XS_WATCH_TOKEN], "fe:%" PRIxPTR, &ptr) == 1) xenstore_update_fe(vec[XS_WATCH_PATH], (void*)ptr); cleanup: @@ -622,7 +622,7 @@ int xen_be_init(void) goto err; xen_xc = xc_interface_open(); - if (-1 == xen_xc) { + if (xen_xc == -1) { fprintf(stderr, "can''t open xen interface\n"); goto err; } @@ -647,7 +647,7 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) return 0; xendev->local_port = xc_evtchn_bind_interdomain (xendev->evtchndev, xendev->dom, xendev->remote_port); - if (-1 == xendev->local_port) { + if (xendev->local_port == -1) { xen_be_printf(xendev, 0, "xc_evtchn_bind_interdomain failed\n"); return -1; } diff --git a/hw/xen_console.c b/hw/xen_console.c index c172cf2..707075e 100644 --- a/hw/xen_console.c +++ b/hw/xen_console.c @@ -15,9 +15,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include <stdlib.h> @@ -214,11 +214,11 @@ static int con_connect(struct XenDevice *xendev) struct XenConsole *con = container_of(xendev, struct XenConsole, xendev); int limit; - if (-1 == xenstore_read_int(con->console, "ring-ref", &con->ring_ref)) + if (xenstore_read_int(con->console, "ring-ref", &con->ring_ref) == -1) return -1; - if (-1 == xenstore_read_int(con->console, "port", &con->xendev.remote_port)) + if (xenstore_read_int(con->console, "port", &con->xendev.remote_port) == -1) return -1; - if (0 == xenstore_read_int(con->console, "limit", &limit)) + if (xenstore_read_int(con->console, "limit", &limit) == 0) con->buffer.max_capacity = limit; con->sring = xc_map_foreign_range(xen_xc, con->xendev.dom, diff --git a/hw/xen_machine_pv.c b/hw/xen_machine_pv.c index 4c0ee92..34fe4d4 100644 --- a/hw/xen_machine_pv.c +++ b/hw/xen_machine_pv.c @@ -62,7 +62,7 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size, env->halted = 1; /* Initialize backend core & drivers */ - if (-1 == xen_be_init()) { + if (xen_be_init() != 0) { fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__); exit(1); } diff --git a/hw/xenfb.c b/hw/xenfb.c index 135764d..8336c82 100644 --- a/hw/xenfb.c +++ b/hw/xenfb.c @@ -20,9 +20,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include <stdarg.h> @@ -102,15 +102,15 @@ static int common_bind(struct common *c) { int mfn; - if (-1 == xenstore_read_fe_int(&c->xendev, "page-ref", &mfn)) + if (xenstore_read_fe_int(&c->xendev, "page-ref", &mfn) == -1) return -1; - if (-1 == xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port)) + if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1) return -1; c->page = xc_map_foreign_range(xen_xc, c->xendev.dom, XC_PAGE_SIZE, PROT_READ | PROT_WRITE, mfn); - if (NULL == c->page) + if (c->page == NULL) return -1; xen_be_bind_evtchn(&c->xendev); @@ -366,11 +366,12 @@ static int input_connect(struct XenDevice *xendev) struct XenInput *in = container_of(xendev, struct XenInput, c.xendev); int rc; - if (-1 == xenstore_read_fe_int(xendev, "request-abs-pointer", &in->abs_pointer_wanted)) + if (xenstore_read_fe_int(xendev, "request-abs-pointer", + &in->abs_pointer_wanted) == -1) in->abs_pointer_wanted = 0; rc = common_bind(&in->c); - if (0 != rc) + if (rc != 0) return rc; qemu_add_kbd_event_handler(xenfb_key_event, in); @@ -450,7 +451,7 @@ static int xenfb_map_fb(struct XenFB *xenfb) ptr64 = (void*)page->pd; #endif if (ptr32) { - if (0 == ptr32[1]) { + if (ptr32[1] == 0) { mode = 32; pd = ptr32; } else { @@ -459,12 +460,12 @@ static int xenfb_map_fb(struct XenFB *xenfb) } } #if defined(__x86_64__) - } else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32)) { + } else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_32) == 0) { /* 64bit dom0, 32bit domU */ mode = 32; pd = ((void*)page->pd) - 4; #elif defined(__i386__) - } else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_64)) { + } else if (strcmp(protocol, XEN_IO_PROTO_ABI_X86_64) == 0) { /* 32bit dom0, 64bit domU */ mode = 64; pd = ((void*)page->pd) + 4; @@ -874,22 +875,22 @@ static int fb_connect(struct XenDevice *xendev) int videoram; int rc; - if (-1 == xenstore_read_fe_int(xendev, "videoram", &videoram)) + if (xenstore_read_fe_int(xendev, "videoram", &videoram) == -1) videoram = 0; rc = common_bind(&fb->c); - if (0 != rc) + if (rc != 0) return rc; fb_page = fb->c.page; rc = xenfb_configure_fb(fb, videoram * 1024 * 1024U, fb_page->width, fb_page->height, fb_page->depth, fb_page->mem_length, 0, fb_page->line_length); - if (0 != rc) + if (rc != 0) return rc; rc = xenfb_map_fb(fb); - if (0 != rc) + if (rc != 0) return rc; #if 0 /* handled in xen_init_display() for now */ @@ -903,7 +904,7 @@ static int fb_connect(struct XenDevice *xendev) } #endif - if (-1 == xenstore_read_fe_int(xendev, "feature-update", &fb->feature_update)) + if (xenstore_read_fe_int(xendev, "feature-update", &fb->feature_update) == -1) fb->feature_update = 0; if (fb->feature_update) xenstore_write_be_int(xendev, "request-update", 1); @@ -939,7 +940,7 @@ static void fb_frontend_changed(struct XenDevice *xendev, const char *node) * to connected. We must trigger the watch a second time to * workaround a frontend bug. */ - if (0 == fb->bug_trigger && 0 == strcmp(node, "state") && + if (fb->bug_trigger == 0 && strcmp(node, "state") == 0 && xendev->fe_state == XenbusStateConnected && xendev->be_state == XenbusStateConnected) { xen_be_printf(xendev, 2, "re-trigger connected (frontend bug)\n"); -- 1.6.2.2 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Gerd Hoffmann
2009-Apr-21 16:38 UTC
[Xen-devel] [PATCH 4/7] merge review: no malloc failure checks.
qemu_malloc() will never return errors. It will abort instead. Thus no checks for failure are needed. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/xen_backend.c | 14 ++++++++++---- hw/xenfb.c | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/xen_backend.c b/hw/xen_backend.c index 56b001f..bb02634 100644 --- a/hw/xen_backend.c +++ b/hw/xen_backend.c @@ -67,9 +67,17 @@ char *xenstore_read_str(const char *base, const char *node) { char abspath[XEN_BUFSIZE]; unsigned int len; + char *str, *ret = NULL; snprintf(abspath, sizeof(abspath), "%s/%s", base, node); - return xs_read(xenstore, 0, abspath, &len); + str = xs_read(xenstore, 0, abspath, &len); + if (str != NULL) { + /* move to qemu-allocated memory to make sure + * callers can savely qemu_free() stuff. */ + ret = qemu_strdup(str); + free(str); + } + return ret; } int xenstore_write_int(const char *base, const char *node, int ival) @@ -184,8 +192,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, /* init new xendev */ xendev = qemu_mallocz(ops->size); - if (!xendev) - return NULL; xendev->type = type; xendev->dom = dom; xendev->dev = dev; @@ -519,7 +525,7 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops) continue; xen_be_check_state(xendev); } - qemu_free(dev); + free(dev); return 0; } diff --git a/hw/xenfb.c b/hw/xenfb.c index 8336c82..1764ac2 100644 --- a/hw/xenfb.c +++ b/hw/xenfb.c @@ -483,8 +483,6 @@ static int xenfb_map_fb(struct XenFB *xenfb) pgmfns = qemu_mallocz(sizeof(unsigned long) * n_fbdirs); fbmfns = qemu_mallocz(sizeof(unsigned long) * xenfb->fbpages); - if (!pgmfns || !fbmfns) - goto out; xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd); map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom, -- 1.6.2.2 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Use new logging API. Kill a few fprintf(stderr, "...") calls. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/xen_backend.c | 42 +++++++++++++++++++++++++++++------------- hw/xen_console.c | 6 ------ hw/xenfb.c | 15 +++++++-------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/hw/xen_backend.c b/hw/xen_backend.c index bb02634..2f2ec7f 100644 --- a/hw/xen_backend.c +++ b/hw/xen_backend.c @@ -209,7 +209,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->evtchndev = xc_evtchn_open(); if (xendev->evtchndev < 0) { - fprintf(stderr, "can''t open evtchn device\n"); + xen_be_printf(NULL, 0, "can''t open evtchn device\n"); qemu_free(xendev); return NULL; } @@ -218,7 +218,7 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) { xendev->gnttabdev = xc_gnttab_open(); if (xendev->gnttabdev < 0) { - fprintf(stderr, "can''t open gnttab device\n"); + xen_be_printf(NULL, 0, "can''t open gnttab device\n"); xc_evtchn_close(xendev->evtchndev); qemu_free(xendev); return NULL; @@ -511,7 +511,7 @@ static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops) snprintf(path, sizeof(path), "%s/backend/%s/%d", dom0, type, dom); free(dom0); if (!xs_watch(xenstore, path, token)) { - fprintf(stderr, "xen be: watching backend path (%s) failed\n", path); + xen_be_printf(NULL, 0, "xen be: watching backend path (%s) failed\n", path); return -1; } @@ -620,7 +620,7 @@ int xen_be_init(void) { xenstore = xs_daemon_open(); if (!xenstore) { - fprintf(stderr, "can''t connect to xenstored\n"); + xen_be_printf(NULL, 0, "can''t connect to xenstored\n"); return -1; } @@ -629,7 +629,7 @@ int xen_be_init(void) xen_xc = xc_interface_open(); if (xen_xc == -1) { - fprintf(stderr, "can''t open xen interface\n"); + xen_be_printf(NULL, 0, "can''t open xen interface\n"); goto err; } return 0; @@ -680,19 +680,35 @@ int xen_be_send_notify(struct XenDevice *xendev) /* * msg_level: - * 0 == errors. - * 1 == informative debug messages. - * 2 == noisy debug messages. - * 3 == will flood your log. + * 0 == errors (stderr + logfile). + * 1 == informative debug messages (logfile only). + * 2 == noisy debug messages (logfile only). + * 3 == will flood your log (logfile only). */ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...) { va_list args; - if (msg_level > xendev->debug) - return; - fprintf(stderr, "xen be: %s: ", xendev->name); + if (xendev) { + if (msg_level > xendev->debug) + return; + qemu_log("xen be: %s: ", xendev->name); + if (msg_level == 0) + fprintf(stderr, "xen be: %s: ", xendev->name); + } else { + if (msg_level > debug) + return; + qemu_log("xen be core: "); + if (msg_level == 0) + fprintf(stderr, "xen be core: "); + } va_start(args, fmt); - vfprintf(stderr, fmt, args); + qemu_log_vprintf(fmt, args); va_end(args); + if (msg_level == 0) { + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); + } + qemu_log_flush(); } diff --git a/hw/xen_console.c b/hw/xen_console.c index 707075e..27f809d 100644 --- a/hw/xen_console.c +++ b/hw/xen_console.c @@ -38,8 +38,6 @@ #include "qemu-char.h" #include "xen_backend.h" -#define dolog(val, fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__) - struct buffer { uint8_t *data; size_t consumed; @@ -75,10 +73,6 @@ static void buffer_append(struct XenConsole *con) if ((buffer->capacity - buffer->size) < size) { buffer->capacity += (size + 1024); buffer->data = qemu_realloc(buffer->data, buffer->capacity); - if (buffer->data == NULL) { - dolog(LOG_ERR, "Memory allocation failed"); - exit(ENOMEM); - } } while (cons != prod) diff --git a/hw/xenfb.c b/hw/xenfb.c index 1764ac2..d9e5c33 100644 --- a/hw/xenfb.c +++ b/hw/xenfb.c @@ -813,15 +813,14 @@ static void xenfb_handle_events(struct XenFB *xenfb) w = MIN(event->update.width, xenfb->width - x); h = MIN(event->update.height, xenfb->height - y); if (w < 0 || h < 0) { - fprintf(stderr, "xen be: %s: bogus update ignored\n", - xenfb->c.xendev.name); + xen_be_printf(&xenfb->c.xendev, 1, "bogus update ignored\n"); break; } - if (x != event->update.x || y != event->update.y - || w != event->update.width - || h != event->update.height) { - fprintf(stderr, "xen be: %s: bogus update clipped\n", - xenfb->c.xendev.name); + if (x != event->update.x || + y != event->update.y || + w != event->update.width || + h != event->update.height) { + xen_be_printf(&xenfb->c.xendev, 1, "bogus update clipped\n"); } if (w == xenfb->width && h > xenfb->height / 2) { /* scroll detector: updated more than 50% of the lines, @@ -993,7 +992,7 @@ wait_more: if (!xfb || !xin) { if (i < 256) goto wait_more; - fprintf(stderr, "%s: displaystate setup failed\n", __FUNCTION__); + xen_be_printf(NULL, 1, "displaystate setup failed\n"); return; } -- 1.6.2.2 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/xenfb.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/hw/xenfb.c b/hw/xenfb.c index d9e5c33..97960ba 100644 --- a/hw/xenfb.c +++ b/hw/xenfb.c @@ -695,8 +695,6 @@ static void xenfb_update(void *opaque) { struct XenFB *xenfb = opaque; struct DisplayChangeListener *l; - int dw = ds_get_width(xenfb->c.ds); - int dh = ds_get_height(xenfb->c.ds); int i; if (xenfb->c.xendev.be_state != XenbusStateConnected) -- 1.6.2.2 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Gerd Hoffmann
2009-Apr-21 16:38 UTC
[Xen-devel] [PATCH 7/7] xen_backend logging: add missing include
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/xen_backend.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/hw/xen_backend.c b/hw/xen_backend.c index 2f2ec7f..76d07ec 100644 --- a/hw/xen_backend.c +++ b/hw/xen_backend.c @@ -38,6 +38,7 @@ #include "hw.h" #include "qemu-char.h" +#include "qemu-log.h" #include "xen_backend.h" /* ------------------------------------------------------------- */ -- 1.6.2.2 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel