summaryrefslogtreecommitdiffstats
path: root/src/shared/copy.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* copy: Introduce COPY_NOCOW_AFTER and use it when copying imagesDaan De Meyer2024-09-041-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When dealing with copying COW images, we have to make a tradeoff: - Either we don't touch the NOCOW bit on the copied file COW and get an instant copy because we're able to reflink, but we might get reduced performance if the source file was COW as COW files and lots of random writes don't play well together. - Or we force NOCOW for the copied file, which means we have to do a full copy as reflinking from COW files to NOCOW files or vice versa is not supported. In exec-invoke.c, we've opted for the first option. In nspawn.c and discover-image.c, we've opted for the second option. In nspawn, this applies to the --ephemeral option to make ephemeral copies. In discover-image.c, this applies to cloning images into /var/lib/machines. Both these features might be used to run many machines of the same original image. We really don't want to force a full copy onto users in these scenarios when they're expecting reflink behavior, leading to them running out of disk space. Instead, degraded performance in their machines is a much less severe issue, which they will discover on their own if it affects them, at which point they can make their original image NOCOW at which point they'll get both the reflinks and better performance. Given the above reasoning, let's switch nspawn.c and discover-image.c to use COPY_NOCOW_AFTER as well instead of enabling NOCOW upfront and forcing a copy if the original source image is COW.
* repart: Keep existing directory timestamps intact when copyingDaan De Meyer2024-08-301-19/+20
| | | | | | | | Otherwise, when merging multiple directory trees, the output becomes unreproducible as the directory timestamps will be changed to the current time when copying identical directories from the second tree. We introduce a new copy flag to achieve this behavior.
* copy: introduce COPY_VERIFY_LINKED flagYu Watanabe2024-02-151-0/+1
| | | | | If the flag is set, then copy_file() and friends check if the source file still exists when the copy operation finished.
* copy: do not ignore chattr_flags and friends passed to copy_file_atomic_full()Yu Watanabe2024-02-081-1/+1
| | | | Fixes a bug introduced by 427d9c34e61a8f5bfe369f1d5a0426143fe5741e.
* copy: Add support for creating subvolumes to copy_tree_at()Daan De Meyer2023-08-141-5/+5
| | | | | | | The subvolumes set is a set of source inodes similar to how the denylist hashmap contains source inodes as keys. It indicates directories in the source tree that should become subvolumes in the target tree.
* copy: Add COPY_LOCK_BSDDaan De Meyer2023-06-151-0/+1
| | | | | | | When making ephemeral copies of files/directories whose cleanup depends on whether they're locked or not, it's necessary to have the lock from the very beginning, so let's support that with a new COPY_LOCK_BSD flag.
* Merge pull request #27882 from DaanDeMeyer/repart-truncateZbigniew Jędrzejewski-Szmek2023-06-071-0/+1
|\ | | | | copy: Add COPY_TRUNCATE
| * copy: Add COPY_TRUNCATEDaan De Meyer2023-06-011-0/+1
| | | | | | | | | | | | The file might grow more than the amount of data we end up writing, so let's add a flag to truncate after writing to make sure the file is only as large as it needs to be.
* | copy: Merge copy_directory() and copy_directory_fd() into copy_directory_at()Daan De Meyer2023-06-061-8/+3
|/ | | | | Let's merge these two into a single function that can handle both variants and more.
* copy: rename reflink_full() -> reflink_range()Yu Watanabe2023-04-281-1/+1
| | | | | | | | | | | | The commit b640e274a7c363a2b6394c9dce5671d9404d2e2a introduced reflink() and reflink_full(). We usually name function xyz_full() for fully parameterized version of xyz(), and xyz() is typically a inline alias of xyz_full(). But in this case, reflink() and reflink_full() call different ioctl(). Moreover, reflink_full() does partial reflink, while reflink() does full file reflink. That's super confusing. Let's rename reflink_full() to reflink_range(), the new name is consistent with ioctl name, and should be fine.
* copy: Introduce reflink() and reflink_full()Daan De Meyer2023-04-281-0/+3
| | | | | | The kernel has had filesystem independent reflink ioctls for a while now, let's try to use them and fall back to the btrfs specific ones if they're not supported.
* copy: Add more at() helpersDaan De Meyer2023-03-211-3/+15
|
* copy: Move chattr arguments to full function signaturesDaan De Meyer2023-03-211-6/+6
| | | | | These are almost never used, so let's move them to the _full() functions signatures.
* copy: Support both inode exclusion and contents exclusionDaan De Meyer2023-02-221-3/+11
| | | | | | | | | | | | In some cases, we want to exclude a directory's contents but not the directory itself. In other cases, we want to exclude a directory and its contents. Let's extend the denylist logic in copy.h to support both by changing the denylist from a set to hashmap so we can store the deny type as the value. We also modify the repart ExcludeFiles= option to make use of this. If a directory to exclude ends with a "/", we'll only exclude its contents. Otherwise, we'll exclude the full directory.
* copy: Add copy_file_at()Daan De Meyer2023-02-201-2/+8
|
* copy: Make copy_xattr() more genericDaan De Meyer2023-02-141-1/+1
| | | | | Let's make copy_xattr() a little more generic in preparation for copying symlink xattrs.
* copy: Add COPY_GRACEFUL_WARNDaan De Meyer2022-12-011-15/+16
| | | | | | | When copying between filesystems, sometimes the target filesystem might not support symlinks/fifos/sockets/... and we want to log and ignore any failures to copy such files when copying. Let's introduce a new flag to enable this behavior.
* copy: Support passing a deny list of files/directories to not copyDaan De Meyer2022-11-101-5/+7
|
* shared: Copy holes in sparse files in copy_bytes_full()Daan De Meyer2022-01-141-0/+1
| | | | | | Previously, all holes in sparse files copied with copy_bytes_full() would be expanded in the target file. Now, we correctly detect holes in the input file and we replicate them in the target file.
* shared/copy: add a new flag COPY_ALL_XATTRSAndrej Lajovic2021-08-111-1/+2
| | | | | | | | When the flag COPY_ALL_XATTRS is set, it causes the complete set of xattrs to be copied. If the flag is unset, only xattrs from the "user" namespace are copied. Fixes #17178.
* copy: add COPY_SIGTERM, matching the existing COPY_SIGINTLennart Poettering2021-08-021-5/+6
|
* copy: add COPY_SYNCFS flagLennart Poettering2021-08-021-0/+1
| | | | | | | | | When copying large directory trees it should be a better idea to sync the whole fs once when we are done instead of individually for each file, hence add COPY_SYNCFS. As opposed to COPY_FSYNC/COPY_FSYNC_FULL this only really applies to the top-level directory, after completion of the whole copy.
* copy: optionally fsync() files after copying themLennart Poettering2021-08-021-9/+11
| | | | | | As a safety precaution it makes sense to fsync() files after copying them, and maybe even the directories they are contained in. Let's add a flag for these two cases.
* basic,shared: move a bunch of files to src/shared/Zbigniew Jędrzejewski-Szmek2021-06-241-0/+71
| | | | | | | | | | | | The goal is to move everything that requires selinux or smack away from src/basic/. This means that src/basic/label.[ch] must move, which implies btrfs-util.[ch], copy.[ch], and a bunch of other files which form a cluster of internal use. This is just moving text around, so there should be no functional difference. test-blockdev-util is new, because path_is_encrypted() is moved to blockdev-util.c, and so far we didn't have any tests for code there.
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-35/+0
| | | | | | | | | | basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/
* util: the chattr flags field is actually unsigned, judging by kernel sourcesLennart Poettering2015-01-141-2/+2
| | | | Unlike some client code suggests...
* machined: when cloning a raw disk image, also set the NOCOW flagLennart Poettering2015-01-081-2/+2
|
* machinectl/machined: implement "rename", "clone", "read-only" verbs for ↵Lennart Poettering2014-12-281-0/+1
| | | | machine images
* copy: try top copy atime/time/xattrs when copying filesLennart Poettering2014-12-261-0/+2
|
* machinectl: add new commands for copying files from/to containersLennart Poettering2014-12-181-1/+2
|
* copy: use btrfs reflinking only whe we know we copy full filesLennart Poettering2014-12-121-2/+2
|
* shared: add new btrfs-util.[ch] helpers for doing common btrfs operationLennart Poettering2014-12-121-0/+1
|
* copy: teach copy_bytes() sendfile() support, and then replace ↵Lennart Poettering2014-11-071-0/+1
| | | | sendfile_full() by it
* shared: add missing includesRonny Chevalier2014-10-311-0/+3
|
* coredump: never write more than the configured processing size limit to diskLennart Poettering2014-06-231-1/+1
|
* tmpfiles: make sure "C" doesn't copy anything if the destination already existsLennart Poettering2014-06-191-1/+1
| | | | | | | | | Previously it would recursively copy the entire tree in, and descend into subdirectories even if the destination already exists. Let's do what the documentation says and not do that. If files down the tree shall be copied too, they should get their own "C" lines.
* sysusers: add minimal tool to reconstruct /etc/passwd and /etc/group from ↵Lennart Poettering2014-06-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | static files systemd-sysusers is a tool to reconstruct /etc/passwd and /etc/group from static definition files that take a lot of inspiration from tmpfiles snippets. These snippets should carry information about system users only. To make sure it is not misused for normal users these snippets only allow configuring UID and gecos field for each user, but do not allow configuration of the home directory or shell, which is necessary for real login users. The purpose of this tool is to enable state-less systems that can populate /etc with the minimal files necessary, solely from static data in /usr. systemd-sysuser is additive only, and will never override existing users. This tool will create these files directly, and not via some user database abtsraction layer. This is appropriate as this tool is supposed to run really early at boot, and is only useful for creating system users, and system users cannot be stored in remote databases anyway. The tool is also useful to be invoked from RPM scriptlets, instead of useradd. This allows moving from imperative user descriptions in RPM to declarative descriptions. The UID/GID for a user/group to be created can either be chosen dynamic, or fixed, or be read from the owner of a file in the file system, in order to support reconstructing the correct IDs for files that shall be owned by them. This also adds a minimal user definition file, that should be sufficient for most basic systems. Distributions are expected to patch these files and augment the contents, for example with fixed UIDs for the users where that's necessary.
* tmpfiles: add new "C" line for copying files or directoriesLennart Poettering2014-06-101-0/+25