11 #include <linux/poll.h>
12 #include <linux/dlm.h>
13 #include <linux/dlm_plock.h>
14 #include <linux/slab.h>
50 (DLM_PLOCK_VERSION_MINOR < info->
version[1])) {
51 log_print(
"plock device version mismatch: "
52 "kernel (%u.%u.%u), user (%u.%u.%u)",
66 set_version(&op->
info);
67 INIT_LIST_HEAD(&op->
list);
70 spin_unlock(&ops_lock);
80 static void do_unlock_close(
struct dlm_ls *ls,
u64 number,
92 op->
info.number = number;
116 xop = kzalloc(
sizeof(*xop),
GFP_NOFS);
128 op->
info.number = number;
150 log_debug(ls,
"dlm_posix_lock: wait killed %llx",
151 (
unsigned long long)number);
152 spin_lock(&ops_lock);
154 spin_unlock(&ops_lock);
156 do_unlock_close(ls, number, file, fl);
164 spin_lock(&ops_lock);
165 if (!list_empty(&op->
list)) {
166 log_error(ls,
"dlm_posix_lock: op on list %llx",
167 (
unsigned long long)number);
170 spin_unlock(&ops_lock);
176 log_error(ls,
"dlm_posix_lock: vfs lock error %llx",
177 (
unsigned long long)number);
188 static int dlm_plock_callback(
struct plock_op *op)
197 spin_lock(&ops_lock);
198 if (!list_empty(&op->
list)) {
199 log_print(
"dlm_plock_callback: op on list %llx",
200 (
unsigned long long)op->
info.number);
203 spin_unlock(&ops_lock);
227 log_print(
"dlm_plock_callback: vfs lock error %llx file %p fl %p",
228 (
unsigned long long)op->
info.number, file, fl);
234 log_print(
"dlm_plock_callback: lock granted after lock request "
235 "failed; dangling lock!\n");
255 op = kzalloc(
sizeof(*op),
GFP_NOFS);
262 log_error(ls,
"dlm_posix_unlock: vfs unlock error %llx",
263 (
unsigned long long)number);
268 op->
info.number = number;
286 spin_lock(&ops_lock);
287 if (!list_empty(&op->
list)) {
288 log_error(ls,
"dlm_posix_unlock: op on list %llx",
289 (
unsigned long long)number);
292 spin_unlock(&ops_lock);
317 op = kzalloc(
sizeof(*op),
GFP_NOFS);
327 op->
info.number = number;
338 spin_lock(&ops_lock);
339 if (!list_empty(&op->
list)) {
340 log_error(ls,
"dlm_posix_get: op on list %llx",
341 (
unsigned long long)number);
344 spin_unlock(&ops_lock);
372 static ssize_t dev_read(
struct file *file,
char __user *
u,
size_t count,
378 if (count <
sizeof(info))
381 spin_lock(&ops_lock);
382 if (!list_empty(&send_list)) {
387 list_move(&op->
list, &recv_list);
390 spin_unlock(&ops_lock);
409 static ssize_t dev_write(
struct file *file,
const char __user *u,
size_t count,
414 int found = 0, do_callback = 0;
416 if (count !=
sizeof(info))
422 if (check_version(&info))
425 spin_lock(&ops_lock);
431 list_del_init(&op->
list);
441 spin_unlock(&ops_lock);
445 dlm_plock_callback(op);
450 (
unsigned long long)info.
number);
456 unsigned int mask = 0;
458 poll_wait(file, &send_wq, wait);
460 spin_lock(&ops_lock);
461 if (!list_empty(&send_list))
463 spin_unlock(&ops_lock);
487 INIT_LIST_HEAD(&send_list);
488 INIT_LIST_HEAD(&recv_list);
494 log_print(
"dlm_plock_init: misc_register failed %d", rv);
501 log_print(
"dlm_plock_exit: misc_deregister failed");