Add ctdb_fork(0 which will fork a child process and drop the real-time
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 10 Jan 2011 02:57:49 +0000 (13:57 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 10 Jan 2011 20:40:41 +0000 (07:40 +1100)
scheduler for the child.

Use ctdb_fork() from callers where we dont want the child to be running
at real-time privilege.

common/ctdb_logging.c
common/ctdb_util.c
include/ctdb_private.h
server/ctdb_lockwait.c
server/ctdb_logging.c
server/ctdb_monitor.c
server/ctdb_persistent.c
server/ctdb_recoverd.c
server/ctdb_traverse.c
server/ctdb_vacuum.c
server/eventscript.c

index de6e039dd0ae08a5af90397bc4a4465f13cdb95c..dee4dfdb364eda731fea6512a83cb917ef418035 100644 (file)
@@ -157,7 +157,7 @@ int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr)
        /* spawn a child process to marshall the huge log blob and send it back
           to the ctdb tool using a MESSAGE
        */
-       child = fork();
+       child = ctdb_fork(ctdb);
        if (child == (pid_t)-1) {
                DEBUG(DEBUG_ERR,("Failed to fork a log collector child\n"));
                return -1;
index 49ede68a20fabef78e50e2f70fce47caecb49916..88741e304d744145d25afc1f98e77536cd5c8e28 100644 (file)
@@ -341,15 +341,20 @@ void ctdb_restore_scheduler(struct ctdb_context *ctdb)
 }
 
 /*
-  make ourselves slightly nicer: eg. a ctdb child.
+ * This function forks a child process and drops the realtime 
+ * scheduler for the child process.
  */
-void ctdb_reduce_priority(struct ctdb_context *ctdb)
+pid_t ctdb_fork(struct ctdb_context *ctdb)
 {
-       errno = 0;
-       if (nice(10) == -1 && errno != 0) {
-               DEBUG(DEBUG_WARNING,("Unable to lower priority: %s\n",
-                                    strerror(errno)));
+       pid_t pid;
+
+       pid = fork();
+       if (pid == 0) {
+               if (ctdb->do_setsched) {
+                       ctdb_restore_scheduler(ctdb);
+               }
        }
+       return pid;
 }
 
 void set_nonblocking(int fd)
index f3b669d794cd5b6f0c3366cd4ae04c97d0d1598b..f62125c9800b53a692a5debefb02d7db15d77070 100644 (file)
@@ -994,6 +994,7 @@ void ctdb_node_connected(struct ctdb_node *node);
 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
 void ctdb_set_scheduler(struct ctdb_context *ctdb);
 void ctdb_restore_scheduler(struct ctdb_context *ctdb);
+pid_t ctdb_fork(struct ctdb_context *ctdb);
 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, 
                                 struct ctdb_req_control *c,
                                 TDB_DATA indata, 
index 48198fd1f67f313a0ae58c9d435826b15157d13f..1d3a59766acdb7cab59abc53c8a23849646129e9 100644 (file)
@@ -117,7 +117,7 @@ struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db,
                return NULL;
        }
 
-       result->child = fork();
+       result->child = ctdb_fork(ctdb_db->ctdb);
 
        if (result->child == (pid_t)-1) {
                close(result->fd[0]);
index 7e5367eab537993df257c3cdda30c6fee0086eef..27b990ef6768b09967b4e8139f0bbf19f9d1f5d8 100644 (file)
@@ -96,7 +96,7 @@ int start_syslog_daemon(struct ctdb_context *ctdb)
                return -1;
        }
        
-       ctdb->syslogd_pid = fork();
+       ctdb->syslogd_pid = ctdb_fork(ctdb);
        if (ctdb->syslogd_pid == (pid_t)-1) {
                printf("Failed to create syslog child process\n");
                close(state->fd[0]);
@@ -454,7 +454,7 @@ struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
                goto free_log;
        }
 
-       *pid = fork();
+       *pid = ctdb_fork(ctdb);
 
        /* Child? */
        if (*pid == 0) {
index dff6f42f86c55d3c3b6173ccb4a0d0ae2b772f7b..416e4c5883f7deb2e18397c21d3b999409a687bc 100644 (file)
@@ -83,7 +83,7 @@ void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event)
                return;
        }
 
-       child = fork();
+       child = ctdb_fork(ctdb);
        if (child == (pid_t)-1) {
                DEBUG(DEBUG_ERR,("Failed to fork() a notification child process\n"));
                return;
index 9346f7d0da4517a6f0f566eb2b046db597b36b5f..f9a20510c989f40b1a2c432f827e97ae5443a331 100644 (file)
@@ -524,7 +524,7 @@ struct childwrite_handle *ctdb_childwrite(struct ctdb_db_context *ctdb_db,
                return NULL;
        }
 
-       result->child = fork();
+       result->child = ctdb_fork(ctdb_db->ctdb);
 
        if (result->child == (pid_t)-1) {
                close(result->fd[0]);
index e0f01fb8ed009a72d82be43f43b9301b10bc6b9c..08a5a665a2f85f0d605b97c263941e7e5023bc95 100644 (file)
@@ -2770,7 +2770,7 @@ static int check_recovery_lock(struct ctdb_context *ctdb)
                return -1;
        }
 
-       state->child = fork();
+       state->child = ctdb_fork(ctdb);
        if (state->child == (pid_t)-1) {
                DEBUG(DEBUG_CRIT,(__location__ " fork() failed in check_reclock child\n"));
                close(state->fd[0]);
index dcb16b227b2056301b012f571f09a8e1b5cec201..5ad374f098da6a8a498c7bfe3ec0640ebe2c7f45 100644 (file)
@@ -153,7 +153,7 @@ static struct ctdb_traverse_local_handle *ctdb_traverse_local(struct ctdb_db_con
                return NULL;
        }
 
-       h->child = fork();
+       h->child = ctdb_fork(ctdb_db->ctdb);
 
        if (h->child == (pid_t)-1) {
                close(h->fd[0]);
index 4104853de1c6f05c083d7719ad8ff8ff7fccadcb..4aac302dca715ea1f89120fc079b145c2b919043 100644 (file)
@@ -836,7 +836,7 @@ ctdb_vacuum_event(struct event_context *ev, struct timed_event *te,
                return;
        }
 
-       child_ctx->child_pid = fork();
+       child_ctx->child_pid = ctdb_fork(ctdb);
        if (child_ctx->child_pid == (pid_t)-1) {
                close(child_ctx->fd[0]);
                close(child_ctx->fd[1]);
index ce2fd89eca5a61fc8dda0dc65d3e06751ed1540b..9ba3a5d9ed802bdb2fe7c1f52bd506f6b7d4f080 100644 (file)
@@ -511,9 +511,8 @@ static void debug_timeout(struct ctdb_event_script_state *state)
        sprintf(buf, "{ pstree -p; cat /proc/locks; ls -li /var/ctdb/ /var/ctdb/persistent; }"
                        " >/tmp/ctdb.event.%s.%d", tbuf, getpid());
 
-       pid = fork();
+       pid = ctdb_fork(state->ctdb);
        if (pid == 0) {
-               ctdb_reduce_priority(state->ctdb);
                system(buf);
                /* Now we can kill the child */
                kill(state->child, SIGTERM);