]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: Handle filesystems that don't support hole punching in COPY_HOLES
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 28 Jan 2022 16:18:49 +0000 (16:18 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 30 Jan 2022 19:43:23 +0000 (04:43 +0900)
src/shared/copy.c

index a92cfc0f6151f29e1dffdcacaf630effe8b04ecb..09417063562131c4245c91fd052a316d93defc45 100644 (file)
@@ -119,9 +119,11 @@ static int create_hole(int fd, off_t size) {
         if (end < 0)
                 return -errno;
 
-        /* If we're not at the end of the target file, punch a hole in the existing space using fallocate(). */
+        /* If we're not at the end of the target file, try to punch a hole in the existing space using fallocate(). */
 
-        if (offset < end && fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, MIN(size, end - offset)) < 0)
+        if (offset < end &&
+            fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, MIN(size, end - offset)) < 0 &&
+            !ERRNO_IS_NOT_SUPPORTED(errno))
                 return -errno;
 
         if (end - offset >= size) {