11 #include <linux/dlm.h>
12 #include <linux/slab.h>
13 #include <linux/types.h>
71 static inline void gfs2_update_reply_times(
struct gfs2_glock *gl)
74 const unsigned gltype = gl->
gl_name.ln_type;
82 gfs2_update_stats(&gl->
gl_stats, index, rtt);
83 gfs2_update_stats(&lks->
lkstats[gltype], index, rtt);
86 trace_gfs2_glock_lock_time(gl, rtt);
98 static inline void gfs2_update_request_times(
struct gfs2_glock *gl)
101 const unsigned gltype = gl->
gl_name.ln_type;
108 irt = ktime_to_ns(ktime_sub(gl->
gl_dstamp, dstamp));
115 static void gdlm_ast(
void *
arg)
120 gfs2_update_reply_times(gl);
126 switch (gl->
gl_lksb.sb_status) {
164 static void gdlm_bast(
void *arg,
int mode)
186 static int make_mode(
const unsigned int lmstate)
203 static u32 make_flags(
struct gfs2_glock *gl,
const unsigned int gfs_flags,
240 static void gfs2_reverse_hex(
char *
c,
u64 value)
248 static int gdlm_lock(
struct gfs2_glock *gl,
unsigned int req_state,
256 req = make_mode(req_state);
257 lkf = make_flags(gl, flags, req);
261 gfs2_update_request_times(gl);
265 gfs2_reverse_hex(strname + 7, gl->
gl_name.ln_type);
266 gfs2_reverse_hex(strname + 23, gl->
gl_name.ln_number);
277 static void gdlm_put_lock(
struct gfs2_glock *gl)
283 if (gl->
gl_lksb.sb_lkid == 0) {
291 gfs2_update_request_times(gl);
297 (
unsigned long long)gl->
gl_name.ln_number, error);
302 static void gdlm_cancel(
struct gfs2_glock *gl)
448 #define JID_BITMAP_OFFSET 8
468 static int all_jid_bits_clear(
char *lvb)
478 static void sync_wait_cb(
void *arg)
491 fs_err(sdp,
"%s lkid %x error %d\n",
499 fs_err(sdp,
"%s lkid %x status %d\n",
507 unsigned int num,
struct dlm_lksb *lksb,
char *name)
518 0, sync_wait_cb, ls,
NULL);
520 fs_err(sdp,
"%s lkid %x flags %x mode %d error %d\n",
521 name, lksb->
sb_lkid, flags, mode, error);
529 if (status && status != -
EAGAIN) {
530 fs_err(sdp,
"%s lkid %x flags %x mode %d status %d\n",
531 name, lksb->
sb_lkid, flags, mode, status);
537 static int mounted_unlock(
struct gfs2_sbd *sdp)
550 static int control_unlock(
struct gfs2_sbd *sdp)
600 if (block_gen == start_gen)
617 fs_err(sdp,
"control lock EX error %d\n", error);
621 control_lvb_read(ls, &lvb_gen, lvb_bits);
626 fs_info(sdp,
"recover generation %u block1 %u %u\n",
635 if (lvb_gen <= start_gen) {
645 for (i = 0; i < recover_size; i++) {
659 if (lvb_gen == start_gen) {
663 for (i = 0; i < recover_size; i++) {
669 }
else if (lvb_gen < start_gen) {
673 for (i = 0; i < recover_size; i++) {
692 control_lvb_write(ls, start_gen, lvb_bits);
700 fs_err(sdp,
"control lock NL error %d\n", error);
711 for (i = 0; i < recover_size; i++) {
713 fs_info(sdp,
"recover generation %u jid %d\n",
733 fs_info(sdp,
"recover generation %u done\n", start_gen);
736 fs_info(sdp,
"recover generation %u block2 %u %u\n",
742 static int control_mount(
struct gfs2_sbd *sdp)
746 uint32_t start_gen, block_gen, mount_gen, lvb_gen;
761 fs_err(sdp,
"control_mount control_lock NL error %d\n", error);
767 fs_err(sdp,
"control_mount mounted_lock NL error %d\n", error);
774 if (retries++ && signal_pending(
current)) {
809 fs_err(sdp,
"control_mount control_lock EX error %d\n", error);
817 }
else if (error != -
EAGAIN) {
818 fs_err(sdp,
"control_mount mounted_lock EX error %d\n", error);
828 fs_err(sdp,
"control_mount mounted_lock PR error %d\n", error);
844 control_lvb_read(ls, &lvb_gen, lvb_bits);
846 if (lvb_gen == 0xFFFFFFFF) {
848 fs_err(sdp,
"control_mount control_lock disabled\n");
860 fs_info(sdp,
"first mounter control generation %u\n", lvb_gen);
874 if (!all_jid_bits_clear(lvb_bits)) {
876 fs_info(sdp,
"control_mount wait for journal recovery\n");
885 if (lvb_gen < mount_gen) {
888 fs_info(sdp,
"control_mount wait1 block %u start %u mount %u "
889 "lvb %u flags %lx\n", block_gen, start_gen, mount_gen,
895 if (lvb_gen != start_gen) {
898 fs_info(sdp,
"control_mount wait2 block %u start %u mount %u "
899 "lvb %u flags %lx\n", block_gen, start_gen, mount_gen,
905 if (block_gen == start_gen) {
907 fs_info(sdp,
"control_mount wait3 block %u start %u mount %u "
908 "lvb %u flags %lx\n", block_gen, start_gen, mount_gen,
927 static int dlm_recovery_wait(
void *
word)
933 static int control_first_done(
struct gfs2_sbd *sdp)
949 fs_err(sdp,
"control_first_done start %u block %u flags %lx\n",
956 if (start_gen == block_gen) {
965 fs_info(sdp,
"control_first_done wait gen %u\n", start_gen);
978 memset(lvb_bits, 0,
sizeof(lvb_bits));
979 control_lvb_write(ls, start_gen, lvb_bits);
983 fs_err(sdp,
"control_first_done mounted PR error %d\n", error);
987 fs_err(sdp,
"control_first_done control NL error %d\n", error);
998 #define RECOVER_SIZE_INC 16
1011 if (max_jid < slots[i].
slot - 1)
1012 max_jid = slots[
i].
slot - 1;
1017 if (old_size >= max_jid + 1)
1024 if (!submit || !result) {
1053 static void gdlm_recover_prep(
void *arg)
1074 static void gdlm_recover_slot(
void *arg,
struct dlm_slot *
slot)
1078 int jid = slot->
slot - 1;
1082 fs_err(sdp,
"recover_slot jid %d gen %u short size %d",
1089 fs_info(sdp,
"recover_slot jid %d gen %u prev %u",
1105 set_recover_size(sdp, slots, num_slots);
1112 ls->
ls_jid = our_slot - 1;
1126 static void gdlm_recovery_result(
struct gfs2_sbd *sdp,
unsigned int jid,
1144 fs_err(sdp,
"recovery_result jid %d short size %d",
1150 fs_info(sdp,
"recover jid %d result %s\n", jid,
1166 .recover_prep = gdlm_recover_prep,
1167 .recover_slot = gdlm_recover_slot,
1168 .recover_done = gdlm_recover_done,
1171 static int gdlm_mount(
struct gfs2_sbd *sdp,
const char *
table)
1177 int error, ops_result;
1193 error = set_recover_size(sdp,
NULL, 0);
1201 fsname =
strchr(table,
':');
1203 fs_info(sdp,
"no fsname found\n");
1207 memset(cluster, 0,
sizeof(cluster));
1218 &gdlm_lockspace_ops, sdp, &ops_result,
1221 fs_err(sdp,
"dlm_new_lockspace error %d\n", error);
1225 if (ops_result < 0) {
1230 fs_info(sdp,
"dlm lockspace ops not used\n");
1231 free_recover_size(ls);
1237 fs_err(sdp,
"dlm lockspace ops disallow jid preset\n");
1247 error = control_mount(sdp);
1249 fs_err(sdp,
"mount control error %d\n", error);
1262 free_recover_size(ls);
1267 static void gdlm_first_done(
struct gfs2_sbd *sdp)
1275 error = control_first_done(sdp);
1277 fs_err(sdp,
"mount first_done error %d\n", error);
1280 static void gdlm_unmount(
struct gfs2_sbd *sdp)
1301 free_recover_size(ls);
1313 .lm_proto_name =
"lock_dlm",
1314 .lm_mount = gdlm_mount,
1315 .lm_first_done = gdlm_first_done,
1316 .lm_recovery_result = gdlm_recovery_result,
1317 .lm_unmount = gdlm_unmount,
1318 .lm_put_lock = gdlm_put_lock,
1319 .lm_lock = gdlm_lock,
1320 .lm_cancel = gdlm_cancel,
1321 .lm_tokens = &dlm_tokens,