14 #define AFS_LOCK_GRANTED 0
15 #define AFS_LOCK_PENDING 1
18 static void afs_fl_release_private(
struct file_lock *
fl);
24 .fl_copy_lock = afs_fl_copy_lock,
25 .fl_release_private = afs_fl_release_private,
31 static int afs_init_lock_manager(
void)
36 if (!afs_lock_manager) {
38 if (!afs_lock_manager) {
41 if (!afs_lock_manager)
72 static void afs_schedule_lock_extension(
struct afs_vnode *vnode)
93 list_move_tail(&p->
fl_u.
afs.link,
117 spin_lock(&vnode->
lock);
121 spin_unlock(&vnode->
lock);
128 " Failed to release lock on {%x:%x} error %d\n",
129 vnode->
fid.vid, vnode->
fid.vnode, ret);
131 spin_lock(&vnode->
lock);
146 key = key_get(fl->
fl_file->private_data);
147 spin_unlock(&vnode->
lock);
154 afs_schedule_lock_extension(vnode);
160 " Failed to extend lock on {%x:%x} error %d\n",
161 vnode->
fid.vid, vnode->
fid.vnode, ret);
180 key = key_get(fl->
fl_file->private_data);
183 spin_unlock(&vnode->
lock);
199 spin_lock(&vnode->
lock);
206 afs_grant_locks(vnode, fl);
208 list_del_init(&fl->
fl_u.
afs.link);
210 spin_unlock(&vnode->
lock);
215 spin_unlock(&vnode->
lock);
228 spin_unlock(&vnode->
lock);
266 ret = afs_init_lock_manager();
270 fl->
fl_ops = &afs_lock_ops;
271 INIT_LIST_HEAD(&fl->
fl_u.
afs.link);
289 spin_lock(&vnode->
lock);
296 _debug(
"instant readlock");
301 goto sharing_existing_lock;
315 spin_unlock(&vnode->
lock);
322 goto acquired_server_lock;
325 spin_lock(&vnode->
lock);
331 spin_lock(&vnode->
lock);
332 list_del_init(&fl->
fl_u.
afs.link);
333 spin_unlock(&vnode->
lock);
347 spin_unlock(&vnode->
lock);
358 spin_lock(&vnode->
lock);
367 spin_lock(&vnode->
lock);
371 spin_unlock(&vnode->
lock);
385 list_del_init(&fl->
fl_u.
afs.link);
389 list_del_init(&fl->
fl_u.
afs.link);
391 spin_unlock(&vnode->
lock);
394 acquired_server_lock:
397 spin_lock(&vnode->
lock);
398 afs_schedule_lock_extension(vnode);
403 sharing_existing_lock:
414 goto vfs_rejected_lock;
415 spin_unlock(&vnode->
lock);
430 _debug(
"vfs refused %d", ret);
431 list_del_init(&fl->
fl_u.
afs.link);
433 afs_defer_unlock(vnode, key);
440 static int afs_do_unlk(
struct file *file,
struct file_lock *fl)
452 fl->
fl_ops = &afs_lock_ops;
453 INIT_LIST_HEAD(&fl->
fl_u.
afs.link);
456 spin_lock(&vnode->
lock);
459 spin_unlock(&vnode->
lock);
460 _leave(
" = %d [vfs]", ret);
466 afs_defer_unlock(vnode, key);
467 spin_unlock(&vnode->
lock);
475 static int afs_do_getlk(
struct file *file,
struct file_lock *fl)
495 lock_count = vnode->
status.lock_count;
517 struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode);
519 _enter(
"{%x:%u},%d,{t=%x,fl=%x,r=%Ld:%Ld}",
520 vnode->
fid.vid, vnode->
fid.vnode, cmd,
529 return afs_do_getlk(file, fl);
531 return afs_do_unlk(file, fl);
532 return afs_do_setlk(file, fl);
540 struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode);
542 _enter(
"{%x:%u},%d,{t=%x,fl=%x}",
543 vnode->
fid.vid, vnode->
fid.vnode, cmd,
562 return afs_do_unlk(file, fl);
563 return afs_do_setlk(file, fl);
576 list_add(&new->fl_u.afs.link, &fl->
fl_u.
afs.link);
583 static void afs_fl_release_private(
struct file_lock *fl)
587 list_del_init(&fl->
fl_u.
afs.link);