[tracker] Fixes GB#633093: Use statvfs64() if available to check for free space
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] Fixes GB#633093: Use statvfs64() if available to check for free space
- Date: Mon, 25 Oct 2010 11:09:39 +0000 (UTC)
commit 94b9126a4760a9ae0fefa38e8149f8c978d39a85
Author: Aleksander Morgado <aleksander lanedo com>
Date: Mon Oct 25 12:57:46 2010 +0200
Fixes GB#633093: Use statvfs64() if available to check for free space
* Fixes retrieving both the exact number of free bytes in a partition (as when
checking if we have enough space to write the tracker databases) and also
the percentage of free space in a partition (as when checking if we reached
the threshold configured for pausing miner-fs).
configure.ac | 8 ++++-
src/libtracker-common/tracker-file-utils.c | 54 +++++++++++++++++++++++----
src/libtracker-common/tracker-file-utils.h | 55 ++++++++++++++++------------
src/miners/fs/tracker-miner-files.c | 20 ++++------
4 files changed, 92 insertions(+), 45 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 544de34..0f44715 100644
--- a/configure.ac
+++ b/configure.ac
@@ -99,7 +99,7 @@ CFLAGS="$CFLAGS"
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.h sitdlib.h string.h sys/time.h unistd.h linux/unistd.h])
+AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/time.h unistd.h linux/unistd.h sys/statvfs.h])
AC_CHECK_HEADER([zlib.h],
[],
@@ -114,6 +114,12 @@ AC_CHECK_DECLS(posix_fadvise, [], [], [
AC_CHECK_FUNCS([posix_fadvise])
AC_CHECK_FUNCS([getline])
+# if statvfs64() is available, enable the 64-bit API extensions
+AC_CHECK_FUNCS([statvfs64], [have_statvfs64=yes], [have_statvfs64=no])
+if test "x$have_statvfs" = "xyes" ; then
+ CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE"
+fi
+
# Check for defines we expect
AC_TRY_COMPILE(,
[
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index f33fa3d..959be4c 100644
--- a/src/libtracker-common/tracker-file-utils.c
+++ b/src/libtracker-common/tracker-file-utils.c
@@ -191,28 +191,66 @@ tracker_file_get_mime_type (GFile *file)
return content_type ? content_type : g_strdup ("unknown");
}
+#if HAVE_STATVFS64
+#define __statvfs statvfs64
+#else
+#define __statvfs statvfs
+#endif
+
+guint64
+tracker_file_system_get_remaining_space (const gchar *path)
+{
+ guint64 remaining;
+ struct __statvfs st;
+
+ if (__statvfs (path, &st) == -1) {
+ remaining = 0;
+ g_critical ("Could not statvfs() '%s': %s",
+ path,
+ g_strerror (errno));
+ } else {
+ remaining = st.f_bsize * st.f_bavail;
+ }
+
+ return remaining;
+}
+
+gdouble
+tracker_file_system_get_remaining_space_percentage (const gchar *path)
+{
+ gdouble remaining;
+ struct __statvfs st;
+
+ if (__statvfs (path, &st) == -1) {
+ remaining = 0.0;
+ g_critical ("Could not statvfs() '%s': %s",
+ path,
+ g_strerror (errno));
+ } else {
+ remaining = (st.f_bavail * 100.0 / st.f_blocks);
+ }
+
+ return remaining;
+}
+
gboolean
tracker_file_system_has_enough_space (const gchar *path,
gulong required_bytes,
gboolean creating_db)
{
- struct statvfs st;
gchar *str1;
gchar *str2;
gboolean enough;
+ guint64 remaining;
g_return_val_if_fail (path != NULL, FALSE);
- if (statvfs (path, &st) == -1) {
- g_critical ("Could not statvfs() '%s'", path);
- return FALSE;
- }
-
- enough = ((long long) st.f_bsize * st.f_bavail) >= required_bytes;
+ remaining = tracker_file_system_get_remaining_space (path);
+ enough = (remaining >= required_bytes);
if (creating_db) {
str1 = g_format_size_for_display (required_bytes);
- str2 = g_format_size_for_display (st.f_bsize * st.f_bavail);
+ str2 = g_format_size_for_display (remaining);
if (!enough) {
g_critical ("Not enough disk space to create databases, "
diff --git a/src/libtracker-common/tracker-file-utils.h b/src/libtracker-common/tracker-file-utils.h
index af39785..d47f373 100644
--- a/src/libtracker-common/tracker-file-utils.h
+++ b/src/libtracker-common/tracker-file-utils.h
@@ -31,30 +31,37 @@ G_BEGIN_DECLS
#error "only <libtracker-common/tracker-common.h> must be included directly."
#endif
-FILE* tracker_file_open (const gchar *uri,
- const gchar *how,
- gboolean sequential);
-void tracker_file_close (FILE *file,
- gboolean need_again_soon);
-goffset tracker_file_get_size (const gchar *uri);
-guint64 tracker_file_get_mtime (const gchar *uri);
-gchar * tracker_file_get_mime_type (GFile *file);
-gboolean tracker_file_system_has_enough_space (const gchar *path,
- gulong required_bytes,
- gboolean creating_db);
-gboolean tracker_path_is_in_path (const gchar *path,
- const gchar *in_path);
-GSList * tracker_path_list_filter_duplicates (GSList *roots,
- const gchar *basename_exception_prefix,
- gboolean is_recursive);
-gchar * tracker_path_evaluate_name (const gchar *uri);
-
-gboolean tracker_path_has_write_access_or_was_created (const gchar *path);
-gboolean tracker_env_check_xdg_dirs (void);
-
-gboolean tracker_file_lock (GFile *file);
-gboolean tracker_file_unlock (GFile *file);
-gboolean tracker_file_is_locked (GFile *file);
+/* File utils */
+FILE* tracker_file_open (const gchar *uri,
+ const gchar *how,
+ gboolean sequential);
+void tracker_file_close (FILE *file,
+ gboolean need_again_soon);
+goffset tracker_file_get_size (const gchar *uri);
+guint64 tracker_file_get_mtime (const gchar *uri);
+gchar * tracker_file_get_mime_type (GFile *file);
+gboolean tracker_file_lock (GFile *file);
+gboolean tracker_file_unlock (GFile *file);
+gboolean tracker_file_is_locked (GFile *file);
+
+/* Path utils */
+gboolean tracker_path_is_in_path (const gchar *path,
+ const gchar *in_path);
+GSList * tracker_path_list_filter_duplicates (GSList *roots,
+ const gchar *basename_exception_prefix,
+ gboolean is_recursive);
+gchar * tracker_path_evaluate_name (const gchar *uri);
+gboolean tracker_path_has_write_access_or_was_created (const gchar *path);
+
+/* File system utils */
+gboolean tracker_file_system_has_enough_space (const gchar *path,
+ gulong required_bytes,
+ gboolean creating_db);
+guint64 tracker_file_system_get_remaining_space (const gchar *path);
+gdouble tracker_file_system_get_remaining_space_percentage (const gchar *path);
+
+/* Environment path utils */
+gboolean tracker_env_check_xdg_dirs (void);
G_END_DECLS
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 0580079..147e3a4 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -41,6 +41,7 @@
#include <libtracker-common/tracker-power.h>
#include <libtracker-common/tracker-type-utils.h>
#include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-file-utils.h>
#include <libtracker-data/tracker-db-manager.h>
@@ -1325,9 +1326,9 @@ mount_pre_unmount_cb (GVolumeMonitor *volume_monitor,
static gboolean
disk_space_check (TrackerMinerFiles *mf)
{
- struct statvfs st;
gint limit;
gchar *data_dir;
+ gdouble remaining;
limit = tracker_config_get_low_disk_space_limit (mf->private->config);
@@ -1335,20 +1336,15 @@ disk_space_check (TrackerMinerFiles *mf)
return FALSE;
}
+ /* Get % of remaining space in the partition where the cache is */
data_dir = g_build_filename (g_get_user_cache_dir (), "tracker", NULL);
-
- if (statvfs (data_dir, &st) == -1) {
- g_warning ("Could not statvfs() '%s'", data_dir);
- g_free (data_dir);
- return FALSE;
- }
-
+ remaining = tracker_file_system_get_remaining_space_percentage (data_dir);
g_free (data_dir);
- if (((long long) st.f_bavail * 100 / st.f_blocks) <= limit) {
- g_message ("WARNING: Available disk space is below configured "
- "threshold for acceptable working (%d%%)",
- limit);
+ if (remaining <= limit) {
+ g_message ("WARNING: Available disk space (%lf%%) is below "
+ "configured threshold for acceptable working (%d%%)",
+ remaining, limit);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]