From nobody Mon Feb 9 12:11:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1649262419702160.8587407169931; Wed, 6 Apr 2022 09:26:59 -0700 (PDT) Received: from localhost ([::1]:34920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nc8Uk-000173-7I for importer@patchew.org; Wed, 06 Apr 2022 12:26:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nc8T7-0008MF-SM for qemu-devel@nongnu.org; Wed, 06 Apr 2022 12:25:17 -0400 Received: from 2603-8080-1600-366f-8436-e75e-5f0f-0f6e.res6.spectrum.com ([2603:8080:1600:366f:8436:e75e:5f0f:f6e]:50682 helo=geekhouse) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nc8T6-0000Qp-70 for qemu-devel@nongnu.org; Wed, 06 Apr 2022 12:25:17 -0400 Received: from geekhouse (localhost [127.0.0.1]) by geekhouse (8.15.2/8.15.2/Debian-10) with ESMTP id 236GPDpO008591; Wed, 6 Apr 2022 11:25:13 -0500 Received: (from sk@localhost) by geekhouse (8.15.2/8.15.2/Submit) id 236GPCdJ008583; Wed, 6 Apr 2022 11:25:12 -0500 From: Sakshi Kaushik To: qemu-devel@nongnu.org Subject: [PATCH] [PATCH RFC v4] Implements Backend Program conventions for vhost-user-scsi Date: Wed, 6 Apr 2022 11:24:10 -0500 Message-Id: <20220406162410.8536-1-sakshikaushik717@gmail.com> X-Mailer: git-send-email 2.17.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2603:8080:1600:366f:8436:e75e:5f0f:f6e; envelope-from=sk@geekhouse; helo=geekhouse X-Spam_score_int: 40 X-Spam_score: 4.0 X-Spam_bar: ++++ X-Spam_report: (4.0 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, FSL_HELO_NON_FQDN_1=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HELO_NO_DOMAIN=0.001, KHOP_HELO_FCRDNS=0.187, NML_ADSP_CUSTOM_MED=0.9, PDS_RDNS_DYNAMIC_FP=0.001, RDNS_DYNAMIC=0.982, SPF_NONE=0.001, SPOOFED_FREEMAIL=1.522, SPOOF_GMAIL_MID=0.799, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: raphel.norwitz@nutanix.com, Sakshi Kaushik , stefanha@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1649262420484100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sakshi Kaushik --- contrib/vhost-user-scsi/vhost-user-scsi.c | 78 +++++++++++++++-------- 1 file changed, 52 insertions(+), 26 deletions(-) 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: =20 /** vhost-user-scsi **/ =20 +static int opt_fdnum =3D -1; +static char *opt_socket_path; +static gboolean opt_print_caps; +static char *iscsi_uri; + +static GOptionEntry entries[] =3D { + { "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, + "Use inherited fd socket", "FDNUM" }, + { "socket-path", 's', 0, G_OPTION_ARG_FILENAME, &opt_socket_path, + "Use UNIX socket path", "PATH" } +}; + int main(int argc, char **argv) { VusDev *vdev_scsi =3D NULL; - char *unix_fn =3D NULL; - char *iscsi_uri =3D NULL; - int lsock =3D -1, csock =3D -1, opt, err =3D EXIT_SUCCESS; - - while ((opt =3D getopt(argc, argv, "u:i:")) !=3D -1) { - switch (opt) { - case 'h': - goto help; - case 'u': - unix_fn =3D g_strdup(optarg); - break; - case 'i': - iscsi_uri =3D g_strdup(optarg); - break; - default: - goto help; - } + int lsock =3D -1, csock =3D -1, err =3D EXIT_SUCCESS; + + GError *error =3D NULL; + GOptionContext *context; + + context =3D 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) { goto help; } =20 - lsock =3D unix_sock_new(unix_fn); - if (lsock < 0) { - goto err; + if (opt_socket_path) { + lsock =3D unix_sock_new(opt_socket_path); + 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 =3D opt_fdnum; } =20 csock =3D accept(lsock, NULL, NULL); @@ -408,7 +432,7 @@ out: if (vdev_scsi) { g_main_loop_unref(vdev_scsi->loop); g_free(vdev_scsi); - unlink(unix_fn); + unlink(opt_socket_path); } if (csock >=3D 0) { close(csock); @@ -416,7 +440,7 @@ out: if (lsock >=3D 0) { close(lsock); } - g_free(unix_fn); + g_free(opt_socket_path); g_free(iscsi_uri); =20 return err; @@ -426,10 +450,12 @@ err: goto out; =20 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 prin= t-capabilities ] | [ -h ]\n", argv[0]); - fprintf(stderr, " -u path to unix socket\n"); - fprintf(stderr, " -i iscsi uri for lun 0\n"); + fprintf(stderr, " -s, --socket-path=3DSOCKET_PATH path to uni= x socket\n"); + fprintf(stderr, " -i, --iscsi_uri=3DISCSI_URI iscsi uri for l= un 0\n"); + fprintf(stderr, " -f --fd=3DFILE_DESCRIPTOR file-descriptor\n= "); + fprintf(stderr, " -p --print-capabilities=3DPRINT_CAPABILITIE= S denotes print-capabilities\n"); fprintf(stderr, " -h print help and quit\n"); =20 goto err; --=20 2.17.1