| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
#include <linux/capability.h> |
|---|
| 118 |
#include <linux/file.h> |
|---|
| 119 |
#include <linux/fs.h> |
|---|
| 120 |
#include <linux/init.h> |
|---|
| 121 |
#include <linux/module.h> |
|---|
| 122 |
#include <linux/security.h> |
|---|
| 123 |
#include <linux/slab.h> |
|---|
| 124 |
#include <linux/smp_lock.h> |
|---|
| 125 |
#include <linux/time.h> |
|---|
| 126 |
|
|---|
| 127 |
#include <asm/semaphore.h> |
|---|
| 128 |
#include <asm/uaccess.h> |
|---|
| 129 |
|
|---|
| 130 |
#define IS_POSIX(fl) (fl->fl_flags & FL_POSIX) |
|---|
| 131 |
#define IS_FLOCK(fl) (fl->fl_flags & FL_FLOCK) |
|---|
| 132 |
#define IS_LEASE(fl) (fl->fl_flags & FL_LEASE) |
|---|
| 133 |
|
|---|
| 134 |
int leases_enable = 1; |
|---|
| 135 |
int lease_break_time = 45; |
|---|
| 136 |
|
|---|
| 137 |
#define for_each_lock(inode, lockp) \ |
|---|
| 138 |
for (lockp = &inode->i_flock; *lockp != NULL; lockp = &(*lockp)->fl_next) |
|---|
| 139 |
|
|---|
| 140 |
LIST_HEAD(file_lock_list); |
|---|
| 141 |
|
|---|
| 142 |
EXPORT_SYMBOL(file_lock_list); |
|---|
| 143 |
|
|---|
| 144 |
static LIST_HEAD(blocked_list); |
|---|
| 145 |
|
|---|
| 146 |
static kmem_cache_t *filelock_cache; |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
static struct file_lock *locks_alloc_lock(void) |
|---|
| 150 |
{ |
|---|
| 151 |
return kmem_cache_alloc(filelock_cache, SLAB_KERNEL); |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
static inline void locks_free_lock(struct file_lock *fl) |
|---|
| 156 |
{ |
|---|
| 157 |
if (fl == NULL) { |
|---|
| 158 |
BUG(); |
|---|
| 159 |
return; |
|---|
| 160 |
} |
|---|
| 161 |
if (waitqueue_active(&fl->fl_wait)) |
|---|
| 162 |
panic("Attempting to free lock with active wait queue"); |
|---|
| 163 |
|
|---|
| 164 |
if (!list_empty(&fl->fl_block)) |
|---|
| 165 |
panic("Attempting to free lock with active block list"); |
|---|
| 166 |
|
|---|
| 167 |
if (!list_empty(&fl->fl_link)) |
|---|
| 168 |
panic("Attempting to free lock on active lock list"); |
|---|
| 169 |
|
|---|
| 170 |
kmem_cache_free(filelock_cache, fl); |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
void locks_init_lock(struct file_lock *fl) |
|---|
| 174 |
{ |
|---|
| 175 |
INIT_LIST_HEAD(&fl->fl_link); |
|---|
| 176 |
INIT_LIST_HEAD(&fl->fl_block); |
|---|
| 177 |
init_waitqueue_head(&fl->fl_wait); |
|---|
| 178 |
fl->fl_next = NULL; |
|---|
| 179 |
fl->fl_fasync = NULL; |
|---|
| 180 |
fl->fl_owner = 0; |
|---|
| 181 |
fl->fl_pid = 0; |
|---|
| 182 |
fl->fl_file = NULL; |
|---|
| 183 |
fl->fl_flags = 0; |
|---|
| 184 |
fl->fl_type = 0; |
|---|
| 185 |
fl->fl_start = fl->fl_end = 0; |
|---|
| 186 |
fl->fl_notify = NULL; |
|---|
| 187 |
fl->fl_insert = NULL; |
|---|
| 188 |
fl->fl_remove = NULL; |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
EXPORT_SYMBOL(locks_init_lock); |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
static void init_once(void *foo, kmem_cache_t *cache, unsigned long flags) |
|---|
| 198 |
{ |
|---|
| 199 |
struct file_lock *lock = (struct file_lock *) foo; |
|---|
| 200 |
|
|---|
| 201 |
if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) != |
|---|
| 202 |
SLAB_CTOR_CONSTRUCTOR) |
|---|
| 203 |
return; |
|---|
| 204 |
|
|---|
| 205 |
locks_init_lock(lock); |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
void locks_copy_lock(struct file_lock *new, struct file_lock *fl) |
|---|
| 212 |
{ |
|---|
| 213 |
new->fl_owner = fl->fl_owner; |
|---|
| 214 |
new->fl_pid = fl->fl_pid; |
|---|
| 215 |
new->fl_file = fl->fl_file; |
|---|
| 216 |
new->fl_flags = fl->fl_flags; |
|---|
| 217 |
new->fl_type = fl->fl_type; |
|---|
| 218 |
new->fl_start = fl->fl_start; |
|---|
| 219 |
new->fl_end = fl->fl_end; |
|---|
| 220 |
new->fl_notify = fl->fl_notify; |
|---|
| 221 |
new->fl_insert = fl->fl_insert; |
|---|
| 222 |
new->fl_remove = fl->fl_remove; |
|---|
| 223 |
new->fl_u = fl->fl_u; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
EXPORT_SYMBOL(locks_copy_lock); |
|---|
| 227 |
|
|---|
| 228 |
static inline int flock_translate_cmd(int cmd) { |
|---|
| 229 |
if (cmd & LOCK_MAND) |
|---|
| 230 |
return cmd & (LOCK_MAND | LOCK_RW); |
|---|
| 231 |
switch (cmd) { |
|---|
| 232 |
case LOCK_SH: |
|---|
| 233 |
return F_RDLCK; |
|---|
| 234 |
case LOCK_EX: |
|---|
| 235 |
return F_WRLCK; |
|---|
| 236 |
case LOCK_UN: |
|---|
| 237 |
return F_UNLCK; |
|---|
| 238 |
} |
|---|
| 239 |
return -EINVAL; |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
static int flock_make_lock(struct file *filp, struct file_lock **lock, |
|---|
| 244 |
unsigned int cmd) |
|---|
| 245 |
{ |
|---|
| 246 |
struct file_lock *fl; |
|---|
| 247 |
int type = flock_translate_cmd(cmd); |
|---|
| 248 |
if (type < 0) |
|---|
| 249 |
return type; |
|---|
| 250 |
|
|---|
| 251 |
fl = locks_alloc_lock(); |
|---|
| 252 |
if (fl == NULL) |
|---|
| 253 |
return -ENOMEM; |
|---|
| 254 |
|
|---|
| 255 |
fl->fl_file = filp; |
|---|
| 256 |
fl->fl_pid = current->tgid; |
|---|
| 257 |
fl->fl_flags = FL_FLOCK; |
|---|
| 258 |
fl->fl_type = type; |
|---|
| 259 |
fl->fl_end = OFFSET_MAX; |
|---|
| 260 |
|
|---|
| 261 |
*lock = fl; |
|---|
| 262 |
return 0; |
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
static int assign_type(struct file_lock *fl, int type) |
|---|
| 266 |
{ |
|---|
| 267 |
switch (type) { |
|---|
| 268 |
case F_RDLCK: |
|---|
| 269 |
case F_WRLCK: |
|---|
| 270 |
case F_UNLCK: |
|---|
| 271 |
fl->fl_type = type; |
|---|
| 272 |
break; |
|---|
| 273 |
default: |
|---|
| 274 |
return -EINVAL; |
|---|
| 275 |
} |
|---|
| 276 |
return 0; |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
static int flock_to_posix_lock(struct file *filp, struct file_lock *fl, |
|---|
| 283 |
struct flock *l) |
|---|
| 284 |
{ |
|---|
| 285 |
off_t start, end; |
|---|
| 286 |
|
|---|
| 287 |
switch (l->l_whence) { |
|---|
| 288 |
case 0: |
|---|
| 289 |
start = 0; |
|---|
| 290 |
break; |
|---|
| 291 |
case 1: |
|---|
| 292 |
start = filp->f_pos; |
|---|
| 293 |
break; |
|---|
| 294 |
case 2: |
|---|
| 295 |
start = i_size_read(filp->f_dentry->d_inode); |
|---|
| 296 |
break; |
|---|
| 297 |
default: |
|---|
| 298 |
return -EINVAL; |
|---|
| 299 |
} |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
start += l->l_start; |
|---|
| 304 |
end = start + l->l_len - 1; |
|---|
| 305 |
if (l->l_len < 0) { |
|---|
| 306 |
end = start - 1; |
|---|
| 307 |
start += l->l_len; |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
if (start < 0) |
|---|
| 311 |
return -EINVAL; |
|---|
| 312 |
if (l->l_len > 0 && end < 0) |
|---|
| 313 |
return -EOVERFLOW; |
|---|
| 314 |
|
|---|
| 315 |
fl->fl_start = start; |
|---|
| 316 |
fl->fl_end = end; |
|---|
| 317 |
if (l->l_len == 0) |
|---|
| 318 |
fl->fl_end = OFFSET_MAX; |
|---|
| 319 |
|
|---|
| 320 |
fl->fl_owner = current->files; |
|---|
| 321 |
fl->fl_pid = current->tgid; |
|---|
| 322 |
fl->fl_file = filp; |
|---|
| 323 |
fl->fl_flags = FL_POSIX; |
|---|
| 324 |
fl->fl_notify = NULL; |
|---|
| 325 |
fl->fl_insert = NULL; |
|---|
| 326 |
fl->fl_remove = NULL; |
|---|
| 327 |
|
|---|
| 328 |
return assign_type(fl, l->l_type); |
|---|
| 329 |
} |
|---|
| 330 |
|
|---|
| 331 |
#if BITS_PER_LONG == 32 |
|---|
| 332 |
static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl, |
|---|
| 333 |
struct flock64 *l) |
|---|
| 334 |
{ |
|---|
| 335 |
loff_t start; |
|---|
| 336 |
|
|---|
| 337 |
switch (l->l_whence) { |
|---|
| 338 |
case 0: |
|---|
| 339 |
start = 0; |
|---|
| 340 |
break; |
|---|
| 341 |
case 1: |
|---|
| 342 |
start = filp->f_pos; |
|---|
| 343 |
break; |
|---|
| 344 |
case 2: |
|---|
| 345 |
start = i_size_read(filp->f_dentry->d_inode); |
|---|
| 346 |
break; |
|---|
| 347 |
default: |
|---|
| 348 |
return -EINVAL; |
|---|
| 349 |
} |
|---|
| 350 |
|
|---|
| 351 |
if (((start += l->l_start) < 0) || (l->l_len < 0)) |
|---|
| 352 |
return -EINVAL; |
|---|
| 353 |
fl->fl_end = start + l->l_len - 1; |
|---|
| 354 |
if (l->l_len > 0 && fl->fl_end < 0) |
|---|
| 355 |
return -EOVERFLOW; |
|---|
| 356 |
fl->fl_start = start; |
|---|
| 357 |
if (l->l_len == 0) |
|---|
| 358 |
fl->fl_end = OFFSET_MAX; |
|---|
| 359 |
|
|---|
| 360 |
fl->fl_owner = current->files; |
|---|
| 361 |
fl->fl_pid = current->tgid; |
|---|
| 362 |
fl->fl_file = filp; |
|---|
| 363 |
fl->fl_flags = FL_POSIX; |
|---|
| 364 |
fl->fl_notify = NULL; |
|---|
| 365 |
fl->fl_insert = NULL; |
|---|
| 366 |
fl->fl_remove = NULL; |
|---|
| 367 |
|
|---|
| 368 |
switch (l->l_type) { |
|---|
| 369 |
case F_RDLCK: |
|---|
| 370 |
case F_WRLCK: |
|---|
| 371 |
case F_UNLCK: |
|---|
| 372 |
fl->fl_type = l->l_type; |
|---|
| 373 |
break; |
|---|
| 374 |
default: |
|---|
| 375 |
return -EINVAL; |
|---|
| 376 |
} |
|---|
| 377 |
|
|---|
| 378 |
return (0); |
|---|
| 379 |
} |
|---|
| 380 |
#endif |
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
static int lease_alloc(struct file *filp, int type, struct file_lock **flp) |
|---|
| 384 |
{ |
|---|
| 385 |
struct file_lock *fl = locks_alloc_lock(); |
|---|
| 386 |
if (fl == NULL) |
|---|
| 387 |
return -ENOMEM; |
|---|
| 388 |
|
|---|
| 389 |
fl->fl_owner = current->files; |
|---|
| 390 |
fl->fl_pid = current->tgid; |
|---|
| 391 |
|
|---|
| 392 |
fl->fl_file = filp; |
|---|
| 393 |
fl->fl_flags = FL_LEASE; |
|---|
| 394 |
if (assign_type(fl, type) != 0) { |
|---|
| 395 |
locks_free_lock(fl); |
|---|
| 396 |
return -EINVAL; |
|---|
| 397 |
} |
|---|
| 398 |
fl->fl_start = 0; |
|---|
| 399 |
fl->fl_end = OFFSET_MAX; |
|---|
| 400 |
fl->fl_notify = NULL; |
|---|
| 401 |
fl->fl_insert = NULL; |
|---|
| 402 |
fl->fl_remove = NULL; |
|---|
| 403 |
|
|---|
| 404 |
*flp = fl; |
|---|
| 405 |
return 0; |
|---|
| 406 |
} |
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
static inline int locks_overlap(struct file_lock *fl1, struct file_lock *fl2) |
|---|
| 411 |
{ |
|---|
| 412 |
return ((fl1->fl_end >= fl2->fl_start) && |
|---|
| 413 |
(fl2->fl_end >= fl1->fl_start)); |
|---|
| 414 |
} |
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
static inline int |
|---|
| 421 |
posix_same_owner(struct file_lock *fl1, struct file_lock *fl2) |
|---|
| 422 |
{ |
|---|
| 423 |
return (fl1->fl_owner == fl2->fl_owner) && |
|---|
| 424 |
(fl1->fl_pid == fl2->fl_pid); |
|---|
| 425 |
} |
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
static inline void __locks_delete_block(struct file_lock *waiter) |
|---|
| 431 |
{ |
|---|
| 432 |
list_del_init(&waiter->fl_block); |
|---|
| 433 |
list_del_init(&waiter->fl_link); |
|---|
| 434 |
waiter->fl_next = NULL; |
|---|
| 435 |
} |
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
static void locks_delete_block(struct file_lock *waiter) |
|---|
| 440 |
{ |
|---|
| 441 |
lock_kernel(); |
|---|
| 442 |
__locks_delete_block(waiter); |
|---|
| 443 |
unlock_kernel(); |
|---|
| 444 |
} |
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
static void locks_insert_block(struct file_lock *blocker, |
|---|
| 452 |
struct file_lock *waiter) |
|---|
| 453 |
{ |
|---|
| 454 |
if (!list_empty(&waiter->fl_block)) { |
|---|
| 455 |
printk(KERN_ERR "locks_insert_block: removing duplicated lock " |
|---|
| 456 |
"(pid=%d %Ld-%Ld type=%d)\n", waiter->fl_pid, |
|---|
| 457 |
waiter->fl_start, waiter->fl_end, waiter->fl_type); |
|---|
| 458 |
__locks_delete_block(waiter); |
|---|
| 459 |
} |
|---|
| 460 |
list_add_tail(&waiter->fl_block, &blocker->fl_block); |
|---|
| 461 |
waiter->fl_next = blocker; |
|---|
| 462 |
list_add(&waiter->fl_link, &blocked_list); |
|---|
| 463 |
} |
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
static void locks_wake_up_blocks(struct file_lock *blocker) |
|---|
| 470 |
{ |
|---|
| 471 |
while (!list_empty(&blocker->fl_block)) { |
|---|
| 472 |
struct file_lock *waiter = list_entry(blocker->fl_block.next, |
|---|
| 473 |
struct file_lock, fl_block); |
|---|
| 474 |
__locks_delete_block(waiter); |
|---|
| 475 |
if (waiter->fl_notify) |
|---|
| 476 |
waiter->fl_notify(waiter); |
|---|
| 477 |
else |
|---|
| 478 |
wake_up(&waiter->fl_wait); |
|---|
| 479 |
} |
|---|
| 480 |
} |
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
static void locks_insert_lock(struct file_lock **pos, struct file_lock *fl) |
|---|
| 486 |
{ |
|---|
| 487 |
list_add(&fl->fl_link, &file_lock_list); |
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
fl->fl_next = *pos; |
|---|
| 491 |
*pos = fl; |
|---|
| 492 |
|
|---|
| 493 |
if (fl->fl_insert) |
|---|
| 494 |
fl->fl_insert(fl); |
|---|
| 495 |
} |
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
static void locks_delete_lock(struct file_lock **thisfl_p) |
|---|
| 504 |
{ |
|---|
| 505 |
struct file_lock *fl = *thisfl_p; |
|---|
| 506 |
|
|---|
| 507 |
*thisfl_p = fl->fl_next; |
|---|
| 508 |
fl->fl_next = NULL; |
|---|
| 509 |
list_del_init(&fl->fl_link); |
|---|
| 510 |
|
|---|
| 511 |
fasync_helper(0, fl->fl_file, 0, &fl->fl_fasync); |
|---|
| 512 |
if (fl->fl_fasync != NULL) { |
|---|
| 513 |
printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync); |
|---|
| 514 |
fl->fl_fasync = NULL; |
|---|
| 515 |
} |
|---|
| 516 |
|
|---|
| 517 |
if (fl->fl_remove) |
|---|
| 518 |
fl->fl_remove(fl); |
|---|
| 519 |
|
|---|
| 520 |
locks_wake_up_blocks(fl); |
|---|
| 521 |
locks_free_lock(fl); |
|---|
| 522 |
} |
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
static int locks_conflict(struct file_lock *caller_fl, struct file_lock *sys_fl) |
|---|
| 528 |
{ |
|---|
| 529 |
if (sys_fl->fl_type == F_WRLCK) |
|---|
| 530 |
return 1; |
|---|
| 531 |
if (caller_fl->fl_type == F_WRLCK) |
|---|
| 532 |
return 1; |
|---|
| 533 |
return 0; |
|---|
| 534 |
} |
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
static int posix_locks_conflict(struct file_lock *caller_fl, struct file_lock *sys_fl) |
|---|
| 540 |
{ |
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
if (!IS_POSIX(sys_fl) || posix_same_owner(caller_fl, sys_fl)) |
|---|
| 545 |
return (0); |
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
if (!locks_overlap(caller_fl, sys_fl)) |
|---|
| 549 |
return 0; |
|---|
| 550 |
|
|---|
| 551 |
return (locks_conflict(caller_fl, sys_fl)); |
|---|
| 552 |
} |
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
static int flock_locks_conflict(struct file_lock *caller_fl, struct file_lock *sys_fl) |
|---|
| 558 |
{ |
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
if (!IS_FLOCK(sys_fl) || (caller_fl->fl_file == sys_fl->fl_file)) |
|---|
| 563 |
return (0); |
|---|
| 564 |
if ((caller_fl->fl_type & LOCK_MAND) || (sys_fl->fl_type & LOCK_MAND)) |
|---|
| 565 |
return 0; |
|---|
| 566 |
|
|---|
| 567 |
return (locks_conflict(caller_fl, sys_fl)); |
|---|
| 568 |
} |
|---|
| 569 |
|
|---|
| 570 |
static int interruptible_sleep_on_locked(wait_queue_head_t *fl_wait, int timeout) |
|---|
| 571 |
{ |
|---|
| 572 |
int result = 0; |
|---|
| 573 |
DECLARE_WAITQUEUE(wait, current); |
|---|
| 574 |
|
|---|
| 575 |
__set_current_state(TASK_INTERRUPTIBLE); |
|---|
| 576 |
add_wait_queue(fl_wait, &wait); |
|---|
| 577 |
if (timeout == 0) |
|---|
| 578 |
schedule(); |
|---|
| 579 |
else |
|---|
| 580 |
result = schedule_timeout(timeout); |
|---|
| 581 |
if (signal_pending(current)) |
|---|
| 582 |
result = -ERESTARTSYS; |
|---|
| 583 |
remove_wait_queue(fl_wait, &wait); |
|---|
| 584 |
__set_current_state(TASK_RUNNING); |
|---|
| 585 |
return result; |
|---|
| 586 |
} |
|---|
| 587 |
|
|---|
| 588 |
static int locks_block_on_timeout(struct file_lock *blocker, struct file_lock *waiter, int time) |
|---|
| 589 |
{ |
|---|
| 590 |
int result; |
|---|
| 591 |
locks_insert_block(blocker, waiter); |
|---|
| 592 |
result = interruptible_sleep_on_locked(&waiter->fl_wait, time); |
|---|
| 593 |
__locks_delete_block(waiter); |
|---|
| 594 |
return result; |
|---|
| 595 |
} |
|---|
| 596 |
|
|---|
| 597 |
struct file_lock * |
|---|
| 598 |
posix_test_lock(struct file *filp, struct file_lock *fl) |
|---|
| 599 |
{ |
|---|
| 600 |
struct file_lock *cfl; |
|---|
| 601 |
|
|---|
| 602 |
lock_kernel(); |
|---|
| 603 |
for (cfl = filp->f_dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) { |
|---|
| 604 |
if (!IS_POSIX(cfl)) |
|---|
| 605 |
continue; |
|---|
| 606 |
if (posix_locks_conflict(cfl, fl)) |
|---|
| 607 |
break; |
|---|
| 608 |
} |
|---|
| 609 |
unlock_kernel(); |
|---|
| 610 |
|
|---|
| 611 |
return (cfl); |
|---|
| 612 |
} |
|---|
| 613 |
|
|---|
| 614 |
EXPORT_SYMBOL(posix_test_lock); |
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 |
|
|---|
| 621 |
|
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
|
|---|
| 627 |
|
|---|
| 628 |
|
|---|
| 629 |
|
|---|
| 630 |
int posix_locks_deadlock(struct file_lock *caller_fl, |
|---|
| 631 |
struct file_lock *block_fl) |
|---|
| 632 |
{ |
|---|
| 633 |
struct list_head *tmp; |
|---|
| 634 |
fl_owner_t caller_owner, blocked_owner; |
|---|
| 635 |
unsigned int caller_pid, blocked_pid; |
|---|
| 636 |
|
|---|
| 637 |
caller_owner = caller_fl->fl_owner; |
|---|
| 638 |
caller_pid = caller_fl->fl_pid; |
|---|
| 639 |
blocked_owner = block_fl->fl_owner; |
|---|
| 640 |
blocked_pid = block_fl->fl_pid; |
|---|
| 641 |
|
|---|
| 642 |
next_task: |
|---|
| 643 |
if (caller_owner == blocked_owner && caller_pid == blocked_pid) |
|---|
| 644 |
return 1; |
|---|
| 645 |
list_for_each(tmp, &blocked_list) { |
|---|
| 646 |
struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link); |
|---|
| 647 |
if ((fl->fl_owner == blocked_owner) |
|---|
| 648 |
&& (fl->fl_pid == blocked_pid)) { |
|---|
| 649 |
fl = fl->fl_next; |
|---|
| 650 |
blocked_owner = fl->fl_owner; |
|---|
| 651 |
blocked_pid = fl->fl_pid; |
|---|
| 652 |
goto next_task; |
|---|
| 653 |
} |
|---|
| 654 |
} |
|---|
| 655 |
return 0; |
|---|
| 656 |
} |
|---|
| 657 |
|
|---|
| 658 |
EXPORT_SYMBOL(posix_locks_deadlock); |
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 |
|
|---|
| 664 |
static int flock_lock_file(struct file *filp, struct file_lock *new_fl) |
|---|
| 665 |
{ |
|---|
| 666 |
struct file_lock **before; |
|---|
| 667 |
struct inode * inode = filp->f_dentry->d_inode; |
|---|
| 668 |
int error = 0; |
|---|
| 669 |
int found = 0; |
|---|
| 670 |
|
|---|
| 671 |
lock_kernel(); |
|---|
| 672 |
for_each_lock(inode, before) { |
|---|
| 673 |
struct file_lock *fl = *before; |
|---|
| 674 |
if (IS_POSIX(fl)) |
|---|
| 675 |
break; |
|---|
| 676 |
if (IS_LEASE(fl)) |
|---|
| 677 |
continue; |
|---|
| 678 |
if (filp != fl->fl_file) |
|---|
| 679 |
continue; |
|---|
| 680 |
if (new_fl->fl_type == fl->fl_type) |
|---|
| 681 |
goto out; |
|---|
| 682 |
found = 1; |
|---|
| 683 |
locks_delete_lock(before); |
|---|
| 684 |
break; |
|---|
| 685 |
} |
|---|
| 686 |
unlock_kernel(); |
|---|
| 687 |
|
|---|
| 688 |
if (new_fl->fl_type == F_UNLCK) |
|---|
| 689 |
return 0; |
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
if (found) |
|---|
| 696 |
cond_resched(); |
|---|
| 697 |
|
|---|
| 698 |
lock_kernel(); |
|---|
| 699 |
for_each_lock(inode, before) { |
|---|
| 700 |
struct file_lock *fl = *before; |
|---|
| 701 |
if (IS_POSIX(fl)) |
|---|
| 702 |
break; |
|---|
| 703 |
if (IS_LEASE(fl)) |
|---|
| 704 |
continue; |
|---|
| 705 |
if (!flock_locks_conflict(new_fl, fl)) |
|---|
| 706 |
continue; |
|---|
| 707 |
error = -EAGAIN; |
|---|
| 708 |
if (new_fl->fl_flags & FL_SLEEP) { |
|---|
| 709 |
locks_insert_block(fl, new_fl); |
|---|
| 710 |
} |
|---|
| 711 |
goto out; |
|---|
| 712 |
} |
|---|
| 713 |
locks_insert_lock(&inode->i_flock, new_fl); |
|---|
| 714 |
error = 0; |
|---|
| 715 |
|
|---|
| 716 |
out: |
|---|
| 717 |
unlock_kernel(); |
|---|
| 718 |
return error; |
|---|
| 719 |
} |
|---|
| 720 |
|
|---|
| 721 |
EXPORT_SYMBOL(posix_lock_file); |
|---|
| 722 |
|
|---|
| 723 |
static int __posix_lock_file(struct inode *inode, struct file_lock *request) |
|---|
| 724 |
{ |
|---|
| 725 |
struct file_lock *fl; |
|---|
| 726 |
struct file_lock *new_fl, *new_fl2; |
|---|
| 727 |
struct file_lock *left = NULL; |
|---|
| 728 |
struct file_lock *right = NULL; |
|---|
| 729 |
struct file_lock **before; |
|---|
| 730 |
int error, added = 0; |
|---|
| 731 |
|
|---|
| 732 |
|
|---|
| 733 |
|
|---|
| 734 |
|
|---|
| 735 |
|
|---|
| 736 |
new_fl = locks_alloc_lock(); |
|---|
| 737 |
new_fl2 = locks_alloc_lock(); |
|---|
| 738 |
|
|---|
| 739 |
lock_kernel(); |
|---|
| 740 |
if (request->fl_type != F_UNLCK) { |
|---|
| 741 |
for_each_lock(inode, before) { |
|---|
| 742 |
struct file_lock *fl = *before; |
|---|
| 743 |
if (!IS_POSIX(fl)) |
|---|
| 744 |
continue; |
|---|
| 745 |
if (!posix_locks_conflict(request, fl)) |
|---|
| 746 |
continue; |
|---|
| 747 |
error = -EAGAIN; |
|---|
| 748 |
if (!(request->fl_flags & FL_SLEEP)) |
|---|
| 749 |
goto out; |
|---|
| 750 |
error = -EDEADLK; |
|---|
| 751 |
if (posix_locks_deadlock(request, fl)) |
|---|
| 752 |
goto out; |
|---|
| 753 |
error = -EAGAIN; |
|---|
| 754 |
locks_insert_block(fl, request); |
|---|
| 755 |
goto out; |
|---|
| 756 |
} |
|---|
| 757 |
} |
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 |
error = 0; |
|---|
| 761 |
if (request->fl_flags & FL_ACCESS) |
|---|
| 762 |
goto out; |
|---|
| 763 |
|
|---|
| 764 |
error = -ENOLCK; |
|---|
| 765 |
if (!(new_fl && new_fl2)) |
|---|
| 766 |
goto out; |
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
|
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
before = &inode->i_flock; |
|---|
| 776 |
|
|---|
| 777 |
|
|---|
| 778 |
while ((fl = *before) && (!IS_POSIX(fl) || |
|---|
| 779 |
!posix_same_owner(request, fl))) { |
|---|
| 780 |
before = &fl->fl_next; |
|---|
| 781 |
} |
|---|
| 782 |
|
|---|
| 783 |
|
|---|
| 784 |
while ((fl = *before) && posix_same_owner(request, fl)) { |
|---|
| 785 |
|
|---|
| 786 |
|
|---|
| 787 |
if (request->fl_type == fl->fl_type) { |
|---|
| 788 |
if (fl->fl_end < request->fl_start - 1) |
|---|
| 789 |
goto next_lock; |
|---|
| 790 |
|
|---|
| 791 |
|
|---|
| 792 |
|
|---|
| 793 |
if (fl->fl_start > request->fl_end + 1) |
|---|
| 794 |
break; |
|---|
| 795 |
|
|---|
| 796 |
|
|---|
| 797 |
|
|---|
| 798 |
|
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 |
if (fl->fl_start > request->fl_start) |
|---|
| 802 |
fl->fl_start = request->fl_start; |
|---|
| 803 |
else |
|---|
| 804 |
request->fl_start = fl->fl_start; |
|---|
| 805 |
if (fl->fl_end < request->fl_end) |
|---|
| 806 |
fl->fl_end = request->fl_end; |
|---|
| 807 |
else |
|---|
| 808 |
request->fl_end = fl->fl_end; |
|---|
| 809 |
if (added) { |
|---|
| 810 |
locks_delete_lock(before); |
|---|
| 811 |
continue; |
|---|
| 812 |
} |
|---|
| 813 |
request = fl; |
|---|
| 814 |
added = 1; |
|---|
| 815 |
} |
|---|
| 816 |
else { |
|---|
| 817 |
|
|---|
| 818 |
|
|---|
| 819 |
|
|---|
| 820 |
if (fl->fl_end < request->fl_start) |
|---|
| 821 |
goto next_lock; |
|---|
| 822 |
if (fl->fl_start > request->fl_end) |
|---|
| 823 |
break; |
|---|
| 824 |
if (request->fl_type == F_UNLCK) |
|---|
| 825 |
added = 1; |
|---|
| 826 |
if (fl->fl_start < request->fl_start) |
|---|
| 827 |
left = fl; |
|---|
| 828 |
|
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 |
if (fl->fl_end > request->fl_end) { |
|---|
| 832 |
right = fl; |
|---|
| 833 |
break; |
|---|
| 834 |
} |
|---|
| 835 |
if (fl->fl_start >= request->fl_start) { |
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
|
|---|
| 839 |
if (added) { |
|---|
| 840 |
locks_delete_lock(before); |
|---|
| 841 |
continue; |
|---|
| 842 |
} |
|---|
| 843 |
|
|---|
| 844 |
|
|---|
| 845 |
|
|---|
| 846 |
|
|---|
| 847 |
|
|---|
| 848 |
locks_wake_up_blocks(fl); |
|---|
| 849 |
fl->fl_start = request->fl_start; |
|---|
| 850 |
fl->fl_end = request->fl_end; |
|---|
| 851 |
fl->fl_type = request->fl_type; |
|---|
| 852 |
fl->fl_u = request->fl_u; |
|---|
| 853 |
request = fl; |
|---|
| 854 |
added = 1; |
|---|
| 855 |
} |
|---|
| 856 |
} |
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
next_lock: |
|---|
| 860 |
before = &fl->fl_next; |
|---|
| 861 |
} |
|---|
| 862 |
|
|---|
| 863 |
error = 0; |
|---|
| 864 |
if (!added) { |
|---|
| 865 |
if (request->fl_type == F_UNLCK) |
|---|
| 866 |
goto out; |
|---|
| 867 |
locks_copy_lock(new_fl, request); |
|---|
| 868 |
locks_insert_lock(before, new_fl); |
|---|
| 869 |
new_fl = NULL; |
|---|
| 870 |
} |
|---|
| 871 |
if (right) { |
|---|
| 872 |
if (left == right) { |
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 |
|
|---|
| 876 |
left = new_fl2; |
|---|
| 877 |
new_fl2 = NULL; |
|---|
| 878 |
locks_copy_lock(left, right); |
|---|
| 879 |
locks_insert_lock(before, left); |
|---|
| 880 |
} |
|---|
| 881 |
right->fl_start = request->fl_end + 1; |
|---|
| 882 |
locks_wake_up_blocks(right); |
|---|
| 883 |
} |
|---|
| 884 |
if (left) { |
|---|
| 885 |
left->fl_end = request->fl_start - 1; |
|---|
| 886 |
locks_wake_up_blocks(left); |
|---|
| 887 |
} |
|---|
| 888 |
out: |
|---|
| 889 |
unlock_kernel(); |
|---|
| 890 |
|
|---|
| 891 |
|
|---|
| 892 |
|
|---|
| 893 |
if (new_fl) |
|---|
| 894 |
locks_free_lock(new_fl); |
|---|
| 895 |
if (new_fl2) |
|---|
| 896 |
locks_free_lock(new_fl2); |
|---|
| 897 |
return error; |
|---|
| 898 |
} |
|---|
| 899 |
|
|---|
| 900 |
|
|---|
| 901 |
|
|---|
| 902 |
|
|---|
| 903 |
|
|---|
| 904 |
|
|---|
| 905 |
|
|---|
| 906 |
|
|---|
| 907 |
|
|---|
| 908 |
|
|---|
| 909 |
int posix_lock_file(struct file *filp, struct file_lock *fl) |
|---|
| 910 |
{ |
|---|
| 911 |
return __posix_lock_file(filp->f_dentry->d_inode, fl); |
|---|
| 912 |
} |
|---|
| 913 |
|
|---|
| 914 |
|
|---|
| 915 |
|
|---|
| 916 |
|
|---|
| 917 |
|
|---|
| 918 |
|
|---|
| 919 |
|
|---|
| 920 |
|
|---|
| 921 |
int locks_mandatory_locked(struct inode *inode) |
|---|
| 922 |
{ |
|---|
| 923 |
fl_owner_t owner = current->files; |
|---|
| 924 |
struct file_lock *fl; |
|---|
| 925 |
|
|---|
| 926 |
|
|---|
| 927 |
|
|---|
| 928 |
|
|---|
| 929 |
lock_kernel(); |
|---|
| 930 |
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
|---|
| 931 |
if (!IS_POSIX(fl)) |
|---|
| 932 |
continue; |
|---|
| 933 |
if (fl->fl_owner != owner) |
|---|
| 934 |
break; |
|---|
| 935 |
} |
|---|
| 936 |
unlock_kernel(); |
|---|
| 937 |
return fl ? -EAGAIN : 0; |
|---|
| 938 |
} |
|---|
| 939 |
|
|---|
| 940 |
|
|---|
| 941 |
|
|---|
| 942 |
|
|---|
| 943 |
|
|---|
| 944 |
|
|---|
| 945 |
|
|---|
| 946 |
|
|---|
| 947 |
|
|---|
| 948 |
|
|---|
| 949 |
|
|---|
| 950 |
|
|---|
| 951 |
|
|---|
| 952 |
|
|---|
| 953 |
int locks_mandatory_area(int read_write, struct inode *inode, |
|---|
| 954 |
struct file *filp, loff_t offset, |
|---|
| 955 |
size_t count) |
|---|
| 956 |
{ |
|---|
| 957 |
struct file_lock fl; |
|---|
| 958 |
int error; |
|---|
| 959 |
|
|---|
| 960 |
locks_init_lock(&fl); |
|---|
| 961 |
fl.fl_owner = current->files; |
|---|
| 962 |
fl.fl_pid = current->tgid; |
|---|
| 963 |
fl.fl_file = filp; |
|---|
| 964 |
fl.fl_flags = FL_POSIX | FL_ACCESS; |
|---|
| 965 |
if (filp && !(filp->f_flags & O_NONBLOCK)) |
|---|
| 966 |
fl.fl_flags |= FL_SLEEP; |
|---|
| 967 |
fl.fl_type = (read_write == FLOCK_VERIFY_WRITE) ? F_WRLCK : F_RDLCK; |
|---|
| 968 |
fl.fl_start = offset; |
|---|
| 969 |
fl.fl_end = offset + count - 1; |
|---|
| 970 |
|
|---|
| 971 |
for (;;) { |
|---|
| 972 |
error = __posix_lock_file(inode, &fl); |
|---|
| 973 |
if (error != -EAGAIN) |
|---|
| 974 |
break; |
|---|
| 975 |
if (!(fl.fl_flags & FL_SLEEP)) |
|---|
| 976 |
break; |
|---|
| 977 |
error = wait_event_interruptible(fl.fl_wait, !fl.fl_next); |
|---|
| 978 |
if (!error) { |
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 |
|
|---|
| 982 |
|
|---|
| 983 |
if ((inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) |
|---|
| 984 |
continue; |
|---|
| 985 |
} |
|---|
| 986 |
|
|---|
| 987 |
locks_delete_block(&fl); |
|---|
| 988 |
break; |
|---|
| 989 |
} |
|---|
| 990 |
|
|---|
| 991 |
return error; |
|---|
| 992 |
} |
|---|
| 993 |
|
|---|
| 994 |
EXPORT_SYMBOL(locks_mandatory_area); |
|---|
| 995 |
|
|---|
| 996 |
|
|---|
| 997 |
static int lease_modify(struct file_lock **before, int arg) |
|---|
| 998 |
{ |
|---|
| 999 |
struct file_lock *fl = *before; |
|---|
| 1000 |
int error = assign_type(fl, arg); |
|---|
| 1001 |
|
|---|
| 1002 |
if (error) |
|---|
| 1003 |
return error; |
|---|
| 1004 |
locks_wake_up_blocks(fl); |
|---|
| 1005 |
if (arg == F_UNLCK) { |
|---|
| 1006 |
struct file *filp = fl->fl_file; |
|---|
| 1007 |
|
|---|
| 1008 |
f_delown(filp); |
|---|
| 1009 |
filp->f_owner.signum = 0; |
|---|
| 1010 |
locks_delete_lock(before); |
|---|
| 1011 |
} |
|---|
| 1012 |
return 0; |
|---|
| 1013 |
} |
|---|
| 1014 |
|
|---|
| 1015 |
static void time_out_leases(struct inode *inode) |
|---|
| 1016 |
{ |
|---|
| 1017 |
struct file_lock **before; |
|---|
| 1018 |
struct file_lock *fl; |
|---|
| 1019 |
|
|---|
| 1020 |
before = &inode->i_flock; |
|---|
| 1021 |
while ((fl = *before) && IS_LEASE(fl) && (fl->fl_type & F_INPROGRESS)) { |
|---|
| 1022 |
if ((fl->fl_break_time == 0) |
|---|
| 1023 |
|| time_before(jiffies, fl->fl_break_time)) { |
|---|
| 1024 |
before = &fl->fl_next; |
|---|
| 1025 |
continue; |
|---|
| 1026 |
} |
|---|
| 1027 |
printk(KERN_INFO "lease broken - owner pid = %d\n", fl->fl_pid); |
|---|
| 1028 |
lease_modify(before, fl->fl_type & ~F_INPROGRESS); |
|---|
| 1029 |
if (fl == *before) |
|---|
| 1030 |
before = &fl->fl_next; |
|---|
| 1031 |
} |
|---|
| 1032 |
} |
|---|
| 1033 |
|
|---|
| 1034 |
|
|---|
| 1035 |
|
|---|
| 1036 |
|
|---|
| 1037 |
|
|---|
| 1038 |
|
|---|
| 1039 |
|
|---|
| 1040 |
|
|---|
| 1041 |
|
|---|
| 1042 |
|
|---|
| 1043 |
|
|---|
| 1044 |
int __break_lease(struct inode *inode, unsigned int mode) |
|---|
| 1045 |
{ |
|---|
| 1046 |
int error = 0, future; |
|---|
| 1047 |
struct file_lock *new_fl, *flock; |
|---|
| 1048 |
struct file_lock *fl; |
|---|
| 1049 |
int alloc_err; |
|---|
| 1050 |
unsigned long break_time; |
|---|
| 1051 |
int i_have_this_lease = 0; |
|---|
| 1052 |
|
|---|
| 1053 |
alloc_err = lease_alloc(NULL, mode & FMODE_WRITE ? F_WRLCK : F_RDLCK, |
|---|
| 1054 |
&new_fl); |
|---|
| 1055 |
|
|---|
| 1056 |
lock_kernel(); |
|---|
| 1057 |
|
|---|
| 1058 |
time_out_leases(inode); |
|---|
| 1059 |
|
|---|
| 1060 |
flock = inode->i_flock; |
|---|
| 1061 |
if ((flock == NULL) || !IS_LEASE(flock)) |
|---|
| 1062 |
goto out; |
|---|
| 1063 |
|
|---|
| 1064 |
for (fl = flock; fl && IS_LEASE(fl); fl = fl->fl_next) |
|---|
| 1065 |
if (fl->fl_owner == current->files) |
|---|
| 1066 |
i_have_this_lease = 1; |
|---|
| 1067 |
|
|---|
| 1068 |
if (mode & FMODE_WRITE) { |
|---|
| 1069 |
|
|---|
| 1070 |
future = F_UNLCK | F_INPROGRESS; |
|---|
| 1071 |
} else if (flock->fl_type & F_INPROGRESS) { |
|---|
| 1072 |
|
|---|
| 1073 |
future = flock->fl_type; |
|---|
| 1074 |
} else if (flock->fl_type & F_WRLCK) { |
|---|
| 1075 |
|
|---|
| 1076 |
future = F_RDLCK | F_INPROGRESS; |
|---|
| 1077 |
} else { |
|---|
| 1078 |
|
|---|
| 1079 |
goto out; |
|---|
| 1080 |
} |
|---|
| 1081 |
|
|---|
| 1082 |
if (alloc_err && !i_have_this_lease && ((mode & O_NONBLOCK) == 0)) { |
|---|
| 1083 |
error = alloc_err; |
|---|
| 1084 |
goto out; |
|---|
| 1085 |
} |
|---|
| 1086 |
|
|---|
| 1087 |
break_time = 0; |
|---|
| 1088 |
if (lease_break_time > 0) { |
|---|
| 1089 |
break_time = jiffies + lease_break_time * HZ; |
|---|
| 1090 |
if (break_time == 0) |
|---|
| 1091 |
break_time++; |
|---|
| 1092 |
} |
|---|
| 1093 |
|
|---|
| 1094 |
for (fl = flock; fl && IS_LEASE(fl); fl = fl->fl_next) { |
|---|
| 1095 |
if (fl->fl_type != future) { |
|---|
| 1096 |
fl->fl_type = future; |
|---|
| 1097 |
fl->fl_break_time = break_time; |
|---|
| 1098 |
kill_fasync(&fl->fl_fasync, SIGIO, POLL_MSG); |
|---|
| 1099 |
} |
|---|
| 1100 |
} |
|---|
| 1101 |
|
|---|
| 1102 |
if (i_have_this_lease || (mode & O_NONBLOCK)) { |
|---|
| 1103 |
error = -EWOULDBLOCK; |
|---|
| 1104 |
goto out; |
|---|
| 1105 |
} |
|---|
| 1106 |
|
|---|
| 1107 |
restart: |
|---|
| 1108 |
break_time = flock->fl_break_time; |
|---|
| 1109 |
if (break_time != 0) { |
|---|
| 1110 |
break_time -= jiffies; |
|---|
| 1111 |
if (break_time == 0) |
|---|
| 1112 |
break_time++; |
|---|
| 1113 |
} |
|---|
| 1114 |
error = locks_block_on_timeout(flock, new_fl, break_time); |
|---|
| 1115 |
if (error >= 0) { |
|---|
| 1116 |
if (error == 0) |
|---|
| 1117 |
time_out_leases(inode); |
|---|
| 1118 |
|
|---|
| 1119 |
for (flock = inode->i_flock; flock && IS_LEASE(flock); |
|---|
| 1120 |
flock = flock->fl_next) { |
|---|
| 1121 |
if (flock->fl_type & F_INPROGRESS) |
|---|
| 1122 |
goto restart; |
|---|
| 1123 |
} |
|---|
| 1124 |
error = 0; |
|---|
| 1125 |
} |
|---|
| 1126 |
|
|---|
| 1127 |
out: |
|---|
| 1128 |
unlock_kernel(); |
|---|
| 1129 |
if (!alloc_err) |
|---|
| 1130 |
locks_free_lock(new_fl); |
|---|
| 1131 |
return error; |
|---|
| 1132 |
} |
|---|
| 1133 |
|
|---|
| 1134 |
EXPORT_SYMBOL(__break_lease); |
|---|
| 1135 |
|
|---|
| 1136 |
|
|---|
| 1137 |
|
|---|
| 1138 |
|
|---|
| 1139 |
|
|---|
| 1140 |
|
|---|
| 1141 |
|
|---|
| 1142 |
|
|---|
| 1143 |
|
|---|
| 1144 |
|
|---|
| 1145 |
void lease_get_mtime(struct inode *inode, struct timespec *time) |
|---|
| 1146 |
{ |
|---|
| 1147 |
struct file_lock *flock = inode->i_flock; |
|---|
| 1148 |
if (flock && IS_LEASE(flock) && (flock->fl_type & F_WRLCK)) |
|---|
| 1149 |
*time = CURRENT_TIME; |
|---|
| 1150 |
else |
|---|
| 1151 |
*time = inode->i_mtime; |
|---|
| 1152 |
} |
|---|
| 1153 |
|
|---|
| 1154 |
EXPORT_SYMBOL(lease_get_mtime); |
|---|
| 1155 |
|
|---|
| 1156 |
|
|---|
| 1157 |
|
|---|
| 1158 |
|
|---|
| 1159 |
|
|---|
| 1160 |
|
|---|
| 1161 |
|
|---|
| 1162 |
|
|---|
| 1163 |
|
|---|
| 1164 |
|
|---|
| 1165 |
|
|---|
| 1166 |
|
|---|
| 1167 |
|
|---|
| 1168 |
|
|---|
| 1169 |
|
|---|
| 1170 |
|
|---|
| 1171 |
|
|---|
| 1172 |
|
|---|
| 1173 |
|
|---|
| 1174 |
|
|---|
| 1175 |
|
|---|
| 1176 |
|
|---|
| 1177 |
|
|---|
| 1178 |
|
|---|
| 1179 |
int fcntl_getlease(struct file *filp) |
|---|
| 1180 |
{ |
|---|
| 1181 |
struct file_lock *fl; |
|---|
| 1182 |
int type = F_UNLCK; |
|---|
| 1183 |
|
|---|
| 1184 |
lock_kernel(); |
|---|
| 1185 |
time_out_leases(filp->f_dentry->d_inode); |
|---|
| 1186 |
for (fl = filp->f_dentry->d_inode->i_flock; fl && IS_LEASE(fl); |
|---|
| 1187 |
fl = fl->fl_next) { |
|---|
| 1188 |
if (fl->fl_file == filp) { |
|---|
| 1189 |
type = fl->fl_type & ~F_INPROGRESS; |
|---|
| 1190 |
break; |
|---|
| 1191 |
} |
|---|
| 1192 |
} |
|---|
| 1193 |
unlock_kernel(); |
|---|
| 1194 |
return type; |
|---|
| 1195 |
} |
|---|
| 1196 |
|
|---|
| 1197 |
|
|---|
| 1198 |
|
|---|
| 1199 |
|
|---|
| 1200 |
|
|---|
| 1201 |
|
|---|
| 1202 |
|
|---|
| 1203 |
|
|---|
| 1204 |
|
|---|
| 1205 |
|
|---|
| 1206 |
|
|---|
| 1207 |
int fcntl_setlease(unsigned int fd, struct file *filp, long arg) |
|---|
| 1208 |
{ |
|---|
| 1209 |
struct file_lock *fl, **before, **my_before = NULL; |
|---|
| 1210 |
struct dentry *dentry; |
|---|
| 1211 |
struct inode *inode; |
|---|
| 1212 |
int error, rdlease_count = 0, wrlease_count = 0; |
|---|
| 1213 |
|
|---|
| 1214 |
dentry = filp->f_dentry; |
|---|
| 1215 |
inode = dentry->d_inode; |
|---|
| 1216 |
|
|---|
| 1217 |
if ((current->fsuid != inode->i_uid) && !capable(CAP_LEASE)) |
|---|
| 1218 |
return -EACCES; |
|---|
| 1219 |
if (!S_ISREG(inode->i_mode)) |
|---|
| 1220 |
return -EINVAL; |
|---|
| 1221 |
error = security_file_lock(filp, arg); |
|---|
| 1222 |
if (error) |
|---|
| 1223 |
return error; |
|---|
| 1224 |
|
|---|
| 1225 |
lock_kernel(); |
|---|
| 1226 |
|
|---|
| 1227 |
time_out_leases(inode); |
|---|
| 1228 |
|
|---|
| 1229 |
|
|---|
| 1230 |
|
|---|
| 1231 |
|
|---|
| 1232 |
error = -EAGAIN; |
|---|
| 1233 |
if ((arg == F_WRLCK) |
|---|
| 1234 |
&& ((atomic_read(&dentry->d_count) > 1) |
|---|
| 1235 |
|| (atomic_read(&inode->i_count) > 1))) |
|---|
| 1236 |
goto out_unlock; |
|---|
| 1237 |
|
|---|
| 1238 |
|
|---|
| 1239 |
|
|---|
| 1240 |
|
|---|
| 1241 |
|
|---|
| 1242 |
|
|---|
| 1243 |
|
|---|
| 1244 |
|
|---|
| 1245 |
|
|---|
| 1246 |
for (before = &inode->i_flock; |
|---|
| 1247 |
((fl = *before) != NULL) && IS_LEASE(fl); |
|---|
| 1248 |
before = &fl->fl_next) { |
|---|
| 1249 |
if (fl->fl_file == filp) |
|---|
| 1250 |
my_before = before; |
|---|
| 1251 |
else if (fl->fl_type == (F_INPROGRESS | F_UNLCK)) |
|---|
| 1252 |
|
|---|
| 1253 |
|
|---|
| 1254 |
|
|---|
| 1255 |
|
|---|
| 1256 |
|
|---|
| 1257 |
wrlease_count++; |
|---|
| 1258 |
else |
|---|
| 1259 |
rdlease_count++; |
|---|
| 1260 |
} |
|---|
| 1261 |
|
|---|
| 1262 |
if ((arg == F_RDLCK && (wrlease_count > 0)) || |
|---|
| 1263 |
(arg == F_WRLCK && ((rdlease_count + wrlease_count) > 0))) |
|---|
| 1264 |
goto out_unlock; |
|---|
| 1265 |
|
|---|
| 1266 |
if (my_before != NULL) { |
|---|
| 1267 |
error = lease_modify(my_before, arg); |
|---|
| 1268 |
goto out_unlock; |
|---|
| 1269 |
} |
|---|
| 1270 |
|
|---|
| 1271 |
error = 0; |
|---|
| 1272 |
if (arg == F_UNLCK) |
|---|
| 1273 |
goto out_unlock; |
|---|
| 1274 |
|
|---|
| 1275 |
error = -EINVAL; |
|---|
| 1276 |
if (!leases_enable) |
|---|
| 1277 |
goto out_unlock; |
|---|
| 1278 |
|
|---|
| 1279 |
error = lease_alloc(filp, arg, &fl); |
|---|
| 1280 |
if (error) |
|---|
| 1281 |
goto out_unlock; |
|---|
| 1282 |
|
|---|
| 1283 |
error = fasync_helper(fd, filp, 1, &fl->fl_fasync); |
|---|
| 1284 |
if (error < 0) { |
|---|
| 1285 |
locks_free_lock(fl); |
|---|
| 1286 |
goto out_unlock; |
|---|
| 1287 |
} |
|---|
| 1288 |
|
|---|
| 1289 |
locks_insert_lock(before, fl); |
|---|
| 1290 |
|
|---|
| 1291 |
error = f_setown(filp, current->pid, 0); |
|---|
| 1292 |
out_unlock: |
|---|
| 1293 |
unlock_kernel(); |
|---|
| 1294 |
return error; |
|---|
| 1295 |
} |
|---|
| 1296 |
|
|---|
| 1297 |
|
|---|
| 1298 |
|
|---|
| 1299 |
|
|---|
| 1300 |
|
|---|
| 1301 |
|
|---|
| 1302 |
|
|---|
| 1303 |
|
|---|
| 1304 |
|
|---|
| 1305 |
|
|---|
| 1306 |
|
|---|
| 1307 |
|
|---|
| 1308 |
|
|---|
| 1309 |
|
|---|
| 1310 |
|
|---|
| 1311 |
|
|---|
| 1312 |
|
|---|
| 1313 |
|
|---|
| 1314 |
|
|---|
| 1315 |
|
|---|
| 1316 |
asmlinkage long sys_flock(unsigned int fd, unsigned int cmd) |
|---|
| 1317 |
{ |
|---|
| 1318 |
struct file *filp; |
|---|
| 1319 |
struct file_lock *lock; |
|---|
| 1320 |
int can_sleep, unlock; |
|---|
| 1321 |
int error; |
|---|
| 1322 |
|
|---|
| 1323 |
error = -EBADF; |
|---|
| 1324 |
filp = fget(fd); |
|---|
| 1325 |
if (!filp) |
|---|
| 1326 |
goto out; |
|---|
| 1327 |
|
|---|
| 1328 |
can_sleep = !(cmd & LOCK_NB); |
|---|
| 1329 |
cmd &= ~LOCK_NB; |
|---|
| 1330 |
unlock = (cmd == LOCK_UN); |
|---|
| 1331 |
|
|---|
| 1332 |
if (!unlock && !(cmd & LOCK_MAND) && !(filp->f_mode & 3)) |
|---|
| 1333 |
goto out_putf; |
|---|
| 1334 |
|
|---|
| 1335 |
error = flock_make_lock(filp, &lock, cmd); |
|---|
| 1336 |
if (error) |
|---|
| 1337 |
goto out_putf; |
|---|
| 1338 |
if (can_sleep) |
|---|
| 1339 |
lock->fl_flags |= FL_SLEEP; |
|---|
| 1340 |
|
|---|
| 1341 |
error = security_file_lock(filp, cmd); |
|---|
| 1342 |
if (error) |
|---|
| 1343 |
goto out_free; |
|---|
| 1344 |
|
|---|
| 1345 |
for (;;) { |
|---|
| 1346 |
error = flock_lock_file(filp, lock); |
|---|
| 1347 |
if ((error != -EAGAIN) || !can_sleep) |
|---|
| 1348 |
break; |
|---|
| 1349 |
error = wait_event_interruptible(lock->fl_wait, !lock->fl_next); |
|---|
| 1350 |
if (!error) |
|---|
| 1351 |
continue; |
|---|
| 1352 |
|
|---|
| 1353 |
locks_delete_block(lock); |
|---|
| 1354 |
break; |
|---|
| 1355 |
} |
|---|
| 1356 |
|
|---|
| 1357 |
out_free: |
|---|
| 1358 |
if (list_empty(&lock->fl_link)) { |
|---|
| 1359 |
locks_free_lock(lock); |
|---|
| 1360 |
} |
|---|
| 1361 |
|
|---|
| 1362 |
out_putf: |
|---|
| 1363 |
fput(filp); |
|---|
| 1364 |
out: |
|---|
| 1365 |
return error; |
|---|
| 1366 |
} |
|---|
| 1367 |
|
|---|
| 1368 |
|
|---|
| 1369 |
|
|---|
| 1370 |
|
|---|
| 1371 |
int fcntl_getlk(struct file *filp, struct flock __user *l) |
|---|
| 1372 |
{ |
|---|
| 1373 |
struct file_lock *fl, file_lock; |
|---|
| 1374 |
struct flock flock; |
|---|
| 1375 |
int error; |
|---|
| 1376 |
|
|---|
| 1377 |
error = -EFAULT; |
|---|
| 1378 |
if (copy_from_user(&flock, l, sizeof(flock))) |
|---|
| 1379 |
goto out; |
|---|
| 1380 |
error = -EINVAL; |
|---|
| 1381 |
if ((flock.l_type != F_RDLCK) && (flock.l_type != F_WRLCK)) |
|---|
| 1382 |
goto out; |
|---|
| 1383 |
|
|---|
| 1384 |
error = flock_to_posix_lock(filp, &file_lock, &flock); |
|---|
| 1385 |
if (error) |
|---|
| 1386 |
goto out; |
|---|
| 1387 |
|
|---|
| 1388 |
if (filp->f_op && filp->f_op->lock) { |
|---|
| 1389 |
error = filp->f_op->lock(filp, F_GETLK, &file_lock); |
|---|
| 1390 |
if (error < 0) |
|---|
| 1391 |
goto out; |
|---|
| 1392 |
else if (error == LOCK_USE_CLNT) |
|---|
| 1393 |
|
|---|
| 1394 |
fl = posix_test_lock(filp, &file_lock); |
|---|
| 1395 |
else |
|---|
| 1396 |
fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock); |
|---|
| 1397 |
} else { |
|---|
| 1398 |
fl = posix_test_lock(filp, &file_lock); |
|---|
| 1399 |
} |
|---|
| 1400 |
|
|---|
| 1401 |
flock.l_type = F_UNLCK; |
|---|
| 1402 |
if (fl != NULL) { |
|---|
| 1403 |
flock.l_pid = fl->fl_pid; |
|---|
| 1404 |
#if BITS_PER_LONG == 32 |
|---|
| 1405 |
|
|---|
| 1406 |
* Make sure we can represent the posix lock via |
|---|
| 1407 |
* legacy 32bit flock. |
|---|
| 1408 |
*/ |
|---|
| 1409 |
error = -EOVERFLOW; |
|---|
| 1410 |
if (fl->fl_start > OFFT_OFFSET_MAX) |
|---|
| 1411 |
goto out; |
|---|
| 1412 |
if ((fl->fl_end != OFFSET_MAX) |
|---|
| 1413 |
&& (fl->fl_end > OFFT_OFFSET_MAX)) |
|---|
| 1414 |
goto out; |
|---|
| 1415 |
#endif |
|---|
| 1416 |
flock.l_start = fl->fl_start; |
|---|
| 1417 |
flock.l_len = fl->fl_end == OFFSET_MAX ? 0 : |
|---|
| 1418 |
fl->fl_end - fl->fl_start + 1; |
|---|
| 1419 |
flock.l_whence = 0; |
|---|
| 1420 |
flock.l_type = fl->fl_type; |
|---|
| 1421 |
} |
|---|
| 1422 |
error = -EFAULT; |
|---|
| 1423 |
if (!copy_to_user(l, &flock, sizeof(flock))) |
|---|
| 1424 |
error = 0; |
|---|
| 1425 |
|
|---|
| 1426 |
out: |
|---|
| 1427 |
return error; |
|---|
| 1428 |
} |
|---|
| 1429 |
|
|---|
| 1430 |
|
|---|
| 1431 |
|
|---|
| 1432 |
|
|---|
| 1433 |
int fcntl_setlk(struct file *filp, unsigned int cmd, struct flock __user *l) |
|---|
| 1434 |
{ |
|---|
| 1435 |
struct file_lock *file_lock = locks_alloc_lock(); |
|---|
| 1436 |
struct flock flock; |
|---|
| 1437 |
struct inode *inode; |
|---|
| 1438 |
int error; |
|---|
| 1439 |
|
|---|
| 1440 |
if (file_lock == NULL) |
|---|
| 1441 |
return -ENOLCK; |
|---|
| 1442 |
|
|---|
| 1443 |
|
|---|
| 1444 |
|
|---|
| 1445 |
|
|---|
| 1446 |
error = -EFAULT; |
|---|
| 1447 |
if (copy_from_user(&flock, l, sizeof(flock))) |
|---|
| 1448 |
goto out; |
|---|
| 1449 |
|
|---|
| 1450 |
inode = filp->f_dentry->d_inode; |
|---|
| 1451 |
|
|---|
| 1452 |
|
|---|
| 1453 |
|
|---|
| 1454 |
|
|---|
| 1455 |
if (IS_MANDLOCK(inode) && |
|---|
| 1456 |
(inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID && |
|---|
| 1457 |
mapping_writably_mapped(filp->f_mapping)) { |
|---|
| 1458 |
error = -EAGAIN; |
|---|
| 1459 |
goto out; |
|---|
| 1460 |
} |
|---|
| 1461 |
|
|---|
| 1462 |
error = flock_to_posix_lock(filp, file_lock, &flock); |
|---|
| 1463 |
if (error) |
|---|
| 1464 |
goto out; |
|---|
| 1465 |
if (cmd == F_SETLKW) { |
|---|
| 1466 |
file_lock->fl_flags |= FL_SLEEP; |
|---|
| 1467 |
} |
|---|
| 1468 |
|
|---|
| 1469 |
error = -EBADF; |
|---|
| 1470 |
switch (flock.l_type) { |
|---|
| 1471 |
case F_RDLCK: |
|---|
| 1472 |
if (!(filp->f_mode & FMODE_READ)) |
|---|
| 1473 |
goto out; |
|---|
| 1474 |
break; |
|---|
| 1475 |
case F_WRLCK: |
|---|
| 1476 |
if (!(filp->f_mode & FMODE_WRITE)) |
|---|
| 1477 |
goto out; |
|---|
| 1478 |
break; |
|---|
| 1479 |
case F_UNLCK: |
|---|
| 1480 |
break; |
|---|
| 1481 |
default: |
|---|
| 1482 |
error = -EINVAL; |
|---|
| 1483 |
goto out; |
|---|
| 1484 |
} |
|---|
| 1485 |
|
|---|
| 1486 |
error = security_file_lock(filp, file_lock->fl_type); |
|---|
| 1487 |
if (error) |
|---|
| 1488 |
goto out; |
|---|
| 1489 |
|
|---|
| 1490 |
if (filp->f_op && filp->f_op->lock != NULL) { |
|---|
| 1491 |
error = filp->f_op->lock(filp, cmd, file_lock); |
|---|
| 1492 |
if (error < 0) |
|---|
| 1493 |
goto out; |
|---|
| 1494 |
} |
|---|
| 1495 |
|
|---|
| 1496 |
for (;;) { |
|---|
| 1497 |
error = __posix_lock_file(inode, file_lock); |
|---|
| 1498 |
if ((error != -EAGAIN) || (cmd == F_SETLK)) |
|---|
| 1499 |
break; |
|---|
| 1500 |
error = wait_event_interruptible(file_lock->fl_wait, |
|---|
| 1501 |
!file_lock->fl_next); |
|---|
| 1502 |
if (!error) |
|---|
| 1503 |
continue; |
|---|
| 1504 |
|
|---|
| 1505 |
locks_delete_block(file_lock); |
|---|
| 1506 |
break; |
|---|
| 1507 |
} |
|---|
| 1508 |
|
|---|
| 1509 |
out: |
|---|
| 1510 |
locks_free_lock(file_lock); |
|---|
| 1511 |
return error; |
|---|
| 1512 |
} |
|---|
| 1513 |
|
|---|
| 1514 |
#if BITS_PER_LONG == 32 |
|---|
| 1515 |
|
|---|
| 1516 |
* This implements the F_GETLK command of fcntl(). |
|---|
| 1517 |
*/ |
|---|
| 1518 |
int fcntl_getlk64(struct file *filp, struct flock64 __user *l) |
|---|
| 1519 |
{ |
|---|
| 1520 |
struct file_lock *fl, file_lock; |
|---|
| 1521 |
struct flock64 flock; |
|---|
| 1522 |
int error; |
|---|
| 1523 |
|
|---|
| 1524 |
error = -EFAULT; |
|---|
| 1525 |
if (copy_from_user(&flock, l, sizeof(flock))) |
|---|
| 1526 |
goto out; |
|---|
| 1527 |
error = -EINVAL; |
|---|
| 1528 |
if ((flock.l_type != F_RDLCK) && (flock.l_type != F_WRLCK)) |
|---|
| 1529 |
goto out; |
|---|
| 1530 |
|
|---|
| 1531 |
error = flock64_to_posix_lock(filp, &file_lock, &flock); |
|---|
| 1532 |
if (error) |
|---|
| 1533 |
goto out; |
|---|
| 1534 |
|
|---|
| 1535 |
if (filp->f_op && filp->f_op->lock) { |
|---|
| 1536 |
error = filp->f_op->lock(filp, F_GETLK, &file_lock); |
|---|
| 1537 |
if (error < 0) |
|---|
| 1538 |
goto out; |
|---|
| 1539 |
else if (error == LOCK_USE_CLNT) |
|---|
| 1540 |
|
|---|
| 1541 |
fl = posix_test_lock(filp, &file_lock); |
|---|
| 1542 |
else |
|---|
| 1543 |
fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock); |
|---|
| 1544 |
} else { |
|---|
| 1545 |
fl = posix_test_lock(filp, &file_lock); |
|---|
| 1546 |
} |
|---|
| 1547 |
|
|---|
| 1548 |
flock.l_type = F_UNLCK; |
|---|
| 1549 |
if (fl != NULL) { |
|---|
| 1550 |
flock.l_pid = fl->fl_pid; |
|---|
| 1551 |
flock.l_start = fl->fl_start; |
|---|
| 1552 |
flock.l_len = fl->fl_end == OFFSET_MAX ? 0 : |
|---|
| 1553 |
fl->fl_end - fl->fl_start + 1; |
|---|
| 1554 |
flock.l_whence = 0; |
|---|
| 1555 |
flock.l_type = fl->fl_type; |
|---|
| 1556 |
} |
|---|
| 1557 |
error = -EFAULT; |
|---|
| 1558 |
if (!copy_to_user(l, &flock, sizeof(flock))) |
|---|
| 1559 |
error = 0; |
|---|
| 1560 |
|
|---|
| 1561 |
out: |
|---|
| 1562 |
return error; |
|---|
| 1563 |
} |
|---|
| 1564 |
|
|---|
| 1565 |
|
|---|
| 1566 |
|
|---|
| 1567 |
|
|---|
| 1568 |
int fcntl_setlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l) |
|---|
| 1569 |
{ |
|---|
| 1570 |
struct file_lock *file_lock = locks_alloc_lock(); |
|---|
| 1571 |
struct flock64 flock; |
|---|
| 1572 |
struct inode *inode; |
|---|
| 1573 |
int error; |
|---|
| 1574 |
|
|---|
| 1575 |
if (file_lock == NULL) |
|---|
| 1576 |
return -ENOLCK; |
|---|
| 1577 |
|
|---|
| 1578 |
|
|---|
| 1579 |
|
|---|
| 1580 |
|
|---|
| 1581 |
error = -EFAULT; |
|---|
| 1582 |
if (copy_from_user(&flock, l, sizeof(flock))) |
|---|
| 1583 |
goto out; |
|---|
| 1584 |
|
|---|
| 1585 |
inode = filp->f_dentry->d_inode; |
|---|
| 1586 |
|
|---|
| 1587 |
|
|---|
| 1588 |
|
|---|
| 1589 |
|
|---|
| 1590 |
if (IS_MANDLOCK(inode) && |
|---|
| 1591 |
(inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID && |
|---|
| 1592 |
mapping_writably_mapped(filp->f_mapping)) { |
|---|
| 1593 |
error = -EAGAIN; |
|---|
| 1594 |
goto out; |
|---|
| 1595 |
} |
|---|
| 1596 |
|
|---|
| 1597 |
error = flock64_to_posix_lock(filp, file_lock, &flock); |
|---|
| 1598 |
if (error) |
|---|
| 1599 |
goto out; |
|---|
| 1600 |
if (cmd == F_SETLKW64) { |
|---|
| 1601 |
file_lock->fl_flags |= FL_SLEEP; |
|---|
| 1602 |
} |
|---|
| 1603 |
|
|---|
| 1604 |
error = -EBADF; |
|---|
| 1605 |
switch (flock.l_type) { |
|---|
| 1606 |
case F_RDLCK: |
|---|
| 1607 |
if (!(filp->f_mode & FMODE_READ)) |
|---|
| 1608 |
goto out; |
|---|
| 1609 |
break; |
|---|
| 1610 |
case F_WRLCK: |
|---|
| 1611 |
if (!(filp->f_mode & FMODE_WRITE)) |
|---|
| 1612 |
goto out; |
|---|
| 1613 |
break; |
|---|
| 1614 |
case F_UNLCK: |
|---|
| 1615 |
break; |
|---|
| 1616 |
default: |
|---|
| 1617 |
error = -EINVAL; |
|---|
| 1618 |
goto out; |
|---|
| 1619 |
} |
|---|
| 1620 |
|
|---|
| 1621 |
error = security_file_lock(filp, file_lock->fl_type); |
|---|
| 1622 |
if (error) |
|---|
| 1623 |
goto out; |
|---|
| 1624 |
|
|---|
| 1625 |
if (filp->f_op && filp->f_op->lock != NULL) { |
|---|
| 1626 |
error = filp->f_op->lock(filp, cmd, file_lock); |
|---|
| 1627 |
if (error < 0) |
|---|
| 1628 |
goto out; |
|---|
| 1629 |
} |
|---|
| 1630 |
|
|---|
| 1631 |
for (;;) { |
|---|
| 1632 |
error = __posix_lock_file(inode, file_lock); |
|---|
| 1633 |
if ((error != -EAGAIN) || (cmd == F_SETLK64)) |
|---|
| 1634 |
break; |
|---|
| 1635 |
error = wait_event_interruptible(file_lock->fl_wait, |
|---|
| 1636 |
!file_lock->fl_next); |
|---|
| 1637 |
if (!error) |
|---|
| 1638 |
continue; |
|---|
| 1639 |
|
|---|
| 1640 |
locks_delete_block(file_lock); |
|---|
| 1641 |
break; |
|---|
| 1642 |
} |
|---|
| 1643 |
|
|---|
| 1644 |
out: |
|---|
| 1645 |
locks_free_lock(file_lock); |
|---|
| 1646 |
return error; |
|---|
| 1647 |
} |
|---|
| 1648 |
#endif |
|---|
| 1649 |
|
|---|
| 1650 |
|
|---|
| 1651 |
|
|---|
| 1652 |
|
|---|
| 1653 |
|
|---|
| 1654 |
|
|---|
| 1655 |
void locks_remove_posix(struct file *filp, fl_owner_t owner) |
|---|
| 1656 |
{ |
|---|
| 1657 |
struct file_lock lock, **before; |
|---|
| 1658 |
|
|---|
| 1659 |
|
|---|
| 1660 |
|
|---|
| 1661 |
|
|---|
| 1662 |
|
|---|
| 1663 |
|
|---|
| 1664 |
before = &filp->f_dentry->d_inode->i_flock; |
|---|
| 1665 |
if (*before == NULL) |
|---|
| 1666 |
return; |
|---|
| 1667 |
|
|---|
| 1668 |
lock.fl_type = F_UNLCK; |
|---|
| 1669 |
lock.fl_flags = FL_POSIX; |
|---|
| 1670 |
lock.fl_start = 0; |
|---|
| 1671 |
lock.fl_end = OFFSET_MAX; |
|---|
| 1672 |
lock.fl_owner = owner; |
|---|
| 1673 |
lock.fl_pid = current->tgid; |
|---|
| 1674 |
lock.fl_file = filp; |
|---|
| 1675 |
|
|---|
| 1676 |
if (filp->f_op && filp->f_op->lock != NULL) { |
|---|
| 1677 |
filp->f_op->lock(filp, F_SETLK, &lock); |
|---|
| 1678 |
|
|---|
| 1679 |
} |
|---|
| 1680 |
|
|---|
| 1681 |
|
|---|
| 1682 |
|
|---|
| 1683 |
|
|---|
| 1684 |
lock_kernel(); |
|---|
| 1685 |
while (*before != NULL) { |
|---|
| 1686 |
struct file_lock *fl = *before; |
|---|
| 1687 |
if (IS_POSIX(fl) && (fl->fl_owner == owner)) { |
|---|
| 1688 |
locks_delete_lock(before); |
|---|
| 1689 |
continue; |
|---|
| 1690 |
} |
|---|
| 1691 |
before = &fl->fl_next; |
|---|
| 1692 |
} |
|---|
| 1693 |
unlock_kernel(); |
|---|
| 1694 |
} |
|---|
| 1695 |
|
|---|
| 1696 |
EXPORT_SYMBOL(locks_remove_posix); |
|---|
| 1697 |
|
|---|
| 1698 |
|
|---|
| 1699 |
|
|---|
| 1700 |
|
|---|
| 1701 |
void locks_remove_flock(struct file *filp) |
|---|
| 1702 |
{ |
|---|
| 1703 |
struct inode * inode = filp->f_dentry->d_inode; |
|---|
| 1704 |
struct file_lock *fl; |
|---|
| 1705 |
struct file_lock **before; |
|---|
| 1706 |
|
|---|
| 1707 |
if (!inode->i_flock) |
|---|
| 1708 |
return; |
|---|
| 1709 |
|
|---|
| 1710 |
lock_kernel(); |
|---|
| 1711 |
before = &inode->i_flock; |
|---|
| 1712 |
|
|---|
| 1713 |
while ((fl = *before) != NULL) { |
|---|
| 1714 |
if (fl->fl_file == filp) { |
|---|
| 1715 |
if (IS_FLOCK(fl)) { |
|---|
| 1716 |
locks_delete_lock(before); |
|---|
| 1717 |
continue; |
|---|
| 1718 |
} |
|---|
| 1719 |
if (IS_LEASE(fl)) { |
|---|
| 1720 |
lease_modify(before, F_UNLCK); |
|---|
| 1721 |
continue; |
|---|
| 1722 |
} |
|---|
| 1723 |
|
|---|
| 1724 |
|
|---|
| 1725 |
|
|---|
| 1726 |
BUG(); |
|---|
| 1727 |
} |
|---|
| 1728 |
before = &fl->fl_next; |
|---|
| 1729 |
} |
|---|
| 1730 |
unlock_kernel(); |
|---|
| 1731 |
} |
|---|
| 1732 |
|
|---|
| 1733 |
|
|---|
| 1734 |
|
|---|
| 1735 |
|
|---|
| 1736 |
|
|---|
| 1737 |
|
|---|
| 1738 |
|
|---|
| 1739 |
|
|---|
| 1740 |
void |
|---|
| 1741 |
posix_block_lock(struct file_lock *blocker, struct file_lock *waiter) |
|---|
| 1742 |
{ |
|---|
| 1743 |
locks_insert_block(blocker, waiter); |
|---|
| 1744 |
} |
|---|
| 1745 |
|
|---|
| 1746 |
EXPORT_SYMBOL(posix_block_lock); |
|---|
| 1747 |
|
|---|
| 1748 |
|
|---|
| 1749 |
|
|---|
| 1750 |
|
|---|
| 1751 |
|
|---|
| 1752 |
|
|---|
| 1753 |
|
|---|
| 1754 |
|
|---|
| 1755 |
void |
|---|
| 1756 |
posix_unblock_lock(struct file *filp, struct file_lock *waiter) |
|---|
| 1757 |
{ |
|---|
| 1758 |
|
|---|
| 1759 |
|
|---|
| 1760 |
|
|---|
| 1761 |
|
|---|
| 1762 |
lock_kernel(); |
|---|
| 1763 |
if (waiter->fl_next) { |
|---|
| 1764 |
__locks_delete_block(waiter); |
|---|
| 1765 |
unlock_kernel(); |
|---|
| 1766 |
} else { |
|---|
| 1767 |
unlock_kernel(); |
|---|
| 1768 |
waiter->fl_type = F_UNLCK; |
|---|
| 1769 |
posix_lock_file(filp, waiter); |
|---|
| 1770 |
} |
|---|
| 1771 |
} |
|---|
| 1772 |
|
|---|
| 1773 |
EXPORT_SYMBOL(posix_unblock_lock); |
|---|
| 1774 |
|
|---|
| 1775 |
static void lock_get_status(char* out, struct file_lock *fl, int id, char *pfx) |
|---|
| 1776 |
{ |
|---|
| 1777 |
struct inode *inode = NULL; |
|---|
| 1778 |
|
|---|
| 1779 |
if (fl->fl_file != NULL) |
|---|
| 1780 |
inode = fl->fl_file->f_dentry->d_inode; |
|---|
| 1781 |
|
|---|
| 1782 |
out += sprintf(out, "%d:%s ", id, pfx); |
|---|
| 1783 |
if (IS_POSIX(fl)) { |
|---|
| 1784 |
out += sprintf(out, "%6s %s ", |
|---|
| 1785 |
(fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ", |
|---|
| 1786 |
(inode == NULL) ? "*NOINODE*" : |
|---|
| 1787 |
(IS_MANDLOCK(inode) && |
|---|
| 1788 |
(inode->i_mode & (S_IXGRP | S_ISGID)) == S_ISGID) ? |
|---|
| 1789 |
"MANDATORY" : "ADVISORY "); |
|---|
| 1790 |
} else if (IS_FLOCK(fl)) { |
|---|
| 1791 |
if (fl->fl_type & LOCK_MAND) { |
|---|
| 1792 |
out += sprintf(out, "FLOCK MSNFS "); |
|---|
| 1793 |
} else { |
|---|
| 1794 |
out += sprintf(out, "FLOCK ADVISORY "); |
|---|
| 1795 |
} |
|---|
| 1796 |
} else if (IS_LEASE(fl)) { |
|---|
| 1797 |
out += sprintf(out, "LEASE "); |
|---|
| 1798 |
if (fl->fl_type & F_INPROGRESS) |
|---|
| 1799 |
out += sprintf(out, "BREAKING "); |
|---|
| 1800 |
else if (fl->fl_file) |
|---|
| 1801 |
out += sprintf(out, "ACTIVE "); |
|---|
| 1802 |
else |
|---|
| 1803 |
out += sprintf(out, "BREAKER "); |
|---|
| 1804 |
} else { |
|---|
| 1805 |
out += sprintf(out, "UNKNOWN UNKNOWN "); |
|---|
| 1806 |
} |
|---|
| 1807 |
if (fl->fl_type & LOCK_MAND) { |
|---|
| 1808 |
out += sprintf(out, "%s ", |
|---|
| 1809 |
(fl->fl_type & LOCK_READ) |
|---|
| 1810 |
? (fl->fl_type & LOCK_WRITE) ? "RW " : "READ " |
|---|
| 1811 |
: (fl->fl_type & LOCK_WRITE) ? "WRITE" : "NONE "); |
|---|
| 1812 |
} else { |
|---|
| 1813 |
out += sprintf(out, "%s ", |
|---|
| 1814 |
(fl->fl_type & F_INPROGRESS) |
|---|
| 1815 |
? (fl->fl_type & F_UNLCK) ? "UNLCK" : "READ " |
|---|
| 1816 |
: (fl->fl_type & F_WRLCK) ? "WRITE" : "READ "); |
|---|
| 1817 |
} |
|---|
| 1818 |
if (inode) { |
|---|
| 1819 |
#ifdef WE_CAN_BREAK_LSLK_NOW |
|---|
| 1820 |
out += sprintf(out, "%d %s:%ld ", fl->fl_pid, |
|---|
| 1821 |
inode->i_sb->s_id, inode->i_ino); |
|---|
| 1822 |
#else |
|---|
| 1823 |
|
|---|
| 1824 |
out += sprintf(out, "%d %02x:%02x:%ld ", fl->fl_pid, |
|---|
| 1825 |
MAJOR(inode->i_sb->s_dev), |
|---|
| 1826 |
MINOR(inode->i_sb->s_dev), inode->i_ino); |
|---|
| 1827 |
#endif |
|---|
| 1828 |
} else { |
|---|
| 1829 |
out += sprintf(out, "%d <none>:0 ", fl->fl_pid); |
|---|
| 1830 |
} |
|---|
| 1831 |
if (IS_POSIX(fl)) { |
|---|
| 1832 |
if (fl->fl_end == OFFSET_MAX) |
|---|
| 1833 |
out += sprintf(out, "%Ld EOF\n", fl->fl_start); |
|---|
| 1834 |
else |
|---|
| 1835 |
out += sprintf(out, "%Ld %Ld\n", fl->fl_start, |
|---|
| 1836 |
fl->fl_end); |
|---|
| 1837 |
} else { |
|---|
| 1838 |
out += sprintf(out, "0 EOF\n"); |
|---|
| 1839 |
} |
|---|
| 1840 |
} |
|---|
| 1841 |
|
|---|
| 1842 |
static void move_lock_status(char **p, off_t* pos, off_t offset) |
|---|
| 1843 |
{ |
|---|
| 1844 |
int len; |
|---|
| 1845 |
len = strlen(*p); |
|---|
| 1846 |
if(*pos >= offset) { |
|---|
| 1847 |
|
|---|
| 1848 |
*p += len; |
|---|
| 1849 |
*pos += len; |
|---|
| 1850 |
return; |
|---|
| 1851 |
} |
|---|
| 1852 |
if(*pos+len > offset) { |
|---|
| 1853 |
|
|---|
| 1854 |
int i = offset-*pos; |
|---|
| 1855 |
memmove(*p,*p+i,len-i); |
|---|
| 1856 |
*p += len-i; |
|---|
| 1857 |
*pos += len; |
|---|
| 1858 |
return; |
|---|
| 1859 |
} |
|---|
| 1860 |
|
|---|
| 1861 |
*pos += len; |
|---|
| 1862 |
} |
|---|
| 1863 |
|
|---|
| 1864 |
|
|---|
| 1865 |
|
|---|
| 1866 |
|
|---|
| 1867 |
|
|---|
| 1868 |
|
|---|
| 1869 |
|
|---|
| 1870 |
|
|---|
| 1871 |
|
|---|
| 1872 |
int get_locks_status(char *buffer, char **start, off_t offset, int length) |
|---|
| 1873 |
{ |
|---|
| 1874 |
struct list_head *tmp; |
|---|
| 1875 |
char *q = buffer; |
|---|
| 1876 |
off_t pos = 0; |
|---|
| 1877 |
int i = 0; |
|---|
| 1878 |
|
|---|
| 1879 |
lock_kernel(); |
|---|
| 1880 |
list_for_each(tmp, &file_lock_list) { |
|---|
| 1881 |
struct list_head *btmp; |
|---|
| 1882 |
struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link); |
|---|
| 1883 |
lock_get_status(q, fl, ++i, ""); |
|---|
| 1884 |
move_lock_status(&q, &pos, offset); |
|---|
| 1885 |
|
|---|
| 1886 |
if(pos >= offset+length) |
|---|
| 1887 |
goto done; |
|---|
| 1888 |
|
|---|
| 1889 |
list_for_each(btmp, &fl->fl_block) { |
|---|
| 1890 |
struct file_lock *bfl = list_entry(btmp, |
|---|
| 1891 |
struct file_lock, fl_block); |
|---|
| 1892 |
lock_get_status(q, bfl, i, " ->"); |
|---|
| 1893 |
move_lock_status(&q, &pos, offset); |
|---|
| 1894 |
|
|---|
| 1895 |
if(pos >= offset+length) |
|---|
| 1896 |
goto done; |
|---|
| 1897 |
} |
|---|
| 1898 |
} |
|---|
| 1899 |
done: |
|---|
| 1900 |
unlock_kernel(); |
|---|
| 1901 |
*start = buffer; |
|---|
| 1902 |
if(q-buffer < length) |
|---|
| 1903 |
return (q-buffer); |
|---|
| 1904 |
return length; |
|---|
| 1905 |
} |
|---|
| 1906 |
|
|---|
| 1907 |
|
|---|
| 1908 |
|
|---|
| 1909 |
|
|---|
| 1910 |
|
|---|
| 1911 |
|
|---|
| 1912 |
|
|---|
| 1913 |
|
|---|
| 1914 |
|
|---|
| 1915 |
|
|---|
| 1916 |
|
|---|
| 1917 |
|
|---|
| 1918 |
|
|---|
| 1919 |
|
|---|
| 1920 |
int lock_may_read(struct inode *inode, loff_t start, unsigned long len) |
|---|
| 1921 |
{ |
|---|
| 1922 |
struct file_lock *fl; |
|---|
| 1923 |
int result = 1; |
|---|
| 1924 |
lock_kernel(); |
|---|
| 1925 |
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
|---|
| 1926 |
if (IS_POSIX(fl)) { |
|---|
| 1927 |
if (fl->fl_type == F_RDLCK) |
|---|
| 1928 |
continue; |
|---|
| 1929 |
if ((fl->fl_end < start) || (fl->fl_start > (start + len))) |
|---|
| 1930 |
continue; |
|---|
| 1931 |
} else if (IS_FLOCK(fl)) { |
|---|
| 1932 |
if (!(fl->fl_type & LOCK_MAND)) |
|---|
| 1933 |
continue; |
|---|
| 1934 |
if (fl->fl_type & LOCK_READ) |
|---|
| 1935 |
continue; |
|---|
| 1936 |
} else |
|---|
| 1937 |
continue; |
|---|
| 1938 |
result = 0; |
|---|
| 1939 |
break; |
|---|
| 1940 |
} |
|---|
| 1941 |
unlock_kernel(); |
|---|
| 1942 |
return result; |
|---|
| 1943 |
} |
|---|
| 1944 |
|
|---|
| 1945 |
EXPORT_SYMBOL(lock_may_read); |
|---|
| 1946 |
|
|---|
| 1947 |
|
|---|
| 1948 |
|
|---|
| 1949 |
|
|---|
| 1950 |
|
|---|
| 1951 |
|
|---|
| 1952 |
|
|---|
| 1953 |
|
|---|
| 1954 |
|
|---|
| 1955 |
|
|---|
| 1956 |
|
|---|
| 1957 |
|
|---|
| 1958 |
|
|---|
| 1959 |
|
|---|
| 1960 |
int lock_may_write(struct inode *inode, loff_t start, unsigned long len) |
|---|
| 1961 |
{ |
|---|
| 1962 |
struct file_lock *fl; |
|---|
| 1963 |
int result = 1; |
|---|
| 1964 |
lock_kernel(); |
|---|
| 1965 |
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { |
|---|
| 1966 |
if (IS_POSIX(fl)) { |
|---|
| 1967 |
if ((fl->fl_end < start) || (fl->fl_start > (start + len))) |
|---|
| 1968 |
continue; |
|---|
| 1969 |
} else if (IS_FLOCK(fl)) { |
|---|
| 1970 |
if (!(fl->fl_type & LOCK_MAND)) |
|---|
| 1971 |
continue; |
|---|
| 1972 |
if (fl->fl_type & LOCK_WRITE) |
|---|
| 1973 |
continue; |
|---|
| 1974 |
} else |
|---|
| 1975 |
continue; |
|---|
| 1976 |
result = 0; |
|---|
| 1977 |
break; |
|---|
| 1978 |
} |
|---|
| 1979 |
unlock_kernel(); |
|---|
| 1980 |
return result; |
|---|
| 1981 |
} |
|---|
| 1982 |
|
|---|
| 1983 |
EXPORT_SYMBOL(lock_may_write); |
|---|
| 1984 |
|
|---|
| 1985 |
static inline void __steal_locks(struct file *file, fl_owner_t from) |
|---|
| 1986 |
{ |
|---|
| 1987 |
struct inode *inode = file->f_dentry->d_inode; |
|---|
| 1988 |
struct file_lock *fl = inode->i_flock; |
|---|
| 1989 |
|
|---|
| 1990 |
while (fl) { |
|---|
| 1991 |
if (fl->fl_file == file && fl->fl_owner == from) |
|---|
| 1992 |
fl->fl_owner = current->files; |
|---|
| 1993 |
fl = fl->fl_next; |
|---|
| 1994 |
} |
|---|
| 1995 |
} |
|---|
| 1996 |
|
|---|
| 1997 |
|
|---|
| 1998 |
|
|---|
| 1999 |
|
|---|
| 2000 |
|
|---|
| 2001 |
|
|---|
| 2002 |
|
|---|
| 2003 |
void steal_locks(fl_owner_t from) |
|---|
| 2004 |
{ |
|---|
| 2005 |
struct files_struct *files = current->files; |
|---|
| 2006 |
int i, j; |
|---|
| 2007 |
|
|---|
| 2008 |
if (from == files) |
|---|
| 2009 |
return; |
|---|
| 2010 |
|
|---|
| 2011 |
lock_kernel(); |
|---|
| 2012 |
j = 0; |
|---|
| 2013 |
for (;;) { |
|---|
| 2014 |
unsigned long set; |
|---|
| 2015 |
i = j * __NFDBITS; |
|---|
| 2016 |
if (i >= files->max_fdset || i >= files->max_fds) |
|---|
| 2017 |
break; |
|---|
| 2018 |
set = files->open_fds->fds_bits[j++]; |
|---|
| 2019 |
while (set) { |
|---|
| 2020 |
if (set & 1) { |
|---|
| 2021 |
struct file *file = files->fd[i]; |
|---|
| 2022 |
if (file) |
|---|
| 2023 |
__steal_locks(file, from); |
|---|
| 2024 |
} |
|---|
| 2025 |
i++; |
|---|
| 2026 |
set >>= 1; |
|---|
| 2027 |
} |
|---|
| 2028 |
} |
|---|
| 2029 |
unlock_kernel(); |
|---|
| 2030 |
} |
|---|
| 2031 |
EXPORT_SYMBOL(steal_locks); |
|---|
| 2032 |
|
|---|
| 2033 |
static int __init filelock_init(void) |
|---|
| 2034 |
{ |
|---|
| 2035 |
filelock_cache = kmem_cache_create("file_lock_cache", |
|---|
| 2036 |
sizeof(struct file_lock), 0, SLAB_PANIC, |
|---|
| 2037 |
init_once, NULL); |
|---|
| 2038 |
return 0; |
|---|
| 2039 |
} |
|---|
| 2040 |
|
|---|
| 2041 |
module_init(filelock_init) |
|---|