From patchwork Tue Feb 1 11:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12731599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80556C433F5 for ; Tue, 1 Feb 2022 11:46:09 +0000 (UTC) Received: from localhost ([::1]:55348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nErbs-0007X4-GI for qemu-devel@archiver.kernel.org; Tue, 01 Feb 2022 06:46:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nErJR-0004xv-Ic; Tue, 01 Feb 2022 06:27:05 -0500 Received: from [2a00:1450:4864:20::434] (port=33646 helo=mail-wr1-x434.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nErJP-0005rO-Vb; Tue, 01 Feb 2022 06:27:05 -0500 Received: by mail-wr1-x434.google.com with SMTP id e8so31423602wrc.0; Tue, 01 Feb 2022 03:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A/sKypw+AJdF8fRX/xejxpmznIU3PSTyhL7bbZhNB2s=; b=S4v+BgiqUWZDbKw1ctq7qluCNZxU3RhL92rzd3CklpoQKLBKW7IFnooKDDsUuluZsV eJLvQqI+K5GVaUtMFtCzuwQe4dwSoAtllqREPGeclD4GL169QcbTr3xuK3hCGmKEuPUJ VIDjad7H2aJm+7Mwgcks62sTl/Pun4KUEgb9wyv26V5sUOdKeJ7QZxKs6EWeeecTDywr VXKC8sxANBVwLt8LZpsWqJNxmqaGEXmGic2VGfr45eZLJZIcI6LP5RDV+1ABAO7Qp8j7 leRGMNs5pQNswpLfE4vGAobXBHIdhykB1pEqvSzn15RxkfQuy16xu/sXe8rnx/WSNw99 YOUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=A/sKypw+AJdF8fRX/xejxpmznIU3PSTyhL7bbZhNB2s=; b=uA6C+GLNQycoAclFrilI1WtPe0rEsGldqZ1jE+2J9cs5wCwOh/aFC99ZVXsoUchaYf JlzBFv/KcqV7VT8ui4J+2xxEqi4t2MSQ2fHZFIotQl1XPs2hrxFT7rtCkigPBjwjsUZU 82u9juUHpXknaAV18/6rOmYcK705aTYqDCFMkO/K2RAJZwfCmuWkOroG756ebmXH8aI/ EKjbuj7gPu3QYkZ8ms3mb0DSZRPGN9OoC4YQ5x+oSlkOYLoB+xyMd1jn+ZYiDscoz095 fGDvKiGUNjqXB4gdWZGPuzNKKDp/LOt8FBzNt46NThhKxr4hL7//FOepIF2Ifz1prdDO pbUw== X-Gm-Message-State: AOAM530smmtyrMkxuLqKJiUVBPXv0H2tUxSNsCsYka2MmcWjyqm7cRyL //MpmlGjugSGFpQAwzmiClkDWEFl2K0= X-Google-Smtp-Source: ABdhPJzkII3hVvbYhYCwphyKtT/5bnK14WpYi/DWtGUJe4N6M73AqNLildnUl0C8Qqiw7Syi4K7mVQ== X-Received: by 2002:adf:f8c2:: with SMTP id f2mr21674001wrq.150.1643714822249; Tue, 01 Feb 2022 03:27:02 -0800 (PST) Received: from nuc.. (154.red-83-50-83.dynamicip.rima-tde.net. [83.50.83.154]) by smtp.gmail.com with ESMTPSA id t5sm14870691wrw.92.2022.02.01.03.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 03:27:01 -0800 (PST) To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabrice Fontaine , Kevin Wolf , Kyle Evans , Hanna Reitz , Li-Wen Hsu , Ed Maste , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/2] block/export/fuse: Rearrange if-else-if ladder in fuse_fallocate() Date: Tue, 1 Feb 2022 12:26:54 +0100 Message-Id: <20220201112655.344373-2-f4bug@amsat.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220201112655.344373-1-f4bug@amsat.org> References: <20220201112655.344373-1-f4bug@amsat.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::434 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x434.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.248, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= In order to safely maintain a mixture of #ifdef'ry with if-else-if ladder, rearrange the last statement (!mode) first. Since it is mutually exclusive with the other conditions, checking it first doesn't make any logical difference, but allows to add #ifdef'ry around in a more cleanly way. Suggested-by: Kevin Wolf Signed-off-by: Philippe Mathieu-Daudé --- One minor checkpatch error: ERROR: else should follow close brace '}' #29: FILE: block/export/fuse.c:651: + } + else if (mode & FALLOC_FL_PUNCH_HOLE) { --- block/export/fuse.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/block/export/fuse.c b/block/export/fuse.c index 6710d8aed86..d25e478c0a2 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -629,7 +629,26 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, length = MIN(length, blk_len - offset); } - if (mode & FALLOC_FL_PUNCH_HOLE) { + if (!mode) { + /* We can only fallocate at the EOF with a truncate */ + if (offset < blk_len) { + fuse_reply_err(req, EOPNOTSUPP); + return; + } + + if (offset > blk_len) { + /* No preallocation needed here */ + ret = fuse_do_truncate(exp, offset, true, PREALLOC_MODE_OFF); + if (ret < 0) { + fuse_reply_err(req, -ret); + return; + } + } + + ret = fuse_do_truncate(exp, offset + length, true, + PREALLOC_MODE_FALLOC); + } + else if (mode & FALLOC_FL_PUNCH_HOLE) { if (!(mode & FALLOC_FL_KEEP_SIZE)) { fuse_reply_err(req, EINVAL); return; @@ -665,25 +684,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, } while (ret == 0 && length > 0); } #endif /* CONFIG_FALLOCATE_ZERO_RANGE */ - else if (!mode) { - /* We can only fallocate at the EOF with a truncate */ - if (offset < blk_len) { - fuse_reply_err(req, EOPNOTSUPP); - return; - } - - if (offset > blk_len) { - /* No preallocation needed here */ - ret = fuse_do_truncate(exp, offset, true, PREALLOC_MODE_OFF); - if (ret < 0) { - fuse_reply_err(req, -ret); - return; - } - } - - ret = fuse_do_truncate(exp, offset + length, true, - PREALLOC_MODE_FALLOC); - } else { + else { ret = -EOPNOTSUPP; } From patchwork Tue Feb 1 11:26:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12731666 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1E72C433F5 for ; Tue, 1 Feb 2022 12:24:04 +0000 (UTC) Received: from localhost ([::1]:40564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEsCY-000591-8H for qemu-devel@archiver.kernel.org; Tue, 01 Feb 2022 07:24:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nErJY-00056r-MQ; Tue, 01 Feb 2022 06:27:12 -0500 Received: from [2a00:1450:4864:20::330] (port=37501 helo=mail-wm1-x330.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nErJV-0005rk-Dg; Tue, 01 Feb 2022 06:27:12 -0500 Received: by mail-wm1-x330.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso1689958wmj.2; Tue, 01 Feb 2022 03:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pAqNmwI1L4cC383R9Vkhxz++gNKYm9jXECzlFKZVXw8=; b=kfqqNPDBvY3rUafW8T99Dg18Nenu9xLJkfjQ/tl+1u9T+YRED9PUOGurnaakCZAguD AaylIqTx7UQlYooVQRd/Huv30WWHuHRipQIW9zEHA2Cq+RJoIpZikwOIxT5TC5ErpjM5 +02mGzYrGTmv80zHSI8JXDEBKfyMjnhwfNdMfD1in1mxguTmnGE2E0bs/LKDvKwzKDL/ azRQYajvp9LZcQy5oyMzvVsBEJ57QkHH3WMGRthcCxRvrkBCQtC+1zSe1XSDQKaC4SrZ qcvuDOkCqinZ9zsOPKEsxYhoWhqqrfA6ipSfNHbE615kJPHjwlvR10p7h/OAGSiwA44a RTwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=pAqNmwI1L4cC383R9Vkhxz++gNKYm9jXECzlFKZVXw8=; b=jYhk8o01ifDW4wyY43giQzsnqfPOZuNfuqVfEi3vevqge1luq6XT8Wc4vtndqpruCn vpHk/QJiCfAuEgqd9Ya2LF5XsgpwGgdw13b6222b/Xr67UZbRLlpMMJj80u/+17EbAJ5 DxNRAXdBKlz141JZZlnePgwwTIbmOS5Egi19B4sFaeSC/kNAAGaxd/8pvC4liiikw4xk zxGWQxapyJRt34Ifvm7ilmVbdktkyzc6juopgZ9bNVEpWKRhAPEWwMMoKcUSh/p/YCOe fq4SwLfvzlreqgbdnFN0X/NrX9EsEe8v4DZ38QoAP7KE2y67bLSDo6kSu1kYx/lsGTB5 /3pw== X-Gm-Message-State: AOAM530lBnxJx54ytI+T2Wb5nWwZ2qAtNk7JHnWmL100Wf3uZyGX5hRX Cj2uENhZXncTu8BqfglUWb62UMFfkAQ= X-Google-Smtp-Source: ABdhPJyp0ixgIFbT8FSpttLPkZNYyMvDr8tDkwM7I6RX19L2wwUs3wuzYZE1je9DCEjDfp9+yO2sjA== X-Received: by 2002:a7b:c759:: with SMTP id w25mr1352465wmk.10.1643714827058; Tue, 01 Feb 2022 03:27:07 -0800 (PST) Received: from nuc.. (154.red-83-50-83.dynamicip.rima-tde.net. [83.50.83.154]) by smtp.gmail.com with ESMTPSA id b2sm16491835wri.88.2022.02.01.03.27.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 03:27:06 -0800 (PST) To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Fabrice Fontaine , Kevin Wolf , Kyle Evans , Hanna Reitz , Li-Wen Hsu , Ed Maste , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 2/2] block/export/fuse: Fix build failure on FreeBSD Date: Tue, 1 Feb 2022 12:26:55 +0100 Message-Id: <20220201112655.344373-3-f4bug@amsat.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220201112655.344373-1-f4bug@amsat.org> References: <20220201112655.344373-1-f4bug@amsat.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::330 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.248, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Original-From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= via From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= When building on FreeBSD we get: [816/6851] Compiling C object libblockdev.fa.p/block_export_fuse.c.o ../block/export/fuse.c:628:16: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' if (mode & FALLOC_FL_KEEP_SIZE) { ^ ../block/export/fuse.c:651:16: error: use of undeclared identifier 'FALLOC_FL_PUNCH_HOLE' if (mode & FALLOC_FL_PUNCH_HOLE) { ^ ../block/export/fuse.c:652:22: error: use of undeclared identifier 'FALLOC_FL_KEEP_SIZE' if (!(mode & FALLOC_FL_KEEP_SIZE)) { ^ 3 errors generated. FAILED: libblockdev.fa.p/block_export_fuse.c.o Meson indeed reported FALLOC_FL_PUNCH_HOLE is not available: C compiler for the host machine: cc (clang 10.0.1 "FreeBSD clang version 10.0.1") Checking for function "fallocate" : NO Checking for function "posix_fallocate" : YES Header has symbol "FALLOC_FL_PUNCH_HOLE" : NO Header has symbol "FALLOC_FL_ZERO_RANGE" : NO ... Similarly to commit 304332039 ("block/export/fuse.c: fix musl build"), guard the code requiring FALLOC_FL_KEEP_SIZE / FALLOC_FL_PUNCH_HOLE definitions under CONFIG_FALLOCATE_PUNCH_HOLE #ifdef'ry. Signed-off-by: Philippe Mathieu-Daudé --- block/export/fuse.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/export/fuse.c b/block/export/fuse.c index d25e478c0a2..fdda8e3c818 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -625,9 +625,11 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, return; } +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE if (mode & FALLOC_FL_KEEP_SIZE) { length = MIN(length, blk_len - offset); } +#endif /* CONFIG_FALLOCATE_PUNCH_HOLE */ if (!mode) { /* We can only fallocate at the EOF with a truncate */ @@ -648,6 +650,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, ret = fuse_do_truncate(exp, offset + length, true, PREALLOC_MODE_FALLOC); } +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE else if (mode & FALLOC_FL_PUNCH_HOLE) { if (!(mode & FALLOC_FL_KEEP_SIZE)) { fuse_reply_err(req, EINVAL); @@ -662,6 +665,7 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, length -= size; } while (ret == 0 && length > 0); } +#endif /* CONFIG_FALLOCATE_PUNCH_HOLE */ #ifdef CONFIG_FALLOCATE_ZERO_RANGE else if (mode & FALLOC_FL_ZERO_RANGE) { if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + length > blk_len) {