资源简介
qemu5.1版本源码,开源,开源作虚拟机或者仿真开发板。 QEMU 5.0 Supports Recent Armv8.x Features, Cortex-M7 CPU, Host Directory Access, and More
代码片段和文件信息
/*
* Serving QEMU block devices via NBD
*
* Copyright (c) 2012 Red Hat Inc.
*
* Author: Paolo Bonzini
*
* This work is licensed under the terms of the GNU GPL version 2 or
* later. See the COPYING file in the top-level directory.
*/
#include “qemu/osdep.h“
#include “sysemu/blockdev.h“
#include “sysemu/block-backend.h“
#include “hw/block/block.h“
#include “qapi/error.h“
#include “qapi/qapi-commands-block.h“
#include “block/nbd.h“
#include “io/channel-socket.h“
#include “io/net-listener.h“
typedef struct NBDServerData {
QIONetListener *listener;
QCryptoTLSCreds *tlscreds;
char *tlsauthz;
} NBDServerData;
static NBDServerData *nbd_server;
static void nbd_blockdev_client_closed(NBDClient *client bool ignored)
{
nbd_client_put(client);
}
static void nbd_accept(QIONetListener *listener QIOChannelSocket *cioc
gpointer opaque)
{
qio_channel_set_name(QIO_CHANNEL(cioc) “nbd-server“);
nbd_client_new(cioc nbd_server->tlscreds nbd_server->tlsauthz
nbd_blockdev_client_closed);
}
static void nbd_server_free(NBDServerData *server)
{
if (!server) {
return;
}
qio_net_listener_disconnect(server->listener);
object_unref(object(server->listener));
if (server->tlscreds) {
object_unref(object(server->tlscreds));
}
g_free(server->tlsauthz);
g_free(server);
}
static QCryptoTLSCreds *nbd_get_tls_creds(const char *id Error **errp)
{
object *obj;
QCryptoTLSCreds *creds;
obj = object_resolve_path_component(
object_get_objects_root() id);
if (!obj) {
error_setg(errp “No TLS credentials with id ‘%s‘“
id);
return NULL;
}
creds = (QCryptoTLSCreds *)
object_dynamic_cast(obj TYPE_QCRYPTO_TLS_CREDS);
if (!creds) {
error_setg(errp “object with id ‘%s‘ is not TLS credentials“
id);
return NULL;
}
if (creds->endpoint != QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
error_setg(errp
“Expecting TLS credentials with a server endpoint“);
return NULL;
}
object_ref(obj);
return creds;
}
void nbd_server_start(SocketAddress *addr const char *tls_creds
const char *tls_authz Error **errp)
{
if (nbd_server) {
error_setg(errp “NBD server already running“);
return;
}
nbd_server = g_new0(NBDServerData 1);
nbd_server->listener = qio_net_listener_new();
qio_net_listener_set_name(nbd_server->listener
“nbd-listener“);
if (qio_net_listener_open_sync(nbd_server->listener addr 1 errp) < 0) {
goto error;
}
if (tls_creds) {
nbd_server->tlscreds = nbd_get_tls_creds(tls_creds errp);
if (!nbd_server->tlscreds) {
goto error;
}
/* TODO SOCKET_ADDRESS_TYPE_FD where fd has AF_INET or AF_INET6 */
if (addr->type !=
评论
共有 条评论