Skip to content

Commit dc68c7e

Browse files
committed
dlm: detect available userspace daemon
If dlm_controld (the userspace daemon that controls the setup and recovery of the dlm) fails, the kernel should shut down the lockspaces in the kernel rather than leaving them running. This is detected by having dlm_controld hold a misc device open while running, and if the kernel detects a close while the daemon is still needed, it stops the lockspaces in the kernel. Knowing that the userspace daemon isn't running also allows the lockspace create/remove routines to avoid waiting on the daemon for join/leave operations. Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 0f8e0d9 commit dc68c7e

4 files changed

Lines changed: 85 additions & 2 deletions

File tree

‎fs/dlm/lockspace.c‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
378378
if (!try_module_get(THIS_MODULE))
379379
return -EINVAL;
380380

381+
if (!dlm_user_daemon_available()) {
382+
module_put(THIS_MODULE);
383+
return -EUNATCH;
384+
}
385+
381386
error = 0;
382387

383388
spin_lock(&lslist_lock);
@@ -669,7 +674,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)
669674

670675
dlm_device_deregister(ls);
671676

672-
if (force < 3)
677+
if (force < 3 && dlm_user_daemon_available())
673678
do_uevent(ls, 0);
674679

675680
dlm_recoverd_stop(ls);
@@ -791,3 +796,20 @@ int dlm_release_lockspace(void *lockspace, int force)
791796
return error;
792797
}
793798

799+
void dlm_stop_lockspaces(void)
800+
{
801+
struct dlm_ls *ls;
802+
803+
restart:
804+
spin_lock(&lslist_lock);
805+
list_for_each_entry(ls, &lslist, ls_list) {
806+
if (!test_bit(LSFL_RUNNING, &ls->ls_flags))
807+
continue;
808+
spin_unlock(&lslist_lock);
809+
log_error(ls, "no userland control daemon, stopping lockspace");
810+
dlm_ls_stop(ls);
811+
goto restart;
812+
}
813+
spin_unlock(&lslist_lock);
814+
}
815+

‎fs/dlm/lockspace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct dlm_ls *dlm_find_lockspace_global(uint32_t id);
2020
struct dlm_ls *dlm_find_lockspace_local(void *id);
2121
struct dlm_ls *dlm_find_lockspace_device(int minor);
2222
void dlm_put_lockspace(struct dlm_ls *ls);
23+
void dlm_stop_lockspaces(void);
2324

2425
#endif /* __LOCKSPACE_DOT_H__ */
2526

‎fs/dlm/user.c‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
static const char name_prefix[] = "dlm";
2929
static const struct file_operations device_fops;
30+
static atomic_t dlm_monitor_opened;
31+
static int dlm_monitor_unused = 1;
3032

3133
#ifdef CONFIG_COMPAT
3234

@@ -890,6 +892,26 @@ static unsigned int device_poll(struct file *file, poll_table *wait)
890892
return 0;
891893
}
892894

895+
int dlm_user_daemon_available(void)
896+
{
897+
/* dlm_controld hasn't started (or, has started, but not
898+
properly populated configfs) */
899+
900+
if (!dlm_our_nodeid())
901+
return 0;
902+
903+
/* This is to deal with versions of dlm_controld that don't
904+
know about the monitor device. We assume that if the
905+
dlm_controld was started (above), but the monitor device
906+
was never opened, that it's an old version. dlm_controld
907+
should open the monitor device before populating configfs. */
908+
909+
if (dlm_monitor_unused)
910+
return 1;
911+
912+
return atomic_read(&dlm_monitor_opened) ? 1 : 0;
913+
}
914+
893915
static int ctl_device_open(struct inode *inode, struct file *file)
894916
{
895917
cycle_kernel_lock();
@@ -902,6 +924,20 @@ static int ctl_device_close(struct inode *inode, struct file *file)
902924
return 0;
903925
}
904926

927+
static int monitor_device_open(struct inode *inode, struct file *file)
928+
{
929+
atomic_inc(&dlm_monitor_opened);
930+
dlm_monitor_unused = 0;
931+
return 0;
932+
}
933+
934+
static int monitor_device_close(struct inode *inode, struct file *file)
935+
{
936+
if (atomic_dec_and_test(&dlm_monitor_opened))
937+
dlm_stop_lockspaces();
938+
return 0;
939+
}
940+
905941
static const struct file_operations device_fops = {
906942
.open = device_open,
907943
.release = device_close,
@@ -925,19 +961,42 @@ static struct miscdevice ctl_device = {
925961
.minor = MISC_DYNAMIC_MINOR,
926962
};
927963

964+
static const struct file_operations monitor_device_fops = {
965+
.open = monitor_device_open,
966+
.release = monitor_device_close,
967+
.owner = THIS_MODULE,
968+
};
969+
970+
static struct miscdevice monitor_device = {
971+
.name = "dlm-monitor",
972+
.fops = &monitor_device_fops,
973+
.minor = MISC_DYNAMIC_MINOR,
974+
};
975+
928976
int __init dlm_user_init(void)
929977
{
930978
int error;
931979

980+
atomic_set(&dlm_monitor_opened, 0);
981+
932982
error = misc_register(&ctl_device);
933-
if (error)
983+
if (error) {
934984
log_print("misc_register failed for control device");
985+
goto out;
986+
}
935987

988+
error = misc_register(&monitor_device);
989+
if (error) {
990+
log_print("misc_register failed for monitor device");
991+
misc_deregister(&ctl_device);
992+
}
993+
out:
936994
return error;
937995
}
938996

939997
void dlm_user_exit(void)
940998
{
941999
misc_deregister(&ctl_device);
1000+
misc_deregister(&monitor_device);
9421001
}
9431002

‎fs/dlm/user.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, int type);
1313
int dlm_user_init(void);
1414
void dlm_user_exit(void);
1515
int dlm_device_deregister(struct dlm_ls *ls);
16+
int dlm_user_daemon_available(void);
1617

1718
#endif

0 commit comments

Comments
 (0)