From nobody Wed Oct 04 13:43:52 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4S0wrn0m4Qz4vxc7; Wed, 4 Oct 2023 13:43:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S0wrm4lLwz3ZKf; Wed, 4 Oct 2023 13:43:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696427032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/LtBwPaYbrfPUMHCemnmgwz+Effm6KjLLNZINHzvYBk=; b=G7EBxa5DYpKzHLeHcl2MQZkjpRqPHx1yzUcpslnGMXGBT3h9rl3XloLc9Uxrbz038ZzHQ+ fYhz4HsMrIZps52lXJn8AXl1rng9SrThB6YtRJY1MKj4FV7AONeJqroEjj3asFxuiCUILO xY8KsWiSEmcqx1jq277X97BuhubvtqC6Ce4Y6UpmS4oxQlSa1NkO8jQWTMhehsGZWVCUs2 FgMX3iEPkUr7hoxU+X4qV7aRkfVKLIt9Gw7uzPmBiEbbFqk/210I5dFEdrCao53U2flcvR TSU0ioAzTPyzbkQs1vk+vM7sm03U5K1nk0GtUrrzDiPZ/PssMogApCjfTzvCeQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696427032; a=rsa-sha256; cv=none; b=R6qoszgRnFQ9SRKPfQwJ+TodX5vlNoloLtLDOGVFiqDAyitOyh7rKJ96ZCVEQ132/ORtjF 0x9xvvaC30Ki+388Dvw1eZ5Ljl+AyRgxOU/K4vrFblG7XbCIVaU4eqU95BWh/SGx4wS7Bv sGgmIxTIoPyAV6zkMU4FkJegCre6AVOaw38eoFq5CDnwL0VSzHL9aozqHSZLwL/10CU+s+ J11xVrNR9B9On3MUtqA2PgjNUrtdnJ4t6UJZUvSkolIW9t3Vqkd/nr6soLBtMLxN7y3HwM mXZa6morrVAimlso7vfEfIaC569ihy+yZtG39jPpIMkXVhvCslcO/Or5Dq359A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696427032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/LtBwPaYbrfPUMHCemnmgwz+Effm6KjLLNZINHzvYBk=; b=g8w0NiN/O9FNSSYl0WiAEtUBM4sSL6ISw3STnngMULdTZFwvf7PTnQU66d3vKDWwwemkSB RQVEe8CLhcLQ9l/Trg1ZqW8MQK9zE/u5j2PJbjrqkgflrRRS5Rfxc8AiuKlZ8IB8CFAkre NiGioVd8g/UStX+hBRVcYlCbUrreZx7zMEyDJM0C44suTnb1sfaX+Jhirk2SL4PRmryQ6A 2p4h5Hp7vW7Xspz3+SyweyOUZwa1k0WDMDDAsCaGOonmtmryEoKG7TePKrBj7wzQKHI8iM 7JI6qZ2LeAXbTcaEFxG2AML4lk2xGIw/tw/sd4RWu23QgclvSmlsGGBNMGvceQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4S0wrm34Q8zfYV; Wed, 4 Oct 2023 13:43:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 394Dhqpe020272; Wed, 4 Oct 2023 13:43:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 394Dhqr1020269; Wed, 4 Oct 2023 13:43:52 GMT (envelope-from git) Date: Wed, 4 Oct 2023 13:43:52 GMT Message-Id: <202310041343.394Dhqr1020269@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 5175923ef4ac - stable/14 - makefs/zfs: Ensure that the last block of a file has the right size List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 5175923ef4acb6faff370177fb60700721f13f92 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5175923ef4acb6faff370177fb60700721f13f92 commit 5175923ef4acb6faff370177fb60700721f13f92 Author: Mark Johnston AuthorDate: 2023-09-28 20:16:17 +0000 Commit: Mark Johnston CommitDate: 2023-10-04 13:42:37 +0000 makefs/zfs: Ensure that the last block of a file has the right size When copying a file's contents into the pool, a loop copies blocks of the maximum size (128KB), allocating space from the vdev for each block. The space allocator rounds up to the nearest block size, but for files larger than the maximum size, this can result in the last block having a smaller logical size than the rest of the blocks belonging to that dnode. This violates some ZFS invariants when appending to that file. Modify fs_populate_file() to use the same block size for the final block. Reported by: cperciva MFC after: 1 week Sponsored by: The FreeBSD Foundation (cherry picked from commit ef20cd33d3287ebead0d30f2e177fc57a97dc2d5) --- usr.sbin/makefs/zfs/fs.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/usr.sbin/makefs/zfs/fs.c b/usr.sbin/makefs/zfs/fs.c index 0d85ea8eb9d8..b0a4c639f256 100644 --- a/usr.sbin/makefs/zfs/fs.c +++ b/usr.sbin/makefs/zfs/fs.c @@ -515,7 +515,7 @@ fs_populate_file(fsnode *cur, struct fs_populate_arg *arg) uint64_t dnid; ssize_t n; size_t bufsz; - off_t size, target; + off_t nbytes, reqbytes, size; int fd; assert(cur->type == S_IFREG); @@ -546,29 +546,30 @@ fs_populate_file(fsnode *cur, struct fs_populate_arg *arg) bufsz = sizeof(zfs->filebuf); size = cur->inode->st.st_size; c = dnode_cursor_init(zfs, arg->fs->os, dnode, size, 0); - for (off_t foff = 0; foff < size; foff += target) { + for (off_t foff = 0; foff < size; foff += nbytes) { off_t loc, sofar; /* * Fill up our buffer, handling partial reads. */ sofar = 0; - target = MIN(size - foff, (off_t)bufsz); + nbytes = MIN(size - foff, (off_t)bufsz); do { - n = read(fd, buf + sofar, target); + n = read(fd, buf + sofar, nbytes); if (n < 0) err(1, "reading from '%s'", cur->name); if (n == 0) errx(1, "unexpected EOF reading '%s'", cur->name); sofar += n; - } while (sofar < target); + } while (sofar < nbytes); - if (target < (off_t)bufsz) - memset(buf + target, 0, bufsz - target); + if (nbytes < (off_t)bufsz) + memset(buf + nbytes, 0, bufsz - nbytes); - loc = objset_space_alloc(zfs, arg->fs->os, &target); - vdev_pwrite_dnode_indir(zfs, dnode, 0, 1, buf, target, loc, + reqbytes = foff == 0 ? nbytes : MAXBLOCKSIZE; + loc = objset_space_alloc(zfs, arg->fs->os, &reqbytes); + vdev_pwrite_dnode_indir(zfs, dnode, 0, 1, buf, reqbytes, loc, dnode_cursor_next(zfs, c, foff)); } eclose(fd);