mirror of https://github.com/xemu-project/xemu.git
Implements Backend Program conventions for vhost-user-scsi
Signed-off-by: Sakshi Kaushik <sakshikaushik717@gmail.com> Message-id: 20220406162410.8536-1-sakshikaushik717@gmail.com [Name the iSCSI URL long option --iscsi-uri instead of --iscsi_uri for consistency, fix --fd which was rejected due to an outdated --socket-path check, and add missing entries[] terminator. --Stefan] Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
9c125d17e9
commit
747421e949
|
@ -351,34 +351,59 @@ fail:
|
||||||
|
|
||||||
/** vhost-user-scsi **/
|
/** vhost-user-scsi **/
|
||||||
|
|
||||||
|
static int opt_fdnum = -1;
|
||||||
|
static char *opt_socket_path;
|
||||||
|
static gboolean opt_print_caps;
|
||||||
|
static char *iscsi_uri;
|
||||||
|
|
||||||
|
static GOptionEntry entries[] = {
|
||||||
|
{ "print-capabilities", 'c', 0, G_OPTION_ARG_NONE, &opt_print_caps,
|
||||||
|
"Print capabilities", NULL },
|
||||||
|
{ "fd", 'f', 0, G_OPTION_ARG_INT, &opt_fdnum,
|
||||||
|
"Use inherited fd socket", "FDNUM" },
|
||||||
|
{ "iscsi-uri", 'i', 0, G_OPTION_ARG_FILENAME, &iscsi_uri,
|
||||||
|
"iSCSI URI to connect to", "FDNUM" },
|
||||||
|
{ "socket-path", 's', 0, G_OPTION_ARG_FILENAME, &opt_socket_path,
|
||||||
|
"Use UNIX socket path", "PATH" },
|
||||||
|
{ NULL, }
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
VusDev *vdev_scsi = NULL;
|
VusDev *vdev_scsi = NULL;
|
||||||
char *unix_fn = NULL;
|
int lsock = -1, csock = -1, err = EXIT_SUCCESS;
|
||||||
char *iscsi_uri = NULL;
|
|
||||||
int lsock = -1, csock = -1, opt, err = EXIT_SUCCESS;
|
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "u:i:")) != -1) {
|
GError *error = NULL;
|
||||||
switch (opt) {
|
GOptionContext *context;
|
||||||
case 'h':
|
|
||||||
goto help;
|
context = g_option_context_new(NULL);
|
||||||
case 'u':
|
g_option_context_add_main_entries(context, entries, NULL);
|
||||||
unix_fn = g_strdup(optarg);
|
if (!g_option_context_parse(context, &argc, &argv, &error)) {
|
||||||
break;
|
g_printerr("Option parsing failed: %s\n", error->message);
|
||||||
case 'i':
|
exit(EXIT_FAILURE);
|
||||||
iscsi_uri = g_strdup(optarg);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
goto help;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!unix_fn || !iscsi_uri) {
|
|
||||||
|
if (opt_print_caps) {
|
||||||
|
g_print("{\n");
|
||||||
|
g_print(" \"type\": \"scsi\"\n");
|
||||||
|
g_print("}\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!iscsi_uri) {
|
||||||
goto help;
|
goto help;
|
||||||
}
|
}
|
||||||
|
|
||||||
lsock = unix_sock_new(unix_fn);
|
if (opt_socket_path) {
|
||||||
if (lsock < 0) {
|
lsock = unix_sock_new(opt_socket_path);
|
||||||
goto err;
|
if (lsock < 0) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
} else if (opt_fdnum < 0) {
|
||||||
|
g_print("%s\n", g_option_context_get_help(context, true, NULL));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else {
|
||||||
|
lsock = opt_fdnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
csock = accept(lsock, NULL, NULL);
|
csock = accept(lsock, NULL, NULL);
|
||||||
|
@ -408,7 +433,7 @@ out:
|
||||||
if (vdev_scsi) {
|
if (vdev_scsi) {
|
||||||
g_main_loop_unref(vdev_scsi->loop);
|
g_main_loop_unref(vdev_scsi->loop);
|
||||||
g_free(vdev_scsi);
|
g_free(vdev_scsi);
|
||||||
unlink(unix_fn);
|
unlink(opt_socket_path);
|
||||||
}
|
}
|
||||||
if (csock >= 0) {
|
if (csock >= 0) {
|
||||||
close(csock);
|
close(csock);
|
||||||
|
@ -416,7 +441,7 @@ out:
|
||||||
if (lsock >= 0) {
|
if (lsock >= 0) {
|
||||||
close(lsock);
|
close(lsock);
|
||||||
}
|
}
|
||||||
g_free(unix_fn);
|
g_free(opt_socket_path);
|
||||||
g_free(iscsi_uri);
|
g_free(iscsi_uri);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -426,10 +451,12 @@ err:
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
help:
|
help:
|
||||||
fprintf(stderr, "Usage: %s [ -u unix_sock_path -i iscsi_uri ] | [ -h ]\n",
|
fprintf(stderr, "Usage: %s [ -s socket-path -i iscsi-uri -f fd -p print-capabilities ] | [ -h ]\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
fprintf(stderr, " -u path to unix socket\n");
|
fprintf(stderr, " -s, --socket-path=SOCKET_PATH path to unix socket\n");
|
||||||
fprintf(stderr, " -i iscsi uri for lun 0\n");
|
fprintf(stderr, " -i, --iscsi-uri=ISCSI_URI iscsi uri for lun 0\n");
|
||||||
|
fprintf(stderr, " -f, --fd=FILE_DESCRIPTOR file-descriptor\n");
|
||||||
|
fprintf(stderr, " -p, --print-capabilities=PRINT_CAPABILITIES denotes print-capabilities\n");
|
||||||
fprintf(stderr, " -h print help and quit\n");
|
fprintf(stderr, " -h print help and quit\n");
|
||||||
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
Loading…
Reference in New Issue