public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Harvey Harrison <harvey.harrison@gmail.com>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	Al Viro <viro@ZenIV.linux.org.uk>
Subject: Re: [PATCH] scsi: sd_dif.c use unaligned access helpers
Date: Fri, 25 Jul 2008 22:14:00 -0700	[thread overview]
Message-ID: <1217049240.5971.51.camel@brick> (raw)
In-Reply-To: <yq1od4l8eb2.fsf@sermon.lab.mkp.net>

On Sat, 2008-07-26 at 00:22 -0400, Martin K. Petersen wrote:
> >>>>> "Harvey" == Harvey Harrison <harvey.harrison@gmail.com> writes:
> 
> [Sorry about the delayed response.  I've been traveling for a few
> days.]
> 
> Harvey> This code should be looked at carefully, while this patch
> Harvey> doesn't change any behaviour, the handling of app_tag, ref_tag
> Harvey> seems odd.  The struct defines both as __be16/32 but in these
> Harvey> locations it is read in/written out as cpu-byteorder.
> 
> The opaque tag space (app in Type 1+2, app + ref in Type 3) is
> provided for use by filesystems.  The SCSI layer doesn't know anything
> about the contents of the tag buffer.  It has no idea whether it
> contains bytes, shorts, ints or longs.  So we can't swab on the
> assumption that each DIF tuple contains an u16.  Just like we don't
> byteswap any other data coming down from above.
> 
> Filesystems must prepare tags in an endianness-aware fashion just like
> they prepare normal filesystem metadata.  And at the SCSI layer we
> treat it as a byte stream.

OK.  But everywhere in this file app_tag is treated as host-order,
and causes no end of sparse warnings.

Looking just at type1 (with some comments):

static void sd_dif_type1_set_tag(void *prot, void *tag_buf, unsigned int sectors)
{
	struct sd_dif_tuple *sdt = prot;
	char *tag = tag_buf;
	unsigned int i, j;

	for (i = 0, j = 0 ; i < sectors ; i++, j += 2, sdt++) {
//app_tag is host-order, read in as raw byte in be-order
		sdt->app_tag = tag[j] << 8 | tag[j+1];
		BUG_ON(sdt->app_tag == 0xffff);
	}
}

static void sd_dif_type1_get_tag(void *prot, void *tag_buf, unsigned int sectors)
{
	struct sd_dif_tuple *sdt = prot;
	char *tag = tag_buf;
	unsigned int i, j;

	for (i = 0, j = 0 ; i < sectors ; i++, j += 2, sdt++) {
//app_tag is host order again, read out in be-byteorder
		tag[j] = (sdt->app_tag & 0xff00) >> 8;
		tag[j+1] = sdt->app_tag & 0xff;
	}
}

So who cares what the spec says, the code is treating it as a host-order
u16 everywhere.  Similarly for the ref_tag.  So if you're going to 
manipulate them in host-order, just declare the struct in host order.

Anyways, maybe I'm mistaken here.

Harvey




  reply	other threads:[~2008-07-26  5:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-23 23:07 [PATCH] scsi: sd_dif.c use unaligned access helpers Harvey Harrison
2008-07-26  4:22 ` Martin K. Petersen
2008-07-26  5:14   ` Harvey Harrison [this message]
2008-07-26 12:26     ` Martin K. Petersen
2008-07-26 16:46       ` Harvey Harrison

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=1217049240.5971.51.camel@brick \
    --to=harvey.harrison@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --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