]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: avoid truncate clocks.txt to improve performance
authorGoldwyn Rodrigues <rgoldwyn@suse.de>
Tue, 10 Oct 2023 23:08:59 +0000 (18:08 -0500)
committerKarel Zak <kzak@redhat.com>
Mon, 13 Nov 2023 13:52:50 +0000 (14:52 +0100)
Instead of explicitly truncating clocks.txt file, pad with
whitespaces in the end of file.
This is done to improve performance of libuuid on xfs
filesystems. Instead of truncating the file, pad it with whitespaces.
This is anyways used as a failsafe method in case truncate fails.

The reason why this regression was introduced was because of:
869ae85dae64 ("xfs: flush new eof page on truncate to avoid post-eof corruption")

An attempt to move the clocks.txt to /run (tmpfs) has been attempted before
[1] and with commit ab2e7dd17 ("libuuid: move clock state file from
/var/lib to /var/run"). The latter was reverted.

[1] https://www.spinics.net/lists/util-linux-ng/msg17331.html

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
libuuid/src/gen_uuid.c

index db793c374a3493467b6c1a3251059c5b1061645d..826cd22456796ca653e71ff23ea65be07a46f91a 100644 (file)
@@ -229,7 +229,6 @@ static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
        struct timeval                  tv;
        uint64_t                        clock_reg;
        mode_t                          save_umask;
-       int                             len;
        int                             ret = 0;
 
        if (state_fd == -1)
@@ -324,14 +323,10 @@ try_again:
 
        if (state_fd >= 0) {
                rewind(state_f);
-               len = fprintf(state_f,
-                             "clock: %04x tv: %016ld %08ld adj: %08d\n",
+               fprintf(state_f,
+                             "clock: %04x tv: %016ld %08ld adj: %08d                   \n",
                              clock_seq, (long)last.tv_sec, (long)last.tv_usec, adjustment);
                fflush(state_f);
-               if (ftruncate(state_fd, len) < 0) {
-                       fprintf(state_f, "                   \n");
-                       fflush(state_f);
-               }
                rewind(state_f);
                flock(state_fd, LOCK_UN);
        }