From nobody Sat May 4 01:27:05 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1575856596; cv=none; d=zohomail.com; s=zohoarc; b=e5Yfy2tTPvgqnp0T7jd95IboB5NYYnrpYNXkQx4qdFV1mHc9BlwQRjlHOULNU46zf8JQADpcTZm51e0pUu9WaOr0u1Xu04FiA3bEC1TYmPETiDJRJZrqi4QdSXbsbgddj1aAtlQjGnXj3UD3xmOiqS65q9SVG+6CMRUCp2Bjehk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575856596; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=f/CHHckRiBXqEtYZAXyiuak0sc3yM7WzqBVmKgFk66E=; b=FklXoIchbs7HKMhis8WTnX19LLOWwHOViAflhstAyL4rkO7FanlASihbWwQ1f8mrQmnxwI0szIs/Mc9TCqqjkPGs/hf79UgtEp+wjtKVOMjyyzwMVrNe8NorQALtTkK5muyvS+FMQ2B/i8M5t6RcdP52eXG4oqPGXSU8uEZzXFM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575856596463624.7495631130852; Sun, 8 Dec 2019 17:56:36 -0800 (PST) Received: from localhost ([::1]:35024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ie8Hr-0003HX-9k for importer@patchew.org; Sun, 08 Dec 2019 20:56:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45393) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ie8FB-0001ss-Q3 for qemu-devel@nongnu.org; Sun, 08 Dec 2019 20:53:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ie8FA-0001p2-5w for qemu-devel@nongnu.org; Sun, 08 Dec 2019 20:53:49 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:42050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ie8F9-0001ni-VZ for qemu-devel@nongnu.org; Sun, 08 Dec 2019 20:53:48 -0500 Received: by mail-pg1-x542.google.com with SMTP id i5so6283671pgj.9 for ; Sun, 08 Dec 2019 17:53:46 -0800 (PST) Received: from localhost.localdomain.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o3sm9911374pju.13.2019.12.08.17.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 17:53:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f/CHHckRiBXqEtYZAXyiuak0sc3yM7WzqBVmKgFk66E=; b=lYhKu9K0jp7gOGX4P6z+lIGEQAr3XwENkkeoR2S3dG74qvP5IrrobNSXAH+1xe3dQz RuzP6pKDEBWxBKtAr+U1n1n4sGAXtl7oSK9MAuGydMSKr1RZfSalBK7NoIr+3nzcDWW/ cDaTif99A0Rnwo0TH+ex4FG6mwIrBioaelW09x8Vob+zw66WVCnpFSGZmgCTjV+F48Bm 2HnEsfqbF9fCDd2X0YQvxBwcCpwOPh6xRJSuVKmI9pnAEAOC1ciTPF0qYiruk2R910rD 4tny1uxoxhKG4pjpGiaDEXKHhdO3cl8MkaLw4/9cItillGBBhmSeL9VPgcj7gtAN95y0 dqbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f/CHHckRiBXqEtYZAXyiuak0sc3yM7WzqBVmKgFk66E=; b=rzRxgJxHGgOhz19IH9BTpP8GFkINym30P2Os4CDybvVpEQiaAf16RF9ZkEUcIxAtYp zHYtXUt02Q2h2YLusC8eBpUsjmGPjd9/Bgn3jHKJlm7BQGkTMLzFcM31Kt+oS3p31c3d m+4t499X+AJgLuRoKPGg4zeI9kDA/vqUt8J6qzWi2/FL5UTUJcUqCGYMedz+gPaPJPLO aOhymyOmXJkruM1VC4jNbywh8sW86ZWx5ME6wKyINqdjd/8m/K0l7kD1Ke74LK1rfN+L /4FwSV+NgA8UMf49BaXjE3DsVIcLfmLxHl3+88+rTRAJmsEVX223zOAygISlTyS60Wgq Z7bw== X-Gm-Message-State: APjAAAUVGY8BgYgwhUda3pqIpG++O31DlAt5AIHLSMOb0VkL2QjETbmS BDFoksSZnE/OKZtxLzhLf4VCRuiRc53olXUk X-Google-Smtp-Source: APXvYqzgLh5ot0tq+ikNTisNDlz79Uuc8Q2QP6Zr0FyYJcW2eG1MIyaQ8XqfXiZRPJsmkoGEbcTzvA== X-Received: by 2002:aa7:9629:: with SMTP id r9mr27351522pfg.51.1575856425118; Sun, 08 Dec 2019 17:53:45 -0800 (PST) From: "Micky Yun Chan(michiboo)" To: qemu-devel@nongnu.org Subject: [PATCH v8] Implement backend program convention command for vhost-user-blk Date: Mon, 9 Dec 2019 09:53:31 +0800 Message-Id: <20191209015331.5455-1-chanmickyyun@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Micky Yun Chan , stefanha@redhat.com, "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Micky Yun Chan This patch is to add standard commands defined in docs/interop/vhost-user.r= st For vhost-user-* program Signed-off-by: Micky Yun Chan (michiboo) --- contrib/vhost-user-blk/vhost-user-blk.c | 108 ++++++++++++++---------- docs/interop/vhost-user.json | 31 +++++++ docs/interop/vhost-user.rst | 17 ++++ 3 files changed, 112 insertions(+), 44 deletions(-) diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index ae61034656..6fd91c7e99 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -576,70 +576,90 @@ vub_new(char *blk_file) return vdev_blk; } =20 +static int opt_fdnum =3D -1; +static char *opt_socket_path; +static char *opt_blk_file; +static gboolean opt_print_caps; +static gboolean opt_read_only; + +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" }, + { "socket-path", 's', 0, G_OPTION_ARG_FILENAME, &opt_socket_path, + "Use UNIX socket path", "PATH" }, + {"blk-file", 'b', 0, G_OPTION_ARG_FILENAME, &opt_blk_file, + "block device or file path", "PATH"}, + { "read-only", 'r', 0, G_OPTION_ARG_NONE, &opt_read_only, + "Enable read-only", NULL } +}; + int main(int argc, char **argv) { - int opt; - char *unix_socket =3D NULL; - char *blk_file =3D NULL; - bool enable_ro =3D false; int lsock =3D -1, csock =3D -1; VubDev *vdev_blk =3D NULL; + GError *error =3D NULL; + GOptionContext *context; =20 - while ((opt =3D getopt(argc, argv, "b:rs:h")) !=3D -1) { - switch (opt) { - case 'b': - blk_file =3D g_strdup(optarg); - break; - case 's': - unix_socket =3D g_strdup(optarg); - break; - case 'r': - enable_ro =3D true; - break; - case 'h': - default: - printf("Usage: %s [ -b block device or file, -s UNIX domain so= cket" - " | -r Enable read-only ] | [ -h ]\n", argv[0]); - return 0; + 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 (opt_print_caps) { + g_print("{\n"); + g_print(" \"type\": \"block\",\n"); + g_print(" \"features\": [\n"); + g_print(" \"read-only\",\n"); + g_print(" \"blk-file\"\n"); + g_print(" ]\n"); + g_print("}\n"); + exit(EXIT_SUCCESS); + } + + if (!opt_blk_file) { + g_print("%s\n", g_option_context_get_help(context, true, NULL)); + exit(EXIT_FAILURE); + } + + 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 - if (!unix_socket || !blk_file) { - printf("Usage: %s [ -b block device or file, -s UNIX domain socket" - " | -r Enable read-only ] | [ -h ]\n", argv[0]); - return -1; - } - - lsock =3D unix_sock_new(unix_socket); - if (lsock < 0) { - goto err; - } - - csock =3D accept(lsock, (void *)0, (void *)0); + csock =3D accept(lsock, NULL, NULL); if (csock < 0) { - fprintf(stderr, "Accept error %s\n", strerror(errno)); - goto err; + g_printerr("Accept error %s\n", strerror(errno)); + exit(EXIT_FAILURE); } =20 - vdev_blk =3D vub_new(blk_file); + vdev_blk =3D vub_new(opt_blk_file); if (!vdev_blk) { - goto err; + exit(EXIT_FAILURE); } - if (enable_ro) { + if (opt_read_only) { vdev_blk->enable_ro =3D true; } =20 if (!vug_init(&vdev_blk->parent, VHOST_USER_BLK_MAX_QUEUES, csock, vub_panic_cb, &vub_iface)) { - fprintf(stderr, "Failed to initialized libvhost-user-glib\n"); - goto err; + g_printerr("Failed to initialize libvhost-user-glib\n"); + exit(EXIT_FAILURE); } =20 g_main_loop_run(vdev_blk->loop); - + g_main_loop_unref(vdev_blk->loop); + g_option_context_free(context); vug_deinit(&vdev_blk->parent); - -err: vub_free(vdev_blk); if (csock >=3D 0) { close(csock); @@ -647,8 +667,8 @@ err: if (lsock >=3D 0) { close(lsock); } - g_free(unix_socket); - g_free(blk_file); + g_free(opt_socket_path); + g_free(opt_blk_file); =20 return 0; } diff --git a/docs/interop/vhost-user.json b/docs/interop/vhost-user.json index da6aaf51c8..ce0ef74db5 100644 --- a/docs/interop/vhost-user.json +++ b/docs/interop/vhost-user.json @@ -54,6 +54,37 @@ ] } =20 +## +# @VHostUserBackendBlockFeature: +# +# List of vhost user "block" features. +# +# @read-only: The --read-only command line option is supported. +# @blk-file: The --blk-file command line option is supported. +# +# Since: 5.0 +## +{ + 'enum': 'VHostUserBackendBlockFeature', + 'data': [ 'read-only', 'blk-file' ] +} + +## +# @VHostUserBackendCapabilitiesBlock: +# +# Capabilities reported by vhost user "block" backends +# +# @features: list of supported features. +# +# Since: 5.0 +## +{ + 'struct': 'VHostUserBackendCapabilitiesBlock', + 'data': { + 'features': [ 'VHostUserBackendBlockFeature' ] + } +} + ## # @VHostUserBackendInputFeature: # diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst index 7827b710aa..015ac08177 100644 --- a/docs/interop/vhost-user.rst +++ b/docs/interop/vhost-user.rst @@ -1376,3 +1376,20 @@ Command line options: Enable virgl rendering support. =20 (optional) + +vhost-user-blk +-------------- + +Command line options: + +--blk-file=3DPATH + + Specify block device or file path. + + (optional) + +--read-only + + Enable read-only. + + (optional) --=20 2.21.0