console: screendump improvements
cover 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
PATCH 1/7 console: add graphic_hw_update_done()
Add 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
Re: [PATCH 1/7] console: add graphic_hw_update_done()
Quoted 8 lines · Marc-André Lureau
Add a function to be called when a graphic update is done.
Declare the QXL renderer as async:
render_update_cookie_numcounts the number of outstanding updates, andgraphic_hw_update_done()is called when it reaches none.(note: this is preliminary work for asynchronous screendump support)
Quoted 8 lines
Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Gerd Hoffmann <[email protected]>--- 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(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 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
Re: [PATCH 2/7] ppm-save: pass opened fd
Quoted 10 lines · Marc-André Lureau
This 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)
Signed-off-by Marc-André Lureau <[email protected]>--- ui/console.c | 45 ++++++++++++++++++++++----------------------- ui/trace-events | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 3/7 ui: add pixman image g_autoptr support
In reply to Marc-André Lureau--- 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
Re: [PATCH 3/7] ui: add pixman image g_autoptr support
Quoted 4 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- include/ui/qemu-pixman.h | 2 ++ 1 file changed, 2 insertions(+)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 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
@@ -1747,4 +1747,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
Re: [PATCH 4/7] object: add g_autoptr support
Quoted 4 lines · Marc-André Lureau
Signed-off-by Marc-André Lureau <[email protected]>--- include/qom/object.h | 3 +++ 1 file changed, 3 insertions(+)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 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
Re: [PATCH 5/7] screendump: replace FILE with QIOChannel and fix close()/qemu_close()
Quoted 6 lines · Marc-André Lureau
The 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 callingqemu_close(), instead of the implicitclose()onfclose().I don't see a convenient way to solve that with stdio streams, so I switched the code to QIOChannel which uses
qemu_close().
The only way is to duplicate what qemu_close() does in the ppm_save method by calling monitor_fdset_dup_fd_remove(fd). Using QIOChannel is fine too though.
Quoted 4 lines
Signed-off-by Marc-André Lureau <[email protected]>--- ui/console.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 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
Re: [PATCH 6/7] osdep: add qemu_unlink()
Quoted 9 lines · Marc-André Lureau
Add a helper function to match
qemu_open()which may return files under the/dev/fdsetprefix. Those shouldn't be removed, since it's only a qemu namespace.Signed-off-by Marc-André Lureau <[email protected]>--- include/qemu/osdep.h | 1 + util/osdep.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 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
Re: [PATCH 7/7] screendump: use qemu_unlink()
Quoted 6 lines · Marc-André Lureau
Don't attempt to remove
/dev/fdsetfiles.Signed-off-by Marc-André Lureau <[email protected]>--- ui/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [PATCH 0/7] console: screendump improvements
Type: series
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
fatal: git fetch_pack: expected ACK/NAK, got 'ERR upload-pack: not our ref 4aa8cc3583eabafc01c50020f7887c3509a8f0c4'
fatal: The remote end hung up unexpectedly
error: Could not fetch 3c8cf5a9c21ff8782164d1def7f44bd888713384
Traceback (most recent call last):
File "patchew-tester/src/patchew-cli", line 521, in test_one
git_clone_repo(clone, r["repo"], r["head"], logf, True)
File "patchew-tester/src/patchew-cli", line 48, in git_clone_repo
stdout=logf, stderr=logf)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'remote', 'add', '-f', '--mirror=fetch', '3c8cf5a9c21ff8782164d1def7f44bd888713384', 'https://github.com/patchew-project/qemu']' returned non-zero exit status 1.
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Hi Gerd,
Quoted 11 lines · Marc-André Lureau
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.
Quoted 8 lines
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()
The series has been reviewed by Daniel. Can I send a PR or do you plan to take a look and make the PR yourself?
thanks
Quoted 16 lines
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(-)--
2.24.0
Signature · 1 line
Marc-André Lureau
Gerd Hoffmann
Acked-byQuoted 24 lines · Marc-André Lureau
Hi Gerd,
Quoted 11 lines · Marc-André Lureau
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.
Quoted 8 lines
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()
Quoted 2 lines
The series has been reviewed by Daniel. Can I send a PR or do you plan to take a look and make the PR yourself?
Looks all sane. Feel free to send a PR.
cheers,
Gerd