};
extern int get_cluster_name(char **name);
-extern int is_clustered(struct supertype *st);
-extern int cluster_get_dlmlock(struct supertype *st, int *lockid);
-extern int cluster_release_dlmlock(struct supertype *st, int lockid);
+extern int dlm_funs_ready(void);
+extern int cluster_get_dlmlock(int *lockid);
+extern int cluster_release_dlmlock(int lockid);
extern void set_dlm_hooks(void);
#define _ROUND_UP(val, base) (((val) + (base) - 1) & ~(base - 1))
int rv = 0;
int lockid;
struct mdp_superblock_1 *sb = st->sb;
+ bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MAX_SB_SIZE);
- if (is_clustered(st)) {
- rv = cluster_get_dlmlock(st, &lockid);
+ if (bms->version == BITMAP_MAJOR_CLUSTERED && dlm_funs_ready()) {
+ rv = cluster_get_dlmlock(&lockid);
if (rv) {
pr_err("Cannot get dlmlock in %s return %d\n", __func__, rv);
- cluster_release_dlmlock(st, lockid);
+ cluster_release_dlmlock(lockid);
return rv;
}
}
rv = -1;
sb->sb_csum = calc_sb_1_csum(sb);
- if (is_clustered(st))
- cluster_release_dlmlock(st, lockid);
+ if (bms->version == BITMAP_MAJOR_CLUSTERED && dlm_funs_ready())
+ cluster_release_dlmlock(lockid);
return rv;
}
struct mdp_superblock_1 *sb = st->sb;
__u16 *rp = sb->dev_roles + dk->number;
struct devinfo *di, **dip;
+ bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MAX_SB_SIZE);
int rv, lockid;
- if (is_clustered(st)) {
- rv = cluster_get_dlmlock(st, &lockid);
+ if (bms->version == BITMAP_MAJOR_CLUSTERED && dlm_funs_ready()) {
+ rv = cluster_get_dlmlock(&lockid);
if (rv) {
pr_err("Cannot get dlmlock in %s return %d\n", __func__, rv);
- cluster_release_dlmlock(st, lockid);
+ cluster_release_dlmlock(lockid);
return rv;
}
}
di->next = NULL;
*dip = di;
- if (is_clustered(st))
- cluster_release_dlmlock(st, lockid);
+ if (bms->version == BITMAP_MAJOR_CLUSTERED && dlm_funs_ready())
+ cluster_release_dlmlock(lockid);
return 0;
}
struct align_fd afd;
int sbsize;
unsigned long long dsize;
+ bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MAX_SB_SIZE);
int rv, lockid;
- if (is_clustered(st)) {
- rv = cluster_get_dlmlock(st, &lockid);
+ if (bms->version == BITMAP_MAJOR_CLUSTERED && dlm_funs_ready()) {
+ rv = cluster_get_dlmlock(&lockid);
if (rv) {
pr_err("Cannot get dlmlock in %s return %d\n", __func__, rv);
- cluster_release_dlmlock(st, lockid);
+ cluster_release_dlmlock(lockid);
return rv;
}
}
}
}
fsync(fd);
- if (is_clustered(st))
- cluster_release_dlmlock(st, lockid);
+ if (bms->version == BITMAP_MAJOR_CLUSTERED && dlm_funs_ready())
+ cluster_release_dlmlock(lockid);
return 0;
}
struct dlm_lksb lksb;
};
-int is_clustered(struct supertype *st)
+int dlm_funs_ready(void)
{
- /* is it a cluster md or not */
- if (is_dlm_hooks_ready && st->cluster_name)
- return 1;
- else
- return 0;
+ return is_dlm_hooks_ready ? 1 : 0;
}
/* Using poll(2) to wait for and dispatch ASTs */
ast_called = 1;
}
+static char *cluster_name = NULL;
/* Create the lockspace, take bitmapXXX locks on all the bitmaps. */
-int cluster_get_dlmlock(struct supertype *st, int *lockid)
+int cluster_get_dlmlock(int *lockid)
{
int ret = -1;
char str[64];
int flags = LKF_NOQUEUE;
+ ret = get_cluster_name(&cluster_name);
+ if (ret) {
+ pr_err("The md can't get cluster name\n");
+ return -1;
+ }
+
dlm_lock_res = xmalloc(sizeof(struct dlm_lock_resource));
- dlm_lock_res->ls = dlm_hooks->create_lockspace(st->cluster_name, O_RDWR);
+ 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", st->cluster_name);
+ pr_err("%s failed to create lockspace\n", cluster_name);
goto out;
}
if (flags & LKF_CONVERT)
dlm_lock_res->lksb.sb_lkid = *lockid;
- snprintf(str, 64, "bitmap%04d", st->nodes);
+ 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,
return ret;
}
-int cluster_release_dlmlock(struct supertype *st, int lockid)
+int cluster_release_dlmlock(int lockid)
{
int ret = -1;
+ 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,
goto out;
}
- ret = dlm_hooks->release_lockspace(st->cluster_name, dlm_lock_res->ls, 1);
+ ret = dlm_hooks->release_lockspace(cluster_name, dlm_lock_res->ls, 1);
if (ret) {
pr_err("error %d happened when release lockspace\n", errno);
/* XXX make sure the lockspace is released eventually */