From nobody Thu Sep 28 20:39:39 2023 X-Original-To: dev-commits-src-main@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 4RxQMH6BW2z4vZ8q; Thu, 28 Sep 2023 20:39:39 +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 4RxQMH5hhbz4tZH; Thu, 28 Sep 2023 20:39:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695933579; 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=+Rivfbj1Uf7ux919zwIxTiAYtJgk7/uCGyZzDhTOJKA=; b=rYjIBy0N9W3RBj7ra3LdiSFA7HsJLo5ePBV6uziquAY8e7oRuXupuHQAcpIInDOcl62SOd lCfy5lLxAf+HEoSbSNzG47veEIhD7wbWBsX/hzJF24UocQ94EvVGKDZK+AoHlVPqzfHXHn ++rn5hTEBXbgE92JnmWkmb5xlYygIvpJvf0u/c7GiOjttUBgGA2IrsVixiLS/yncFwf7eY YSRPxbyiKhFvC0ph3jl83mzcblkAtrUqzd0Es061V4mCh/aSbC74vzytqPkHJW3FqtX2Uc 3TaiCsQW7SeePJztZpPRDmQkzD5lRTMoy5rU1vclaUvRYvB9fJK/GIMQRUvIuA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695933579; a=rsa-sha256; cv=none; b=Hyv4RB9KQhIQVvgTwRj/+D5+5TVDVj6lhSgI+jtPDG7P+YqBPQMYT5tmAxzSQa5o6TPEW/ EpojLuaMp5HE+p1fgpB2uos3jCoGrodkhiOtoZ5J9/Ttp8Il8Xsbc3YDnPp61eNH3D8bcE Y7YlMMVucj75XMmR2Nz4zkkZ5ck01gd/q+TTltbsUXtaQqy/gVWpTKXUDPXW75f8utWKhh vA5MDjv3M5KB2q5nqKEGDMokGTnpQJQZ+IGstmzG/Bax7rNBG2h8AbkX1g0xRxNpmSZJzM VDsv9fFX6dRFhr79rgbZPcbW/8Sk7vqV0E3DMBY2J/jtyi/7bhvR8Zo7HXe9tQ== 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=1695933579; 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=+Rivfbj1Uf7ux919zwIxTiAYtJgk7/uCGyZzDhTOJKA=; b=azhRP1m4rbtRbuJi4ZjOKczJL2EzZQrrH9WKoc0g9abSNjpPAAXjIqEzeSGBbYcnlQ4xdu HHcTQNFavE1Pi5ZWW4FyyosAmILsEi41jMaP/h7d51RLRydSt0M/AILcAhrU1Z0zJxJpzQ 08ouSSkEaEjq82Zr7fy2i161Zw260hHGdShkU/dRpjg8712HVaK+PCo4+Rh8BA+jAccBA6 TbP+zy6Gn4xi5xRBe1OGTfOkh7y/cMDjsVzDYLjGlhYziLPw40OL/LNkV8xN2GlsNO9GXD s7khTbJ0e8kP3H1Lw+rNwmGPrFufkPdwGkx4iQ0FQde1GidI/+bl2+SZ3XqvDg== 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 4RxQMH4mTMzc3j; Thu, 28 Sep 2023 20:39:39 +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 38SKddAU089603; Thu, 28 Sep 2023 20:39:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38SKdd0O089600; Thu, 28 Sep 2023 20:39:39 GMT (envelope-from git) Date: Thu, 28 Sep 2023 20:39:39 GMT Message-Id: <202309282039.38SKdd0O089600@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: ef20cd33d328 - main - makefs/zfs: Ensure that the last block of a file has the right size List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: ef20cd33d3287ebead0d30f2e177fc57a97dc2d5 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=ef20cd33d3287ebead0d30f2e177fc57a97dc2d5 commit ef20cd33d3287ebead0d30f2e177fc57a97dc2d5 Author: Mark Johnston AuthorDate: 2023-09-28 20:16:17 +0000 Commit: Mark Johnston CommitDate: 2023-09-28 20:16:17 +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 --- 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);