for (;;) { error = __posix_lock_file(inode, file_lock); if ((error != -EAGAIN) || (cmd == F_SETLK)) break; error = wait_event_interruptible(file_lock->fl_wait, !file_lock->fl_next); if (!error) continue;  locks_delete_block(file_lock); break;
if (!error && fcheck(fd) != filp && flock.l_type != F_UNLCK) { flock.l_type = F_UNLCK; goto again;
int fcntl_setlk(struct file *filp, unsigned int cmd, struct flock __user *l){	struct file_lock *file_lock = locks_alloc_lock();	struct flock flock;	struct inode *inode;	int error;	if (file_lock == NULL)		return -ENOLCK;	/*	 * This might block, so we do it before checking the inode.	 */	error = -EFAULT;	if (copy_from_user(&flock, l, sizeof(flock)))		goto out;	inode = filp->f_dentry->d_inode;	/* Don't allow mandatory locks on files that may be memory mapped	 * and shared.	 */	if (IS_MANDLOCK(inode) &&	    (inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID &&	    mapping_writably_mapped(filp->f_mapping)) {		error = -EAGAIN;		goto out;	}	error = flock_to_posix_lock(filp, file_lock, &flock);	if (error)		goto out;	if (cmd == F_SETLKW) {		file_lock->fl_flags |= FL_SLEEP;	}		error = -EBADF;	switch (flock.l_type) {	case F_RDLCK:		if (!(filp->f_mode & FMODE_READ))			goto out;		break;	case F_WRLCK:		if (!(filp->f_mode & FMODE_WRITE))			goto out;		break;	case F_UNLCK:		break;	default:		error = -EINVAL;		goto out;	}	error = security_file_lock(filp, file_lock->fl_type);	if (error)		goto out;	if (filp->f_op && filp->f_op->lock != NULL) {		error = filp->f_op->lock(filp, cmd, file_lock);		goto out;	}	for (;;) {		error = __posix_lock_file(inode, file_lock);		if ((error != -EAGAIN) || (cmd == F_SETLK))			break;		error = wait_event_interruptible(file_lock->fl_wait,				!file_lock->fl_next);		if (!error)			continue;		locks_delete_block(file_lock);		break;	} out:	locks_free_lock(file_lock);	return error;}