提交 53a2e1b5 编写于 作者: M Marc-André Lureau

vhost-user-scsi: remove server_sock from VusDev

It is unneeded in the VusDev device structure, and also simplify a bit
the code.
Signed-off-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: NPhilippe Mathieu-Daudé <f4bug@amsat.org>
上级 62ddfba0
......@@ -28,7 +28,6 @@ typedef struct VusIscsiLun {
typedef struct VusDev {
VugDev parent;
int server_sock;
VusIscsiLun lun;
GMainLoop *loop;
} VusDev;
......@@ -357,57 +356,12 @@ fail:
/** vhost-user-scsi **/
static void vdev_scsi_free(VusDev *vdev_scsi)
{
if (vdev_scsi->server_sock >= 0) {
close(vdev_scsi->server_sock);
}
g_main_loop_unref(vdev_scsi->loop);
g_free(vdev_scsi);
}
static VusDev *vdev_scsi_new(int server_sock)
{
VusDev *vdev_scsi;
vdev_scsi = g_new0(VusDev, 1);
vdev_scsi->server_sock = server_sock;
vdev_scsi->loop = g_main_loop_new(NULL, FALSE);
return vdev_scsi;
}
static int vdev_scsi_run(VusDev *vdev_scsi)
{
int cli_sock;
assert(vdev_scsi);
assert(vdev_scsi->server_sock >= 0);
cli_sock = accept(vdev_scsi->server_sock, NULL, NULL);
if (cli_sock < 0) {
perror("accept");
return -1;
}
vug_init(&vdev_scsi->parent,
cli_sock,
vus_panic_cb,
&vus_iface);
g_main_loop_run(vdev_scsi->loop);
vug_deinit(&vdev_scsi->parent);
return 0;
}
int main(int argc, char **argv)
{
VusDev *vdev_scsi = NULL;
char *unix_fn = NULL;
char *iscsi_uri = NULL;
int sock, opt, err = EXIT_SUCCESS;
int lsock = -1, csock = -1, opt, err = EXIT_SUCCESS;
while ((opt = getopt(argc, argv, "u:i:")) != -1) {
switch (opt) {
......@@ -427,25 +381,42 @@ int main(int argc, char **argv)
goto help;
}
sock = unix_sock_new(unix_fn);
if (sock < 0) {
lsock = unix_sock_new(unix_fn);
if (lsock < 0) {
goto err;
}
vdev_scsi = vdev_scsi_new(sock);
if (vus_iscsi_add_lun(&vdev_scsi->lun, iscsi_uri) != 0) {
csock = accept(lsock, NULL, NULL);
if (csock < 0) {
perror("accept");
goto err;
}
if (vdev_scsi_run(vdev_scsi) != 0) {
vdev_scsi = g_new0(VusDev, 1);
vdev_scsi->loop = g_main_loop_new(NULL, FALSE);
if (vus_iscsi_add_lun(&vdev_scsi->lun, iscsi_uri) != 0) {
goto err;
}
vug_init(&vdev_scsi->parent, csock, vus_panic_cb, &vus_iface);
g_main_loop_run(vdev_scsi->loop);
vug_deinit(&vdev_scsi->parent);
out:
if (vdev_scsi) {
vdev_scsi_free(vdev_scsi);
g_main_loop_unref(vdev_scsi->loop);
g_free(vdev_scsi);
unlink(unix_fn);
}
if (csock >= 0) {
close(csock);
}
if (lsock >= 0) {
close(lsock);
}
g_free(unix_fn);
g_free(iscsi_uri);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册