lib/commit: Directly use FICLONE for payload link
authorJonathan Lebon <jonathan@jlebon.com>
Mon, 15 Aug 2022 17:54:35 +0000 (13:54 -0400)
committerJonathan Lebon <jonathan@jlebon.com>
Mon, 15 Aug 2022 18:00:08 +0000 (14:00 -0400)
The idea of payload linking is to reflink between objects where
possible. Instead of relying on `glnx_regfile_copy_bytes` to hit the
`FICLONE` path, just call `FICLONE` directly. At that point in the code,
we've already established that the source and dest repos are on the same
filesystem and that it supports `FICLONE`.

Related: https://gitlab.gnome.org/GNOME/libglnx/-/merge_requests/41
Related: https://github.com/ostreedev/ostree/pull/2684#issuecomment-1204068437

src/libostree/ostree-repo-commit.c

index 35b16c713b7821fa6b627f9f411de0abf2bb2100..6cfdc32b427c8604fad1838608e54567ac9b7c17 100644 (file)
@@ -881,11 +881,8 @@ _try_clone_from_payload_link (OstreeRepo   *self,
       else
         {
           /* This undoes all of the previous writes; we want to generate reflinked data.   */
-          if (ftruncate (tmpf->fd, 0) < 0)
-            return glnx_throw_errno_prefix (error, "ftruncate");
-
-          if (glnx_regfile_copy_bytes (fdf, tmpf->fd, -1) < 0)
-            return glnx_throw_errno_prefix (error, "regfile copy");
+          if (ioctl (tmpf->fd, FICLONE, fdf) < 0)
+            return glnx_throw_errno_prefix (error, "FICLONE");
 
           return TRUE;
         }