From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
James Bottomley <james.bottomley@hansenpartnership.com>,
Johannes Thumshirn <jth@kernel.org>,
Doug Gilberg <dgilbert@interlog.com>,
linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.com>
Subject: Re: [PATCH 4/4] sg: use standard lists for sg_requests
Date: Fri, 3 Feb 2017 11:48:34 +0100 [thread overview]
Message-ID: <3da1ab0a-8bb2-cf4a-c0bb-ab47535e68fe@suse.de> (raw)
In-Reply-To: <20170203104327.GB29497@lst.de>
On 02/03/2017 11:43 AM, Christoph Hellwig wrote:
>> typedef struct sg_request { /* SG_MAX_QUEUE requests outstanding per file */
>> - struct sg_request *nextrp; /* NULL -> tail request (slist) */
>> + struct list_head nextrp; /* list entry */
>
> s/nextrp/entry/
>
>> @@ -2078,16 +2076,13 @@ static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned lon
>> if (k < SG_MAX_QUEUE) {
>> memset(rp, 0, sizeof (Sg_request));
>> rp->parentfp = sfp;
>> + list_add(&rp->nextrp, &sfp->rq_list);
>
> The old code did a tail insertation. And this whole function should
> become a lot simpler with proper lists anyway:
>
Yeah, thought about that, too, but then I just went for the sloppy
approach to minimize changes.
> static Sg_request *
> sg_add_request(Sg_fd * sfp)
> {
> int k;
> unsigned long iflags;
> Sg_request *rp = sfp->req_arr;
>
> write_lock_irqsave(&sfp->rq_list_lock, iflags);
> if (!list_empty(&sfp->rq_list)) {
> if (!sfp->cmd_q)
> goto out_unlock;
>
> for (k = 0; k < SG_MAX_QUEUE; ++k, ++rp) {
> if (!rp->parentfp)
> break;
> }
> if (k >= SG_MAX_QUEUE)
> goto out_unlock;
> }
>
> memset(rp, 0, sizeof (Sg_request));
> rp->parentfp = sfp;
> rp->header.duration = jiffies_to_msecs(jiffies);
> list_add_tail(&rp->nextrp, &sfp->rq_list);
> write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
> return rp;
>
> out_unlock:
> write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
> return NULL;
>
Okay, will be updating the patch.
>> + if ((!sfp) || (!srp) || (list_empty(&sfp->rq_list)))
>
> No need for all these braces.
>
Okay.
>> + if (!list_empty(&srp->nextrp)) {
>> + list_del_init(&srp->nextrp);
>
> I don't think we need the _init as we never check for an empty entry.
>
Yes.
>> {
>> struct sg_fd *sfp = container_of(work, struct sg_fd, ew.work);
>> struct sg_device *sdp = sfp->parentdp;
>> + Sg_request *srp, *tmp;
>>
>> /* Cleanup any responses which were never read(). */
>> - while (sfp->headrp)
>> - sg_finish_rem_req(sfp->headrp);
>> + list_for_each_entry_safe(srp, tmp, &sfp->rq_list, nextrp)
>> + sg_finish_rem_req(srp);
>
> What protects us from concurrent removals here?
>
Nothing.
But this patch is intended to just replace the hand-rolled list
implementation, not fixing bugs here.
The problem is that 'sg_finish_rem_req()' is taking the rq_list_lock,
so it needs a bit of rework to make that work properly.
But I'll give it a go.
> Either way I'd rather keep the whіle not empty style even with
> proper lists.
>
Okay.
Cheers,
Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare@suse.de +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
prev parent reply other threads:[~2017-02-03 10:48 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-03 8:54 [PATCH 0/4] sanitize sg Hannes Reinecke
2017-02-03 8:54 ` [PATCH 1/4] sg: disable SET_FORCE_LOW_DMA Hannes Reinecke
2017-02-03 9:32 ` Johannes Thumshirn
2017-02-03 10:16 ` Hannes Reinecke
2017-02-03 10:23 ` Christoph Hellwig
2017-02-03 8:54 ` [PATCH 2/4] sg: protect access to to 'reserved' page array Hannes Reinecke
2017-02-03 9:34 ` Johannes Thumshirn
2017-02-03 10:24 ` Christoph Hellwig
2017-02-03 10:45 ` Hannes Reinecke
2017-02-03 8:54 ` [PATCH 3/4] sg: check for valid direction before starting the request Hannes Reinecke
2017-02-03 10:28 ` Christoph Hellwig
2017-02-03 10:50 ` Hannes Reinecke
2017-02-03 11:46 ` Hannes Reinecke
2017-02-03 8:54 ` [PATCH 4/4] sg: use standard lists for sg_requests Hannes Reinecke
2017-02-03 9:38 ` Johannes Thumshirn
2017-02-03 10:43 ` Christoph Hellwig
2017-02-03 10:48 ` Hannes Reinecke [this message]
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=3da1ab0a-8bb2-cf4a-c0bb-ab47535e68fe@suse.de \
--to=hare@suse.de \
--cc=dgilbert@interlog.com \
--cc=hare@suse.com \
--cc=hch@lst.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=jth@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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;
as well as URLs for NNTP newsgroup(s).