core: Use O_NOATIME to open metadata
We really don't need atime for metadata, it's just a speed hit.
This commit is contained in:
parent
2396608754
commit
4d2f770748
|
|
@ -812,12 +812,8 @@ ensure_file_data_synced (GFile *file,
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
|
||||||
fd = g_open (ot_gfile_get_path_cached (file), O_RDONLY | O_NOATIME | O_CLOEXEC | O_LARGEFILE, 0);
|
if (!ot_unix_open_noatime (ot_gfile_get_path_cached (file), &fd, error))
|
||||||
if (fd < 0)
|
goto out;
|
||||||
{
|
|
||||||
ot_util_set_error_from_errno (error, errno);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ot_unix_fdatasync (fd, error))
|
if (!ot_unix_fdatasync (fd, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,17 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
#include <glib/gstdio.h>
|
||||||
#include <gio/gunixoutputstream.h>
|
#include <gio/gunixoutputstream.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
@ -225,3 +229,29 @@ ot_unix_close (int fd, GError **error)
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ot_unix_open_noatime:
|
||||||
|
*
|
||||||
|
* Open a file for reading, using O_NOATIME if possible.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
ot_unix_open_noatime (const char *path,
|
||||||
|
int *out_fd,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
#ifdef O_NOATIME
|
||||||
|
fd = g_open (path, O_RDONLY | O_NOATIME | O_CLOEXEC, 0);
|
||||||
|
if (fd == -1 && errno == EPERM)
|
||||||
|
#endif
|
||||||
|
fd = g_open (path, O_RDONLY | O_CLOEXEC, 0);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
ot_util_set_error_from_errno (error, errno);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
*out_fd = fd;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,8 @@ gboolean ot_unix_fdatasync (int fd, GError **error);
|
||||||
|
|
||||||
gboolean ot_unix_close (int fd, GError **error);
|
gboolean ot_unix_close (int fd, GError **error);
|
||||||
|
|
||||||
|
gboolean ot_unix_open_noatime (const char *path, int *out_fd, GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -118,11 +118,16 @@ ot_util_variant_map (GFile *src,
|
||||||
const char *path = NULL;
|
const char *path = NULL;
|
||||||
ot_lvariant GVariant *ret_variant = NULL;
|
ot_lvariant GVariant *ret_variant = NULL;
|
||||||
GMappedFile *mfile = NULL;
|
GMappedFile *mfile = NULL;
|
||||||
|
int fd;
|
||||||
|
|
||||||
path = ot_gfile_get_path_cached (src);
|
path = ot_gfile_get_path_cached (src);
|
||||||
mfile = g_mapped_file_new (path, FALSE, error);
|
if (!ot_unix_open_noatime (path, &fd, error))
|
||||||
|
goto out;
|
||||||
|
mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
|
||||||
if (!mfile)
|
if (!mfile)
|
||||||
goto out;
|
goto out;
|
||||||
|
if (!ot_unix_close (fd, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
ret_variant = g_variant_new_from_data (type,
|
ret_variant = g_variant_new_from_data (type,
|
||||||
g_mapped_file_get_contents (mfile),
|
g_mapped_file_get_contents (mfile),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue