Blame SOURCES/0230-dd-log-lock-warning-only-once-not-x-times-per-sec.patch

4b6aa8
From 4553ec1bed2a65dbeb5f2f93f23d5332e6750522 Mon Sep 17 00:00:00 2001
4b6aa8
From: Matej Habrnal <mhabrnal@redhat.com>
4b6aa8
Date: Thu, 13 Sep 2018 16:25:42 +0200
4b6aa8
Subject: [PATCH] dd: log lock warning only once not x times per sec
4b6aa8
4b6aa8
Related to #1588272
4b6aa8
4b6aa8
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
4b6aa8
4b6aa8
Conflicts:
4b6aa8
	src/lib/dump_dir.c
4b6aa8
---
4b6aa8
 src/include/dump_dir.h |  3 ++-
4b6aa8
 src/lib/dump_dir.c     | 19 ++++++++++++++-----
4b6aa8
 2 files changed, 16 insertions(+), 6 deletions(-)
4b6aa8
4b6aa8
diff --git a/src/include/dump_dir.h b/src/include/dump_dir.h
4b6aa8
index 84cabbf8..690695a0 100644
4b6aa8
--- a/src/include/dump_dir.h
4b6aa8
+++ b/src/include/dump_dir.h
4b6aa8
@@ -37,7 +37,8 @@ extern "C" {
4b6aa8
 
4b6aa8
 /* Utility function */
4b6aa8
 int create_symlink_lockfile(const char *filename, const char *pid_str);
4b6aa8
-int create_symlink_lockfile_at(int dir_fd, const char *filename, const char *pid_str);
4b6aa8
+int create_symlink_lockfile_at(int dir_fd, const char *filename,
4b6aa8
+                               const char *pid_str, bool log_all_warnings);
4b6aa8
 
4b6aa8
 /* Opens filename for reading relatively to a directory represented by dir_fd.
4b6aa8
  * The function fails if the file is symbolic link, directory or hard link.
4b6aa8
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
4b6aa8
index acc5e561..c0117380 100644
4b6aa8
--- a/src/lib/dump_dir.c
4b6aa8
+++ b/src/lib/dump_dir.c
4b6aa8
@@ -231,7 +231,8 @@ static time_t parse_time_file_at(int dir_fd, const char *filename)
4b6aa8
  *  0: failed to lock (someone else has it locked)
4b6aa8
  *  1: success
4b6aa8
  */
4b6aa8
-int create_symlink_lockfile_at(int dir_fd, const char* lock_file, const char* pid)
4b6aa8
+int create_symlink_lockfile_at(int dir_fd, const char* lock_file,
4b6aa8
+                               const char* pid, bool log_all_warnings)
4b6aa8
 {
4b6aa8
     while (symlinkat(pid, dir_fd, lock_file) != 0)
4b6aa8
     {
4b6aa8
@@ -272,7 +273,8 @@ int create_symlink_lockfile_at(int dir_fd, const char* lock_file, const char* pi
4b6aa8
             snprintf(pid_str, sizeof(pid_str), "/proc/%s", pid_buf);
4b6aa8
             if (access(pid_str, F_OK) == 0)
4b6aa8
             {
4b6aa8
-                log("Lock file '%s' is locked by process %s", lock_file, pid_buf);
4b6aa8
+                if (log_all_warnings)
4b6aa8
+                    log_warning("Lock file '%s' is locked by process %s. Waiting...", lock_file, pid_buf);
4b6aa8
                 return 0;
4b6aa8
             }
4b6aa8
             log("Lock file '%s' was locked by process %s, but it crashed?", lock_file, pid_buf);
4b6aa8
@@ -292,7 +294,7 @@ int create_symlink_lockfile_at(int dir_fd, const char* lock_file, const char* pi
4b6aa8
 
4b6aa8
 int create_symlink_lockfile(const char *filename, const char *pid_str)
4b6aa8
 {
4b6aa8
-    return create_symlink_lockfile_at(AT_FDCWD, filename, pid_str);
4b6aa8
+    return create_symlink_lockfile_at(AT_FDCWD, filename, pid_str, true);
4b6aa8
 }
4b6aa8
 
4b6aa8
 static const char *dd_check(struct dump_dir *dd)
4b6aa8
@@ -333,10 +335,16 @@ static int dd_lock(struct dump_dir *dd, unsigned sleep_usec, int flags)
4b6aa8
 
4b6aa8
     unsigned count = NO_TIME_FILE_COUNT;
4b6aa8
 
4b6aa8
- retry:
4b6aa8
+ retry: ;
4b6aa8
+    /* If the file is locked by another process, warning "Lock file '.lock' is
4b6aa8
+     * locked by process $PID" is logged every $sleep_usec usec and fill up log
4b6aa8
+     * file.
4b6aa8
+     * rhbz#1588272
4b6aa8
+     */
4b6aa8
+    bool log_all_warnings = true;
4b6aa8
     while (1)
4b6aa8
     {
4b6aa8
-        int r = create_symlink_lockfile_at(dd->dd_fd, ".lock", pid_buf);
4b6aa8
+        int r = create_symlink_lockfile_at(dd->dd_fd, ".lock", pid_buf, log_all_warnings);
4b6aa8
         if (r < 0)
4b6aa8
             return r; /* error */
4b6aa8
         if (r > 0)
4b6aa8
@@ -348,6 +356,7 @@ static int dd_lock(struct dump_dir *dd, unsigned sleep_usec, int flags)
4b6aa8
         }
4b6aa8
         /* Other process has the lock, wait for it to go away */
4b6aa8
         usleep(sleep_usec);
4b6aa8
+        log_all_warnings = false;
4b6aa8
     }
4b6aa8
 
4b6aa8
     /* Are we called by dd_opendir (as opposed to dd_create)? */
4b6aa8
-- 
4b6aa8
2.17.2
4b6aa8