From nobody Thu Oct 05 15:10:21 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 4S1Zk55TTyz4vjs5; Thu, 5 Oct 2023 15:10:21 +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 4S1Zk54f7Vz4XlW; Thu, 5 Oct 2023 15:10:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696518621; 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=BtbmO8tdhK1XfnivjCef804L9XtBogN+uJlYmlQY3Ds=; b=KPmHF0yz2lsyqazQCxwjGd3cWTrrwn8nqK3TtURJzEW3WrOEFpQGPUECUAzu8dAzozcrCs EgvhHWA5Iz35tMrSyi7MiA+BezXdbFVCoBX2AncWOvPq/h3p3EKazPfhx2i3xqcr0UG4pr 2hHUI4LGfhnJf64ulC4F90ijYQRIBTBdShumkCXh316DkbzpdeFyErC8FoAIPjFpCR/HNX j2bfrG3WWqz2B16Ne7UgwZaCmsTFpt35QQoqnun7XXzKF8/StLwQdPy+rlZ1U3QOj35/vT ie8R3BGorTJaLEpId+FnERSbev7i/zEsiZ9FD4QaI/OhRIj/IWiVQUY4hIAq6A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696518621; a=rsa-sha256; cv=none; b=mFO+08C4lkeRREdIgmH21oebY6Wy9igdbNZWVRVIowp2xPIXoyYpxkFefzDAcmY85TwMy3 hxttyDXSUVezsmux4fdNaS03UMN/g4eSDfBzEV2vxWKnKtIJRPtmubxmPz+FYgvATAlpnq Gx7man44tuMzJO6rWB1Golc1tZ2KtDDi4M3w0ViabrzfQA3i3fFl1orxK+2EQFHLA0IbqK UQr+l5cm5KB2MzOFasZDmT3zT6javnS/i4trMdLr3G62KlszjOa4NJmOYj/lCi7iwq/iVq YAVCvWJ4g3RL/jOUIAC+Vo8qbCiymSCENM3SLOWsTDM3h+BeRBv9v32hdRhl+A== 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=1696518621; 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=BtbmO8tdhK1XfnivjCef804L9XtBogN+uJlYmlQY3Ds=; b=dVKHFbiFlwJgZmUo39riLKj3W6wk5qz5sDA2vCcHlvxR/jpZHPDnqPFQib+25+OOTsrcEz kst4/bOEm0U6qzntMZawycfcro5hsITdVrHS/000TSP4zFBoOqXriwgjXhwmw9Z8cAvEwi k21Ab+LcSDH8dRpZYsvAyWvFJzdH7i9khhSfNzorYEsMNwNooEWiRWZAa7l1JPHrEb1GyQ zENjvLof+veG0aNYMEGgjIjxr+AHtyiuVS2sEbqsPzazW5sj3ZQ075kVB9YU3cDi/ohTfi dtot/BlmH1+kIwz9b9tGAn/GYG9HF6ajs9vdLCcnpB5I4kkr9XsY5eUjyqWjAw== 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 4S1Zk53YMyz1PcY; Thu, 5 Oct 2023 15:10:21 +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 395FALRe071545; Thu, 5 Oct 2023 15:10:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 395FALsq071541; Thu, 5 Oct 2023 15:10:21 GMT (envelope-from git) Date: Thu, 5 Oct 2023 15:10:21 GMT Message-Id: <202310051510.395FALsq071541@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: 3042b1d8159a - releng/14.0 - 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/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 3042b1d8159a44faa2bac8c28810ec05025ebfbb Auto-Submitted: auto-generated The branch releng/14.0 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=3042b1d8159a44faa2bac8c28810ec05025ebfbb commit 3042b1d8159a44faa2bac8c28810ec05025ebfbb Author: Mark Johnston AuthorDate: 2023-09-28 20:16:17 +0000 Commit: Mark Johnston CommitDate: 2023-10-05 14:01:29 +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. Approved by: re (gjb) Reported by: cperciva MFC after: 1 week Sponsored by: The FreeBSD Foundation (cherry picked from commit ef20cd33d3287ebead0d30f2e177fc57a97dc2d5) (cherry picked from commit 5175923ef4acb6faff370177fb60700721f13f92) --- 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);