#include <fcntl.h>
#include <signal.h>
#include <dirent.h>
-
+#ifdef USE_PTHREADS
+#include <pthread.h>
+#else
#include <sched.h>
+#endif
#include "mdadm.h"
#include "mdmon.h"
int sigterm;
-int run_child(void *v)
+#ifdef USE_PTHREADS
+static void *run_child(void *v)
+{
+ struct supertype *c = v;
+
+ mon_tid = syscall(SYS_gettid);
+ do_monitor(c);
+ return 0;
+}
+
+static int clone_monitor(struct supertype *container)
+{
+ pthread_attr_t attr;
+ pthread_t thread;
+ int rc;
+
+ mon_tid = -1;
+ pthread_attr_init(&attr);
+ pthread_attr_setstacksize(&attr, 4096);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ rc = pthread_create(&thread, &attr, run_child, container);
+ if (rc)
+ return rc;
+ while (mon_tid == -1)
+ usleep(10);
+ pthread_attr_destroy(&attr);
+
+ mgr_tid = syscall(SYS_gettid);
+
+ return mon_tid;
+}
+#else /* USE_PTHREADS */
+static int run_child(void *v)
{
struct supertype *c = v;
int flags, void *arg, ...
/* pid_t *pid, struct user_desc *tls, pid_t *ctid */ );
#endif
- int clone_monitor(struct supertype *container)
+static int clone_monitor(struct supertype *container)
{
static char stack[4096];
return mon_tid;
}
-
-static struct superswitch *find_metadata_methods(char *vers)
-{
- if (strcmp(vers, "ddf") == 0)
- return &super_ddf;
- if (strcmp(vers, "imsm") == 0)
- return &super_imsm;
- return NULL;
-}
+#endif /* USE_PTHREADS */
static int make_pidfile(char *devname)
{
return 0;
}
-int is_container_member(struct mdstat_ent *mdstat, char *container)
-{
- if (mdstat->metadata_version == NULL ||
- strncmp(mdstat->metadata_version, "external:", 9) != 0 ||
- !is_subarray(mdstat->metadata_version+9) ||
- strncmp(mdstat->metadata_version+10, container, strlen(container)) != 0 ||
- mdstat->metadata_version[10+strlen(container)] != '/')
- return 0;
-
- return 1;
-}
-
static void try_kill_monitor(pid_t pid, char *devname, int sock)
{
char buf[100];
exit(3);
}
- mdi = sysfs_read(mdfd, container->devnum,
- GET_VERSION|GET_LEVEL|GET_DEVS|SKIP_GONE_DEVS);
+ mdi = sysfs_read(mdfd, container->devnum, GET_VERSION|GET_LEVEL|GET_DEVS);
if (!mdi) {
fprintf(stderr, "mdmon: failed to load sysfs info for %s\n",
exit(3);
}
- container->ss = find_metadata_methods(mdi->text_version);
+ container->ss = version_to_superswitch(mdi->text_version);
if (container->ss == NULL) {
- fprintf(stderr, "mdmon: %s uses unknown metadata: %s\n",
+ fprintf(stderr, "mdmon: %s uses unsupported metadata: %s\n",
devname, mdi->text_version);
exit(3);
}