Lines Matching defs:fl

82 static bool lease_breaking(struct file_lease *fl)
84 return fl->c.flc_flags & (FL_UNLOCK_PENDING | FL_DOWNGRADE_PENDING);
87 static int target_leasetype(struct file_lease *fl)
89 if (fl->c.flc_flags & FL_UNLOCK_PENDING)
91 if (fl->c.flc_flags & FL_DOWNGRADE_PENDING)
93 return fl->c.flc_type;
161 * In addition, it also protects the fl->fl_blocked_requests list, and the
162 * fl->fl_blocker pointer for file_lock structures that are acting as lock
275 struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
277 if (fl)
278 locks_init_lock_heads(&fl->c);
280 return fl;
287 struct file_lease *fl = kmem_cache_zalloc(filelease_cache, GFP_KERNEL);
289 if (fl)
290 locks_init_lock_heads(&fl->c);
292 return fl;
296 void locks_release_private(struct file_lock *fl)
298 struct file_lock_core *flc = &fl->c;
306 if (fl->fl_ops) {
307 if (fl->fl_ops->fl_release_private)
308 fl->fl_ops->fl_release_private(fl);
309 fl->fl_ops = NULL;
312 if (fl->fl_lmops) {
313 if (fl->fl_lmops->lm_put_owner) {
314 fl->fl_lmops->lm_put_owner(flc->flc_owner);
317 fl->fl_lmops = NULL;
350 void locks_free_lock(struct file_lock *fl)
352 locks_release_private(fl);
353 kmem_cache_free(filelock_cache, fl);
358 void locks_free_lease(struct file_lease *fl)
360 kmem_cache_free(filelease_cache, fl);
379 void locks_init_lock(struct file_lock *fl)
381 memset(fl, 0, sizeof(struct file_lock));
382 locks_init_lock_heads(&fl->c);
386 void locks_init_lease(struct file_lease *fl)
388 memset(fl, 0, sizeof(*fl));
389 locks_init_lock_heads(&fl->c);
396 void locks_copy_conflock(struct file_lock *new, struct file_lock *fl)
398 new->c.flc_owner = fl->c.flc_owner;
399 new->c.flc_pid = fl->c.flc_pid;
401 new->c.flc_flags = fl->c.flc_flags;
402 new->c.flc_type = fl->c.flc_type;
403 new->fl_start = fl->fl_start;
404 new->fl_end = fl->fl_end;
405 new->fl_lmops = fl->fl_lmops;
408 if (fl->fl_lmops) {
409 if (fl->fl_lmops->lm_get_owner)
410 fl->fl_lmops->lm_get_owner(fl->c.flc_owner);
415 void locks_copy_lock(struct file_lock *new, struct file_lock *fl)
420 locks_copy_conflock(new, fl);
422 new->c.flc_file = fl->c.flc_file;
423 new->fl_ops = fl->fl_ops;
425 if (fl->fl_ops) {
426 if (fl->fl_ops->fl_copy_lock)
427 fl->fl_ops->fl_copy_lock(new, fl);
432 static void locks_move_blocks(struct file_lock *new, struct file_lock *fl)
441 if (list_empty(&fl->c.flc_blocked_requests))
444 list_splice_init(&fl->c.flc_blocked_requests,
465 static void flock_make_lock(struct file *filp, struct file_lock *fl, int type)
467 locks_init_lock(fl);
469 fl->c.flc_file = filp;
470 fl->c.flc_owner = filp;
471 fl->c.flc_pid = current->tgid;
472 fl->c.flc_flags = FL_FLOCK;
473 fl->c.flc_type = type;
474 fl->fl_end = OFFSET_MAX;
491 static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl,
496 fl->fl_start = 0;
499 fl->fl_start = filp->f_pos;
502 fl->fl_start = i_size_read(file_inode(filp));
507 if (l->l_start > OFFSET_MAX - fl->fl_start)
509 fl->fl_start += l->l_start;
510 if (fl->fl_start < 0)
516 if (l->l_len - 1 > OFFSET_MAX - fl->fl_start)
518 fl->fl_end = fl->fl_start + (l->l_len - 1);
521 if (fl->fl_start + l->l_len < 0)
523 fl->fl_end = fl->fl_start - 1;
524 fl->fl_start += l->l_len;
526 fl->fl_end = OFFSET_MAX;
528 fl->c.flc_owner = current->files;
529 fl->c.flc_pid = current->tgid;
530 fl->c.flc_file = filp;
531 fl->c.flc_flags = FL_POSIX;
532 fl->fl_ops = NULL;
533 fl->fl_lmops = NULL;
535 return assign_type(&fl->c, l->l_type);
541 static int flock_to_posix_lock(struct file *filp, struct file_lock *fl,
551 return flock64_to_posix_lock(filp, fl, &ll);
556 lease_break_callback(struct file_lease *fl)
558 kill_fasync(&fl->fl_fasync, SIGIO, POLL_MSG);
563 lease_setup(struct file_lease *fl, void **priv)
565 struct file *filp = fl->c.flc_file;
573 if (!fasync_insert_entry(fa->fa_fd, filp, &fl->fl_fasync, fa))
588 static int lease_init(struct file *filp, int type, struct file_lease *fl)
590 if (assign_type(&fl->c, type) != 0)
593 fl->c.flc_owner = filp;
594 fl->c.flc_pid = current->tgid;
596 fl->c.flc_file = filp;
597 fl->c.flc_flags = FL_LEASE;
598 fl->fl_lmops = &lease_manager_ops;
605 struct file_lease *fl = locks_alloc_lease();
608 if (fl == NULL)
611 error = lease_init(filp, type, fl);
613 locks_free_lease(fl);
616 return fl;
704 struct file_lock *fl;
709 fl = file_lock(waiter);
712 fl->fl_lmops && fl->fl_lmops->lm_notify)
713 fl->fl_lmops->lm_notify(fl);
715 locks_wake_up(fl);
859 locks_insert_lock_ctx(struct file_lock_core *fl, struct list_head *before)
861 list_add_tail(&fl->flc_list, before);
862 locks_insert_global_locks(fl);
866 locks_unlink_lock_ctx(struct file_lock_core *fl)
868 locks_delete_global_locks(fl);
869 list_del_init(&fl->flc_list);
870 locks_wake_up_blocks(fl);
874 locks_delete_lock_ctx(struct file_lock_core *fl, struct list_head *dispose)
876 locks_unlink_lock_ctx(fl);
878 list_add(&fl->flc_list, dispose);
880 locks_free_lock(file_lock(fl));
952 posix_test_lock(struct file *filp, struct file_lock *fl)
962 fl->c.flc_type = F_UNLCK;
969 if (!posix_test_locks_conflict(fl, cfl))
981 locks_copy_conflock(fl, cfl);
984 fl->c.flc_type = F_UNLCK;
1077 struct file_lock *fl;
1101 list_for_each_entry(fl, &ctx->flc_flock, c.flc_list) {
1102 if (request->c.flc_file != fl->c.flc_file)
1104 if (request->c.flc_type == fl->c.flc_type)
1107 locks_delete_lock_ctx(&fl->c, &dispose);
1118 list_for_each_entry(fl, &ctx->flc_flock, c.flc_list) {
1119 if (!flock_locks_conflict(&request->c, &fl->c))
1125 locks_insert_block(&fl->c, &request->c, flock_locks_conflict);
1149 struct file_lock *fl, *tmp;
1187 list_for_each_entry(fl, &ctx->flc_posix, c.flc_list) {
1188 if (!posix_locks_conflict(&request->c, &fl->c))
1190 if (fl->fl_lmops && fl->fl_lmops->lm_lock_expirable
1191 && (*fl->fl_lmops->lm_lock_expirable)(fl)) {
1192 owner = fl->fl_lmops->lm_mod_owner;
1193 func = fl->fl_lmops->lm_expire_lock;
1202 locks_copy_conflock(conflock, fl);
1217 if (likely(!posix_locks_deadlock(request, fl))) {
1219 __locks_insert_block(&fl->c, &request->c,
1233 list_for_each_entry(fl, &ctx->flc_posix, c.flc_list) {
1234 if (posix_same_owner(&request->c, &fl->c))
1239 list_for_each_entry_safe_from(fl, tmp, &ctx->flc_posix, c.flc_list) {
1240 if (!posix_same_owner(&request->c, &fl->c))
1244 if (request->c.flc_type == fl->c.flc_type) {
1249 if (fl->fl_end < request->fl_start - 1)
1254 if (fl->fl_start - 1 > request->fl_end)
1262 if (fl->fl_start > request->fl_start)
1263 fl->fl_start = request->fl_start;
1265 request->fl_start = fl->fl_start;
1266 if (fl->fl_end < request->fl_end)
1267 fl->fl_end = request->fl_end;
1269 request->fl_end = fl->fl_end;
1271 locks_delete_lock_ctx(&fl->c, &dispose);
1274 request = fl;
1280 if (fl->fl_end < request->fl_start)
1282 if (fl->fl_start > request->fl_end)
1286 if (fl->fl_start < request->fl_start)
1287 left = fl;
1291 if (fl->fl_end > request->fl_end) {
1292 right = fl;
1295 if (fl->fl_start >= request->fl_start) {
1300 locks_delete_lock_ctx(&fl->c, &dispose);
1318 &fl->c.flc_list);
1319 locks_delete_lock_ctx(&fl->c, &dispose);
1348 locks_insert_lock_ctx(&new_fl->c, &fl->c.flc_list);
1349 fl = new_fl;
1360 locks_insert_lock_ctx(&left->c, &fl->c.flc_list);
1388 * @fl: The lock to be applied
1399 int posix_lock_file(struct file *filp, struct file_lock *fl,
1402 return posix_lock_inode(file_inode(filp), fl, conflock);
1409 * @fl: The lock to be applied
1413 static int posix_lock_inode_wait(struct inode *inode, struct file_lock *fl)
1418 error = posix_lock_inode(inode, fl, NULL);
1421 error = wait_event_interruptible(fl->c.flc_wait,
1422 list_empty(&fl->c.flc_blocked_member));
1426 locks_delete_block(fl);
1430 static void lease_clear_pending(struct file_lease *fl, int arg)
1434 fl->c.flc_flags &= ~FL_UNLOCK_PENDING;
1437 fl->c.flc_flags &= ~FL_DOWNGRADE_PENDING;
1442 int lease_modify(struct file_lease *fl, int arg, struct list_head *dispose)
1444 int error = assign_type(&fl->c, arg);
1448 lease_clear_pending(fl, arg);
1449 locks_wake_up_blocks(&fl->c);
1451 struct file *filp = fl->c.flc_file;
1455 fasync_helper(0, fl->c.flc_file, 0, &fl->fl_fasync);
1456 if (fl->fl_fasync != NULL) {
1457 printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync);
1458 fl->fl_fasync = NULL;
1460 locks_delete_lock_ctx(&fl->c, dispose);
1477 struct file_lease *fl, *tmp;
1481 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, c.flc_list) {
1482 trace_time_out_leases(inode, fl);
1483 if (past_time(fl->fl_downgrade_time))
1484 lease_modify(fl, F_RDLCK, dispose);
1485 if (past_time(fl->fl_break_time))
1486 lease_modify(fl, F_UNLCK, dispose);
1546 struct file_lease *new_fl, *fl, *tmp;
1578 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, c.flc_list) {
1579 if (!leases_conflict(&fl->c, &new_fl->c))
1582 if (fl->c.flc_flags & FL_UNLOCK_PENDING)
1584 fl->c.flc_flags |= FL_UNLOCK_PENDING;
1585 fl->fl_break_time = break_time;
1587 if (lease_breaking(fl))
1589 fl->c.flc_flags |= FL_DOWNGRADE_PENDING;
1590 fl->fl_downgrade_time = break_time;
1592 if (fl->fl_lmops->lm_break(fl))
1593 locks_delete_lock_ctx(&fl->c, &dispose);
1606 fl = list_first_entry(&ctx->flc_lease, struct file_lease, c.flc_list);
1607 break_time = fl->fl_break_time;
1612 locks_insert_block(&fl->c, &new_fl->c, leases_conflict);
1702 struct file_lease *fl;
1713 list_for_each_entry(fl, &ctx->flc_lease, c.flc_list) {
1714 if (fl->c.flc_file != filp)
1716 type = target_leasetype(fl);
1776 struct file_lease *fl, *my_fl = NULL, *lease;
1818 list_for_each_entry(fl, &ctx->flc_lease, c.flc_list) {
1819 if (fl->c.flc_file == filp &&
1820 fl->c.flc_owner == lease->c.flc_owner) {
1821 my_fl = fl;
1835 if (fl->c.flc_flags & FL_UNLOCK_PENDING)
1885 struct file_lease *fl, *victim = NULL;
1898 list_for_each_entry(fl, &ctx->flc_lease, c.flc_list) {
1899 if (fl->c.flc_file == filp &&
1900 fl->c.flc_owner == owner) {
1901 victim = fl;
1907 error = fl->fl_lmops->lm_change(victim, F_UNLCK, &dispose);
2028 struct file_lease *fl;
2032 fl = lease_alloc(filp, arg);
2033 if (IS_ERR(fl))
2034 return PTR_ERR(fl);
2038 locks_free_lease(fl);
2043 error = vfs_setlease(filp, arg, &fl, (void **)&new);
2044 if (fl)
2045 locks_free_lease(fl);
2071 * @fl: The lock to be applied
2075 static int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl)
2080 error = flock_lock_inode(inode, fl);
2083 error = wait_event_interruptible(fl->c.flc_wait,
2084 list_empty(&fl->c.flc_blocked_member));
2088 locks_delete_block(fl);
2095 * @fl: The lock to be applied
2099 int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
2102 switch (fl->c.flc_flags & (FL_POSIX|FL_FLOCK)) {
2104 res = posix_lock_inode_wait(inode, fl);
2107 res = flock_lock_inode_wait(inode, fl);
2134 struct file_lock fl;
2162 flock_make_lock(f.file, &fl, type);
2164 error = security_file_lock(f.file, fl.c.flc_type);
2170 fl.c.flc_flags |= FL_SLEEP;
2175 &fl);
2177 error = locks_lock_file_wait(f.file, &fl);
2179 locks_release_private(&fl);
2189 * @fl: The lock to test; also used to hold result
2194 int vfs_test_lock(struct file *filp, struct file_lock *fl)
2196 WARN_ON_ONCE(filp != fl->c.flc_file);
2198 return filp->f_op->lock(filp, F_GETLK, fl);
2199 posix_test_lock(filp, fl);
2206 * @fl: The file_lock who's fl_pid should be translated
2211 static pid_t locks_translate_pid(struct file_lock_core *fl, struct pid_namespace *ns)
2216 if (fl->flc_flags & FL_OFDLCK)
2220 if (fl->flc_pid <= 0)
2221 return fl->flc_pid;
2229 return (pid_t) fl->flc_pid;
2232 pid = find_pid_ns(fl->flc_pid, &init_pid_ns);
2238 static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)
2240 flock->l_pid = locks_translate_pid(&fl->c, task_active_pid_ns(current));
2246 if (fl->fl_start > OFFT_OFFSET_MAX)
2248 if (fl->fl_end != OFFSET_MAX && fl->fl_end > OFFT_OFFSET_MAX)
2251 flock->l_start = fl->fl_start;
2252 flock->l_len = fl->fl_end == OFFSET_MAX ? 0 :
2253 fl->fl_end - fl->fl_start + 1;
2255 flock->l_type = fl->c.flc_type;
2260 static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl)
2262 flock->l_pid = locks_translate_pid(&fl->c, task_active_pid_ns(current));
2263 flock->l_start = fl->fl_start;
2264 flock->l_len = fl->fl_end == OFFSET_MAX ? 0 :
2265 fl->fl_end - fl->fl_start + 1;
2267 flock->l_type = fl->c.flc_type;
2276 struct file_lock *fl;
2279 fl = locks_alloc_lock();
2280 if (fl == NULL)
2287 error = flock_to_posix_lock(filp, fl, flock);
2296 fl->c.flc_flags |= FL_OFDLCK;
2297 fl->c.flc_owner = filp;
2300 error = vfs_test_lock(filp, fl);
2304 flock->l_type = fl->c.flc_type;
2305 if (fl->c.flc_type != F_UNLCK) {
2306 error = posix_lock_to_flock(flock, fl);
2311 locks_free_lock(fl);
2319 * @fl: The lock to be applied
2350 int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf)
2352 WARN_ON_ONCE(filp != fl->c.flc_file);
2354 return filp->f_op->lock(filp, cmd, fl);
2356 return posix_lock_file(filp, fl, conf);
2361 struct file_lock *fl)
2365 error = security_file_lock(filp, fl->c.flc_type);
2370 error = vfs_lock_file(filp, cmd, fl, NULL);
2373 error = wait_event_interruptible(fl->c.flc_wait,
2374 list_empty(&fl->c.flc_blocked_member));
2378 locks_delete_block(fl);
2383 /* Ensure that fl->fl_file has compatible f_mode for F_SETLK calls */
2385 check_fmode_for_setlk(struct file_lock *fl)
2387 switch (fl->c.flc_type) {
2389 if (!(fl->c.flc_file->f_mode & FMODE_READ))
2393 if (!(fl->c.flc_file->f_mode & FMODE_WRITE))
2485 struct file_lock *fl;
2488 fl = locks_alloc_lock();
2489 if (fl == NULL)
2497 error = flock64_to_posix_lock(filp, fl, flock);
2506 fl->c.flc_flags |= FL_OFDLCK;
2507 fl->c.flc_owner = filp;
2510 error = vfs_test_lock(filp, fl);
2514 flock->l_type = fl->c.flc_type;
2515 if (fl->c.flc_type != F_UNLCK)
2516 posix_lock_to_flock64(flock, fl);
2519 locks_free_lock(fl);
2646 struct file_lock fl;
2652 flock_make_lock(filp, &fl, F_UNLCK);
2653 fl.c.flc_flags |= FL_CLOSE;
2656 filp->f_op->flock(filp, F_SETLKW, &fl);
2658 flock_lock_inode(inode, &fl);
2660 if (fl.fl_ops && fl.fl_ops->fl_release_private)
2661 fl.fl_ops->fl_release_private(&fl);
2668 struct file_lease *fl, *tmp;
2676 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, c.flc_list)
2677 if (filp == fl->c.flc_file)
2678 lease_modify(fl, F_UNLCK, &dispose);
2715 * @fl: The lock to be unblocked
2719 int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
2721 WARN_ON_ONCE(filp != fl->c.flc_file);
2723 return filp->f_op->lock(filp, F_CANCELLK, fl);
2767 struct file_lock *fl = file_lock(flc);
2827 if (fl->fl_end == OFFSET_MAX)
2828 seq_printf(f, "%Ld EOF\n", fl->fl_start);
2830 seq_printf(f, "%Ld %Ld\n", fl->fl_start, fl->fl_end);
2904 struct file_lock_core *fl;
2906 list_for_each_entry(fl, head, flc_list) {
2908 if (filp != fl->flc_file)
2910 if (fl->flc_owner != files && fl->flc_owner != filp)
2915 lock_get_status(f, fl, *id, "", 0);