From nobody Wed Dec 17 05:41:37 2025 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=1607712186; cv=none; d=zohomail.com; s=zohoarc; b=J3JNeNFifBYuAGS7SqotPUsBEpbDdn+TcMtziR4elljYxmBvXALYRTeXIljy6/Zr1MB+RhQCRhX6rVpRQ8Em0y1llCGY8uCsf+AfQKSsva9EMJUlMpOf98a1l5F9Xx0j+IUh3k07mGyqkC/iOJX570nehG/cuezQDtnd2VEZRmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607712186; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=i7YYa3LFi0Y4wK4CNURxUtOEL+L50jCecL5ttIgFZE8=; b=Lt3Y267uZJThg3EKHkmYWQuMUyp6p+dsUPvN/kcmoy8O7NA14rOSd1eafb5lvTpyjo18Ul517J0NIy3G/id3fmnWJZjCTnMVDZ7kVLD+MNIyQfq7KRtKDewURuPm/jEqeTDOY5k8WvbVfmjlRgqGdj3mIH5Sf/7lvl1ulxbz87Y= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1607712186876675.8374012970984; Fri, 11 Dec 2020 10:43:06 -0800 (PST) Received: from localhost ([::1]:58828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1knmEv-0005db-R5 for importer@patchew.org; Fri, 11 Dec 2020 12:29:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1knluW-0003m1-24 for qemu-devel@nongnu.org; Fri, 11 Dec 2020 12:08:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34786) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1knluE-00026z-Rd for qemu-devel@nongnu.org; Fri, 11 Dec 2020 12:08:51 -0500 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-324-ontAnAgzMfaex2Hv-6JRfg-1; Fri, 11 Dec 2020 12:08:31 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2521107ACF7; Fri, 11 Dec 2020 17:08:30 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-231.ams2.redhat.com [10.36.114.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id B11435D71D; Fri, 11 Dec 2020 17:08:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607706514; 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=i7YYa3LFi0Y4wK4CNURxUtOEL+L50jCecL5ttIgFZE8=; b=QytCz3XhLIPTB0SCUNsea9m37EEEIGU84TUxcy56TNdpcrWzGQSs738a6AkVnQFOk4aV80 9aPmNfwcrkxfF9OkIs8mYIMKFo8779Cd0jB4HsfKI1m9GbTFIRTVSaLlDFj9fbBqgGEM5k dVq4rs2udBrUPXDwQHBXkK6npbxcZGY= X-MC-Unique: ontAnAgzMfaex2Hv-6JRfg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 09/34] fuse: (Partially) implement fallocate() Date: Fri, 11 Dec 2020 18:07:47 +0100 Message-Id: <20201211170812.228643-10-kwolf@redhat.com> In-Reply-To: <20201211170812.228643-1-kwolf@redhat.com> References: <20201211170812.228643-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=63.128.21.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz This allows allocating areas after the (old) EOF as part of a growing resize, writing zeroes, and discarding. Signed-off-by: Max Reitz Message-Id: <20201027190600.192171-6-mreitz@redhat.com> Signed-off-by: Kevin Wolf --- block/export/fuse.c | 84 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/block/export/fuse.c b/block/export/fuse.c index 92d2f50bcc..0b9d226b2f 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -521,6 +521,89 @@ static void fuse_write(fuse_req_t req, fuse_ino_t inod= e, const char *buf, } } =20 +/** + * Let clients perform various fallocate() operations. + */ +static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, + off_t offset, off_t length, + struct fuse_file_info *fi) +{ + FuseExport *exp =3D fuse_req_userdata(req); + int64_t blk_len; + int ret; + + if (!exp->writable) { + fuse_reply_err(req, EACCES); + return; + } + + blk_len =3D blk_getlength(exp->common.blk); + if (blk_len < 0) { + fuse_reply_err(req, -blk_len); + return; + } + + if (mode & FALLOC_FL_KEEP_SIZE) { + length =3D MIN(length, blk_len - offset); + } + + if (mode & FALLOC_FL_PUNCH_HOLE) { + if (!(mode & FALLOC_FL_KEEP_SIZE)) { + fuse_reply_err(req, EINVAL); + return; + } + + do { + int size =3D MIN(length, BDRV_REQUEST_MAX_BYTES); + + ret =3D blk_pdiscard(exp->common.blk, offset, size); + offset +=3D size; + length -=3D size; + } while (ret =3D=3D 0 && length > 0); + } else if (mode & FALLOC_FL_ZERO_RANGE) { + if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + length > blk_len) { + /* No need for zeroes, we are going to write them ourselves */ + ret =3D fuse_do_truncate(exp, offset + length, false, + PREALLOC_MODE_OFF); + if (ret < 0) { + fuse_reply_err(req, -ret); + return; + } + } + + do { + int size =3D MIN(length, BDRV_REQUEST_MAX_BYTES); + + ret =3D blk_pwrite_zeroes(exp->common.blk, + offset, size, 0); + offset +=3D size; + length -=3D size; + } while (ret =3D=3D 0 && length > 0); + } 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 { + ret =3D -EOPNOTSUPP; + } + + fuse_reply_err(req, ret < 0 ? -ret : 0); +} + /** * Let clients fsync the exported image. */ @@ -552,6 +635,7 @@ static const struct fuse_lowlevel_ops fuse_ops =3D { .open =3D fuse_open, .read =3D fuse_read, .write =3D fuse_write, + .fallocate =3D fuse_fallocate, .flush =3D fuse_flush, .fsync =3D fuse_fsync, }; --=20 2.29.2