From nobody Mon Feb 9 14:15:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=nutanix.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1629733284536534.3368621222584; Mon, 23 Aug 2021 08:41:24 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-ZUp-5FEzOcGswmVwp6XUDg-1; Mon, 23 Aug 2021 11:41:21 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B631F804169; Mon, 23 Aug 2021 15:41:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C05D1017CE7; Mon, 23 Aug 2021 15:41:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 80F884BB7B; Mon, 23 Aug 2021 15:41:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17NFfBVH025717 for ; Mon, 23 Aug 2021 11:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7AE48215673B; Mon, 23 Aug 2021 15:41:11 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F6EE200AD03 for ; Mon, 23 Aug 2021 15:41:04 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 13419800159 for ; Mon, 23 Aug 2021 15:41:04 +0000 (UTC) Received: from mx0b-002c1b01.pphosted.com (mx0b-002c1b01.pphosted.com [148.163.155.12]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-552-qX_HNJdtNi2kT9tMxO5mpA-1; Mon, 23 Aug 2021 11:41:02 -0400 Received: from pps.filterd (m0127844.ppops.net [127.0.0.1]) by mx0b-002c1b01.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 17NEgRGY000717 for ; Mon, 23 Aug 2021 08:41:01 -0700 Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam08lp2173.outbound.protection.outlook.com [104.47.73.173]) by mx0b-002c1b01.pphosted.com with ESMTP id 3ambwg917s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 23 Aug 2021 08:41:01 -0700 Received: from BN8PR02MB6433.namprd02.prod.outlook.com (2603:10b6:408:ad::10) by BN8PR02MB5892.namprd02.prod.outlook.com (2603:10b6:408:ba::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Mon, 23 Aug 2021 15:40:59 +0000 Received: from BN8PR02MB6433.namprd02.prod.outlook.com ([fe80::bdb2:16e:e432:a7b0]) by BN8PR02MB6433.namprd02.prod.outlook.com ([fe80::bdb2:16e:e432:a7b0%5]) with mapi id 15.20.4436.024; Mon, 23 Aug 2021 15:40:59 +0000 Received: from simon-rowe.ubvm.nutanix.com (192.146.154.247) by BY5PR16CA0018.namprd16.prod.outlook.com (2603:10b6:a03:1a0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Mon, 23 Aug 2021 15:40:58 +0000 X-MC-Unique: ZUp-5FEzOcGswmVwp6XUDg-1 X-MC-Unique: qX_HNJdtNi2kT9tMxO5mpA-1 From: Simon Rowe To: libvir-list@redhat.com Subject: [PATCHv2 1/2] iohelper: skip lseek() and ftruncate() on block devices Date: Mon, 23 Aug 2021 15:40:47 +0000 Message-Id: <20210823154048.94655-2-simon.rowe@nutanix.com> In-Reply-To: <20210823154048.94655-1-simon.rowe@nutanix.com> References: <20210823154048.94655-1-simon.rowe@nutanix.com> X-ClientProxiedBy: BY5PR16CA0018.namprd16.prod.outlook.com (2603:10b6:a03:1a0::31) To BN8PR02MB6433.namprd02.prod.outlook.com (2603:10b6:408:ad::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 35b3dd49-e698-4ac8-6853-08d9664c6793 X-MS-TrafficTypeDiagnostic: BN8PR02MB5892: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-proofpoint-crosstenant: true X-MS-Oob-TLC-OOBClassifiers: OLM:655 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: bkiRYk6CKtReuTk8wvbwtnGeCeRzQr0WZmfugoNrYoYz6JiL4qGNocoqCJFSAPgJ/pruZC/NNIGUkj9goTkjIIx3KXH3sKMTR0iqLkzeVes2RljK7OHfRF16fvv8dNNjbC1ez41N4R3GNBAcbB5RLLLQUI3MBgFh9rFIz2hdi3fUY56u5ubdi9Gz9CsimkVvbLsc2iblA1cAUSUDQnGCa4/92Vgi5v1OR71y/Dnlhck/Ao//AqJh8LvnLvEokvadIVkW3PrWt/tW49fVgGaAXiZVp5/uXRoR0ylaKQPS/sfaB2/Cf1g8yI210kWTTYlxCPbICllFFLCNAHDpgqzNYkxphQq+x035itiYmSRBKCBdbB6sOB0tnanM5BjMUAykdOAok4diVUkY6XfDFiVEmpWsTHut0Swc2cPsssgqhgf7lB8ZMFQpx4AqcnikNS5k/ASTjSbGoy28DkVeTv2Dtt707fAeDJqsK/pnwUZlHG93uJKi7+cvK2VKNVaCcIIGDQQM24IK/ExRTrWeu1lBGcHRlYX2AGGl0X7N30AWQ3awFV3yhOjax98N4yUX9KGtx1Wocsq979ih2jQWvFIFMH4Qh5plig1whQIaF+VgX15oud2f31BXNAGJx5UrGK/KfKyq6YKEmO/QiyHIboBkhXkceZILJIMwvYmqDAqeUioTYwRrW5W+cga4YSLiPvX2B5H1St0P80UWDqMpKKigPg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN8PR02MB6433.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(136003)(366004)(39860400002)(346002)(376002)(6486002)(38350700002)(478600001)(6666004)(2906002)(83380400001)(26005)(38100700002)(186003)(36756003)(6916009)(4326008)(1076003)(316002)(86362001)(66476007)(66556008)(66946007)(7696005)(2616005)(107886003)(44832011)(8936002)(8676002)(5660300002)(956004)(52116002); DIR:OUT; SFP:1102 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?D4XcKI75D8kM7BazAHg/BlEIQPg0vEoKefOaVLmLoAx6ENowvwG4LH8q2h0o?= =?us-ascii?Q?u30kU7nuTLG8//8UjxZopcLysqXd+gnveKRenpxwGxGAb2V9ZgDGkhwDJdnX?= =?us-ascii?Q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P6?= =?us-ascii?Q?nmOY0rZS7ciBDnMM4JOsPoD9aKfezS+cKKY7ijLtYKCJVhhKS6joabeC9wIW?= =?us-ascii?Q?io9qxffucVXgeNIOqNzzwEkTuGZAnG7gxQ9xi7f/VltNh8pfqMD2199BM+KQ?= =?us-ascii?Q?+fgYixYkpBdE7xe6Ipz1EZSeCK1xeuV/arRPdqbLL7rvRaBSYJXhuHLja8P8?= =?us-ascii?Q?f/vP1SWtAQrk7QBW42op9AB4kHiG7I483xKumPq/Xs9JtSOxwmIYzx92ZbdA?= =?us-ascii?Q?KvX5cht0y5WYuoT9lA9QLfAQX5EtZ8NK9SSJxx8jSVCzgPmJiK+g9uhwfZ6a?= =?us-ascii?Q?JYxoaljpAk/aP8lIEA9oVEh2?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35b3dd49-e698-4ac8-6853-08d9664c6793 X-MS-Exchange-CrossTenant-AuthSource: BN8PR02MB6433.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2021 15:40:59.2406 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: M0DpJqn2XpNI4bXC8F/hYVbWYYLKHw1ojR65eOGK+LL+S1tQQvPxIvQGl2T4Zy/JcRNU6VLID6WmHxEWJBjGRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR02MB5892 X-Proofpoint-ORIG-GUID: S9fodZGaToSlh0bLaAfH6DCsPqmjDz2m X-Proofpoint-GUID: S9fodZGaToSlh0bLaAfH6DCsPqmjDz2m X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1, Aquarius:18.0.790, Hydra:6.0.391, FMLib:17.0.607.475 definitions=2021-08-23_03,2021-08-23_01,2020-04-07_01 X-Proofpoint-Spam-Reason: safe X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Simon Rowe X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1629733286263100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Simon Rowe --- src/util/iohelper.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index b8810d16d3..e6eb178fde 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include =20 #include "virthread.h" #include "virfile.h" @@ -56,6 +58,8 @@ runIO(const char *path, int fd, int oflags) unsigned long long total =3D 0; bool direct =3D O_DIRECT && ((oflags & O_DIRECT) !=3D 0); off_t end =3D 0; + struct stat sb; + bool isBlockDev =3D false; =20 #if WITH_POSIX_MEMALIGN if (posix_memalign(&base, alignMask + 1, buflen)) @@ -86,9 +90,11 @@ runIO(const char *path, int fd, int oflags) fdinname =3D "stdin"; fdout =3D fd; fdoutname =3D path; + if (fstat(fd, &sb) =3D=3D 0) + isBlockDev =3D S_ISBLK(sb.st_mode); /* To make the implementation simpler, we give up on any * attempt to use O_DIRECT in a non-trivial manner. */ - if (direct && (end =3D lseek(fd, 0, SEEK_END)) !=3D 0) { + if (!isBlockDev && direct && (end =3D lseek(fd, 0, SEEK_END)) !=3D= 0) { virReportSystemError(end < 0 ? errno : EINVAL, "%s", _("O_DIRECT write needs empty seekable fi= le")); goto cleanup; @@ -140,7 +146,7 @@ runIO(const char *path, int fd, int oflags) goto cleanup; } =20 - if (ftruncate(fd, total) < 0) { + if (!isBlockDev && ftruncate(fd, total) < 0) { virReportSystemError(errno, _("Unable to truncate %s"), fd= outname); goto cleanup; } --=20 2.22.3