#include "mdadm.h"
#include "md_p.h"
-#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/vfs.h>
#include <linux/magic.h>
+#include <poll.h>
#include <ctype.h>
#include <dirent.h>
#include <signal.h>
aren't permitted). */
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
-static struct dlm_hooks *dlm_hooks = NULL;
static int is_dlm_hooks_ready = 0;
+
+int dlm_funs_ready(void)
+{
+ return is_dlm_hooks_ready ? 1 : 0;
+}
+
+#ifndef MDASSEMBLE
+static struct dlm_hooks *dlm_hooks = NULL;
struct dlm_lock_resource *dlm_lock_res = NULL;
static int ast_called = 0;
struct dlm_lksb lksb;
};
-int dlm_funs_ready(void)
-{
- return is_dlm_hooks_ready ? 1 : 0;
-}
-
/* Using poll(2) to wait for and dispatch ASTs */
static int poll_for_ast(dlm_lshandle_t ls)
{
dlm_lock_res->ls = dlm_hooks->create_lockspace(cluster_name, O_RDWR);
if (!dlm_lock_res->ls) {
pr_err("%s failed to create lockspace\n", cluster_name);
- goto out;
+ return -ENOMEM;
}
- /* Conversions need the lockid in the LKSB */
- if (flags & LKF_CONVERT)
- dlm_lock_res->lksb.sb_lkid = *lockid;
-
snprintf(str, 64, "bitmap%s", cluster_name);
- /* if flags with LKF_CONVERT causes below return ENOENT which means
- * "No such file or directory" */
ret = dlm_hooks->ls_lock(dlm_lock_res->ls, LKM_PWMODE, &dlm_lock_res->lksb,
flags, str, strlen(str), 0, dlm_ast,
dlm_lock_res, NULL, NULL);
if (ret) {
pr_err("error %d when get PW mode on lock %s\n", errno, str);
- goto out;
+ dlm_hooks->release_lockspace(cluster_name, dlm_lock_res->ls, 1);
+ return ret;
}
/* Wait for it to complete */
poll_for_ast(dlm_lock_res->ls);
*lockid = dlm_lock_res->lksb.sb_lkid;
- errno = dlm_lock_res->lksb.sb_status;
- if (errno) {
- pr_err("error %d happened in ast with lock %s\n", errno, str);
- goto out;
- }
-
-out:
- return ret;
+ return dlm_lock_res->lksb.sb_status;
}
int cluster_release_dlmlock(int lockid)
if (!cluster_name)
return -1;
- /* if flags with LKF_CONVERT causes below return EINVAL which means
- * "Invalid argument" */
ret = dlm_hooks->ls_unlock(dlm_lock_res->ls, lockid, 0,
&dlm_lock_res->lksb, dlm_lock_res);
if (ret) {
out:
return ret;
}
+#else
+int cluster_get_dlmlock(int *lockid)
+{
+ return -1;
+}
+int cluster_release_dlmlock(int lockid)
+{
+ return -1;
+}
+#endif
/*
* Parse a 128 bit uuid in 4 integers
return data_disks;
}
-int devnm2devid(char *devnm)
+dev_t devnm2devid(char *devnm)
{
/* First look in /sys/block/$DEVNM/dev for %d:%d
* If that fails, try parsing out a number
int major;
int minor;
- if (!dev) return -1;
+ if (!dev)
+ return -1;
flags |= O_DIRECT;
if (get_maj_min(dev, &major, &minor)) {
int open_dev_flags(char *devnm, int flags)
{
- int devid;
+ dev_t devid;
char buf[20];
devid = devnm2devid(devnm);
char buf[20];
int i;
int flags = O_RDWR;
- int devid = devnm2devid(devnm);
+ dev_t devid = devnm2devid(devnm);
long delay = 1000;
sprintf(buf, "%d:%d", major(devid), minor(devid));
subarray = xstrdup(subarray);
}
strcpy(container, dev);
- if (sra)
- sysfs_free(sra);
+ sysfs_free(sra);
sra = sysfs_read(-1, container, GET_VERSION);
if (sra && sra->text_version[0])
verstr = sra->text_version;
for (i = 0; st == NULL && superlist[i] ; i++)
st = superlist[i]->match_metadata_desc(verstr);
- if (sra)
- sysfs_free(sra);
+ sysfs_free(sra);
if (st) {
st->sb = NULL;
if (subarrayp)
*/
struct superswitch *ss;
struct supertype *st;
- time_t besttime = 0;
+ unsigned int besttime = 0;
int bestsuper = -1;
int i;
dup2(fd, mdfd);
}
+#ifndef MDASSEMBLE
static struct cmap_hooks *cmap_hooks = NULL;
static int is_cmap_hooks_ready = 0;
-#ifndef MDASSEMBLE
void set_cmap_hooks(void)
{
cmap_hooks = xmalloc(sizeof(struct cmap_hooks));