linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Douglas Gilbert <dgilbert@interlog.com>
Cc: SCSI development list <linux-scsi@vger.kernel.org>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	vaughan <vaughan.cao@oracle.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] sg: O_EXCL and other lock handling
Date: Thu, 31 Oct 2013 08:56:53 -0700	[thread overview]
Message-ID: <20131031155653.GA16944@infradead.org> (raw)
In-Reply-To: <52718713.7050906@interlog.com>

> +	struct semaphore or_sem;  /* protect co-incident opens and releases */

Seems like this should be a mutex.

> sfds_list_empty(Sg_device *sdp)
>  {
>  	unsigned long flags;
>  	int ret;
>  
> +	spin_lock_irqsave(&sdp->sfd_lock, flags);
> +	ret = list_empty(&sdp->sfds);
> +	spin_unlock_irqrestore(&sdp->sfd_lock, flags);
>  	return ret;

Protecting just a list_empty check with a local will give you racy
results.  Seems like you should take the look over the check and the
resulting action that modifies the list.  That'd also mean replacing the
wait_event* calls with open coded prepare_wait / finish_wait loops.

> +	down(&sdp->or_sem);
> +	alone = sfds_list_empty(sdp);
> +	if ((flags & O_EXCL) && (O_RDONLY == (flags & O_ACCMODE))) {
> +		retval = -EPERM; /* Don't allow O_EXCL with read only access */
> +		goto error_out;
> +	}

Seems like the pure flags check should move to the beginning of the
function before taking any locks.


  reply	other threads:[~2013-10-31 15:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-30 22:24 [PATCH v2] sg: O_EXCL and other lock handling Douglas Gilbert
2013-10-31 15:56 ` Christoph Hellwig [this message]
2013-10-31 19:20   ` Douglas Gilbert
2013-11-01  5:14     ` vaughan
2013-11-01  5:16     ` vaughan
2013-11-02 18:22       ` Douglas Gilbert
2013-11-03  6:32         ` Vaughan Cao
2013-11-06 15:50     ` Christoph Hellwig
2013-11-06 19:30       ` Douglas Gilbert
2013-11-07 21:44         ` Christoph Hellwig

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=20131031155653.GA16944@infradead.org \
    --to=hch@infradead.org \
    --cc=dgilbert@interlog.com \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=vaughan.cao@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).