Implements Backend Program conventions for vhost-user-scsi
RFC PATCH v2 1/1 Implements Backend Program conventions for vhost-user-scsi
--- contrib/vhost-user-scsi/vhost-user-scsi.c | 35 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-)
contrib/vhost-user-scsi/vhost-user-scsi.c +29 -6
@@ -353,6 +353,8 @@ fail:int main (int argc,char **argv) { +static int opt_fdnum =-1 ; +static gboolean opt_print_caps;VusDev *vdev_scsi =NULL ;char *unix_fn =NULL ;char *iscsi_uri =NULL ;
@@ -362,12 +364,18 @@ int main(int argc, char **argv)switch (opt) {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); +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 )); +exit (EXIT_FAILURE ); + }else { + lsock = opt_fdnum; + } + +if (opt_print_caps) { +if (opt_print_caps["type" ] !="scsi" ) { + goto err; + } } 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;
Signature · 1 line
2.17.1
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.
Quoted 10 lines
Signed-off-by Sakshi Kaushik <[email protected]>--- contrib/vhost-user-scsi/vhost-user-scsi.c | 35 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-)contrib/vhost-user-scsi/vhost-user-scsi.c +0
-0
contrib/vhost-user-scsi/vhost-user-scsi.c fail: · line 357
Quoted 5 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +2
-0@@ -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?
contrib/vhost-user-scsi/vhost-user-scsi.c int main(int argc, char **argv) · line 364
Quoted 5 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +0
-0VusDev *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.
Quoted 4 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +1
-1case 'h' : goto help; -case 'u' : +case 's' :
contrib/vhost-user-scsi/vhost-user-scsi.c int main(int argc, char **argv) · line 377
Quoted 10 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +5
-0unix_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;
Quoted 8 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +1
-0+break ;default : goto help; }@@ -376,9 +384,22 @@ int main(int argc, char **argv) goto help; }
contrib/vhost-user-scsi/vhost-user-scsi.c int main(int argc, char **argv) · line 393
Quoted 10 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +7
-3- 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.
contrib/vhost-user-scsi/vhost-user-scsi.c int main(int argc, char **argv) · line 402
Quoted 9 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +9
-0+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;Quoted 22 lines
contrib/vhost-user-scsi/vhost-user-scsi.c +4
-2} 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;Signature · 1 line
2.17.1
A message that is not in the archive (sent off-list or not yet received): CAFt73e_Rku3pgQ+YAj-zAcrq36JJd1A1pBA-AX8JMrqRY0f5TA@mail.gmail.com
Quoted 4 lines · Sakshi Kaushik
I have made the suggested changes and submitted v3.
But I am not sure how to check this code by running it? When I try to run the .c code I get the error message: 'qemu/osdep.h' no such file or directory.I have followed the building step without error. Not sure if I'm doing it correctly.
The executable will be in build/contrib/vhost-user-scsi/vhost-user-scsi after you run 'make'. If you ran make from the root of the QEMU source tree you can run the program like this:
$ build/contrib/vhost-user-scsi/vhost-user-scsi
This will let you check that the new command-line options work and that the help output is updated.
The simplest way to check that vhost-user-scsi is listening on the given UNIX domain socket path (--socket-path) or file descriptor (--fd) is using:
$ netstat --unix --listening --program
This shows all processes that are listening on a UNIX domain socket. You can search for the PID of the vhost-user-scsi process to see if it's listed.
Stefan
A message that is not in the archive (sent off-list or not yet received): CAFt73e-2pf1XDp66PVCPq4kUiegChJGhaiEyHAvyWUf77jbNEw@mail.gmail.com
Quoted 1 line · Sakshi Kaushik
I am not able to find vhost-user-scsi inside build/contrib/vhost-user-scsi despite running the 'make' command.
It is probably not being built because the dependencies are not installed on your machine. Here are the contents of the contrib/vhost-user-scsi/meson.build file:
if libiscsi.found()
executable('vhost-user-scsi', files('vhost-user-scsi.c'),
dependencies: [qemuutil, libiscsi, vhost_user],
build_by_default: targetos == 'linux',
install: false)
endif
The build machine must be a Linux machine and it must have the libiscsi-dev (Debian/Ubuntu), libiscsi-devel (Fedora/CentOS/RHEL), or similarly-named package installed. You can run QEMU's ./configure script and look at the output to see if it detected libiscsi.
Stefan