From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oren Laadan Subject: Re: [C/R v20][PATCH 20/96] c/r: make file_pos_read/write() public Date: Mon, 22 Mar 2010 20:56:39 -0400 Message-ID: <4BA811C7.80800@cs.columbia.edu> References: <1268960401-16680-1-git-send-email-orenl@cs.columbia.edu> <1268960401-16680-2-git-send-email-orenl@cs.columbia.edu> <20100322063113.GD17637@laptop> <20100323004304.GL26495@laptop> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: linux-fsdevel@vger.kernel.org, containers@lists.linux-foundation.org, Matt Helsley , Andreas Dilger To: Nick Piggin Return-path: Received: from serrano.cc.columbia.edu ([128.59.29.6]:51467 "EHLO serrano.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754048Ab0CWAzy (ORCPT ); Mon, 22 Mar 2010 20:55:54 -0400 In-Reply-To: <20100323004304.GL26495@laptop> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Nick Piggin wrote: > 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. Right. Another place is fs/exec.c that provides kernel_read(). I'll put the common code in kernel/read_write.c then. Oren. > >> + */ >> + >> +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@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >