| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2005 Red Hat, Inc.  All rights reserved. | 
 | 3 |  * | 
 | 4 |  * This copyrighted material is made available to anyone wishing to use, | 
 | 5 |  * modify, copy, or redistribute it subject to the terms and conditions | 
| Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 6 |  * of the GNU General Public License version 2. | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 7 |  */ | 
 | 8 |  | 
 | 9 | #include <linux/miscdevice.h> | 
 | 10 | #include <linux/lock_dlm_plock.h> | 
| Al Viro | bd01f84 | 2006-10-19 17:23:57 -0400 | [diff] [blame] | 11 | #include <linux/poll.h> | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 12 |  | 
 | 13 | #include "lock_dlm.h" | 
 | 14 |  | 
 | 15 |  | 
 | 16 | static spinlock_t ops_lock; | 
 | 17 | static struct list_head send_list; | 
 | 18 | static struct list_head recv_list; | 
 | 19 | static wait_queue_head_t send_wq; | 
 | 20 | static wait_queue_head_t recv_wq; | 
 | 21 |  | 
 | 22 | struct plock_op { | 
 | 23 | 	struct list_head list; | 
 | 24 | 	int done; | 
 | 25 | 	struct gdlm_plock_info info; | 
 | 26 | }; | 
 | 27 |  | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 28 | struct plock_xop { | 
 | 29 | 	struct plock_op xop; | 
 | 30 | 	void *callback; | 
 | 31 | 	void *fl; | 
 | 32 | 	void *file; | 
 | 33 | 	struct file_lock flc; | 
 | 34 | }; | 
 | 35 |  | 
 | 36 |  | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 37 | static inline void set_version(struct gdlm_plock_info *info) | 
 | 38 | { | 
 | 39 | 	info->version[0] = GDLM_PLOCK_VERSION_MAJOR; | 
 | 40 | 	info->version[1] = GDLM_PLOCK_VERSION_MINOR; | 
 | 41 | 	info->version[2] = GDLM_PLOCK_VERSION_PATCH; | 
 | 42 | } | 
 | 43 |  | 
 | 44 | static int check_version(struct gdlm_plock_info *info) | 
 | 45 | { | 
 | 46 | 	if ((GDLM_PLOCK_VERSION_MAJOR != info->version[0]) || | 
 | 47 | 	    (GDLM_PLOCK_VERSION_MINOR < info->version[1])) { | 
 | 48 | 		log_error("plock device version mismatch: " | 
 | 49 | 			  "kernel (%u.%u.%u), user (%u.%u.%u)", | 
 | 50 | 			  GDLM_PLOCK_VERSION_MAJOR, | 
 | 51 | 			  GDLM_PLOCK_VERSION_MINOR, | 
 | 52 | 			  GDLM_PLOCK_VERSION_PATCH, | 
 | 53 | 			  info->version[0], | 
 | 54 | 			  info->version[1], | 
 | 55 | 			  info->version[2]); | 
 | 56 | 		return -EINVAL; | 
 | 57 | 	} | 
 | 58 | 	return 0; | 
 | 59 | } | 
 | 60 |  | 
 | 61 | static void send_op(struct plock_op *op) | 
 | 62 | { | 
 | 63 | 	set_version(&op->info); | 
 | 64 | 	INIT_LIST_HEAD(&op->list); | 
 | 65 | 	spin_lock(&ops_lock); | 
 | 66 | 	list_add_tail(&op->list, &send_list); | 
 | 67 | 	spin_unlock(&ops_lock); | 
 | 68 | 	wake_up(&send_wq); | 
 | 69 | } | 
 | 70 |  | 
| Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 71 | int gdlm_plock(void *lockspace, struct lm_lockname *name, | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 72 | 	       struct file *file, int cmd, struct file_lock *fl) | 
 | 73 | { | 
| Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 74 | 	struct gdlm_ls *ls = lockspace; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 75 | 	struct plock_op *op; | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 76 | 	struct plock_xop *xop; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 77 | 	int rv; | 
 | 78 |  | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 79 | 	xop = kzalloc(sizeof(*xop), GFP_KERNEL); | 
 | 80 | 	if (!xop) | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 81 | 		return -ENOMEM; | 
 | 82 |  | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 83 | 	op = &xop->xop; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 84 | 	op->info.optype		= GDLM_PLOCK_OP_LOCK; | 
| David Teigland | 3a2a9c9 | 2006-04-25 15:45:51 -0400 | [diff] [blame] | 85 | 	op->info.pid		= fl->fl_pid; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 86 | 	op->info.ex		= (fl->fl_type == F_WRLCK); | 
 | 87 | 	op->info.wait		= IS_SETLKW(cmd); | 
 | 88 | 	op->info.fsid		= ls->id; | 
 | 89 | 	op->info.number		= name->ln_number; | 
 | 90 | 	op->info.start		= fl->fl_start; | 
 | 91 | 	op->info.end		= fl->fl_end; | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 92 | 	if (fl->fl_lmops && fl->fl_lmops->fl_grant) { | 
| David Teigland | 2066b58 | 2007-12-06 09:35:25 -0600 | [diff] [blame] | 93 | 		/* fl_owner is lockd which doesn't distinguish | 
 | 94 | 		   processes on the nfs client */ | 
 | 95 | 		op->info.owner	= (__u64) fl->fl_pid; | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 96 | 		xop->callback	= fl->fl_lmops->fl_grant; | 
 | 97 | 		locks_init_lock(&xop->flc); | 
 | 98 | 		locks_copy_lock(&xop->flc, fl); | 
 | 99 | 		xop->fl		= fl; | 
 | 100 | 		xop->file	= file; | 
| David Teigland | 2066b58 | 2007-12-06 09:35:25 -0600 | [diff] [blame] | 101 | 	} else { | 
 | 102 | 		op->info.owner	= (__u64)(long) fl->fl_owner; | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 103 | 		xop->callback	= NULL; | 
| David Teigland | 2066b58 | 2007-12-06 09:35:25 -0600 | [diff] [blame] | 104 | 	} | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 105 |  | 
 | 106 | 	send_op(op); | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 107 |  | 
 | 108 | 	if (xop->callback == NULL) | 
 | 109 | 		wait_event(recv_wq, (op->done != 0)); | 
 | 110 | 	else | 
 | 111 | 		return -EINPROGRESS; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 112 |  | 
 | 113 | 	spin_lock(&ops_lock); | 
 | 114 | 	if (!list_empty(&op->list)) { | 
| Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 115 | 		printk(KERN_INFO "plock op on list\n"); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 116 | 		list_del(&op->list); | 
 | 117 | 	} | 
 | 118 | 	spin_unlock(&ops_lock); | 
 | 119 |  | 
 | 120 | 	rv = op->info.rv; | 
 | 121 |  | 
 | 122 | 	if (!rv) { | 
 | 123 | 		if (posix_lock_file_wait(file, fl) < 0) | 
 | 124 | 			log_error("gdlm_plock: vfs lock error %x,%llx", | 
| David Teigland | 9229f01 | 2006-05-24 09:21:30 -0400 | [diff] [blame] | 125 | 				  name->ln_type, | 
 | 126 | 				  (unsigned long long)name->ln_number); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 127 | 	} | 
 | 128 |  | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 129 | 	kfree(xop); | 
 | 130 | 	return rv; | 
 | 131 | } | 
 | 132 |  | 
 | 133 | /* Returns failure iff a succesful lock operation should be canceled */ | 
 | 134 | static int gdlm_plock_callback(struct plock_op *op) | 
 | 135 | { | 
 | 136 | 	struct file *file; | 
 | 137 | 	struct file_lock *fl; | 
 | 138 | 	struct file_lock *flc; | 
 | 139 | 	int (*notify)(void *, void *, int) = NULL; | 
 | 140 | 	struct plock_xop *xop = (struct plock_xop *)op; | 
 | 141 | 	int rv = 0; | 
 | 142 |  | 
 | 143 | 	spin_lock(&ops_lock); | 
 | 144 | 	if (!list_empty(&op->list)) { | 
 | 145 | 		printk(KERN_INFO "plock op on list\n"); | 
 | 146 | 		list_del(&op->list); | 
 | 147 | 	} | 
 | 148 | 	spin_unlock(&ops_lock); | 
 | 149 |  | 
 | 150 | 	/* check if the following 2 are still valid or make a copy */ | 
 | 151 | 	file = xop->file; | 
 | 152 | 	flc = &xop->flc; | 
 | 153 | 	fl = xop->fl; | 
 | 154 | 	notify = xop->callback; | 
 | 155 |  | 
 | 156 | 	if (op->info.rv) { | 
 | 157 | 		notify(flc, NULL, op->info.rv); | 
 | 158 | 		goto out; | 
 | 159 | 	} | 
 | 160 |  | 
 | 161 | 	/* got fs lock; bookkeep locally as well: */ | 
 | 162 | 	flc->fl_flags &= ~FL_SLEEP; | 
 | 163 | 	if (posix_lock_file(file, flc, NULL)) { | 
 | 164 | 		/* | 
 | 165 | 		 * This can only happen in the case of kmalloc() failure. | 
 | 166 | 		 * The filesystem's own lock is the authoritative lock, | 
 | 167 | 		 * so a failure to get the lock locally is not a disaster. | 
 | 168 | 		 * As long as GFS cannot reliably cancel locks (especially | 
 | 169 | 		 * in a low-memory situation), we're better off ignoring | 
 | 170 | 		 * this failure than trying to recover. | 
 | 171 | 		 */ | 
 | 172 | 		log_error("gdlm_plock: vfs lock error file %p fl %p", | 
 | 173 | 				file, fl); | 
 | 174 | 	} | 
 | 175 |  | 
 | 176 | 	rv = notify(flc, NULL, 0); | 
 | 177 | 	if (rv) { | 
 | 178 | 		/* XXX: We need to cancel the fs lock here: */ | 
 | 179 | 		printk("gfs2 lock granted after lock request failed;" | 
 | 180 | 						" dangling lock!\n"); | 
 | 181 | 		goto out; | 
 | 182 | 	} | 
 | 183 |  | 
 | 184 | out: | 
 | 185 | 	kfree(xop); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 186 | 	return rv; | 
 | 187 | } | 
 | 188 |  | 
| Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 189 | int gdlm_punlock(void *lockspace, struct lm_lockname *name, | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 190 | 		 struct file *file, struct file_lock *fl) | 
 | 191 | { | 
| Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 192 | 	struct gdlm_ls *ls = lockspace; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 193 | 	struct plock_op *op; | 
 | 194 | 	int rv; | 
 | 195 |  | 
 | 196 | 	op = kzalloc(sizeof(*op), GFP_KERNEL); | 
 | 197 | 	if (!op) | 
 | 198 | 		return -ENOMEM; | 
 | 199 |  | 
 | 200 | 	if (posix_lock_file_wait(file, fl) < 0) | 
 | 201 | 		log_error("gdlm_punlock: vfs unlock error %x,%llx", | 
| David Teigland | 9229f01 | 2006-05-24 09:21:30 -0400 | [diff] [blame] | 202 | 			  name->ln_type, (unsigned long long)name->ln_number); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 203 |  | 
 | 204 | 	op->info.optype		= GDLM_PLOCK_OP_UNLOCK; | 
| David Teigland | 3a2a9c9 | 2006-04-25 15:45:51 -0400 | [diff] [blame] | 205 | 	op->info.pid		= fl->fl_pid; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 206 | 	op->info.fsid		= ls->id; | 
 | 207 | 	op->info.number		= name->ln_number; | 
 | 208 | 	op->info.start		= fl->fl_start; | 
 | 209 | 	op->info.end		= fl->fl_end; | 
| David Teigland | 2066b58 | 2007-12-06 09:35:25 -0600 | [diff] [blame] | 210 | 	if (fl->fl_lmops && fl->fl_lmops->fl_grant) | 
 | 211 | 		op->info.owner	= (__u64) fl->fl_pid; | 
 | 212 | 	else | 
 | 213 | 		op->info.owner	= (__u64)(long) fl->fl_owner; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 214 |  | 
 | 215 | 	send_op(op); | 
 | 216 | 	wait_event(recv_wq, (op->done != 0)); | 
 | 217 |  | 
 | 218 | 	spin_lock(&ops_lock); | 
 | 219 | 	if (!list_empty(&op->list)) { | 
| Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 220 | 		printk(KERN_INFO "punlock op on list\n"); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 221 | 		list_del(&op->list); | 
 | 222 | 	} | 
 | 223 | 	spin_unlock(&ops_lock); | 
 | 224 |  | 
 | 225 | 	rv = op->info.rv; | 
 | 226 |  | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 227 | 	if (rv == -ENOENT) | 
 | 228 | 		rv = 0; | 
 | 229 |  | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 230 | 	kfree(op); | 
 | 231 | 	return rv; | 
 | 232 | } | 
 | 233 |  | 
| Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 234 | int gdlm_plock_get(void *lockspace, struct lm_lockname *name, | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 235 | 		   struct file *file, struct file_lock *fl) | 
 | 236 | { | 
| Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 237 | 	struct gdlm_ls *ls = lockspace; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 238 | 	struct plock_op *op; | 
 | 239 | 	int rv; | 
 | 240 |  | 
 | 241 | 	op = kzalloc(sizeof(*op), GFP_KERNEL); | 
 | 242 | 	if (!op) | 
 | 243 | 		return -ENOMEM; | 
 | 244 |  | 
 | 245 | 	op->info.optype		= GDLM_PLOCK_OP_GET; | 
| David Teigland | 3a2a9c9 | 2006-04-25 15:45:51 -0400 | [diff] [blame] | 246 | 	op->info.pid		= fl->fl_pid; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 247 | 	op->info.ex		= (fl->fl_type == F_WRLCK); | 
 | 248 | 	op->info.fsid		= ls->id; | 
 | 249 | 	op->info.number		= name->ln_number; | 
 | 250 | 	op->info.start		= fl->fl_start; | 
 | 251 | 	op->info.end		= fl->fl_end; | 
| David Teigland | 2066b58 | 2007-12-06 09:35:25 -0600 | [diff] [blame] | 252 | 	if (fl->fl_lmops && fl->fl_lmops->fl_grant) | 
 | 253 | 		op->info.owner	= (__u64) fl->fl_pid; | 
 | 254 | 	else | 
 | 255 | 		op->info.owner	= (__u64)(long) fl->fl_owner; | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 256 |  | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 257 | 	send_op(op); | 
 | 258 | 	wait_event(recv_wq, (op->done != 0)); | 
 | 259 |  | 
 | 260 | 	spin_lock(&ops_lock); | 
 | 261 | 	if (!list_empty(&op->list)) { | 
| Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 262 | 		printk(KERN_INFO "plock_get op on list\n"); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 263 | 		list_del(&op->list); | 
 | 264 | 	} | 
 | 265 | 	spin_unlock(&ops_lock); | 
 | 266 |  | 
| David Teigland | a7a2ff8 | 2007-06-08 17:01:40 -0500 | [diff] [blame] | 267 | 	/* info.rv from userspace is 1 for conflict, 0 for no-conflict, | 
 | 268 | 	   -ENOENT if there are no locks on the file */ | 
 | 269 |  | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 270 | 	rv = op->info.rv; | 
 | 271 |  | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 272 | 	fl->fl_type = F_UNLCK; | 
 | 273 | 	if (rv == -ENOENT) | 
 | 274 | 		rv = 0; | 
| David Teigland | a7a2ff8 | 2007-06-08 17:01:40 -0500 | [diff] [blame] | 275 | 	else if (rv > 0) { | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 276 | 		fl->fl_type = (op->info.ex) ? F_WRLCK : F_RDLCK; | 
 | 277 | 		fl->fl_pid = op->info.pid; | 
 | 278 | 		fl->fl_start = op->info.start; | 
 | 279 | 		fl->fl_end = op->info.end; | 
| David Teigland | a7a2ff8 | 2007-06-08 17:01:40 -0500 | [diff] [blame] | 280 | 		rv = 0; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 281 | 	} | 
 | 282 |  | 
 | 283 | 	kfree(op); | 
 | 284 | 	return rv; | 
 | 285 | } | 
 | 286 |  | 
 | 287 | /* a read copies out one plock request from the send list */ | 
 | 288 | static ssize_t dev_read(struct file *file, char __user *u, size_t count, | 
 | 289 | 			loff_t *ppos) | 
 | 290 | { | 
 | 291 | 	struct gdlm_plock_info info; | 
 | 292 | 	struct plock_op *op = NULL; | 
 | 293 |  | 
 | 294 | 	if (count < sizeof(info)) | 
 | 295 | 		return -EINVAL; | 
 | 296 |  | 
 | 297 | 	spin_lock(&ops_lock); | 
 | 298 | 	if (!list_empty(&send_list)) { | 
 | 299 | 		op = list_entry(send_list.next, struct plock_op, list); | 
 | 300 | 		list_move(&op->list, &recv_list); | 
 | 301 | 		memcpy(&info, &op->info, sizeof(info)); | 
 | 302 | 	} | 
 | 303 | 	spin_unlock(&ops_lock); | 
 | 304 |  | 
 | 305 | 	if (!op) | 
 | 306 | 		return -EAGAIN; | 
 | 307 |  | 
 | 308 | 	if (copy_to_user(u, &info, sizeof(info))) | 
 | 309 | 		return -EFAULT; | 
 | 310 | 	return sizeof(info); | 
 | 311 | } | 
 | 312 |  | 
 | 313 | /* a write copies in one plock result that should match a plock_op | 
 | 314 |    on the recv list */ | 
 | 315 | static ssize_t dev_write(struct file *file, const char __user *u, size_t count, | 
 | 316 | 			 loff_t *ppos) | 
 | 317 | { | 
 | 318 | 	struct gdlm_plock_info info; | 
 | 319 | 	struct plock_op *op; | 
 | 320 | 	int found = 0; | 
 | 321 |  | 
 | 322 | 	if (count != sizeof(info)) | 
 | 323 | 		return -EINVAL; | 
 | 324 |  | 
 | 325 | 	if (copy_from_user(&info, u, sizeof(info))) | 
 | 326 | 		return -EFAULT; | 
 | 327 |  | 
 | 328 | 	if (check_version(&info)) | 
 | 329 | 		return -EINVAL; | 
 | 330 |  | 
 | 331 | 	spin_lock(&ops_lock); | 
 | 332 | 	list_for_each_entry(op, &recv_list, list) { | 
| Steven Whitehouse | 9b47c11 | 2006-09-08 10:17:58 -0400 | [diff] [blame] | 333 | 		if (op->info.fsid == info.fsid && op->info.number == info.number && | 
| David Teigland | 08eac93 | 2006-08-04 16:19:20 -0500 | [diff] [blame] | 334 | 		    op->info.owner == info.owner) { | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 335 | 			list_del_init(&op->list); | 
 | 336 | 			found = 1; | 
 | 337 | 			op->done = 1; | 
 | 338 | 			memcpy(&op->info, &info, sizeof(info)); | 
 | 339 | 			break; | 
 | 340 | 		} | 
 | 341 | 	} | 
 | 342 | 	spin_unlock(&ops_lock); | 
 | 343 |  | 
| Marc Eshel | 586759f | 2006-11-14 16:37:25 -0500 | [diff] [blame] | 344 | 	if (found) { | 
 | 345 | 		struct plock_xop *xop; | 
 | 346 | 		xop = (struct plock_xop *)op; | 
 | 347 | 		if (xop->callback) | 
 | 348 | 			count = gdlm_plock_callback(op); | 
 | 349 | 		else | 
 | 350 | 			wake_up(&recv_wq); | 
 | 351 | 	} else | 
| Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 352 | 		printk(KERN_INFO "gdlm dev_write no op %x %llx\n", info.fsid, | 
| David Teigland | 9229f01 | 2006-05-24 09:21:30 -0400 | [diff] [blame] | 353 | 			(unsigned long long)info.number); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 354 | 	return count; | 
 | 355 | } | 
 | 356 |  | 
 | 357 | static unsigned int dev_poll(struct file *file, poll_table *wait) | 
 | 358 | { | 
| Denis Cheng | cee23c7 | 2007-07-25 17:53:58 +0800 | [diff] [blame] | 359 | 	unsigned int mask = 0; | 
 | 360 |  | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 361 | 	poll_wait(file, &send_wq, wait); | 
 | 362 |  | 
 | 363 | 	spin_lock(&ops_lock); | 
| Denis Cheng | cee23c7 | 2007-07-25 17:53:58 +0800 | [diff] [blame] | 364 | 	if (!list_empty(&send_list)) | 
 | 365 | 		mask = POLLIN | POLLRDNORM; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 366 | 	spin_unlock(&ops_lock); | 
| Denis Cheng | cee23c7 | 2007-07-25 17:53:58 +0800 | [diff] [blame] | 367 |  | 
 | 368 | 	return mask; | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 369 | } | 
 | 370 |  | 
| Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 371 | static const struct file_operations dev_fops = { | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 372 | 	.read    = dev_read, | 
 | 373 | 	.write   = dev_write, | 
 | 374 | 	.poll    = dev_poll, | 
 | 375 | 	.owner   = THIS_MODULE | 
 | 376 | }; | 
 | 377 |  | 
 | 378 | static struct miscdevice plock_dev_misc = { | 
 | 379 | 	.minor = MISC_DYNAMIC_MINOR, | 
 | 380 | 	.name = GDLM_PLOCK_MISC_NAME, | 
 | 381 | 	.fops = &dev_fops | 
 | 382 | }; | 
 | 383 |  | 
 | 384 | int gdlm_plock_init(void) | 
 | 385 | { | 
 | 386 | 	int rv; | 
 | 387 |  | 
 | 388 | 	spin_lock_init(&ops_lock); | 
 | 389 | 	INIT_LIST_HEAD(&send_list); | 
 | 390 | 	INIT_LIST_HEAD(&recv_list); | 
 | 391 | 	init_waitqueue_head(&send_wq); | 
 | 392 | 	init_waitqueue_head(&recv_wq); | 
 | 393 |  | 
 | 394 | 	rv = misc_register(&plock_dev_misc); | 
 | 395 | 	if (rv) | 
| Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 396 | 		printk(KERN_INFO "gdlm_plock_init: misc_register failed %d", | 
 | 397 | 		       rv); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 398 | 	return rv; | 
 | 399 | } | 
 | 400 |  | 
 | 401 | void gdlm_plock_exit(void) | 
 | 402 | { | 
 | 403 | 	if (misc_deregister(&plock_dev_misc) < 0) | 
| Steven Whitehouse | d92a8d4 | 2006-02-27 10:57:14 -0500 | [diff] [blame] | 404 | 		printk(KERN_INFO "gdlm_plock_exit: misc_deregister failed"); | 
| David Teigland | 869d81d | 2006-01-17 08:47:12 +0000 | [diff] [blame] | 405 | } | 
 | 406 |  |