Index: ocfs2-tools/ocfs2_controld/main.c =================================================================== --- ocfs2-tools.orig/ocfs2_controld/main.c +++ ocfs2-tools/ocfs2_controld/main.c @@ -948,6 +948,68 @@ static void cpg_joined(int first) } } +static int find_minors(void) +{ + FILE *fl; + char name[256]; + uint32_t number; + int c; + int control_minor = 0; + + if (!(fl = fopen("/proc/misc", "r"))) { + log_error("failed to open /proc/misc: %s", strerror(errno)); + goto out; + } + + while (!feof(fl)) { + if (fscanf(fl, "%d %255s\n", &number, &name[0]) == 2) { + if (!strcmp(name, "ocfs2_control")) + control_minor = number; + } else do { + c = fgetc(fl); + } while (c != EOF && c != '\n'); + + if (control_minor) + break; + } + fclose(fl); + + if (!control_minor) + log_error("Is ocfs2 missing from kernel? No misc devices found"); +out: + return control_minor; +} + +static int find_udev_device(const char *path, uint32_t minor) +{ + struct stat st; + int i; + + for (i = 0; i < 10; i++) { + if (stat(path, &st) == 0 && minor(st.st_rdev) == minor) + return 0; + sleep(1); + } + + log_error("cannot find device %s with minor %d", path, minor); + return -1; +} + +static int setup_misc_device(void) +{ + int rv = -1; + int control_minor = find_minors(); + + if (control_minor) { + rv = find_udev_device("/dev/misc/ocfs2_control", control_minor); + if (rv < 0) + return rv; + log_debug("found /dev/misc/ocfs2_control %u", control_minor); + } + + return rv; +} + static int loop(void) { int rv, i, poll_timeout = -1; @@ -968,6 +1030,10 @@ static int loop(void) if (rv < 0) goto out; + rv = setup_misc_device(); + if (rv < 0) + goto out; + rv = setup_cpg(cpg_joined); if (rv < 0) goto out;