/* Make sure there's data to read. Wait for input if we can, otherwise return an appropriate error.  */
static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
/* Make sure there's data to read. Wait for input if we can, otherwise return an appropriate error.  */
static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
{
	int ret;
	if (pipe->nrbufs)
		return 0;
	ret = 0;
	pipe_lock(pipe);
	while (!pipe->nrbufs) {
		if (signal_pending(current)) {
			ret = -ERESTARTSYS;
			break;
		}
		if (!pipe->writers)
			break;
		if (!pipe->waiting_writers) {
			if (flags & SPLICE_F_NONBLOCK) {
				ret = -EAGAIN;
				break;
			}
		}
		pipe_wait(pipe);
	}
	pipe_unlock(pipe);
	return ret;
}