aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/makefs/zfs
Commit message (Collapse)AuthorAgeFilesLines
* makefs: zfs uberblock location is calculated wrongToomas Soome2025-08-151-1/+1
| | | | | | | | | | | The shift used to calculate uberblock location depends both on minimum size (UBERBLOCK_SHIFT) and MAX_UBERBLOCK_SHIFT. Since makefs defaults to use ashift 12, it incidentally does get the correct size, but ashift 9 does not work with current code. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51860
* makefs: zfs dataset mountpoints are considered non-emptyToomas Soome2025-07-291-15/+27
| | | | | | | | | | | | The dataset mountpoints get link count and size calculated by content of dataset root directory, but this will break libzfs dir_is_empty_stat() test. For fix, we need to check if the directory is mountpoint for dataset, and calculate the link count and size accordingly. Reviewed by: markj Differential revision: https://reviews.freebsd.org/D51593
* makefs: clean up warningsToomas Soome2025-07-295-18/+25
| | | | | | | | | | | | | | | | | | | | | | | | zfs/fs.c: zfs/objset.c: zfs/vdev.c: zfs/zap.c: Add include sys/param.h dsl_dir_alloc() needs to set parent = NULL to silence warning about 'parent' may be used uninitialized. Warning is given because we break the loop when nextdir == NULL and parent was not previously set. (it should not happen, but compiler does not know that). zap_add() and zap_fat_write_array_chunk() takes uint8_t *, use type cast. zap_fat_write_array_chunk() should check sz for 0 to avoid use of uninitialized pointer. unchecked function returns. Reviewed by: markj Differential revision: https://reviews.freebsd.org/D51592
* makefs/zfs: Make it possible to set a compression propertyMark Johnston2025-07-211-5/+39
| | | | | | | | | | | | | | | | | makefs currently does not implement compression for ZFS datasets, as doing so seems somewhat fraught with compatibility issues. As a result, the root dataset has compression disabled, and all others inherit from that. However, it may be useful to enable compression for new files once the generated pool is actually imported. Thus, implement a per-data compression option. By default, compression is inherited from the parent dataset and disabled on the root dataset. Add a regression test. PR: 288241 MFC after: 1 month
* makefs: Implement the collision differentiator for micro ZAPsMark Johnston2025-06-161-1/+7
| | | | | | | | | | | | | | | | | | | In the unlikely event of a hash collision, the collision differentiator is used to create a unique lookup key for ZAP entries. While the fat ZAP implementation in makefs implemented this, the micro ZAP implementation did not, so it's possible to end up with collisions in directory entries. These are caught deterministically by OpenZFS, but the result is a panic. Implement a simple differentiator by simply assigning a unique value to each ZAP entry. This scheme works since the 16-bit space of differentiators is larger than the maximum number of entries in a micro ZAP. (While the on-disk encoding provides 32 bits of space for the differentiator, the in-memory representation of micro ZAP entries is smaller.) PR: 287482 MFC after: 1 week
* makefs: Handle special file types when creating a zpoolMark Johnston2025-01-071-7/+32
| | | | | | | | | | Previously, anything other than a regular file, directory or symlink would cause makefs to exit with an assertion failure. Make it a bit more resilient to user error: print a warning and skip the file. Add a regression test wherein we create an image from a devfs mount. PR: 283583 MFC after: 2 weeks
* makefs: Record a larger TXG number in the uberblockMark Johnston2024-10-141-0/+2
| | | | | | | | | | | | | By default, OpenZFS will perform metadata verification of the most recent TXGs, but this can be very slow since all data in a pool generated by makefs was logically written in a single transaction. Avoid triggering this verification by default, but add an option to restore the previous behaviour and enable it in regression test cases. Reported by: cperciva Tested by: cperciva (previous version) MFC after: 2 weeks
* makefs: Remove the warning printed when makefs -t zfs is usedMark Johnston2024-10-041-1/+1
| | | | | | | | We haven't seen bug reports relating to this feature for a while, so stop printing a warning. Reviewed by: cperciva MFC after: 2 weeks
* makefs/zfs: Add a helper function for adding ZAP entriesMark Johnston2024-06-013-3/+11
| | | | | | | | Some ZAPs are used to represent sets, in which keys and values are the same. Add a helper function for this case. No functional change intended. MFC after: 1 week
* makefs/zfs: Don't set ZFS_NO_EXECS_DENIED in file flagsMark Johnston2023-11-081-2/+2
| | | | | | | | This flag was leftover from testing and should have been removed. PR: 274938 MFC after: 3 days Sponsored by: The FreeBSD Foundation
* makefs/zfs: Update dd_used_breakdown after writing the MOSMark Johnston2023-10-233-5/+18
| | | | | Fixes: 96092bf9108c ("makefs/zfs: Fill out dd_used_breakdown fields in DSL directories") Sponsored by: The FreeBSD Foundation
* makefs/zfs: Fill out dd_used_breakdown fields in DSL directoriesMark Johnston2023-10-231-3/+8
| | | | | | | | | | This is required for the "used", "usedds" and "usedchild" dataset properties to be displayed. PR: 274613 Reported by: Mike Tancsa <mike@sentex.net> MFC after: 1 week Sponsored by: The FreeBSD Foundation
* makefs/zfs: Ensure that the last block of a file has the right sizeMark Johnston2023-09-281-9/+10
| | | | | | | | | | | | | | | | 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
* makefs/zfs: Remove a nonsensical commentMark Johnston2023-09-271-2/+0
| | | | | | | | | | When populating files, makefs needs to copy their contents into userspace in order to compute a checksum, so copy_file_range(2) is out of the question. Though, it could possibly be used when building other types of filesystems. MFC after: 1 week Sponsored by: The FreeBSD Foundation
* makefs/zfs: Set the objset block pointer fill field correctlyMark Johnston2023-09-271-2/+3
| | | | | | | | | It is supposed to contain the number of objects allocated from the set, excluding the meta dnode. Reported by: mav MFC after: 1 week Sponsored by: The FreeBSD Foundation
* makefs/zfs: Avoid generating a GUID of zeroMark Johnston2023-05-262-1/+2
|
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-126-6/+6
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* makefs: don't needlessly require directories to existBrooks Davis2023-01-121-1/+17
| | | | | | | | | | | | | | If a type=dir entry exists and all contents are directories, files added with contents=, or symlinks with link= attributes then it doesn't need to exist. Just let openat fail in that case. It's conceivable this will make debugging some cases weird, but it's sufficent to handle the way we add /root/.ssh in CheriBSD VM images. This is a recommit of 794154149f95d0cbc11aade166f9da919747e397 with bugfixes. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38029
* Revert "makefs: don't needlessly require directories to exist"Brooks Davis2023-01-121-16/+1
| | | | | | I pushed prematurely and this version is broken. This reverts commit 794154149f95d0cbc11aade166f9da919747e397.
* makefs: don't needlessly require directories to existBrooks Davis2023-01-121-1/+16
| | | | | | | | | | | If a type=dir entry exists and all contents are directories, files added with contents=, or symlinks with link= attributes then it doesn't need to exist. Just let openat fail in that case. It's conceivable this will make debugging some cases weird, but it's sufficent to handle the way we add /root/.ssh in CheriBSD VM images. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38029
* makefs: handle mtree link= for ZFSBrooks Davis2023-01-121-6/+14
| | | | | | | | When a link target is specified use it rather than attempting to read a potentially non-existant file. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38028
* makefs: handle mtree contents= in zfsBrooks Davis2023-01-121-1/+7
| | | | | | | When a source path is provided use it rather than constructing one. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38027
* makefs: Ignore some sign comparison warnings from GCC.John Baldwin2022-11-231-0/+1
| | | | | Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D37470
* makefs zfs: Disable -Wunused-function for GCC as well.John Baldwin2022-11-231-3/+3
| | | | | Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D37469
* makefs: Fix handling of inherited mountpointsMark Johnston2022-10-281-14/+14
| | | | | | | | Commit d7eec79b7021 overlooked the fact that nvlist_find(DATA_TYPE_STRING) does not provide a nul-terminated string. Fix the leak a different way. Fixes: d7eec79b7021 ("makefs: Plug a memory leak")
* makefs: Add a cast to placate static analyzersMark Johnston2022-10-041-1/+1
| | | | | | | "prefixlen" will always be smaller than 32 but adding a cast is harmless. Reported by: Coverity
* makefs: Plug a memory leakMark Johnston2022-10-041-4/+2
| | | | | | | | nvlist_find_string() would return a copy of the found value, but callers assumed they would have to make their own copy. It's simpler to change nvlist_find_string() than it is to change callers, so do that. Reported by: Coverity
* makefs: Remove some redundant initializationsMark Johnston2022-08-291-3/+0
| | | | No functional change intended.
* makefs: Fix issues building as a cross-tool on non-FreeBSDJessica Clarke2022-08-186-1/+12
| | | | | | | | | | | | | This adds missing includes, uses the standard dirent.h rather than the BSD-specific sys/dirent.h subset (which works on macOS but not Linux) and works around Linux's lack of st_birthtim. This allows usr.sbin/makefs to be added to LOCAL_XTOOL_DIRS again on macOS and Linux so that disk images can be cross-built. Reviewed by: markj Fixes: 240afd8c1fcc ("makefs: Add ZFS support") Differential Revision: https://reviews.freebsd.org/D36135
* makefs: Fix 32-bit issues in ZFS time attributes settingJessica Clarke2022-08-181-8/+19
| | | | | | | | | | | | | | | | | | | | | | | | | Currently the code copies a struct timespec's raw bits as a pair of uint64_t. On 64-bit systems this has the same representation, but on 32-bit issues there are two issues: 1. tv_sec is a time_t which is 32-bit on i386 specifically 2. tv_nsec is a long not a 64-bit integer On i386, this means the assertion should fire as the size doesn't match. On other 32-bit systems there are 4 bytes of padding after tv_nsec, which in practice are probably 0, as this data is ultimately coming from the kernel, so it's deterministic (though the padding bytes are not required to be preserved by the compiler, so are strictly unspecified). However, on 32-bit big-endian systems, the padding bytes are in the wrong half to be harmless, resulting in the nanoseconds being multiplied by 2^32. Fix this all by marshalling via a real uint64_t pair like is done by the real ZFS_TIME_ENCODE. Reviewed by: markj Fixes: 240afd8c1fcc ("makefs: Add ZFS support") Differential Revision: https://reviews.freebsd.org/D36131
* makefs: Handle multiple staging directories when creating ZFS poolsMark Johnston2022-08-171-22/+77
| | | | | | | | | | | | | | | The fsnode tree traversal routines used in ZFS mode assume that all children of a (directory) fsnode can be accessed using a directory fd for the parent and the child name. This is true when populating the image using an mtree manifest or from a single staging directory, but doesn't work when multiple staging directories are specified. Change the traversal routines to use absolute path lookups when an mtree manifest is not in use. This isn't ideal, but it's the simplest way to fix the problem. Reported by: imp Sponsored by: The FreeBSD Foundation
* makefs: Fix space accounting for the root DSL directoryMark Johnston2022-08-163-9/+20
| | | | | | | | | | | | Space used by the MOS is summed after all on-disk data structures are finalized, so the MOS DSL directory represents a special case when counting bytes used for each directory. The DSL layer failed to update the MOS DSL directory's parent, the root directory, accordingly, so the root directory reported less space used than was used in reality. Be careful to update the root directory after the MOS is finalized. PR: 265849 Sponsored by: The FreeBSD Foundation
* makefs: Align the block buffer used in ZFS modeMark Johnston2022-08-161-3/+7
| | | | | | | For some dnode types, particularly ZAPs, we want the buffer to have uint64_t alignment. Sponsored by: The FreeBSD Foundation
* makefs: Fix a memory leak in fs_layout_one()Mark Johnston2022-08-111-2/+2
| | | | | | | | Check the canmount property before building the mountpoint string. Reported by: Coverity Fixes: 240afd8c1fcc ("makefs: Add ZFS support") Sponsored by: The FreeBSD Foundation
* makefs: Fix memory leaks in dsl_dir_finalize_props()Mark Johnston2022-08-111-3/+6
| | | | | | | | | nvstring_get() returns a copy of the string, not a pointer into the nvlist's internal buffer. Reported by: Coverity Fixes: 240afd8c1fcc ("makefs: Add ZFS support") Sponsored by: The FreeBSD Foundation
* makefs: Add ZFS supportMark Johnston2022-08-057-0/+3003
This allows one to take a staged directory tree and create a file consisting of a ZFS pool with one or more datasets that contain the contents of the directory tree. This is useful for creating virtual machine images without using the kernel to create a pool; "zpool create" requires root privileges and currently is not permitted in jails. makefs -t zfs also provides reproducible images by using a fixed seed for pseudo-random number generation, used for generating GUIDs and hash salts. makefs -t zfs requires relatively little by way of machine resources. The "zpool_reguid" rc.conf setting can be used to ask a FreeBSD guest to generate a unique pool GUID upon first boot. A small number of pool and dataset properties are supported. The pool is backed by a single disk vdev. Data is always checksummed using Fletcher-4, no redundant copies are made, and no compression is used. The manual page documents supported pool and filesystem properties. The implementation uses a few pieces of ZFS support from with the boot loader, especially definitions for various on-disk structures, but is otherwise standalone and in particular doesn't depend on OpenZFS. This feature should be treated as experimental for now, i.e., important data shouldn't be trusted to a makefs-created pool, and the command-line interface is subject to change. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35248