On Wed, Apr 06, 2022 at 11:24:10AM -0500, Sakshi Kaushik wrote:
> Signed-off-by: Sakshi Kaushik <sakshikaushik...@gmail.com>
> ---
>  contrib/vhost-user-scsi/vhost-user-scsi.c | 78 +++++++++++++++--------
>  1 file changed, 52 insertions(+), 26 deletions(-)

Thanks, I have applied this patch to my block-next branch!

I made a few small adjustments when merging. You do not need to resend
the patch. Details below:

> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c 
> b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index 4f6e3e2a24..0c38c2988c 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -351,34 +351,58 @@ fail:
>  
>  /** 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,

For consistency with --print-capabilities and --socket-path this option
should be called --iscsi-uri.

> +      "Use inherited fd socket", "FDNUM" },
> +    { "socket-path", 's', 0, G_OPTION_ARG_FILENAME, &opt_socket_path,
> +      "Use UNIX socket path", "PATH" }

A zero terminator is required here so
g_option_context_add_main_entries() knows when the array ends.

> +};
> +
>  int main(int argc, char **argv)
>  {
>      VusDev *vdev_scsi = NULL;
> -    char *unix_fn = NULL;
> -    char *iscsi_uri = NULL;
> -    int lsock = -1, csock = -1, opt, err = EXIT_SUCCESS;
> -
> -    while ((opt = getopt(argc, argv, "u:i:")) != -1) {
> -        switch (opt) {
> -        case 'h':
> -            goto help;
> -        case 'u':
> -            unix_fn = g_strdup(optarg);
> -            break;
> -        case 'i':
> -            iscsi_uri = g_strdup(optarg);
> -            break;
> -        default:
> -            goto help;
> -        }
> +    int lsock = -1, csock = -1, err = EXIT_SUCCESS;
> +
> +    GError *error = NULL;
> +    GOptionContext *context;
> +
> +    context = g_option_context_new(NULL);
> +    g_option_context_add_main_entries(context, entries, NULL);
> +    if (!g_option_context_parse(context, &argc, &argv, &error)) {
> +        g_printerr("Option parsing failed: %s\n", error->message);
> +        exit(EXIT_FAILURE);
>      }
> -    if (!unix_fn || !iscsi_uri) {
> +
> +    if (opt_print_caps) {
> +        g_print("{\n");
> +        g_print("  \"type\": \"scsi\"\n");
> +        g_print("}\n");
> +        goto out;
> +    }
> +
> +    if (!opt_socket_path || !iscsi_uri) {

This check rejects --fd and only allows --socket-path. We can drop
!opt_socket_path since the if statement below checks that already.

Attachment: signature.asc
Description: PGP signature

Reply via email to