util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: Tony Asleson <tasleson@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH RFC 1/1] libblkid: Add support for stratis
Date: Mon, 8 Jan 2018 12:16:14 +0100	[thread overview]
Message-ID: <20180108111614.wd2eueagamfbcsil@ws.net.home> (raw)
In-Reply-To: <20180105171539.5948-2-tasleson@redhat.com>

On Fri, Jan 05, 2018 at 11:15:39AM -0600, Tony Asleson wrote:
> +static int stratis_valid_sb(blkid_probe pr, uint8_t *p)
> +{
> +	const struct stratis_sb *stratis = (const struct stratis_sb *)p;
> +	uint32_t crc = 0;
> +
> +	// generate CRC from byte position 4 for length 508 == 512 byte sector
> +	crc = crc32c(~0L, p + sizeof(stratis->crc32),
> +			BS - sizeof(stratis->crc32));
> +	crc ^= ~0L;
> +
> +	return blkid_probe_verify_csum(pr, crc, le32_to_cpu(stratis->crc32));

Not sure that blkid_probe_verify_csum() is a good idea for your
use-case. 

The function ignores (returns 1) bad checksums if BLKID_SUBLKS_BADCSUM
flag is enabled. I guess you want to use second (backup) superblock 
if the primary one is broken. It would be better to use

    return crc == le32_to_cpu(stratis->crc32);

and do not use blkid_probe_verify_csum() at all.

> +static int probe_stratis(blkid_probe pr,
> +		const struct blkid_idmag *mag __attribute__((__unused__)))
> +{
> +	const struct stratis_sb *stratis = NULL;
> +	uint8_t *buf = blkid_probe_get_buffer(pr, 0, SB_AREA_SIZE);
> +
> +	if (!buf)
> +		return errno ? -errno : 1;
> +
> +	if (stratis_valid_sb(pr, buf + FIRST_COPY_OFFSET)) {
> +		stratis = (const struct stratis_sb *)(buf + FIRST_COPY_OFFSET);
> +	} else {
> +		if (!stratis_valid_sb(pr, buf + SECOND_COPY_OFFSET))
> +			return 1;
> +
> +		stratis = (const struct stratis_sb *)
> +				(buf + SECOND_COPY_OFFSET);
> +	}
> +
> +	blkid_probe_strncpy_uuid(pr, (unsigned char *)stratis->dev_uuid,
> +					sizeof(stratis->dev_uuid));
> +	blkid_probe_set_value(pr, "POOL_UUID",
> +				(unsigned char *)stratis->pool_uuid,
> +				sizeof(stratis->pool_uuid));
> +
> +	blkid_probe_sprintf_value(pr, "SECTORS", "%" PRIu64, stratis->sectors);

Hmm... SECTORS sounds pretty generic. Don't forget it will be
stored in udevd db. Would be possible to use any prefix?

For example:

    POOL_SECTORS

> +	blkid_probe_sprintf_value(pr, "INITIALIZATION_TIME", "%" PRIu64,
> +					stratis->initialization_time);

    POOL_INITTIME

Karel



-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

  reply	other threads:[~2018-01-08 11:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-05 17:15 [PATCH RFC 0/1] libblkid: Initial support for Stratis Tony Asleson
2018-01-05 17:15 ` [PATCH RFC 1/1] libblkid: Add support for stratis Tony Asleson
2018-01-08 11:16   ` Karel Zak [this message]
2018-01-09 21:13     ` Tony Asleson

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=20180108111614.wd2eueagamfbcsil@ws.net.home \
    --to=kzak@redhat.com \
    --cc=tasleson@redhat.com \
    --cc=util-linux@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 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).