static void test_qom_partial_path(void) { Object *root = object_get_objects_root(); Object *cont1 = container_get(root, "/cont1"); Object *obj1 = object_new(TYPE_DUMMY); Object *obj2a = object_new(TYPE_DUMMY); Object *obj2b = object_new(TYPE_DUMMY); bool ambiguous; /* Objects created: * /cont1 * /cont1/obj1 * /cont1/obj2 (obj2a) * /obj2 (obj2b) */ object_property_add_child(cont1, "obj1", obj1, &error_abort); object_unref(obj1); object_property_add_child(cont1, "obj2", obj2a, &error_abort); object_unref(obj2a); object_property_add_child(root, "obj2", obj2b, &error_abort); object_unref(obj2b); ambiguous = false; g_assert(!object_resolve_path_type("", TYPE_DUMMY, &ambiguous)); g_assert(ambiguous); g_assert(!object_resolve_path_type("", TYPE_DUMMY, NULL)); ambiguous = false; g_assert(!object_resolve_path("obj2", &ambiguous)); g_assert(ambiguous); g_assert(!object_resolve_path("obj2", NULL)); ambiguous = false; g_assert(object_resolve_path("obj1", &ambiguous) == obj1); g_assert(!ambiguous); g_assert(object_resolve_path("obj1", NULL) == obj1); object_unparent(obj2b); object_unparent(cont1); }
static void test_dummy_createlist(void) { Error *err = NULL; Object *parent = object_get_objects_root(); DummyObject *dobj = DUMMY_OBJECT( new_helper(&err, parent, "bv", "yes", "sv", "Hiss hiss hiss", "av", "platypus", NULL)); g_assert(err == NULL); g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); g_assert(dobj->bv == true); g_assert(dobj->av == DUMMY_PLATYPUS); g_assert(object_resolve_path_component(parent, "dummy0") == OBJECT(dobj)); object_unparent(OBJECT(dobj)); }
static QCryptoTLSCreds *test_tls_creds_create(QCryptoTLSCredsEndpoint endpoint, const char *certdir, Error **errp) { Object *parent = object_get_objects_root(); Object *creds = object_new_with_props( TYPE_QCRYPTO_TLS_CREDS_X509, parent, "testtlscreds", errp, "endpoint", (endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER ? "server" : "client"), "dir", certdir, "verify-peer", "yes", "sanity-check", "yes", NULL); if (*errp) { return NULL; } return QCRYPTO_TLS_CREDS(creds); }
PRManager *pr_manager_lookup(const char *id, Error **errp) { Object *obj; PRManager *pr_mgr; obj = object_resolve_path_component(object_get_objects_root(), id); if (!obj) { error_setg(errp, "No persistent reservation manager with id '%s'", id); return NULL; } pr_mgr = (PRManager *) object_dynamic_cast(obj, TYPE_PR_MANAGER); if (!pr_mgr) { error_setg(errp, "Object with id '%s' is not a persistent reservation manager", id); return NULL; } return pr_mgr; }
static void test_dummy_badenum(void) { Error *err = NULL; Object *parent = object_get_objects_root(); Object *dobj = object_new_with_props(TYPE_DUMMY, parent, "dummy0", &err, "bv", "yes", "sv", "Hiss hiss hiss", "av", "yeti", NULL); g_assert(dobj == NULL); g_assert(err != NULL); g_assert_cmpstr(error_get_pretty(err), ==, "Invalid parameter 'yeti'"); g_assert(object_resolve_path_component(parent, "dummy0") == NULL); error_free(err); }
Object *user_creatable_add_type(const char *type, const char *id, const QDict *qdict, Visitor *v, Error **errp) { Object *obj; ObjectClass *klass; const QDictEntry *e; Error *local_err = NULL; klass = object_class_by_name(type); if (!klass) { error_setg(errp, "invalid object type: %s", type); return NULL; } if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) { error_setg(errp, "object type '%s' isn't supported by object-add", type); return NULL; } if (object_class_is_abstract(klass)) { error_setg(errp, "object type '%s' is abstract", type); return NULL; } assert(qdict); obj = object_new(type); visit_start_struct(v, NULL, NULL, 0, &local_err); if (local_err) { goto out; } for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) { object_property_set(obj, v, e->key, &local_err); if (local_err) { break; } } if (!local_err) { visit_check_struct(v, &local_err); } visit_end_struct(v, NULL); if (local_err) { goto out; } if (id != NULL) { object_property_add_child(object_get_objects_root(), id, obj, &local_err); if (local_err) { goto out; } } user_creatable_complete(USER_CREATABLE(obj), &local_err); if (local_err) { if (id != NULL) { object_property_del(object_get_objects_root(), id, &error_abort); } goto out; } out: if (local_err) { error_propagate(errp, local_err); object_unref(obj); return NULL; } return obj; }
void user_creatable_cleanup(void) { object_unparent(object_get_objects_root()); }
static void qmp_chardev_open_socket(Chardev *chr, ChardevBackend *backend, bool *be_opened, Error **errp) { SocketChardev *s = SOCKET_CHARDEV(chr); ChardevSocket *sock = backend->u.socket.data; SocketAddress *addr = sock->addr; bool do_nodelay = sock->has_nodelay ? sock->nodelay : false; bool is_listen = sock->has_server ? sock->server : true; bool is_telnet = sock->has_telnet ? sock->telnet : false; bool is_waitconnect = sock->has_wait ? sock->wait : false; int64_t reconnect = sock->has_reconnect ? sock->reconnect : 0; QIOChannelSocket *sioc = NULL; s->is_unix = addr->type == SOCKET_ADDRESS_KIND_UNIX; s->is_listen = is_listen; s->is_telnet = is_telnet; s->do_nodelay = do_nodelay; if (sock->tls_creds) { Object *creds; creds = object_resolve_path_component( object_get_objects_root(), sock->tls_creds); if (!creds) { error_setg(errp, "No TLS credentials with id '%s'", sock->tls_creds); goto error; } s->tls_creds = (QCryptoTLSCreds *) object_dynamic_cast(creds, TYPE_QCRYPTO_TLS_CREDS); if (!s->tls_creds) { error_setg(errp, "Object with id '%s' is not TLS credentials", sock->tls_creds); goto error; } object_ref(OBJECT(s->tls_creds)); if (is_listen) { if (s->tls_creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) { error_setg(errp, "%s", "Expected TLS credentials for server endpoint"); goto error; } } else { if (s->tls_creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) { error_setg(errp, "%s", "Expected TLS credentials for client endpoint"); goto error; } } } s->addr = QAPI_CLONE(SocketAddress, sock->addr); qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_RECONNECTABLE); if (s->is_unix) { qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_FD_PASS); } /* be isn't opened until we get a connection */ *be_opened = false; chr->filename = SocketAddress_to_str("disconnected:", addr, is_listen, is_telnet); if (is_listen) { if (is_telnet) { s->do_telnetopt = 1; } } else if (reconnect > 0) { s->reconnect_time = reconnect; } if (s->reconnect_time) { sioc = qio_channel_socket_new(); tcp_chr_set_client_ioc_name(chr, sioc); qio_channel_socket_connect_async(sioc, s->addr, qemu_chr_socket_connected, chr, NULL); } else { if (s->is_listen) { char *name; sioc = qio_channel_socket_new(); name = g_strdup_printf("chardev-tcp-listener-%s", chr->label); qio_channel_set_name(QIO_CHANNEL(sioc), name); g_free(name); if (qio_channel_socket_listen_sync(sioc, s->addr, errp) < 0) { goto error; } s->listen_ioc = sioc; if (is_waitconnect && qemu_chr_wait_connected(chr, errp) < 0) { return; } if (!s->ioc) { s->listen_tag = qio_channel_add_watch( QIO_CHANNEL(s->listen_ioc), G_IO_IN, tcp_chr_accept, chr, NULL); } } else if (qemu_chr_wait_connected(chr, errp) < 0) { goto error; } } return; error: if (sioc) { object_unref(OBJECT(sioc)); } }