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 02:57:49 +0000 (13:57 +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 80390899c7f46e0753e48fa6bbb3a0c3f541353f..1ff4c1f9aa2052cb97b46c54af6c579ab9ed430f 100644 (file)
@@ -334,15 +334,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 deba46b215883decb8ef5aa9da0b027fe1e5c60c..2d9315f6ac49bf0a79f4b2947c540bdf1ab3098c 100644 (file)
@@ -993,6 +993,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 7f5da5c3377875d817519f7f50cc2cdc90ea04ab..fa642fb3fd7269a98a9267a5c58cbbf61976a86f 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 9caa5024dd653e89bbabd97fc651e066a4f6ecfc..b2c08ced0c5bc3b5a2cf520f79e47d9d7e524a79 100644 (file)
@@ -2768,7 +2768,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);