1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

ctdb-locking: Conditionally set real-time priority in lock helper

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
Amitay Isaacs 2016-06-17 18:33:27 +10:00 committed by Michael Adam
parent 2828b9a8c6
commit a21a4de2cb

View File

@ -28,6 +28,35 @@
#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)
{
@ -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;
bool realtime;
/* 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;
}
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",
@ -100,9 +124,7 @@ static int lock_record(const char *dbpath, const char *dbflags, const char *dbke
return 1;
}
if (realtime) {
reset_scheduler();
}
reset_priority();
return 0;
@ -113,7 +135,6 @@ static int lock_db(const char *dbpath, const char *dbflags)
{
struct tdb_context *tdb;
int tdb_flags;
bool realtime;
/* 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;
}
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",
@ -136,9 +153,7 @@ static int lock_db(const char *dbpath, const char *dbflags)
return 1;
}
if (realtime) {
reset_scheduler();
}
reset_priority();
return 0;
}