• R/O
  • SSH

pm_diskd: Commit

※ リポジトリは、pm-diskd ブランチが https://github.com/linux-ha-japan/pm_diskd-1.0 へ、pm-diskd-2.0ブランチが https://github.com/linux-ha-japan/pm_diskd へ移行しました。

Pacemaker 対応ディスク故障監視機能。

Pacemaker-1.0公式リポジトリのクローンに対し、パッチ作成用のブランチを作成して管理する。
ブランチ名: pm-diskd

初回 hg clone 実行後は、hg update -r pm-diskd を実行すること。

Heartbeat-2.1.4 用 hb-diskd(*) のPacemaker対応版
(*) http://sourceforge.jp/projects/linux-ha/releases/?package_id=10555


Commit MetaInfo

Revision9a7339fc5159476f0343f7067263c230ef6ad426 (tree)
Time2011-10-27 12:40:09
Author <hideoyamauchi@hg.s...>

Log Message

Support of the timer thread

Change Summary

Incremental Difference

diff -r 8da842972567 -r 9a7339fc5159 tools/Makefile.am
--- a/tools/Makefile.am Wed Dec 15 12:21:19 2010 +0900
+++ b/tools/Makefile.am Thu Oct 27 12:40:09 2011 +0900
@@ -113,7 +113,7 @@
113113 pingd_LDADD = $(COMMONLIBS)
114114
115115 diskd_SOURCES = diskd.c
116-diskd_LDADD = $(COMMONLIBS)
116+diskd_LDADD = $(COMMONLIBS) -lgthread-2.0
117117
118118 attrd_updater_SOURCES = attrd_updater.c
119119 attrd_updater_LDADD = $(COMMONLIBS)
diff -r 8da842972567 -r 9a7339fc5159 tools/diskd.c
--- a/tools/diskd.c Wed Dec 15 12:21:19 2010 +0900
+++ b/tools/diskd.c Thu Oct 27 12:40:09 2011 +0900
@@ -25,12 +25,8 @@
2525 * Ver.2.0 for Pacemaker 1.0.x
2626 */
2727
28-#include <crm_internal.h>
29-
3028 #include <sys/param.h>
3129
32-#include <crm/crm.h>
33-
3430 #include <stdio.h>
3531 #include <sys/types.h>
3632 #include <sys/stat.h>
@@ -47,12 +43,16 @@
4743 #include <clplumbing/Gmain_timeout.h>
4844 #include <clplumbing/lsb_exitcodes.h>
4945
46+#include <crm/crm.h>
47+#include <crm/common/util.h>
5048 #include <crm/common/ipc.h>
5149
5250 #ifdef HAVE_GETOPT_H
5351 # include <getopt.h>
5452 #endif
5553
54+#include <glib.h>
55+
5656 #define MIN_INTERVAL 1
5757 #define MAX_INTERVAL 3600
5858 #define MIN_TIMEOUT 1
@@ -76,7 +76,7 @@
7676 /* GMainLoop *mainloop = NULL; */
7777 const char *crm_system_name = "diskd";
7878
79-#define OPTARGS "N:wd:a:i:p:DV?t:r:I:o"
79+#define OPTARGS "N:wd:a:i:p:DV?t:r:I:oe"
8080
8181 GMainLoop* mainloop = NULL;
8282 const char *diskd_attr = "diskd";
@@ -92,13 +92,24 @@
9292 int retry = 1; /* disk check retry. default 1 times */
9393 int retry_interval = 5; /* disk check retry intarval time. default 5sec. */
9494 int interval = 30; /* disk check interval. default 30sec.*/
95-int timeout = 30; /* disk check read func timeout. default 30sec. */
95+int timeout = 60; /* disk check read func timeout. default 60sec. */
9696 int oneshot_flag = 0; /* */
97+int exec_thread_flag = 0; /* */
9798 const char *diskcheck_value = NULL;
9899 int pagesize = 0;
99100 void *ptr = NULL;
100101 void *buf;
101102
103+static GMutex *diskd_mutex = NULL; /* Thread Mutex */
104+static GCond *diskd_cond = NULL; /* Thread Cond */
105+static gboolean diskd_thread_use = FALSE; /* Tthred Timer Flag */
106+static GThread *th_timer = NULL; /* Thread Timer */
107+
108+static void diskd_thread_timer_init(void);
109+static void diskd_thread_create(void);
110+static void diskd_thread_timer_variable_free(gboolean);
111+static void diskd_thread_condsend(void);
112+static void diskd_thread_timer_end(void);
102113 void send_update(void);
103114
104115 static gboolean
@@ -106,6 +117,8 @@
106117 {
107118 crm_info("Exiting");
108119
120+ diskd_thread_condsend();
121+
109122 if (mainloop != NULL && g_main_is_running(mainloop)) {
110123 g_main_quit(mainloop);
111124 } else {
@@ -121,7 +134,7 @@
121134
122135 stream = exit_status ? stderr : stdout;
123136
124- fprintf(stream, "usage: %s (-N|-w) [-daipDV?trIo]\n", cmd);
137+ fprintf(stream, "usage: %s (-N|-w) [-daipDV?trIoe]\n", cmd);
125138 fprintf(stream, " Basic options\n");
126139 fprintf(stream, "\t--%s (-%c) <devicename>\tDevice name to read\n"
127140 "\t\t\t\t\t* Required option\n", "read-device-name", 'N');
@@ -138,11 +151,14 @@
138151 fprintf(stream, "\t--%s (-%c) \t\tRun in daemon mode\n", "daemonize", 'D');
139152 fprintf(stream, "\t--%s (-%c) \t\t\tRun in verbose mode\n", "verbose", 'V');
140153 fprintf(stream, "\t--%s (-%c) \t\t\tDisk check one time\n", "oneshot", 'o');
154+ fprintf(stream, "\t--%s (-%c) \t\tCheck of the disk status check timeout by the thread\n"
155+ "\t\t\t\t\t* Default=60 sec.(Same value as check-timeout parameter)\n"
156+ "\t\t\t\t\t* Invalid at the time of the oneshot parameter designation\n", "exec-thread", 'e');
141157 fprintf(stream, "\t--%s (-%c) \t\t\tThis text\n", "help", '?');
142158 fprintf(stream, " Note: -N, -w options cannot be specified at the same time.\n\n");
143159 fprintf(stream, " Advanced options\n");
144160 fprintf(stream, "\t--%s (-%c) <time[s]>\tDisk status check timeout for select function\n"
145- "\t\t\t\t\t* Default=30 sec.\n", "check-timeout", 't');
161+ "\t\t\t\t\t* Default=60 sec.\n", "check-timeout", 't');
146162 fprintf(stream, "\t--%s (-%c) <times>\t\tDisk status check retry\n"
147163 "\t\t\t\t\t* Default=1 times\n", "retry", 'r');
148164 fprintf(stream, "\t--%s (-%c) <time[s]>\tDisk status check retry interval time\n"
@@ -165,6 +181,10 @@
165181 return FALSE;
166182 }
167183
184+ if (diskd_thread_use == TRUE) {
185+ g_mutex_lock(diskd_mutex);
186+ }
187+
168188 if (new_status == ERROR) {
169189 diskcheck_value = "ERROR";
170190 crm_warn("disk status is changed, attr_name=%s, target=%s, new_status=%s",
@@ -173,9 +193,135 @@
173193 diskcheck_value = "normal";
174194 }
175195 send_update();
196+
197+ if (diskd_thread_use == TRUE) {
198+ g_mutex_unlock(diskd_mutex);
199+ }
200+
176201 return TRUE;
177202 }
178203
204+static void diskd_thread_timer_init()
205+{
206+ if (exec_thread_flag) {
207+ if( ! g_thread_supported()) {
208+
209+ g_thread_init (NULL);
210+
211+ diskd_mutex = g_mutex_new();
212+ diskd_cond = g_cond_new();
213+ if (diskd_mutex && diskd_cond) {
214+ diskd_thread_use = TRUE;
215+ } else {
216+ diskd_thread_timer_variable_free(FALSE);
217+ crm_warn("Failed in the generation of the thread variable. The thread timer is not available.");
218+ }
219+ } else {
220+ crm_warn("The thread timer of diskd is not supported. By this system, I/O blocking may occur by a check of diskd in read/write.");
221+ }
222+ }
223+}
224+
225+static void diskd_thread_timer_variable_free(gboolean bwait)
226+{
227+ int icnt = 0;
228+ int try_max = ((timeout / 2) == 0) ? 1 : (timeout / 2);
229+
230+ if (diskd_mutex != NULL) {
231+ if (bwait) {
232+ /* TODO:
233+ An next error of glib sometimes occurs.
234+ -- ERROR: crm_glib_handler: GThread: file gthread-posix.c: .. error 'Device or resource busy' during... --
235+ We turn on processing to wait for LOCK liberation.
236+ */
237+ while(icnt < try_max){
238+ if (g_mutex_trylock(diskd_mutex) == FALSE) {
239+ crm_warn("Wait for the liberation of the lock of Mutex.(%d < %d)", icnt, try_max);
240+ sleep(1);
241+ } else {
242+ break;
243+ }
244+ icnt++;
245+ }
246+ }
247+ g_mutex_unlock(diskd_mutex);
248+ g_mutex_free(diskd_mutex);
249+ diskd_mutex = NULL;
250+ }
251+
252+ if (diskd_cond != NULL) {
253+ g_cond_free(diskd_cond);
254+ diskd_cond = NULL;
255+ }
256+}
257+
258+static void diskd_thread_timer_end()
259+{
260+ if (diskd_thread_use == FALSE) return;
261+
262+
263+ diskd_thread_timer_variable_free(TRUE);
264+}
265+
266+static void diskd_thread_condsend()
267+{
268+ if (diskd_thread_use == FALSE) return;
269+
270+ if (diskd_mutex && diskd_cond) {
271+ g_mutex_lock(diskd_mutex);
272+ g_cond_broadcast(diskd_cond);
273+ g_mutex_unlock(diskd_mutex);
274+ } else {
275+ crm_warn("Cannot transmit cond to a thread");
276+ }
277+
278+}
279+
280+static void diskd_thread_timer_func(gpointer data)
281+{
282+ GTimeVal gtime;
283+ glong add_time = (timeout) * 1000 * 1000;
284+ gboolean bret;
285+
286+ /* Awaiting a start */
287+ g_mutex_lock(diskd_mutex);
288+
289+ /* A calculation of the waiting time and practice of the timer.(mergin 1s) */
290+ g_get_current_time(&gtime);
291+ g_time_val_add(&gtime, add_time);
292+
293+ bret = g_cond_timed_wait(diskd_cond, diskd_mutex, &gtime);
294+ g_mutex_unlock(diskd_mutex);
295+
296+ if (bret == FALSE){
297+ crm_warn("Timeout Error(s) occurred in diskd timer thread.");
298+ check_status(ERROR);
299+ g_thread_exit(GINT_TO_POINTER(ERROR));
300+ }
301+
302+ crm_debug_2("Received Cond from Main().");
303+ g_thread_exit(GINT_TO_POINTER(normal));
304+}
305+
306+static void diskd_thread_create()
307+{
308+ GError *gerr = NULL;
309+
310+ if (diskd_thread_use) {
311+
312+ g_mutex_lock(diskd_mutex);
313+
314+ th_timer = g_thread_create ((GThreadFunc)diskd_thread_timer_func, NULL, FALSE, &gerr);
315+ if (th_timer == NULL) {
316+ crm_err("Cannot create diskd timer_thread. %s", gerr->message);
317+ g_error_free(gerr);
318+ diskd_thread_use = FALSE;
319+ }
320+
321+ g_mutex_unlock(diskd_mutex);
322+ }
323+}
324+
179325 static int diskcheck_wt(gpointer data)
180326 {
181327 int fd = -1;
@@ -185,6 +331,9 @@
185331 fd_set write_fd_set;
186332
187333 crm_debug_2("diskcheck_wt start");
334+
335+ diskd_thread_create();
336+
188337 for (i = 0; i <= retry; i++) {
189338 if ( i !=0 ) {
190339 sleep(retry_interval);
@@ -207,6 +356,7 @@
207356 if (-1 == remove((const char *)wfile)) {
208357 crm_warn("failed to remove file %s", wfile);
209358 }
359+ diskd_thread_condsend();
210360 check_status(normal);
211361 return normal; /* OK */
212362 } else if (err != WRITE_DATA && errno == EAGAIN) {
@@ -248,6 +398,8 @@
248398 }
249399 /* after for loop */
250400
401+ diskd_thread_condsend();
402+
251403 crm_warn("Error(s) occurred in diskcheck_wt function.");
252404 check_status(ERROR);
253405
@@ -267,6 +419,8 @@
267419
268420 crm_debug_2("diskcheck start");
269421
422+ diskd_thread_create();
423+
270424 for (i = 0; i <= retry; i++) {
271425 if ( i !=0 ) {
272426 sleep(retry_interval);
@@ -290,6 +444,7 @@
290444 if (err == pagesize) {
291445 crm_debug_2("reading form data is OK");
292446 close(fd);
447+ diskd_thread_condsend();
293448 check_status(normal);
294449 return normal;
295450 } else if (err != pagesize && errno == EAGAIN) {
@@ -315,6 +470,8 @@
315470 }
316471 }
317472
473+ diskd_thread_condsend();
474+
318475 crm_warn("Error(s) occurred in diskcheck function.");
319476 check_status(ERROR);
320477
@@ -384,6 +541,7 @@
384541 {"write-check", 0, 0, 'w'}, /* add option 2008.10.24 */
385542 {"write-directory-name", 1, 0, 'd'}, /* add option 2009.4.17 */
386543 {"oneshot", 0, 0, 'o'}, /* add option 2009.10.01 */
544+ {"exec-thread", 0, 0, 'e'}, /* add option 2011.09.30 */
387545
388546 {0, 0, 0, 0}
389547 };
@@ -468,6 +626,9 @@
468626 case 'o': /* add option 2009.10.01 */
469627 oneshot_flag =1;
470628 break;
629+ case 'e': /* add option 2011.09.30 */
630+ exec_thread_flag =1;
631+ break;
471632 case '?':
472633 usage(crm_system_name, LSB_EXIT_GENERIC);
473634 break;
@@ -509,6 +670,7 @@
509670 }
510671
511672 crm_make_daemon(crm_system_name, daemonize, pid_file);
673+ diskd_thread_timer_init();
512674
513675 if ( wflag ) { /* writer */
514676 if (wfile == NULL) {
@@ -546,6 +708,9 @@
546708 if (wfile != NULL) {
547709 crm_free(wfile);
548710 }
711+
712+ diskd_thread_timer_end();
713+
549714 crm_info("Exiting %s", crm_system_name);
550715 return 0;
551716 }
Show on old repository browser