From nobody Sun Nov 16 16:41:11 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600772173; cv=none; d=zohomail.com; s=zohoarc; b=m041gNZ1Ez7hbOvVsvOnCXnUQtrecryRo9warJjO+UnVwQglqRekGY9WKNgXS64nPwvm5y8oT9h2DC7QprBI2H7znh4p334Dk0kLn1vFvCOmbpwHnNRe1LX25N4QMCkFRsQJlISDwRw3v7HmMMupF1P4gaWdG3pS5i5UOZj1RxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600772173; 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=JVZyCNs/Dn0aSo/qEbqYorUsU/1QreNRX/oTOcK5AQk=; b=hR3I0HhFNrNSQDTIKfEVtQHoOyp9gHm1RlhYIPPI9Ix4IIN38bzG+i8fwklPTMmhbt6D2B585rMiIrEv0IR9KZKPt21Qer9giwJevNGpWWggwhiJ4Q5mNFtlKja0Su4OUf2Rb3Mnfi9KQkcfehQlIdwiyxzLgFhFXVG5MXJH3Iw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1600772173514160.20795107316656; Tue, 22 Sep 2020 03:56:13 -0700 (PDT) Received: from localhost ([::1]:57104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKfy0-0007nW-2P for importer@patchew.org; Tue, 22 Sep 2020 06:56:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKfs3-0000Dy-Nl for qemu-devel@nongnu.org; Tue, 22 Sep 2020 06:50:03 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24695 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKfs1-0000Ti-Ij for qemu-devel@nongnu.org; Tue, 22 Sep 2020 06:50:03 -0400 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-532-sJggnF1eNhqqQOVP0JdP9w-1; Tue, 22 Sep 2020 06:49:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADC358030C7; Tue, 22 Sep 2020 10:49:57 +0000 (UTC) Received: from localhost (ovpn-114-26.ams2.redhat.com [10.36.114.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 552BD73682; Tue, 22 Sep 2020 10:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600771800; 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=JVZyCNs/Dn0aSo/qEbqYorUsU/1QreNRX/oTOcK5AQk=; b=eRE5wpBEKxEDPHuW3LoQ8ByjutWE9KSm5/jpbNCdHiMFdce6zgG6eVZUqyJqw+pcZmcmBh dAntEocAZwGnj6Fx4igTa+PSnEVp7dnrQjumm7EwVWKFX8c8hZs/GgD22fhfWZh568nGNo f1Qy70UYZihzBgVc5D6SrdS9J/0SGxI= X-MC-Unique: sJggnF1eNhqqQOVP0JdP9w-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH v2 05/20] fuse: (Partially) implement fallocate() Date: Tue, 22 Sep 2020 12:49:17 +0200 Message-Id: <20200922104932.46384-6-mreitz@redhat.com> In-Reply-To: <20200922104932.46384-1-mreitz@redhat.com> References: <20200922104932.46384-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@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=205.139.110.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:27:12 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This allows allocating areas after the (old) EOF as part of a growing resize, writing zeroes, and discarding. Signed-off-by: Max Reitz --- block/export/fuse.c | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/block/export/fuse.c b/block/export/fuse.c index f3a84579ba..7dfb4eb280 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -457,6 +457,84 @@ 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); + 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) { + ret =3D fuse_do_truncate(exp, offset + length, PREALLOC_MODE_O= FF); + 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); + 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, PREALLOC_MODE_OFF); + if (ret < 0) { + fuse_reply_err(req, -ret); + return; + } + } + + ret =3D fuse_do_truncate(exp, offset + length, PREALLOC_MODE_FALLO= C); + } else { + ret =3D -EOPNOTSUPP; + } + + fuse_reply_err(req, ret < 0 ? -ret : 0); +} + /** * Let clients flush the exported image. */ @@ -477,6 +555,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, }; =20 --=20 2.26.2