11 #include <linux/wait.h>
12 #include <linux/module.h>
15 #include <linux/poll.h>
16 #include <linux/signal.h>
18 #include <linux/dlm.h>
20 #include <linux/slab.h>
29 static const char name_prefix[] =
"dlm";
32 static int dlm_monitor_unused = 1;
36 struct dlm_lock_params32 {
54 struct dlm_write_request32 {
61 struct dlm_lock_params32
lock;
74 struct dlm_lock_result32 {
80 struct dlm_lksb32 lksb;
88 struct dlm_write_request32 *kb32,
91 kb->
version[0] = kb32->version[0];
92 kb->
version[1] = kb32->version[1];
93 kb->
version[2] = kb32->version[2];
99 kb->
i.
lspace.flags = kb32->i.lspace.flags;
100 kb->
i.
lspace.minor = kb32->i.lspace.minor;
103 kb->
i.
purge.nodeid = kb32->i.purge.nodeid;
104 kb->
i.
purge.pid = kb32->i.purge.pid;
106 kb->
i.
lock.mode = kb32->i.lock.mode;
107 kb->
i.
lock.namelen = kb32->i.lock.namelen;
108 kb->
i.
lock.flags = kb32->i.lock.flags;
109 kb->
i.
lock.lkid = kb32->i.lock.lkid;
110 kb->
i.
lock.parent = kb32->i.lock.parent;
111 kb->
i.
lock.xid = kb32->i.lock.xid;
112 kb->
i.
lock.timeout = kb32->i.lock.timeout;
113 kb->
i.
lock.castparam = (
void *)(
long)kb32->i.lock.castparam;
114 kb->
i.
lock.castaddr = (
void *)(
long)kb32->i.lock.castaddr;
115 kb->
i.
lock.bastparam = (
void *)(
long)kb32->i.lock.bastparam;
116 kb->
i.
lock.bastaddr = (
void *)(
long)kb32->i.lock.bastaddr;
117 kb->
i.
lock.lksb = (
void *)(
long)kb32->i.lock.lksb;
119 memcpy(kb->
i.
lock.name, kb32->i.lock.name, namelen);
124 struct dlm_lock_result32 *res32)
126 res32->version[0] = res->
version[0];
127 res32->version[1] = res->
version[1];
128 res32->version[2] = res->
version[2];
136 res32->length = res->
length;
138 res32->lksb.sb_status = res->
lksb.sb_status;
139 res32->lksb.sb_flags = res->
lksb.sb_flags;
140 res32->lksb.sb_lkid = res->
lksb.sb_lkid;
141 res32->lksb.sb_lvbptr = (
__u32)(
long)res->
lksb.sb_lvbptr;
156 static int lkb_is_endoflife(
int mode,
int status)
205 if ((flags &
DLM_CB_CAST) && lkb_is_endoflife(mode, status))
267 (
unsigned long) params->
timeout);
272 (
unsigned long) params->
timeout);
274 error = ua->
lksb.sb_lkid;
326 static int dlm_device_register(
struct dlm_ls *ls,
char *
name)
405 error = dlm_device_register(ls, params->
name);
456 "user (%d.%d.%d) kernel (%d.%d.%d)\n",
492 size_t count, loff_t *ppos)
500 if (count <
sizeof(
struct dlm_write_request32))
513 kbuf = kzalloc(count + 1,
GFP_NOFS);
522 if (check_version(kbuf)) {
529 struct dlm_write_request32 *k32buf;
532 if (count >
sizeof(
struct dlm_write_request32))
533 namelen = count -
sizeof(
struct dlm_write_request32);
535 k32buf = (
struct dlm_write_request32 *)kbuf;
548 compat_input(kbuf, k32buf, namelen);
560 sigfillset(&allsigs);
569 log_print(
"no locking on control device");
572 error = device_user_lock(proc, &kbuf->
i.
lock);
577 log_print(
"no locking on control device");
580 error = device_user_unlock(proc, &kbuf->
i.
lock);
585 log_print(
"no locking on control device");
588 error = device_user_deadlock(proc, &kbuf->
i.
lock);
593 log_print(
"create/remove only on control device");
596 error = device_create_lockspace(&kbuf->
i.
lspace);
601 log_print(
"create/remove only on control device");
604 error = device_remove_lockspace(&kbuf->
i.
lspace);
609 log_print(
"no locking on control device");
612 error = device_user_purge(proc, &kbuf->
i.
purge);
616 log_print(
"Unknown command passed to DLM device : %d\n",
631 static int device_open(
struct inode *
inode,
struct file *file)
647 INIT_LIST_HEAD(&proc->
asts);
648 INIT_LIST_HEAD(&proc->
locks);
658 static int device_close(
struct inode *inode,
struct file *file)
668 sigfillset(&allsigs);
694 static int copy_result_to_user(
struct dlm_user_args *ua,
int compat,
696 char __user *buf,
size_t count)
699 struct dlm_lock_result32 result32;
731 len =
sizeof(
struct dlm_lock_result32);
755 compat_output(&
result, &result32);
756 resultptr = &result32;
768 static int copy_version_to_user(
char __user *buf,
size_t count)
784 static ssize_t device_read(
struct file *file,
char __user *buf,
size_t count,
791 int rv, resid, copy_lvb = 0;
794 rv = copy_version_to_user(buf, count);
799 log_print(
"non-version read from control device %zu", count);
804 if (count <
sizeof(
struct dlm_lock_result32))
817 if (list_empty(&proc->
asts)) {
827 if (list_empty(&proc->
asts) && !signal_pending(
current)) {
871 int old_mode, new_mode;
876 if (!
cb.sb_status && lkb->
lkb_lksb->sb_lvbptr &&
884 rv = copy_result_to_user(lkb->
lkb_ua,
886 cb.flags,
cb.mode, copy_lvb, buf, count);
895 static unsigned int device_poll(
struct file *file,
poll_table *
wait)
899 poll_wait(file, &proc->
wait, wait);
902 if (!list_empty(&proc->
asts)) {
924 if (dlm_monitor_unused)
930 static int ctl_device_open(
struct inode *inode,
struct file *file)
936 static int ctl_device_close(
struct inode *inode,
struct file *file)
941 static int monitor_device_open(
struct inode *inode,
struct file *file)
944 dlm_monitor_unused = 0;
948 static int monitor_device_close(
struct inode *inode,
struct file *file)
957 .release = device_close,
959 .write = device_write,
966 .open = ctl_device_open,
967 .release = ctl_device_close,
969 .write = device_write,
975 .name =
"dlm-control",
976 .fops = &ctl_device_fops,
981 .open = monitor_device_open,
982 .release = monitor_device_close,
988 .name =
"dlm-monitor",
989 .fops = &monitor_device_fops,
1001 log_print(
"misc_register failed for control device");
1007 log_print(
"misc_register failed for monitor device");