From: Tejun Heo <tj@kernel.org>
To: NeilBrown <neilb@suse.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, Al Viro <viro@ZenIV.linux.org.uk>
Subject: Re: [PATCH 2/2] sysfs/kernfs: make read requests on pre-alloc files use the buffer.
Date: Thu, 9 Oct 2014 09:52:37 -0400 [thread overview]
Message-ID: <20141009135237.GD14387@htj.dyndns.org> (raw)
In-Reply-To: <20141008235706.19126.82634.stgit@notabene.brown>
On Thu, Oct 09, 2014 at 10:57:06AM +1100, NeilBrown wrote:
> To match the previous patch which used the pre-alloc buffer for
> writes, this patch causes reads to use the same buffer.
> This is not strictly necessary as the current seq_read() will allocate
> on first read, so user-space can trigger the required pre-alloc. But
> consistency is valuable.
>
> The read function is somewhat simpler than seq_read() and, for example,
> does not support reading from an offset into the file: reads must be
> at the start of the file.
>
> As seq_read() does not use the prealloc buffer, ->seq_show is
> incompatible with ->prealloc and caused an EINVAL return from open().
> sysfs code which calls into kernfs always chooses the correct function.
>
> As the buffer is shared with writes and other reads, the mutex is
> extended to cover the copy_to_user.
>
> Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Tejun Heo <tj@kernel.org>
Some nitpicks.
> @@ -690,6 +694,12 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
> */
> of->atomic_write_len = ops->atomic_write_len;
>
> + error = -EINVAL;
> + if (ops->prealloc && ops->seq_show)
> + /* ->seq_show is incompatible with ->prealloc,
> + * ->read must be used instead.
> + */
> + goto err_free;
Let's please use fully-winged comments. If it looks weird inside the
if block, it can just be located right on top, I think. Also,
wouldn't it be better if the comment explained the reason for the
incompatibility? Along the same line, I think it'd be better if this
is also explicitly explained where ->prealloc is defined.
> +/* kernfs read callback for regular sysfs files with pre-alloc */
> +static ssize_t sysfs_kf_read(struct kernfs_open_file *of, char *buf,
> + size_t count, loff_t pos)
> +{
> + const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
> + struct kobject *kobj = of->kn->parent->priv;
> +
> + if (pos || buf != of->prealloc_buf)
> + /* If buf != of->prealloc_buf, we don't know how
> + * large it is, so cannot safely pass it to ->show
> + */
> + return 0;
> + return ops->show(kobj, of->kn->priv, buf);
> +}
Ditto on the comment formatting also shouldn't the latter condition be
a WARN_ON_ONCE()?
Thanks.
--
tejun
next prev parent reply other threads:[~2014-10-09 13:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-08 23:57 [PATCH 0/2 V2] Allow access to sysfs attributes without mem allocations NeilBrown
2014-10-08 23:57 ` [PATCH 2/2] sysfs/kernfs: make read requests on pre-alloc files use the buffer NeilBrown
2014-10-09 13:52 ` Tejun Heo [this message]
2014-10-08 23:57 ` [PATCH 1/2] sysfs/kernfs: allow attributes to request write buffer be pre-allocated NeilBrown
2014-10-09 13:32 ` Tejun Heo
-- strict thread matches above, loose matches on Subject: below --
2014-10-13 5:41 [PATCH 0/2 V3] Allow access to sysfs attributes without mem allocations NeilBrown
2014-10-13 5:41 ` [PATCH 2/2] sysfs/kernfs: make read requests on pre-alloc files use the buffer NeilBrown
2014-09-30 2:33 [PATCH 0/2] Allow access to sysfs attributes without mem allocations NeilBrown
2014-09-30 2:33 ` [PATCH 2/2] sysfs/kernfs: make read requests on pre-alloc files use the buffer NeilBrown
2014-10-05 20:02 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141009135237.GD14387@htj.dyndns.org \
--to=tj@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@suse.de \
--cc=viro@ZenIV.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox