#include <sys/utsname.h>
#include <sys/wait.h>
#include <sys/un.h>
+#include <sys/resource.h>
#include <ctype.h>
#include <dirent.h>
#include <signal.h>
size = sb[4]|(sb[5]|(sb[6]|sb[7]<<8)<<8)<<8;
pr_err("%s appears to contain an ext2fs file system\n",
name);
- fprintf(stderr," size=%dK mtime=%s",
+ cont_err("size=%dK mtime=%s",
size*(1<<bsize), ctime(&mtime));
return 1;
}
return 0;
pr_err("%s appears to contain a reiserfs file system\n",name);
size = sb[0]|(sb[1]|(sb[2]|sb[3]<<8)<<8)<<8;
- fprintf(stderr, " size = %luK\n", size*4);
+ cont_err("size = %luK\n", size*4);
return 1;
}
crtime = info.array.ctime;
level = map_num(pers, info.array.level);
if (!level) level = "-unknown-";
- fprintf(stderr, " level=%s devices=%d ctime=%s",
- level, info.array.raid_disks, ctime(&crtime));
+ cont_err("level=%s devices=%d ctime=%s",
+ level, info.array.raid_disks, ctime(&crtime));
return 1;
}
return data_disks;
}
-#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
-
int devnm2devid(char *devnm)
{
/* First look in /sys/block/$DEVNM/dev for %d:%d
return 0;
}
+#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
char *get_md_name(char *devnm)
{
/* find /dev/md%d or /dev/md/%d or make a device /dev/.tmp.md%d */
int i;
int flags = O_RDWR;
int devid = devnm2devid(devnm);
+ long delay = 1000;
sprintf(buf, "%d:%d", major(devid), minor(devid));
for (i = 0 ; i < 25 ; i++) {
}
if (errno != EBUSY)
return fd;
- usleep(200000);
+ usleep(delay);
+ if (delay < 200000)
+ delay *= 2;
}
return -1;
}
{
int i;
struct stat stb_want;
+ long delay = 1000;
if (fstat(fd, &stb_want) != 0 ||
(stb_want.st_mode & S_IFMT) != S_IFBLK)
(stb.st_mode & S_IFMT) == S_IFBLK &&
(stb.st_rdev == stb_want.st_rdev))
return;
- usleep(200000);
+ usleep(delay);
+ if (delay < 200000)
+ delay *= 2;
}
if (i == 25)
dprintf("%s: timeout waiting for %s\n", __func__, dev);
else
skipped = 0;
+ /* Don't want to see error messages from systemctl.
+ * If the service doesn't exist, we start mdmon ourselves.
+ */
+ close(2);
+ open("/dev/null", O_WRONLY);
snprintf(pathbuf, sizeof(pathbuf), "mdmon@%s.service",
devnm);
status = execl("/usr/bin/systemctl", "systemctl", "start",
return 0;
}
-int check_env(char *name)
-{
- char *val = getenv(name);
-
- if (val && atoi(val) == 1)
- return 1;
-
- return 0;
-}
-
__u32 random32(void)
{
__u32 rv;
return 0;
return 1;
}
+
+/* Make sure we can open as many devices as needed */
+void enable_fds(int devices)
+{
+ unsigned int fds = 20 + devices;
+ struct rlimit lim;
+ if (getrlimit(RLIMIT_NOFILE, &lim) != 0
+ || lim.rlim_cur >= fds)
+ return;
+ if (lim.rlim_max < fds)
+ lim.rlim_max = fds;
+ lim.rlim_cur = fds;
+ setrlimit(RLIMIT_NOFILE, &lim);
+}