diff mbox

[v6,1/6] libfs: define simple_read_iter_from_buffer

Message ID 1502808237-2035-2-git-send-email-zohar@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mimi Zohar Aug. 15, 2017, 2:43 p.m. UTC
In preparation for defining an integrity_read file operation
method for efivarfs, define a simple_read_iter_from_buffer()
function.

(Based on Al's code as posted in thread.)

Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>

---
Changelog v6:
- defined as a separate patch
 
 fs/libfs.c         | 32 ++++++++++++++++++++++++++++++++
 include/linux/fs.h |  2 ++
 2 files changed, 34 insertions(+)

Comments

Christoph Hellwig Aug. 16, 2017, 6:35 a.m. UTC | #1
Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Mimi Zohar Aug. 16, 2017, 5:43 p.m. UTC | #2
On Wed, 2017-08-16 at 08:35 +0200, Christoph Hellwig wrote:
> Looks good,
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

Thank you for the reviewed-by's.

Up to now I haven't been removing the Changelog before sending James a
pull request.  Adding the dashes in the commit itself, only changes
how the patches are applied by others to their local branch, not to
what would be upstreamed.  Am I suppose to be removing the changelog
before sending a pull request?

thanks,

Mimi
James Morris Aug. 17, 2017, 2:42 a.m. UTC | #3
On Wed, 16 Aug 2017, Mimi Zohar wrote:

> On Wed, 2017-08-16 at 08:35 +0200, Christoph Hellwig wrote:
> > Looks good,
> > 
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> Thank you for the reviewed-by's.
> 
> Up to now I haven't been removing the Changelog before sending James a
> pull request.  Adding the dashes in the commit itself, only changes
> how the patches are applied by others to their local branch, not to
> what would be upstreamed.  Am I suppose to be removing the changelog
> before sending a pull request?

I don't really understand this, but leave the changelog in?
Mimi Zohar Aug. 17, 2017, 11 a.m. UTC | #4
On Thu, 2017-08-17 at 12:42 +1000, James Morris wrote:
> On Wed, 16 Aug 2017, Mimi Zohar wrote:
> 
> > On Wed, 2017-08-16 at 08:35 +0200, Christoph Hellwig wrote:
> > > Looks good,
> > > 
> > > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > 
> > Thank you for the reviewed-by's.
> > 
> > Up to now I haven't been removing the Changelog before sending James a
> > pull request.  Adding the dashes in the commit itself, only changes
> > how the patches are applied by others to their local branch, not to
> > what would be upstreamed.  Am I suppose to be removing the changelog
> > before sending a pull request?
> 
> I don't really understand this, but leave the changelog in?

Christoph had commented that the "---" should be before the Changelog,
not afterwards, so that git-am skips them.  The changelog is needed by
reviewers, but once upstreamed it isn't really needed any more.  Based
on Christph's response (offline), any information in the changelog
that is still useful, should move into the commit description itself
or code.

Mimi
Dmitry Kasatkin Aug. 22, 2017, 10:04 a.m. UTC | #5
Looks good to me.


On Tue, Aug 15, 2017 at 5:43 PM, Mimi Zohar <zohar@linux.vnet.ibm.com> wrote:
> In preparation for defining an integrity_read file operation
> method for efivarfs, define a simple_read_iter_from_buffer()
> function.
>
> (Based on Al's code as posted in thread.)
>
> Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
> Cc: Matthew Garrett <mjg59@srcf.ucam.org>
>
> ---
> Changelog v6:
> - defined as a separate patch
>
>  fs/libfs.c         | 32 ++++++++++++++++++++++++++++++++
>  include/linux/fs.h |  2 ++
>  2 files changed, 34 insertions(+)
>
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 3aabe553fc45..b6e304c6828b 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -16,6 +16,7 @@
>  #include <linux/exportfs.h>
>  #include <linux/writeback.h>
>  #include <linux/buffer_head.h> /* sync_mapping_buffers */
> +#include <linux/uio.h>
>
>  #include <linux/uaccess.h>
>
> @@ -676,6 +677,37 @@ ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
>  EXPORT_SYMBOL(simple_write_to_buffer);
>
>  /**
> + * simple_read_iter_from_buffer - copy data from the buffer to user space
> + * @iocb: struct containing the file, the current position and other info
> + * @to: the user space buffer to read to
> + * @from: the buffer to read from
> + * @available: the size of the buffer
> + *
> + * The simple_read_iter_from_buffer() function reads up to @available bytes
> + * from the current buffer into the user space buffer.
> + *
> + * On success, the current buffer offset is advanced by the number of bytes
> + * read, or a negative value is returned on error.
> + **/
> +ssize_t simple_read_iter_from_buffer(struct kiocb *iocb, struct iov_iter *to,
> +                                    const void *from, size_t available)
> +{
> +       loff_t pos = iocb->ki_pos;
> +       size_t ret;
> +
> +       if (pos < 0)
> +               return -EINVAL;
> +       if (pos >= available)
> +               return 0;
> +       ret = copy_to_iter(from + pos, available - pos, to);
> +       if (!ret && iov_iter_count(to))
> +               return -EFAULT;
> +       iocb->ki_pos = pos + ret;
> +       return ret;
> +}
> +EXPORT_SYMBOL(simple_read_iter_from_buffer);
> +
> +/**
>   * memory_read_from_buffer - copy data from the buffer
>   * @to: the kernel space buffer to read to
>   * @count: the maximum number of bytes to read
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 6e1fd5d21248..fdec9b763b54 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3097,6 +3097,8 @@ extern void simple_release_fs(struct vfsmount **mount, int *count);
>
>  extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
>                         loff_t *ppos, const void *from, size_t available);
> +extern ssize_t simple_read_iter_from_buffer(struct kiocb *iocb,
> +               struct iov_iter *to, const void *from, size_t available);
>  extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
>                 const void __user *from, size_t count);
>
> --
> 2.7.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/libfs.c b/fs/libfs.c
index 3aabe553fc45..b6e304c6828b 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -16,6 +16,7 @@ 
 #include <linux/exportfs.h>
 #include <linux/writeback.h>
 #include <linux/buffer_head.h> /* sync_mapping_buffers */
+#include <linux/uio.h>
 
 #include <linux/uaccess.h>
 
@@ -676,6 +677,37 @@  ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
 EXPORT_SYMBOL(simple_write_to_buffer);
 
 /**
+ * simple_read_iter_from_buffer - copy data from the buffer to user space
+ * @iocb: struct containing the file, the current position and other info
+ * @to: the user space buffer to read to
+ * @from: the buffer to read from
+ * @available: the size of the buffer
+ *
+ * The simple_read_iter_from_buffer() function reads up to @available bytes
+ * from the current buffer into the user space buffer.
+ *
+ * On success, the current buffer offset is advanced by the number of bytes
+ * read, or a negative value is returned on error.
+ **/
+ssize_t simple_read_iter_from_buffer(struct kiocb *iocb, struct iov_iter *to,
+				     const void *from, size_t available)
+{
+	loff_t pos = iocb->ki_pos;
+	size_t ret;
+
+	if (pos < 0)
+		return -EINVAL;
+	if (pos >= available)
+		return 0;
+	ret = copy_to_iter(from + pos, available - pos, to);
+	if (!ret && iov_iter_count(to))
+		return -EFAULT;
+	iocb->ki_pos = pos + ret;
+	return ret;
+}
+EXPORT_SYMBOL(simple_read_iter_from_buffer);
+
+/**
  * memory_read_from_buffer - copy data from the buffer
  * @to: the kernel space buffer to read to
  * @count: the maximum number of bytes to read
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6e1fd5d21248..fdec9b763b54 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3097,6 +3097,8 @@  extern void simple_release_fs(struct vfsmount **mount, int *count);
 
 extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
 			loff_t *ppos, const void *from, size_t available);
+extern ssize_t simple_read_iter_from_buffer(struct kiocb *iocb,
+		struct iov_iter *to, const void *from, size_t available);
 extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
 		const void __user *from, size_t count);