ctdb-locking: Conditionally set real-time priority in lock helper
authorAmitay Isaacs <amitay@gmail.com>
Fri, 17 Jun 2016 08:33:27 +0000 (18:33 +1000)
committerMichael Adam <obnox@samba.org>
Mon, 20 Jun 2016 14:21:19 +0000 (16:21 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/server/ctdb_lock_helper.c

index cdcbb4ac63592465668b308811edf4578b8d8831..e41d23079199642782a82e29d4d5c7a0a2a08172 100644 (file)
 #include "common/system.h"
 
 static char *progname = NULL;
 #include "common/system.h"
 
 static char *progname = NULL;
+static bool realtime = true;
+
+static void set_priority(void)
+{
+       const char *ptr;
+
+       ptr = getenv("CTDB_NOSETSCHED");
+       if (ptr != NULL) {
+               realtime = false;
+       }
+
+       if (! realtime) {
+               return;
+       }
+
+       realtime = set_scheduler();
+       if (! realtime) {
+               fprintf(stderr,
+                       "%s: Unable to set real-time scheduler priority\n",
+                       progname);
+       }
+}
+
+static void reset_priority(void)
+{
+       if (realtime) {
+               reset_scheduler();
+       }
+}
 
 static void send_result(int fd, char result)
 {
 
 static void send_result(int fd, char result)
 {
@@ -69,7 +98,6 @@ static int lock_record(const char *dbpath, const char *dbflags, const char *dbke
        TDB_DATA key;
        struct tdb_context *tdb;
        int tdb_flags;
        TDB_DATA key;
        struct tdb_context *tdb;
        int tdb_flags;
-       bool realtime;
 
        /* No error checking since CTDB always passes sane values */
        tdb_flags = strtol(dbflags, NULL, 0);
 
        /* No error checking since CTDB always passes sane values */
        tdb_flags = strtol(dbflags, NULL, 0);
@@ -88,11 +116,7 @@ static int lock_record(const char *dbpath, const char *dbflags, const char *dbke
                return 1;
        }
 
                return 1;
        }
 
-       realtime = set_scheduler();
-       if (! realtime) {
-               fprintf(stderr, "%s: Unable to set real-time scheduler priority\n",
-                       progname);
-       }
+       set_priority();
 
        if (tdb_chainlock(tdb, key) < 0) {
                fprintf(stderr, "%s: Error getting record lock (%s)\n",
 
        if (tdb_chainlock(tdb, key) < 0) {
                fprintf(stderr, "%s: Error getting record lock (%s)\n",
@@ -100,9 +124,7 @@ static int lock_record(const char *dbpath, const char *dbflags, const char *dbke
                return 1;
        }
 
                return 1;
        }
 
-       if (realtime) {
-               reset_scheduler();
-       }
+       reset_priority();
 
        return 0;
 
 
        return 0;
 
@@ -113,7 +135,6 @@ static int lock_db(const char *dbpath, const char *dbflags)
 {
        struct tdb_context *tdb;
        int tdb_flags;
 {
        struct tdb_context *tdb;
        int tdb_flags;
-       bool realtime;
 
        /* No error checking since CTDB always passes sane values */
        tdb_flags = strtol(dbflags, NULL, 0);
 
        /* No error checking since CTDB always passes sane values */
        tdb_flags = strtol(dbflags, NULL, 0);
@@ -124,11 +145,7 @@ static int lock_db(const char *dbpath, const char *dbflags)
                return 1;
        }
 
                return 1;
        }
 
-       realtime = set_scheduler();
-       if (! realtime) {
-               fprintf(stderr, "%s: Unable to set real-time scheduler priority\n",
-                       progname);
-       }
+       set_priority();
 
        if (tdb_lockall(tdb) < 0) {
                fprintf(stderr, "%s: Error getting db lock (%s)\n",
 
        if (tdb_lockall(tdb) < 0) {
                fprintf(stderr, "%s: Error getting db lock (%s)\n",
@@ -136,9 +153,7 @@ static int lock_db(const char *dbpath, const char *dbflags)
                return 1;
        }
 
                return 1;
        }
 
-       if (realtime) {
-               reset_scheduler();
-       }
+       reset_priority();
 
        return 0;
 }
 
        return 0;
 }