On Sun, Apr 03, 2022 at 02:21:48AM -0500, Sakshi Kaushik wrote:

Hi Sakshi,
Thanks for the patch. I left comments below on things that are
incomplete. Please compile and run it with the new command-line options
you've added to test if the code works.

> Signed-off-by: Sakshi Kaushik <sakshikaushik...@gmail.com>
> ---
>  contrib/vhost-user-scsi/vhost-user-scsi.c | 35 +++++++++++++++++++----
>  1 file changed, 29 insertions(+), 6 deletions(-)
> 
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c 
> b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index 4f6e3e2a24..9bdc088ce8 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -353,6 +353,8 @@ fail:
>  
>  int main(int argc, char **argv)
>  {
> +    static int opt_fdnum = -1;
> +    static gboolean opt_print_caps;

Why are these variables declared static?

>      VusDev *vdev_scsi = NULL;
>      char *unix_fn = NULL;
>      char *iscsi_uri = NULL;
> @@ -362,12 +364,18 @@ int main(int argc, char **argv)
>          switch (opt) {

The getopt(3) call needs to be extended to parse --socket-path, --fd, and
--print-capabilities. getopt_long(3) or GOptionContext APIs could be
used to parse these long options.

>          case 'h':
>              goto help;
> -        case 'u':
> +        case 's':
>              unix_fn = g_strdup(optarg);
>              break;
>          case 'i':
>              iscsi_uri = g_strdup(optarg);
>              break;
> +        case 'f':
> +            opt_fdnum = g_strdup(optarg);
> +            break;
> +        case 'p':
> +            opt_print_caps = g_strdup(optarg);

This statement sets opt_print_caps to true and leaks the string
allocated by g_strdup(). opt_print_caps is a gboolean, I think this
should just be:

  opt_print_caps = true;

> +            break;
>          default:
>              goto help;
>          }
> @@ -376,9 +384,22 @@ int main(int argc, char **argv)
>          goto help;
>      }
>  
> -    lsock = unix_sock_new(unix_fn);
> -    if (lsock < 0) {
> -        goto err;
> +    if (unix_fn) {
> +        lsock = unix_sock_new(unix_fn);
> +        if (lsock < 0) {
> +            exit(EXIT_FAILURE);
> +        }
> +    } else if (opt_fdnum < 0) {
> +        g_print("%s\n", g_option_context_get_help(context, true, NULL));

This looks like it was copy-pasted from another program that uses
GOptionContext but vhost-user-scsi.c:main() uses getopt(3) (a different
API) so it won't work here.

> +        exit(EXIT_FAILURE);
> +    } else {
> +        lsock = opt_fdnum;
> +    }
> +
> +    if (opt_print_caps) {
> +        if (opt_print_caps["type"] != "scsi") {
> +            goto err;
> +        }

This option does not need to validate input (there is no input). Instead
it needs to output JSON according to the vhost-user.rst backend
convention specification. Something like:

  printf("{\n");
  printf("  \"type\": \"scsi\"\n");
  printf("}\n");
  goto out;

>      }
>  
>      csock = accept(lsock, NULL, NULL);
> @@ -426,10 +447,12 @@ err:
>      goto out;
>  
>  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]);
> -    fprintf(stderr, "          -u path to unix socket\n");
> +    fprintf(stderr, "          -s path to unix socket\n");
>      fprintf(stderr, "          -i iscsi uri for lun 0\n");
> +    fprintf(stderr, "          -f fd, file-descriptor\n");
> +    fprintf(stderr, "          -p denotes print-capabilities\n");
>      fprintf(stderr, "          -h print help and quit\n");
>  
>      goto err;
> -- 
> 2.17.1
> 
> 

Attachment: signature.asc
Description: PGP signature

Reply via email to