From nobody Tue Nov 26 09:50:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709120983; cv=none; d=zohomail.com; s=zohoarc; b=hC4VJ0VUarFsZcZrdh1rJCPbJFQ25PgSCVZi3D+GwG+VYxOtlhOJGgUeCP4NSZnv0KRN64I9/gdydUGr7hbHMTuUQiZMI4BVxJ+Yr7ltygnOfJzeoXOLT+uRrwHM8UVY3nv6TTUmcRMXJkiNQjGpc8y4aR0CfXUVW5c1kyb1kpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709120983; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TLg7okLmDrwykRkhT6hlbl5ORhkxyjg/0KKKGfeq0JU=; b=cBkOx2BELLmUFxDQXTjMMP0DVcR/N995ArdL+VTTJjVcVJXNBaa3S0SM3jY5kwOvIk/+Cse7oFhF3b7VwWxeANx624i87HSCfADduyDGVB9+IwtsdoDcZyXMZRlOlW6VVcAZGLB4gQ/eQFj41QUsvkAMXaqLgbLX9rgoi14ftlY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170912098351621.999239699463146; Wed, 28 Feb 2024 03:49:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIR1-0004wb-Ih; Wed, 28 Feb 2024 06:49:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfIQz-0004m3-AX for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfIQx-00040K-IV for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:49:13 -0500 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-8ApzNfZYP3GFiRwONsmYnA-1; Wed, 28 Feb 2024 06:49:09 -0500 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3c02a63d499so9377492b6e.3 for ; Wed, 28 Feb 2024 03:49:09 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id pd5-20020a056214490500b0068f9592f381sm5184581qvb.10.2024.02.28.03.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:49:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TLg7okLmDrwykRkhT6hlbl5ORhkxyjg/0KKKGfeq0JU=; b=ffSFARpZbUmm7Zja4e6+ajEzaFhDvU85f3scPhRgUc6kOkLSUF9i5re1qF7ctpAHUhPf3o 7IoglWlDitrHD60mNkbaD03pjJ/kUWZwcVgIMZbYjytscyTjO16Dlw+Ze2gbjcqfB6mzYx 8Knbt3z4q8Ev+A9cvH0u413pyZ/l3Ls= X-MC-Unique: 8ApzNfZYP3GFiRwONsmYnA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120945; x=1709725745; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TLg7okLmDrwykRkhT6hlbl5ORhkxyjg/0KKKGfeq0JU=; b=RrIBSxgl7OjuuQJXXh2neCNxGo1DEAFLAztXo3pjCku3u4Pg5Ltbs9Z4gh9+ZNDeSQ yMclz/1sXgxjmsxwgJu7dkSolr3DVAmo0VaiesD1HbLceaBYqRZJZaFJw370Xy3yVahz FwVGVE9skoozWH3o3R8h06b99waAvclFwaLsbC5n5jY34B9OiKqJAP1B3CM/B5GDS2oy YwbO3dlLs/oHAKHtsIE6lYJWcwfoQSu2uTeVKlI0fQRBkANhlIZINSpthY6BxqR4Jl2K zJAa89Aibl+xyxDO3yKca8SFr5Wwvd5ubPIkTzYZXKndgjYAnbid0qIB73MCc3aa/gwF v/Ng== X-Gm-Message-State: AOJu0YwUu06y/nYp4azftHbayThK6NGmCxzkJUrasjd19jp8GLtEvBPG IPHMj+Zlo85FW4AHmpbo+DTuFuiPPxXb/uHsNolXBH/cDxczCDgImzuDAYjM18OxWClI5aByaij qhD2rN5eq/92H5EA+gTYAfy4frUCG108aYkuEluL7cqle4oTERSCHcicLAHXf3oaS/JRw1j6orc x3HJ6fOIwFNPfHbeTg2uHyCHrcmPH2W+4fjAGV X-Received: by 2002:a05:6358:541a:b0:178:e2b3:98da with SMTP id u26-20020a056358541a00b00178e2b398damr16355713rwe.28.1709120944865; Wed, 28 Feb 2024 03:49:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHKAfcJVb6B10yOsJ+Uj2GvaLy5ffB1SRAVsgtZby8PB8+cwyPAzX+9O/DuB/UIwJE+05mlA== X-Received: by 2002:a05:6358:541a:b0:178:e2b3:98da with SMTP id u26-20020a056358541a00b00178e2b398damr16355684rwe.28.1709120944532; Wed, 28 Feb 2024 03:49:04 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella Subject: [PATCH 8/9] contrib/vhost-user-blk: enabled it on any POSIX system Date: Wed, 28 Feb 2024 12:47:58 +0100 Message-ID: <20240228114759.44758-9-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.102, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709120983748100001 Content-Type: text/plain; charset="utf-8" Let's make the code more portable by using the "qemu/bswap.h" API and adding defines from block/file-posix.c to support O_DIRECT in other systems (e.g. macOS). vhost-user-server.c is a dependency, let's enable it for any POSIX system. Signed-off-by: Stefano Garzarella --- meson.build | 2 -- contrib/vhost-user-blk/vhost-user-blk.c | 19 +++++++++++++++++-- util/meson.build | 4 +++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index af15178969..8afda86d3d 100644 --- a/meson.build +++ b/meson.build @@ -1954,8 +1954,6 @@ has_statx =3D cc.has_header_symbol('sys/stat.h', 'STA= TX_BASIC_STATS', prefix: gnu_ has_statx_mnt_id =3D cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', pr= efix: gnu_source_prefix) =20 have_vhost_user_blk_server =3D get_option('vhost_user_blk_server') \ - .require(host_os =3D=3D 'linux', - error_message: 'vhost_user_blk_server requires linux') \ .require(have_vhost_user, error_message: 'vhost_user_blk_server requires vhost-user suppo= rt') \ .disable_auto_if(not have_tools and not have_system) \ diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-b= lk/vhost-user-blk.c index a8ab9269a2..462e584857 100644 --- a/contrib/vhost-user-blk/vhost-user-blk.c +++ b/contrib/vhost-user-blk/vhost-user-blk.c @@ -16,6 +16,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "standard-headers/linux/virtio_blk.h" #include "libvhost-user-glib.h" =20 @@ -24,6 +25,20 @@ #include #endif =20 +/* OS X does not have O_DSYNC */ +#ifndef O_DSYNC +#ifdef O_SYNC +#define O_DSYNC O_SYNC +#elif defined(O_FSYNC) +#define O_DSYNC O_FSYNC +#endif +#endif + +/* Approximate O_DIRECT with O_DSYNC if O_DIRECT isn't available */ +#ifndef O_DIRECT +#define O_DIRECT O_DSYNC +#endif + enum { VHOST_USER_BLK_MAX_QUEUES =3D 8, }; @@ -267,13 +282,13 @@ static int vub_virtio_process_req(VubDev *vdev_blk, req->in =3D (struct virtio_blk_inhdr *)elem->in_sg[in_num - 1].iov_bas= e; in_num--; =20 - type =3D le32toh(req->out->type); + type =3D le32_to_cpu(req->out->type); switch (type & ~VIRTIO_BLK_T_BARRIER) { case VIRTIO_BLK_T_IN: case VIRTIO_BLK_T_OUT: { ssize_t ret =3D 0; bool is_write =3D type & VIRTIO_BLK_T_OUT; - req->sector_num =3D le64toh(req->out->sector); + req->sector_num =3D le64_to_cpu(req->out->sector); if (is_write) { ret =3D vub_writev(req, &elem->out_sg[1], out_num); } else { diff --git a/util/meson.build b/util/meson.build index 0ef9886be0..f52682ce96 100644 --- a/util/meson.build +++ b/util/meson.build @@ -113,10 +113,12 @@ if have_block util_ss.add(files('filemonitor-stub.c')) endif if host_os =3D=3D 'linux' - util_ss.add(files('vhost-user-server.c'), vhost_user) util_ss.add(files('vfio-helpers.c')) util_ss.add(files('chardev_open.c')) endif + if host_os !=3D 'windows' + util_ss.add(files('vhost-user-server.c'), vhost_user) + endif endif =20 if cpu =3D=3D 'aarch64' --=20 2.43.2