[Devel] Re: [C/R v20][PATCH 20/96] c/r: make file_pos_read/write() public

Nick Piggin npiggin at suse.de
Mon Mar 22 17:43:04 PDT 2010


On Mon, Mar 22, 2010 at 08:12:45PM -0400, Oren Laadan wrote:
> On Mon, 22 Mar 2010, Nick Piggin wrote:
> 
> > On Thu, Mar 18, 2010 at 08:59:45PM -0400, Oren Laadan wrote:
> > > These two are used in the next patch when calling vfs_read/write()
> > 
> > Said next patch didn't seem to make it to fsdevel.
> 
> Thanks for reviewing, and sorry about this glitch - see below.
> 
> > 
> > Should it at least go to fs/internal.h?
> 
> Sure.
> 
> So Here is the relevant hunk from said patch (the entire
> patch is: https://patchwork.kernel.org/patch/86389/):
> 
> +/*
> + * Helpers to write(read) from(to) kernel space to(from) the checkpoint
> + * image file descriptor (similar to how a core-dump is performed).
> + *
> + *   ckpt_kwrite() - write a kernel-space buffer to the checkpoint image
> + *   ckpt_kread() - read from the checkpoint image to a kernel-space buffer

Hmm, OK. Slightly-more-write(2) type of write.

fs/splice.c code also has a kernel_write and readv. Not sure if there is
any other common code. But maybe it would be better to put together some
useful helpers under fs/ rather than a ckpt specific thing.

> + */
> +
> +static inline int _ckpt_kwrite(struct file *file, void *addr, int count)
> +{
> +	void __user *uaddr = (__force void __user *) addr;
> +	ssize_t nwrite;
> +	int nleft;
> +
> +	for (nleft = count; nleft; nleft -= nwrite) {
> +		loff_t pos = file_pos_read(file);
> +		nwrite = vfs_write(file, uaddr, nleft, &pos);
> +		file_pos_write(file, pos);
> +		if (nwrite < 0) {
> +			if (nwrite == -EAGAIN)
> +				nwrite = 0;
> +			else
> +				return nwrite;
> +		}
> +		uaddr += nwrite;
> +	}
> +	return 0;
> +}
> +
> +int ckpt_kwrite(struct ckpt_ctx *ctx, void *addr, int count)
> +{
> +	mm_segment_t fs;
> +	int ret;
> +
> +	fs = get_fs();
> +	set_fs(KERNEL_DS);
> +	ret = _ckpt_kwrite(ctx->file, addr, count);
> +	set_fs(fs);
> +
> +	ctx->total += count;
> +	return ret;
> +}
> +
> +static inline int _ckpt_kread(struct file *file, void *addr, int count)
> +{
> +	void __user *uaddr = (__force void __user *) addr;
> +	ssize_t nread;
> +	int nleft;
> +
> +	for (nleft = count; nleft; nleft -= nread) {
> +		loff_t pos = file_pos_read(file);
> +		nread = vfs_read(file, uaddr, nleft, &pos);
> +		file_pos_write(file, pos);
> +		if (nread <= 0) {
> +			if (nread == -EAGAIN) {
> +				nread = 0;
> +				continue;
> +			} else if (nread == 0)
> +				nread = -EPIPE;		/* unexecpted EOF */
> +			return nread;
> +		}
> +		uaddr += nread;
> +	}
> +	return 0;
> +}
> +
> +int ckpt_kread(struct ckpt_ctx *ctx, void *addr, int count)
> +{
> +	mm_segment_t fs;
> +	int ret;
> +
> +	fs = get_fs();
> +	set_fs(KERNEL_DS);
> +	ret = _ckpt_kread(ctx->file , addr, count);
> +	set_fs(fs);
> +
> +	ctx->total += count;
> +	return ret;
> +}
> 
> Oren.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list