From nobody Mon Feb 9 20:32:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) client-ip=209.85.221.51; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f51.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail(p=quarantine dis=quarantine) header.from=amsat.org ARC-Seal: i=1; a=rsa-sha256; t=1643714823; cv=none; d=zohomail.com; s=zohoarc; b=bjMqHvGh56HFYJp80PLr3gltXa8CaGFQk5/ZqeH1QverlWKG4R9vUOp3YS3kSDYiqgyRN/Vmm5AsOR4G13T7Lp2KYyMkf65EXDynUFNZ7epicCsXAS8DOw3IytXAZp2sGNnRefLrBHzwrdTFFcIVkzuVPnPOqfKpyx9cTZYDVwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643714823; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A/sKypw+AJdF8fRX/xejxpmznIU3PSTyhL7bbZhNB2s=; b=eOm5BQkrKLUbIOVBd3DiWcEAURtq8WWyt/VMWqYWHmYFfCoFSRGf1dMT6DEanz+oBhQlvQfv7voIXERLMQ42Czwt9DS2hJBG8GJTcYptNU7cl2NeDSuy4/VG1WJOjynDoCF0vsI0J3k1rO1qGBRSlWYjQG2kmUNg/hC9Hq/JLG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by mx.zohomail.com with SMTPS id 164371482363352.805895130719705; Tue, 1 Feb 2022 03:27:03 -0800 (PST) Received: by mail-wr1-f51.google.com with SMTP id v13so31279398wrv.10 for ; Tue, 01 Feb 2022 03:27:03 -0800 (PST) Return-Path: Return-Path: 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) 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=53Ksan4DvR8DOeAhRUxiiXhEX7N/gjEUn7Xwvw7TK1+yjHwP8Xw9+pQByjVPVd9hqU 3ZXu5m0SWnW+/GaWVLq26i28rP5MBB9pX5haL48LQhXZ+pM+G3S9/VmaLNo6XYeXCpBg YzYR2wJ7TX5X1KgAfSJrEZDYl9hQqzioHHKsmDIYBolzuKh+Rc5dINljkUC0TWsl0nMS e84fZFOQ33Yu0C4DwzgDq7G2pFDNdDbWv8HSGrM+34WM6rR7e42s9002IMRvSSpgBp02 CbIdlUET9xrIbJgawV1dMgR/CD0+3vbE6H5LM7HyL+y4r79ogSoHOtn733ebgmger/mN JSJg== X-Gm-Message-State: AOAM532k7tiCD22gf6zUL+qGn0dmXWKPbN136GkqHHkRqAhelBDyudwe 5Jv6JujY6asJw9orns1e5NA= 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) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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=20Mathieu-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1643714826172100001 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=C3=A9 --- 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 =3D MIN(length, blk_len - offset); } =20 - 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 =3D fuse_do_truncate(exp, offset, true, PREALLOC_MODE_OFF); + if (ret < 0) { + fuse_reply_err(req, -ret); + return; + } + } + + ret =3D 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 =3D=3D 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 =3D fuse_do_truncate(exp, offset, true, PREALLOC_MODE_OFF); - if (ret < 0) { - fuse_reply_err(req, -ret); - return; - } - } - - ret =3D fuse_do_truncate(exp, offset + length, true, - PREALLOC_MODE_FALLOC); - } else { + else { ret =3D -EOPNOTSUPP; } =20 --=20 2.34.1