public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: "hch@lst.de" <hch@lst.de>
To: Bart Van Assche <Bart.VanAssche@sandisk.com>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"hch@lst.de" <hch@lst.de>
Subject: Re: [PATCH 1/2] scsi: sd: Separate zeroout and discard command choices
Date: Mon, 10 Apr 2017 09:13:43 +0200	[thread overview]
Message-ID: <20170410071343.GA5658@lst.de> (raw)
In-Reply-To: <1491595147.2559.26.camel@sandisk.com>

On Fri, Apr 07, 2017 at 07:59:08PM +0000, Bart Van Assche wrote:
> On Wed, 2017-04-05 at 07:41 -0400, Martin K. Petersen wrote:
> > +static ssize_t
> > +zeroing_mode_store(struct device *dev, struct device_attribute *attr,
> > +		   const char *buf, size_t count)
> > +{
> > +	struct scsi_disk *sdkp = to_scsi_disk(dev);
> > +
> > +	if (!capable(CAP_SYS_ADMIN))
> > +		return -EACCES;
> > +
> > +	if (!strncmp(buf, zeroing_mode[SD_ZERO_WRITE], 20))
> > +		sdkp->zeroing_mode = SD_ZERO_WRITE;
> > +	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS], 20))
> > +		sdkp->zeroing_mode = SD_ZERO_WS;
> > +	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS16_UNMAP], 20))
> > +		sdkp->zeroing_mode = SD_ZERO_WS16_UNMAP;
> > +	else if (!strncmp(buf, zeroing_mode[SD_ZERO_WS10_UNMAP], 20))
> > +		sdkp->zeroing_mode = SD_ZERO_WS10_UNMAP;
> > +	else
> > +		return -EINVAL;
> > +
> > +	return count;
> > +}
> 
> An additional question about this function: if the shell command "echo" is used
> without command-line option -n to modify the "zeroing_mode" sysfs attribute then
> a newline character will be present in buf. Does the above code handle newline
> characters correctly?

It ignores the newlines.  But we have a helper called sysfs_streq
to possible ignore it.  It might be a good idea to move the various
sysfs files in scsi to use it.

      reply	other threads:[~2017-04-10  7:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-05 11:41 [PATCH 1/2] scsi: sd: Separate zeroout and discard command choices Martin K. Petersen
2017-04-05 11:41 ` [PATCH 2/2] scsi: sd: Remove LBPRZ dependency for discards Martin K. Petersen
2017-04-07 18:36   ` Bart Van Assche
2017-04-07 18:28 ` [PATCH 1/2] scsi: sd: Separate zeroout and discard command choices Bart Van Assche
2017-04-12  1:04   ` Martin K. Petersen
2017-04-07 19:59 ` Bart Van Assche
2017-04-10  7:13   ` hch [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=20170410071343.GA5658@lst.de \
    --to=hch@lst.de \
    --cc=Bart.VanAssche@sandisk.com \
    --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