Screendump patches
The following changes since commit dd5b0f95490883cd8bc7d070db8de70d5c979cbc:
Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20191219' into staging (2019-12-20 16:37:07 +0000)
are available in the Git repository at:
https://github.com/elmarco/qemu.git tags/screendump-pull-request
for you to fetch changes up to 6b8d2a5132378ac19cf93597dad694ea764cca4f:
screendump: use qemu_unlink() (2020-01-02 13:54:57 +0400)
----------------------------------------------------------------
console: screendump improvements
Hi,
The following patches have been extracted from the "[PATCH v6 00/25]
monitor: add asynchronous command type", as they are reviewable/mergeable independantly.
They introduce some internal API changes, and fix qemu_open()/qemu_close()/unlink() misusages which should be quite harmless.
----------------------------------------------------------------
Marc-André Lureau (7):
console: add graphic_hw_update_done()
ppm-save: pass opened fd
ui: add pixman image g_autoptr support
object: add g_autoptr support
screendump: replace FILE with QIOChannel and fix close()/qemu_close()
osdep: add qemu_unlink()
screendump: use qemu_unlink()
hw/display/qxl-render.c | 9 +++-- hw/display/qxl.c | 1 + include/qemu/osdep.h | 1 + include/qom/object.h | 3 ++ include/ui/console.h | 2 ++ include/ui/qemu-pixman.h | 2 ++ ui/console.c | 74 +++++++++++++++++++++------------------- ui/trace-events | 2 +- util/osdep.c | 15 ++++++++ 9 files changed, 71 insertions(+), 38 deletions(-)
Signature · 1 line
2.24.0.308.g228f53135a
[PULL 3/7] ui: add pixman image g_autoptr support
--- include/ui/qemu-pixman.h | 2 ++ 1 file changed, 2 insertions(+)
include/ui/qemu-pixman.h +2 -0
@@ -90,4 +90,6 @@ void qemu_pixman_glyph_render(pixman_image_t *glyph,pixman_color_t *bgcol, int x, int y, int cw, int ch); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(pixman_image_t, qemu_pixman_image_unref) +#endif /* QEMU_PIXMAN_H */
Signature · 1 line
2.24.0.308.g228f53135a
[PULL 1/7] console: add graphic_hw_update_done()
In reply to Marc-André LureauAdd a function to be called when a graphic update is done.
Declare the QXL renderer as async: render_update_cookie_num counts the number of outstanding updates, and graphic_hw_update_done() is called when it reaches none.
(note: this is preliminary work for asynchronous screendump support)
--- hw/display/qxl-render.c | 9 +++++++-- hw/display/qxl.c | 1 + include/ui/console.h | 2 ++ ui/console.c | 9 +++++++++ 4 files changed, 19 insertions(+), 2 deletions(-)
hw/display/qxl-render.c +7 -2
@@ -109,7 +109,7 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl) qxl->guest_primary.surface.mem, MEMSLOT_GROUP_GUEST);if (!qxl->guest_primary.data) { -return ; + goto end; }qxl_set_rect_to_surface (qxl, &qxl->dirty[0 ]); qxl->num_dirty_rects =1 ;
@@ -137,7 +137,7 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl) }if (!qxl->guest_primary.data) { -return ; + goto end; }for (i =0 ; i < qxl->num_dirty_rects; i++) {if (qemu_spice_rect_is_empty (qxl->dirty+i)) {
@@ -158,6 +158,11 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice *qxl) qxl->dirty[i].bottom - qxl->dirty[i].top); } qxl->num_dirty_rects =0 ; + +end: +if (qxl->render_update_cookie_num ==0 ) { +graphic_hw_update_done (qxl->ssd.dcl.con); + } }/*
hw/display/qxl.c +1 -0
@@ -1181,6 +1181,7 @@ static const QXLInterface qxl_interface = {static const GraphicHwOps qxl_ops = { .gfx_update = qxl_hw_update, + .gfx_update_async = true, };static void qxl_enter_vga_mode (PCIQXLDevice *d)
include/ui/console.h +2 -0
@@ -365,6 +365,7 @@ static inline void console_write_ch(console_ch_t *dest, uint32_t ch) typedef struct GraphicHwOps { void (*invalidate)(void *opaque); void (*gfx_update)(void *opaque); + bool gfx_update_async; /* if true, calls graphic_hw_update_done() */ void (*text_update)(void *opaque, console_ch_t *text); void (*update_interval)(void *opaque, uint64_t interval); int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
@@ -380,6 +381,7 @@ void graphic_console_set_hwops(QemuConsole *con,void graphic_console_close (QemuConsole *con);void graphic_hw_update (QemuConsole *con); +void graphic_hw_update_done (QemuConsole *con);void graphic_hw_invalidate (QemuConsole *con);void graphic_hw_text_update (QemuConsole *con,console_ch_t *chardata);void graphic_hw_gl_block (QemuConsole *con,bool block);
ui/console.c +9 -0
@@ -259,13 +259,22 @@ static void gui_setup_refresh(DisplayState *ds) ds->have_text = have_text; } +void graphic_hw_update_done (QemuConsole *con) +{ +} +void graphic_hw_update (QemuConsole *con) { +bool async = false;if (!con) { con = active_console; }if (con && con->hw_ops->gfx_update) { con->hw_ops->gfx_update (con->hw); + async = con->hw_ops->gfx_update_async; + } +if (!async) { +graphic_hw_update_done (con); } }
Signature · 1 line
2.24.0.308.g228f53135a
[PULL 4/7] object: add g_autoptr support
In reply to Marc-André Lureau--- include/qom/object.h | 3 +++ 1 file changed, 3 insertions(+)
include/qom/object.h +3 -0
@@ -1766,4 +1766,7 @@ Object *container_get(Object *root, const char *path);* Returns the instance_size of the given @typename. */ size_t object_type_get_instance_size (const char *typename); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref) +#endif
Signature · 1 line
2.24.0.308.g228f53135a
[PULL 2/7] ppm-save: pass opened fd
In reply to Marc-André LureauThis will allow to pre-open the file before running the async finish handler and avoid potential monitor fdset races.
(note: this is preliminary work for asynchronous screendump support)
--- ui/console.c | 45 ++++++++++++++++++++++----------------------- ui/trace-events | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-)
ui/console.c +22 -23
@@ -193,6 +193,7 @@ static void dpy_refresh(DisplayState *s);static DisplayState *get_alloc_displaystate (void );static void text_console_update_cursor_timer (void );static void text_console_update_cursor (void *opaque); +static bool ppm_save (int fd,DisplaySurface *ds,Error **errp);static void gui_update (void *opaque) {
@@ -308,29 +309,22 @@ void graphic_hw_invalidate(QemuConsole *con) } } -static void ppm_save (const char *filename,DisplaySurface *ds, -Error **errp) +static bool ppm_save (int fd,DisplaySurface *ds,Error **errp) {int width =pixman_image_get_width (ds->image);int height =pixman_image_get_height (ds->image); -int fd;FILE *f;int y;int ret;pixman_image_t *linebuf; +bool success = false; -trace_ppm_save (filename, ds); - fd =qemu_open (filename,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,0666 ); -if (fd ==-1 ) { -error_setg (errp,"failed to open file '%s': %s" , filename, -strerror (errno)); -return ; - } +trace_ppm_save (fd, ds); f =fdopen (fd,"wb" ); ret =fprintf (f,"P6\n%d %d\n%d\n" , width, height,255 );if (ret <0 ) { linebuf =NULL ; - goto write_err; + goto end; } linebuf =qemu_pixman_linebuf_create (PIXMAN_BE_r8g8b8, width);for (y =0 ; y < height; y++) {
@@ -339,21 +333,16 @@ static void ppm_save(const char *filename, DisplaySurface *ds, ret =fwrite (pixman_image_get_data (linebuf),1 ,pixman_image_get_stride (linebuf), f); (void )ret; -if (ferror (f)) { - goto write_err; - } + success = !ferror (f); } -out: +end: +if (!success) { +error_setg (errp,"failed to write to PPM file: %s" ,strerror (errno)); + }qemu_pixman_image_unref (linebuf);fclose (f); -return ; - -write_err: -error_setg (errp,"failed to write to file '%s': %s" , filename, -strerror (errno)); -unlink (filename); - goto out; +return success; } void qmp_screendump(const char *filename, bool has_device, const char *device,
@@ -361,6 +350,7 @@ void qmp_screendump(const char *filename, bool has_device, const char *device, {QemuConsole *con;DisplaySurface *surface; +int fd;if (has_device) { con = qemu_console_lookup_by_device_name(device, has_head ? head : 0,
@@ -387,7 +377,16 @@ void qmp_screendump(const char *filename, bool has_device, const char *device,return ; } -ppm_save (filename, surface, errp); + fd =qemu_open (filename,O_WRONLY |O_CREAT |O_TRUNC |O_BINARY ,0666 ); +if (fd ==-1 ) { +error_setg (errp,"failed to open file '%s': %s" , filename, +strerror (errno)); +return ; + } + +if (!ppm_save (fd, surface, errp)) { +unlink (filename); + } }void graphic_hw_text_update (QemuConsole *con,console_ch_t *chardata)
ui/trace-events +1 -1
@@ -15,7 +15,7 @@ displaysurface_create_pixman(void *display_surface) "surface=%p" displaysurface_free(void *display_surface) "surface=%p" displaychangelistener_register(void *dcl, const char *name) "%p [ %s ]" displaychangelistener_unregister(void *dcl, const char *name) "%p [ %s ]" -ppm_save(const char *filename, void *display_surface) "%s surface=%p" +ppm_save(int fd, void *display_surface) "fd=%d surface=%p" # gtk.c # gtk-gl-area.c
Signature · 1 line
2.24.0.308.g228f53135a
[PULL 6/7] osdep: add qemu_unlink()
In reply to Marc-André LureauAdd a helper function to match qemu_open() which may return files under the /dev/fdset prefix. Those shouldn't be removed, since it's only a qemu namespace.
--- include/qemu/osdep.h | 1 + util/osdep.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+)
include/qemu/osdep.h +1 -0
@@ -462,6 +462,7 @@ int qemu_mprotect_none(void *addr, size_t size);int qemu_open (const char *name,int flags, ...);int qemu_close (int fd); +int qemu_unlink (const char *name);#ifndef _WIN32int qemu_dup (int fd);#endif
util/osdep.c +15 -0
@@ -370,6 +370,21 @@ int qemu_close(int fd)return close (fd); } +/* +* Delete a file from the filesystem, unless the filename is /dev/fdset/... +* +* Returns: On success, zero is returned. On error, -1 is returned, +* and errno is set appropriately. +*/ +int qemu_unlink (const char *name) +{ +if (g_str_has_prefix (name,"/dev/fdset/" )) { +return 0 ; + } + +return unlink (name); +} +/* * A variant of write(2) which handles partial write. *
Signature · 1 line
2.24.0.308.g228f53135a
[PULL 5/7] screendump: replace FILE with QIOChannel and fix close()/qemu_close()
In reply to Marc-André LureauThe file opened for ppm_save() may be a /dev/fdset, in which case a dup fd is added to the fdset. It should be removed by calling qemu_close(), instead of the implicit close() on fclose().
I don't see a convenient way to solve that with stdio streams, so I switched the code to QIOChannel which uses qemu_close().
--- ui/console.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-)
ui/console.c +17 -21
@@ -33,6 +33,7 @@#include "chardev/char-fe.h" #include "trace.h" #include "exec/memory.h" +#include "io/channel-file.h" #define DEFAULT_BACKSCROLL 512#define CONSOLE_CURSOR_PERIOD 500
@@ -313,36 +314,31 @@ static bool ppm_save(int fd, DisplaySurface *ds, Error **errp) {int width =pixman_image_get_width (ds->image);int height =pixman_image_get_height (ds->image); -FILE *f; +g_autoptr (Object) ioc =OBJECT (qio_channel_file_new_fd (fd)); + g_autofree char *header = NULL; +g_autoptr (pixman_image_t) linebuf =NULL ; +g_autoptr (GError) error =NULL ;int y; -int ret; -pixman_image_t *linebuf; -bool success = false;trace_ppm_save (fd, ds); - f =fdopen (fd,"wb" ); - ret =fprintf (f,"P6\n%d %d\n%d\n" , width, height,255 ); -if (ret <0 ) { - linebuf =NULL ; - goto end; + + header =g_strdup_printf ("P6\n%d %d\n%d\n" , width, height,255 ); +if (qio_channel_write_all (QIO_CHANNEL (ioc), + header,strlen (header), errp) <0 ) { +return false; } + linebuf =qemu_pixman_linebuf_create (PIXMAN_BE_r8g8b8, width);for (y =0 ; y < height; y++) {qemu_pixman_linebuf_fill (linebuf, ds->image, width,0 , y); -clearerr (f); - ret =fwrite (pixman_image_get_data (linebuf),1 , -pixman_image_get_stride (linebuf), f); - (void )ret; - success = !ferror (f); +if (qio_channel_write_all (QIO_CHANNEL (ioc), + (char *)pixman_image_get_data (linebuf), +pixman_image_get_stride (linebuf), errp) <0 ) { +return false; + } } -end: -if (!success) { -error_setg (errp,"failed to write to PPM file: %s" ,strerror (errno)); - } -qemu_pixman_image_unref (linebuf); -fclose (f); -return success; +return true; } void qmp_screendump(const char *filename, bool has_device, const char *device,
Signature · 1 line
2.24.0.308.g228f53135a
[PULL 7/7] screendump: use qemu_unlink()
In reply to Marc-André LureauDon't attempt to remove /dev/fdset files.
--- ui/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ui/console.c +1 -1
@@ -381,7 +381,7 @@ void qmp_screendump(const char *filename, bool has_device, const char *device, }if (!ppm_save (fd, surface, errp)) { -unlink (filename); +qemu_unlink (filename); } }
Signature · 1 line
2.24.0.308.g228f53135a
Quoted 48 lines · Marc-André Lureau
The following changes since commit
dd5b0f95490883cd8bc7d070db8de70d5c979cbc:Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20191219' into staging (2019-12-20 16:37:07 +0000)
are available in the Git repository at:
https://github.com/elmarco/qemu.git tags/screendump-pull-request
for you to fetch changes up to
6b8d2a5132378ac19cf93597dad694ea764cca4f:screendump: use
qemu_unlink()(2020-01-02 13:54:57 +0400)----------------------------------------------------------------
console: screendump improvementsHi,
The following patches have been extracted from the "[PATCH v6 00/25]
monitor: add asynchronous command type", as they are reviewable/mergeable independantly.They introduce some internal API changes, and fix qemu_open()/qemu_close()/unlink() misusages which should be quite harmless.
----------------------------------------------------------------
Marc-André Lureau (7):
console: addgraphic_hw_update_done()
ppm-save: pass opened fd
ui: add pixman imageg_autoptrsupport
object: addg_autoptrsupport
screendump: replace FILE with QIOChannel and fix close()/qemu_close()
osdep: addqemu_unlink()
screendump: useqemu_unlink()hw/display/qxl-render.c | 9 +++-- hw/display/qxl.c | 1 + include/qemu/osdep.h | 1 + include/qom/object.h | 3 ++ include/ui/console.h | 2 ++ include/ui/qemu-pixman.h | 2 ++ ui/console.c | 74 +++++++++++++++++++++------------------- ui/trace-events | 2 +- util/osdep.c | 15 ++++++++ 9 files changed, 71 insertions(+), 38 deletions(-)
Quoted 4 lines
--
2.24.0.308.g228f53135a
nack, travis found an issue:
error: unused variable
'error' [-Werror,-Wunused-variable]
g_autoptr(GError) error = NULL;Signature · 1 line
Marc-André Lureau