chardev: convert to QOM
cover chardev: convert to QOM
Hi,
This has long been on my TODO list. I wanted to put this forward since Gerd has a chardev hotplug series. I think there are a few good reasons to go the QOM route here. Most notably:
1) the conversion cleans up all of the printfs into proper error messages
2) it becomes possible to introspect available character device types
3) it becomes possible (albeit a little awkward) to programmatically query options for a type
There are quite a few things missing from this RFC although I think it can all be done incrementally. The continued items are:
A) Replace chardev properties in devices with links
B) Finish converting all usage of QemuOpts into proper properties
C) Use class methods instead of function pointers in objects
D) General cleanups
I think the main decision point here is whether we introduce a separate chardev_add/chardev_del command or just use the qom-create command that has been posted previously.
Please note, a few of these patches have long lines from a combination of code motion and automated conversion via macros.
PATCH 1/6 object: add object_property_add_bool
--- include/qemu/object.h | 17 ++++++++++++++ qom/object.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)
include/qemu/object.h +17 -0
@@ -947,6 +947,23 @@ void object_property_add_str(Object *obj, const char *name, struct Error **errp);/** +* object_property_add_bool: +* @obj: the object to add a property to +* @name: the name of the property +* @get: the getter or NULL if the property is write-only. This function must +* return a string to be freed by g_free(). +* @set: the setter or NULL if the property is read-only +* @errp: if an error occurs, a pointer to an area to store the error +* +* Add a bool property using getters/setters. This function will add a +* property of type 'bool'. +*/ +void object_property_add_bool (Object *obj,const char *name, +bool (*get)(Object *,struct Error **), +void (*set)(Object *,bool ,struct Error **), +struct Error **errp); + +/** * object_child_foreach: * @obj: the object whose children will be navigated * @fn: the iterator function to be called
qom/object.c +58 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Re: [Qemu-devel] [PATCH 1/6] object: add object_property_add_bool
Am 15.10.2012 21:34, schrieb Anthony Liguori:
Quoted 1 line
Signed-off-by Anthony Liguori <[email protected]>
This feels like a resend or v2. I remember discussing whether an opaque might be a good idea and we decided not to lacking an immanent use case.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 1/6] object: add object_property_add_bool
In reply to Anthony LiguoriQuoted 11 lines · Anthony Liguori
Signed-off-by Anthony Liguori <[email protected]>--- include/qemu/object.h | 17 ++++++++++++++ qom/object.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 0 deletions(-)include/qemu/object.h +0
-0
include/qemu/object.h void object_property_add_str(Object *obj, const char *name, · line 954
Quoted 8 lines
include/qemu/object.h +5
-0@@ -947,6 +947,23 @@ void object_property_add_str(Object *obj, const char *name, struct Error **errp);/** +* object_property_add_bool: +* @obj: the object to add a property to +* @name: the name of the property +* @get: the getter or NULL if the property is write-only. This function must +* return a string to be freed by g_free().
Pasto. It returns a bool.
Quoted 15 lines
include/qemu/object.h +12
-0+* @set: the setter or NULL if the property is read-only +* @errp: if an error occurs, a pointer to an area to store the error +* +* Add a bool property using getters/setters. This function will add a +* property of type 'bool'. +*/ +void object_property_add_bool (Object *obj,const char *name, +bool (*get)(Object *,struct Error **), +void (*set)(Object *,bool ,struct Error **), +struct Error **errp); + +/** * object_child_foreach: * @obj: the object whose children will be navigated * @fn: the iterator function to be called
[...]
PATCH 2/6 chardev: convert to QOM (shallow pass)
In reply to Anthony LiguoriThis just adds an Object to all chardev objects.
--- console.c | 4 ++-- qemu-char.c | 47 ++++++++++++++++++++++++++++++----------------- qemu-char.h | 6 ++++++ spice-qemu-char.c | 2 +- 4 files changed, 39 insertions(+), 20 deletions(-)
console.c +2 -2
@@ -1547,7 +1547,7 @@ CharDriverState *text_console_init(QemuOpts *opts)unsigned width;unsigned height; - chr =g_malloc0 (sizeof (CharDriverState)); + chr =CHARDEV (object_new (TYPE_CHARDEV )); width =qemu_opt_get_number (opts,"width" ,0 );if (width ==0 )
@@ -1564,7 +1564,7 @@ CharDriverState *text_console_init(QemuOpts *opts) }if (!s) { -g_free (chr); +object_delete (OBJECT (chr));return NULL ; }
qemu-char.c +30 -17
152 lines not on this page · raw message
qemu-char.h +6 -0
@@ -1,6 +1,7 @@#ifndef QEMU_CHAR_H #define QEMU_CHAR_H +#include "qemu/object.h" #include "qemu-common.h" #include "qemu-queue.h" #include "qemu-option.h"
@@ -50,9 +51,14 @@ typedef struct {#define CHR_TIOCM_DTR 0x002#define CHR_TIOCM_RTS 0x004 +#define TYPE_CHARDEV "chardev" +#define CHARDEV (obj) OBJECT_CHECK(CharDriverState, (obj), TYPE_CHARDEV) +typedef void IOEventHandler (void *opaque,int event);struct CharDriverState { +Object parent_obj; +void (*init)(struct CharDriverState *s);int (*chr_write)(struct CharDriverState *s,const uint8_t *buf,int len);void (*chr_update_read_handler)(struct CharDriverState *s);
spice-qemu-char.c +1 -1
@@ -214,7 +214,7 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts)return NULL ; } - chr =g_malloc0 (sizeof (CharDriverState)); + chr =CHARDEV (object_new (TYPE_CHARDEV )); s =g_malloc0 (sizeof (SpiceCharDriver)); s->chr = chr; s->debug = debug;
Signature · 1 line
1.7.5.4
PATCH 3/6 chardev: create new QOM types for each sub chardev type
In reply to Anthony Liguori--- console.c | 10 +- console.h | 2 +- hw/msmouse.c | 7 +- hw/msmouse.h | 2 +- qemu-char.c | 479 +++++++++++++++++++++++++++++++++++++++-------------- qemu-char.h | 13 ++ spice-qemu-char.c | 31 ++-- 7 files changed, 388 insertions(+), 156 deletions(-)
console.c +3 -7
@@ -1540,15 +1540,12 @@ static void text_console_do_init(CharDriverState *chr, DisplayState *ds) chr->init (chr); } -CharDriverState *text_console_init (QemuOpts *opts) +void text_console_init (CharDriverState *chr,QemuOpts *opts,Error **errp) { -CharDriverState *chr;TextConsole *s;unsigned width;unsigned height; - chr =CHARDEV (object_new (TYPE_CHARDEV )); - width =qemu_opt_get_number (opts,"width" ,0 );if (width ==0 ) width =qemu_opt_get_number (opts,"cols" ,0 ) *FONT_WIDTH ;
@@ -1564,8 +1561,8 @@ CharDriverState *text_console_init(QemuOpts *opts) }if (!s) { -object_delete (OBJECT (chr)); -return NULL ; +error_setg (errp,"failed to initialize console" ); +return ; } s->chr = chr;
@@ -1573,7 +1570,6 @@ CharDriverState *text_console_init(QemuOpts *opts) s->g_height = height; chr->opaque = s; chr->chr_set_echo = text_console_set_echo; -return chr; }void text_consoles_set_display (DisplayState *ds)
console.h +1 -1
@@ -361,7 +361,7 @@ void vga_hw_text_update(console_ch_t *chardata);int is_graphic_console (void );int is_fixedsize_console (void ); -CharDriverState *text_console_init (QemuOpts *opts); +void text_console_init (CharDriverState *chr,QemuOpts *opts,Error **errp);void text_consoles_set_display (DisplayState *ds);void console_select (unsigned int index);void console_color_init (DisplayState *ds);
hw/msmouse.c +1 -6
@@ -64,15 +64,10 @@ static void msmouse_chr_close (struct CharDriverState *chr)g_free (chr); } -CharDriverState *qemu_chr_open_msmouse (QemuOpts *opts) +void qemu_chr_open_msmouse (CharDriverState *chr,QemuOpts *opts,Error **errp) { -CharDriverState *chr; - - chr =g_malloc0 (sizeof (CharDriverState)); chr->chr_write = msmouse_chr_write; chr->chr_close = msmouse_chr_close;qemu_add_mouse_event_handler (msmouse_event, chr,0 ,"QEMU Microsoft Mouse" ); - -return chr; }
hw/msmouse.h +1 -1
@@ -1,2 +1,2 @@/* msmouse.c */ -CharDriverState *qemu_chr_open_msmouse (QemuOpts *opts); +void qemu_chr_open_msmouse (CharDriverState *chr,QemuOpts *opts,Error **errp);
qemu-char.c +354 -125
816 lines not on this page · raw message
qemu-char.h +13 -0
@@ -53,9 +53,22 @@ typedef struct {#define TYPE_CHARDEV "chardev"#define CHARDEV (obj) OBJECT_CHECK(CharDriverState, (obj), TYPE_CHARDEV) +#define CHARDEV_CLASS (klass) \ + OBJECT_CLASS_CHECK(CharDriverClass, (klass), TYPE_CHARDEV) +#define CHARDEV_GET_CLASS (obj) \ + OBJECT_GET_CLASS(CharDriverClass, (obj), TYPE_CHARDEV)typedef void IOEventHandler (void *opaque,int event); +typedef struct CharDriverClass CharDriverClass ; + +struct CharDriverClass +{ +ObjectClass parent_class; + +void (*open)(struct CharDriverState *chr,QemuOpts *opts,Error **errp); +}; +struct CharDriverState {Object parent_obj;
spice-qemu-char.c +15 -16
@@ -171,26 +171,26 @@ static void spice_chr_guest_close(struct CharDriverState *chr)vmc_unregister_interface (s); } -static void print_allowed_subtypes (void ) +static char *get_allowed_subtypes (void ) { +char *ret =NULL ;const char ** psubtype;int i; -fprintf (stderr,"allowed names: " );for (i=0 , psubtype =spice_server_char_device_recognized_subtypes (); *psubtype !=NULL ; ++psubtype, ++i) {if (i ==0 ) { -fprintf (stderr,"%s" , *psubtype); + ret =g_strdup (*psubtype); }else { -fprintf (stderr,", %s" , *psubtype); +char *old = ret; + ret =g_strdup ("%s, %s" , ret, *psubtype); +g_free (old); } } -fprintf (stderr,"\n" ); } -CharDriverState *qemu_chr_open_spice (QemuOpts *opts) +void qemu_chr_open_spice (CharDriverState *chr,QemuOpts *opts,Error **errp) { -CharDriverState *chr;SpiceCharDriver *s;const char * name =qemu_opt_get (opts,"name" );uint32_t debug =qemu_opt_get_number (opts,"debug" ,0 );
@@ -198,9 +198,10 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts)const char *subtype =NULL ;if (name ==NULL ) { -fprintf (stderr,"spice-qemu-char: missing name parameter\n" ); -print_allowed_subtypes (); -return NULL ; +char *names =get_allowed_subtypes (); +error_setg (errp,"spice-qemu-char: missing name parameter, allowed names: %s" , names); +g_free (names); +return ; }for (;*psubtype !=NULL ; ++psubtype) {if (strcmp (name, *psubtype) ==0 ) {
@@ -209,12 +210,12 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts) } }if (subtype ==NULL ) { -fprintf (stderr,"spice-qemu-char: unsupported name: %s\n" , name); -print_allowed_subtypes (); -return NULL ; +char *names =get_allowed_subtypes (); +error_setg (errp,"spice-qemu-char: unsupported, allowed names: %s" , names); +g_free (names); +return ; } - chr =CHARDEV (object_new (TYPE_CHARDEV )); s =g_malloc0 (sizeof (SpiceCharDriver)); s->chr = chr; s->debug = debug;
@@ -232,6 +233,4 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts) qemu_chr_generic_open(chr); }#endif - -return chr; }
Signature · 1 line
1.7.5.4
PATCH 4/6 chardev: implement realize
In reply to Anthony LiguoriThis can be used to initialize an object independently of setting properties. This makes the 'open' method legacy.
--- qemu-char.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- qemu-char.h | 3 +++ 2 files changed, 48 insertions(+), 3 deletions(-)
qemu-char.c +45 -3
@@ -2981,9 +2981,13 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, chr =CHARDEV (object_new (class_name)); cdc =CHARDEV_GET_CLASS (chr); -g_assert (cdc->open !=NULL ); - - cdc->open (chr, opts, &err); +if (cdc->open) { + cdc->open (chr, opts, &err); + }else { +if (!err) { +object_property_set_bool (OBJECT (chr), true,"realized" , &err); + } + }g_free (class_name);
@@ -3107,11 +3111,49 @@ CharDriverState *qemu_char_get_next_serial(void)return serial_hds[next_serial++]; } +static bool chardev_get_realized (Object *obj,Error **errp) +{ +CharDriverState *chr =CHARDEV (obj); + +return chr->realized; +} + +static void chardev_set_realized (Object *obj,bool value,Error **errp) +{ +CharDriverState *chr =CHARDEV (obj); +CharDriverClass *cdc =CHARDEV_GET_CLASS (chr); + +if (chr->realized == value) { +return ; + } + +if (!value && chr->realized) { +error_set (errp,QERR_PERMISSION_DENIED ); + }else { +Error *local_err =NULL ; + +g_assert (cdc->realize); + cdc->realize (chr, &local_err); +if (local_err) { +error_propagate (errp, local_err); + }else { + chr->realized = true; + } + } +} + +static void chardev_initfn (Object *obj) +{ +object_property_add_bool (obj,"realized" , chardev_get_realized, + chardev_set_realized,NULL ); +} +static const TypeInfo chardev_info = { .name =TYPE_CHARDEV , .parent =TYPE_OBJECT , .instance_size =sizeof (CharDriverState), .class_size =sizeof (CharDriverClass), + .instance_init = chardev_initfn, };static void register_types (void )
qemu-char.h +3 -0
@@ -66,7 +66,9 @@ struct CharDriverClass {ObjectClass parent_class; +/* Objects should implement only one of these two methods */ void (*open)(struct CharDriverState *chr,QemuOpts *opts,Error **errp); +void (*realize)(struct CharDriverState *chr,QemuOpts *opts,Error **errp); };struct CharDriverState {
@@ -94,6 +96,7 @@ struct CharDriverState {int opened;int avail_connections;QTAILQ_ENTRY (CharDriverState) next; +bool realized; };/**
Signature · 1 line
1.7.5.4
PATCH 5/6 chardev: switch the easy backends to realize
In reply to Anthony LiguoriFor backends that take no options, switching to realize is trivially easy.
--- qemu-char.c | 12 ++++++------ qemu-char.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-)
qemu-char.c +6 -6
@@ -221,7 +221,7 @@ static int null_chr_write(CharDriverState *chr, const uint8_t *buf, int len)return len; } -static void qemu_chr_open_null (CharDriverState *chr,QemuOpts *opts,Error **errp) +static void qemu_chr_open_null (CharDriverState *chr,Error **errp) { chr->chr_write = null_chr_write; }
@@ -1763,7 +1763,7 @@ static void qemu_chr_open_win_file(CharDriverState *chr, HANDLE fd_out)qemu_chr_generic_open (chr); } -static void qemu_chr_open_win_con (CharDriverState *chr,QemuOpts *opts,Error **errp) +static void qemu_chr_open_win_con (CharDriverState *chr,Error **errp) {qemu_chr_open_win_file (chr,GetStdHandle (STD_OUTPUT_HANDLE )); }
@@ -1920,7 +1920,7 @@ static void win_stdio_close(CharDriverState *chr) stdio_nb_clients--; } -static void qemu_chr_open_win_stdio (CharDriverState *chr,QemuOpts *opts,Error **errp) +static void qemu_chr_open_win_stdio (CharDriverState *chr,Error **errp) {WinStdioCharState *stdio;DWORD dwMode;
@@ -2693,7 +2693,7 @@ static void chardev_null_class_init(ObjectClass *klass, void *data) {CharDriverClass *cdc =CHARDEV_CLASS (klass); - cdc->open = qemu_chr_open_null; + cdc->realize = qemu_chr_open_null; }static const TypeInfo chardev_null_info = {
@@ -2774,7 +2774,7 @@ static void chardev_console_class_init(ObjectClass *klass, void *data) {CharDriverClass *cdc =CHARDEV_CLASS (klass); - cdc->open = qemu_chr_open_win_con; + cdc->realize = qemu_chr_open_win_con; }static const TypeInfo chardev_console_info = {
@@ -2864,7 +2864,7 @@ static void chardev_stdio_class_init(ObjectClass *klass, void *data)CharDriverClass *cdc =CHARDEV_CLASS (klass);#ifdef _WIN32 - cdc->open = qemu_chr_open_win_stdio; + cdc->realize = qemu_chr_open_win_stdio;#else cdc->open = qemu_chr_open_stdio;#endif
qemu-char.h +1 -1
@@ -68,7 +68,7 @@ struct CharDriverClass/* Objects should implement only one of these two methods */ void (*open)(struct CharDriverState *chr,QemuOpts *opts,Error **errp); -void (*realize)(struct CharDriverState *chr,QemuOpts *opts,Error **errp); +void (*realize)(struct CharDriverState *chr,Error **errp); };struct CharDriverState {
Signature · 1 line
1.7.5.4
PATCH 6/6 chardev: convert file backend to realize
In reply to Anthony Liguori--- qemu-char.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 75 insertions(+), 14 deletions(-)
qemu-char.c +75 -14
@@ -540,9 +540,14 @@ static int stdio_nb_clients;#ifndef _WIN32 +#define TYPE_CHARDEV_FILE "chardev-file" +#define CHARDEV_FILE (obj) OBJECT_CHECK(FDCharDriver, (obj), TYPE_CHARDEV_FILE) +typedef struct { +CharDriverState parent_obj;int fd_in, fd_out;int max_size; +char *path; }FDCharDriver ;
@@ -609,19 +614,20 @@ static void fd_chr_close(struct CharDriverState *chr) } } -g_free (s); +g_free (s->path); +if ((void *)s != (void *)chr) { +g_free (s); + }qemu_chr_be_event (chr,CHR_EVENT_CLOSED ); }/* open a character device to a unix fd */ -static void qemu_chr_open_fd (CharDriverState *chr,int fd_in,int fd_out) +static void qemu_chr_init_fd (CharDriverState *chr,int fd_in,int fd_out) { -FDCharDriver *s; +FDCharDriver *s = chr->opaque; - s =g_malloc0 (sizeof (FDCharDriver)); s->fd_in = fd_in; s->fd_out = fd_out; - chr->opaque = s; chr->chr_write = fd_chr_write; chr->chr_update_read_handler = fd_chr_update_read_handler; chr->chr_close = fd_chr_close;
@@ -629,19 +635,69 @@ static void qemu_chr_open_fd(CharDriverState *chr, int fd_in, int fd_out)qemu_chr_generic_open (chr); } -static void qemu_chr_open_file_out (CharDriverState *chr,QemuOpts *opts,Error **errp) +static void qemu_chr_open_fd (CharDriverState *chr,int fd_in,int fd_out) +{ +FDCharDriver *s; + + s =g_malloc0 (sizeof (FDCharDriver)); + chr->opaque = s; +qemu_chr_init_fd (chr, fd_in, fd_out); +} + +static void qemu_chr_open_file_out (CharDriverState *chr,Error **errp) { +FDCharDriver *s = chr->opaque;int fd_out; -TFR (fd_out =qemu_open (qemu_opt_get (opts,"path" ), -O_WRONLY |O_TRUNC |O_CREAT |O_BINARY ,0666 )); +if (s->path ==NULL || s->path[0 ] ==0 ) { +error_setg (errp,"'path' property must be set" ); +return ; + } + +TFR (fd_out =qemu_open (s->path,O_WRONLY |O_TRUNC |O_CREAT |O_BINARY ,0666 ));if (fd_out <0 ) { -error_setg (errp,"Failed to open file `%s'" ,qemu_opt_get (opts,"path" )); +error_setg (errp,"Failed to open file `%s'" , s->path); +return ; }else {qemu_chr_open_fd (chr,-1 , fd_out); } } +static char *chardev_file_get_path (Object *obj,Error **errp) +{ +CharDriverState *chr =CHARDEV (obj); +FDCharDriver *s = chr->opaque; + +return s->path ?g_strdup (s->path) :g_strdup ("" ); +} + +static void chardev_file_set_path (Object *obj,const char *value,Error **errp) +{ +CharDriverState *chr =CHARDEV (obj); +FDCharDriver *s = chr->opaque; + +if (chr->realized) { +error_set (errp,QERR_PERMISSION_DENIED ); +return ; + } + +if (s->path) { +g_free (s->path); + } + + s->path =g_strdup (value); +} + +static void chardev_file_initfn (Object *obj) +{ +CharDriverState *chr =CHARDEV (obj); + +object_property_add_str (obj,"path" , chardev_file_get_path, chardev_file_set_path,NULL ); +#ifndef _WIN32 + chr->opaque =CHARDEV_FILE (obj); +#endif +} +static void qemu_chr_open_pipe (CharDriverState *chr,QemuOpts *opts,Error **errp) {int fd_in, fd_out;
@@ -2816,9 +2872,6 @@ static const TypeInfo chardev_pty_info = { };#endif -#define TYPE_CHARDEV_file "chardev-file" -#define CHARDEV_file OBJECT_CHECK(CharDriverState, (obj), TYPE_CHARDEV_file) -static void chardev_file_class_init (ObjectClass *klass,void *data) {CharDriverClass *cdc =CHARDEV_CLASS (klass);
@@ -2826,14 +2879,18 @@ static void chardev_file_class_init(ObjectClass *klass, void *data)#ifdef _WIN32 cdc->open = qemu_chr_open_win_file_out;#else - cdc->open = qemu_chr_open_file_out; + cdc->realize = qemu_chr_open_file_out;#endif }static const TypeInfo chardev_file_info = { - .name = TYPE_CHARDEV_file, + .name =TYPE_CHARDEV_FILE , .parent =TYPE_CHARDEV , .class_init = chardev_file_class_init, + .instance_init = chardev_file_initfn, +#ifndef _WIN32 + .instance_size =sizeof (FDCharDriver), +#endif };#define TYPE_CHARDEV_pipe "chardev-pipe"
@@ -2984,6 +3041,10 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,if (cdc->open) { cdc->open (chr, opts, &err); }else { +if (strcmp (class_name,TYPE_CHARDEV_FILE ) ==0 ) { +object_property_set_str (OBJECT (chr),qemu_opt_get (opts,"path" ),"path" , &err); + } +if (!err) {object_property_set_bool (OBJECT (chr), true,"realized" , &err); }
Signature · 1 line
1.7.5.4
Re: [Qemu-devel] [PATCH 6/6] chardev: convert file backend to realize
Il 15/10/2012 21:34, Anthony Liguori ha scritto:
Quoted 25 lines
qemu-char.c +25
-0+static char *chardev_file_get_path (Object *obj,Error **errp) +{ +CharDriverState *chr =CHARDEV (obj); +FDCharDriver *s = chr->opaque; + +return s->path ?g_strdup (s->path) :g_strdup ("" ); +} + +static void chardev_file_set_path (Object *obj,const char *value,Error **errp) +{ +CharDriverState *chr =CHARDEV (obj); +FDCharDriver *s = chr->opaque; + +if (chr->realized) { +error_set (errp,QERR_PERMISSION_DENIED ); +return ; + } + +if (s->path) { +g_free (s->path); + } + + s->path =g_strdup (value); +} +
qemu-char.c static void qemu_chr_open_fd(CharDriverState *chr, int fd_in, int fd_out) · line 700
Quoted 10 lines
qemu-char.c +10
-0+static void chardev_file_initfn (Object *obj) +{ +CharDriverState *chr =CHARDEV (obj); + +object_property_add_str (obj,"path" , chardev_file_get_path, chardev_file_set_path,NULL ); +#ifndef _WIN32 + chr->opaque =CHARDEV_FILE (obj); +#endif +} +
IMHO this really really calls for pushing static properties and realized up to Object...
Paolo
Re: [Qemu-devel] [PATCH 6/6] chardev: convert file backend to realize
Quoted 31 lines · Paolo Bonzini
Il 15/10/2012 21:34, Anthony Liguori ha scritto:
Quoted 30 lines
qemu-char.c +30
-0+static char *chardev_file_get_path (Object *obj,Error **errp) +{ +CharDriverState *chr =CHARDEV (obj); +FDCharDriver *s = chr->opaque; + +return s->path ?g_strdup (s->path) :g_strdup ("" ); +} + +static void chardev_file_set_path (Object *obj,const char *value,Error **errp) +{ +CharDriverState *chr =CHARDEV (obj); +FDCharDriver *s = chr->opaque; + +if (chr->realized) { +error_set (errp,QERR_PERMISSION_DENIED ); +return ; + } + +if (s->path) { +g_free (s->path); + } + + s->path =g_strdup (value); +} + +static void chardev_file_initfn (Object *obj) +{ +CharDriverState *chr =CHARDEV (obj); + +object_property_add_str (obj,"path" , chardev_file_get_path, chardev_file_set_path,NULL );
Quoted 8 lines
qemu-char.c static void qemu_chr_open_fd(CharDriverState *chr, int fd_in, int fd_out) · line 700
Quoted 5 lines
qemu-char.c +5
-0+#ifndef _WIN32 + chr->opaque =CHARDEV_FILE (obj); +#endif +} +IMHO this really really calls for pushing static properties and realized up to Object...
I agree actually. But this doesn't add anything to Object, this just adds a new set of properties that are implemented entirely in terms of the existing property infrastructure.
What I don't want to do though is push the notion of "realize" to Object. Instead, we should have a mechanism to "lock" read/write properties so they no longer are mutable. This should not affect the object's state but rather the individual property state.
IOW, we shouldn't be adding anything to Object to do this.
Regards,
Anthony Liguori
Quoted 2 lines
Paolo
Hi,
Quoted 3 lines
I think the main decision point here is whether we introduce a separate chardev_add/chardev_del command or just use the qom-create command that has been posted previously.
Do you have a git tree with this series + qom-create to look at and play with?
thanks,
Gerd
Quoted 8 lines · Gerd Hoffmann
Hi,
Quoted 3 lines
I think the main decision point here is whether we introduce a separate chardev_add/chardev_del command or just use the qom-create command that has been posted previously.
Do you have a git tree with this series + qom-create to look at and play with?
https://github.com/aliguori/qemu/tree/chardev-qom.1
I haven't tried the qom-new command from Markus but I've also included the -object option that I posted a while ago. That seems to work. Here's an example command line:
$ x86_64-softmmu/qemu-system-x86_64 \
-object chardev-file,path=foo.txt,label=chr0,id=chr0,realized=on \
-device isa-serial,index=0,chardev=chr0 -hda ~/images/linux.img \
-snapshot -enable-kvmA couple caveats:
- The label/id duplication is ugly. The need to use label disappears though once we switch devices over to using links.
- Some error checking is needed to deal with trying to use an unrealized chardev.
- It may still make sense to have a chardev-add operation but I think that operation should work in terms of something like qom-new. Probably with some special casing to fix the container path to /backends/chardev and also to deal with automatically setting label based on id. It may make sense to also always set realized explicitly to 'on' in chardev-add.
Regards,
Anthony Liguori
Quoted 3 lines
thanks,
Gerd