From: Douglas Gilbert <dgilbert@interlog.com>
To: "Jörn Engel" <joern@logfs.org>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 08/10] sg: completely protect sfds
Date: Wed, 16 May 2012 17:57:48 -0400 [thread overview]
Message-ID: <4FB422DC.9030305@interlog.com> (raw)
In-Reply-To: <20120425151729.GB23492@logfs.org>
On 12-04-25 11:17 AM, Jörn Engel wrote:
> sfds is protected by sg_index_lock - except for sg_open(), where it
> isn't. Change that and add some documentation.
>
> Signed-off-by: Joern Engel<joern@logfs.org>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
> ---
> drivers/scsi/sg.c | 19 ++++++++++++++++---
> 1 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index e04b2a5..bb0514d 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -146,6 +146,7 @@ typedef struct sg_request { /* SG_MAX_QUEUE requests outstanding per file */
> } Sg_request;
>
> typedef struct sg_fd { /* holds the state of a file descriptor */
> + /* sfd_siblings is protected by sg_index_lock */
> struct list_head sfd_siblings;
> struct sg_device *parentdp; /* owning device */
> wait_queue_head_t read_wait; /* queue read until command done */
> @@ -172,6 +173,7 @@ typedef struct sg_device { /* holds the state of each scsi generic device */
> wait_queue_head_t o_excl_wait; /* queue open() when O_EXCL in use */
> int sg_tablesize; /* adapter's max scatter-gather table size */
> u32 index; /* device index number */
> + /* sfds is protected by sg_index_lock */
> struct list_head sfds;
> volatile char detached; /* 0->attached, 1->detached pending removal */
> /* exclude protected by sg_open_exclusive_lock */
> @@ -244,6 +246,17 @@ static int set_exclude(Sg_device *sdp, char val)
> return val;
> }
>
> +static int sfds_list_empty(Sg_device *sdp)
> +{
> + unsigned long flags;
> + int ret;
> +
> + read_lock_irqsave(&sg_index_lock, flags);
> + ret = list_empty(&sdp->sfds);
> + read_unlock_irqrestore(&sg_index_lock, flags);
> + return ret;
> +}
> +
> static int
> sg_open(struct inode *inode, struct file *filp)
> {
> @@ -287,12 +300,12 @@ sg_open(struct inode *inode, struct file *filp)
> retval = -EPERM; /* Can't lock it with read only access */
> goto error_out;
> }
> - if (!list_empty(&sdp->sfds)&& (flags& O_NONBLOCK)) {
> + if (!sfds_list_empty(sdp)&& (flags& O_NONBLOCK)) {
> retval = -EBUSY;
> goto error_out;
> }
> res = wait_event_interruptible(sdp->o_excl_wait,
> - ((!list_empty(&sdp->sfds) || get_exclude(sdp)) ? 0 : set_exclude(sdp, 1)));
> + ((!sfds_list_empty(sdp) || get_exclude(sdp)) ? 0 : set_exclude(sdp, 1)));
> if (res) {
> retval = res; /* -ERESTARTSYS because signal hit process */
> goto error_out;
> @@ -312,7 +325,7 @@ sg_open(struct inode *inode, struct file *filp)
> retval = -ENODEV;
> goto error_out;
> }
> - if (list_empty(&sdp->sfds)) { /* no existing opens on this device */
> + if (sfds_list_empty(sdp)) { /* no existing opens on this device */
> sdp->sgdebug = 0;
> q = sdp->device->request_queue;
> sdp->sg_tablesize = queue_max_segments(q);
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-05-16 21:58 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-12 21:32 [PATCH 01/10] sg: remove unnecessary indentation Jörn Engel
2012-04-12 21:32 ` [PATCH 02/10] sg: remove while (1) non-loop Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert
2012-04-12 21:33 ` [PATCH 03/10] " Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert
2012-04-12 21:33 ` [PATCH 04/10] sg: use wait_event_interruptible() Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert
2012-04-12 21:33 ` [PATCH 05/10] sg: remove closed flag Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert
2012-04-12 21:33 ` [PATCH 06/10] sg: prevent unwoken sleep Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert
2012-04-12 21:34 ` [PATCH 07/10] sg: protect sdp->exclude Jörn Engel
2012-04-23 22:13 ` Douglas Gilbert
2012-04-24 20:13 ` [PATCH v2 " Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert
2012-04-24 20:16 ` [PATCH " Jörn Engel
2012-04-12 21:34 ` [PATCH 08/10] sg: completely protect sfds Jörn Engel
2012-04-25 15:17 ` [PATCH v2 " Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert [this message]
2012-04-12 21:35 ` [PATCH 09/10] sg: remove sg_mutex Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert
2012-04-12 21:35 ` [PATCH 10/10] sg: constify sg_proc_leaf_arr Jörn Engel
2012-05-16 21:58 ` Douglas Gilbert
2012-05-07 19:44 ` [PATCH 01/10] sg: remove unnecessary indentation Jörn Engel
2012-05-11 14:43 ` Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert
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=4FB422DC.9030305@interlog.com \
--to=dgilbert@interlog.com \
--cc=JBottomley@parallels.com \
--cc=joern@logfs.org \
--cc=linux-scsi@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.