From: Jeff Moyer <jmoyer@redhat.com>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: Re: [PATCH 4 of 7] block: bio data integrity support
Date: Tue, 10 Jun 2008 16:52:20 -0400 [thread overview]
Message-ID: <x491w359fne.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <f2ae9d5bce4c33e12083.1212814537@sermon.lab.mkp.net> (Martin K. Petersen's message of "Sat, 07 Jun 2008 00:55:37 -0400")
"Martin K. Petersen" <martin.petersen@oracle.com> writes:
Comments inlined below.
> +struct bip *bio_integrity_alloc_bioset(struct bio *bio, gfp_t gfp_mask, unsigned int nr_vecs, struct bio_set *bs)
> +{
> + struct bip *bip;
> + struct bio_vec *bv;
> + unsigned long idx;
> +
> + BUG_ON(bio == NULL);
> +
> + bip = mempool_alloc(bs->bio_integrity_pool, gfp_mask);
> + if (unlikely(bip == NULL)) {
> + printk(KERN_ERR "%s: could not alloc bip\n", __func__);
> + return NULL;
> + }
> +
> + memset(bip, 0, sizeof(*bip));
> + idx = 0;
That assignment isn't necessary.
> +int bio_integrity_set_tag(struct bio *bio, void *tag_buf, unsigned int len)
> +{
> + struct bip *bip = bio->bi_integrity;
> + struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
> + unsigned int nr_sectors;
> +
> + BUG_ON(bip->bip_buf == NULL);
> + BUG_ON(bio_data_dir(bio) != WRITE);
> +
> + if (bi->tag_size == 0)
> + return -1;
> +
> + nr_sectors = len / bi->tag_size;
> +
> + if (len % 2)
> + nr_sectors++;
I see you've changed this to:
nr_sectors = (len + bi->tag_size - 1) / bi->tag_size;
why not simply use DIV_ROUND_UP?
> +
> + if (bi->sector_size == 4096)
> + nr_sectors >>= 3;
> +
> + if (nr_sectors * bi->tuple_size > bip->bip_size) {
> + printk(KERN_ERR "%s: tag too big for bio: %u > %u\n",
> + __func__, nr_sectors * bi->tuple_size, bip->bip_size);
> + return -1;
> + }
> +
> + bi->set_tag_fn(bip->bip_buf, tag_buf, nr_sectors);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(bio_integrity_set_tag);
> +
> +/**
> + * bio_integrity_get_tag - Retrieve a tag buffer from a bio
> + * @bio: bio to retrieve buffer from
> + * @tag_buf: Pointer to a buffer for the tag data
> + * @len: Length of the target buffer
> + *
> + * Description: Use this function to retrieve the tag buffer from a
> + * completed I/O. The size of the integrity buffer must be <= to the
> + * size reported by bio_integrity_tag_size().
> + */
> +int bio_integrity_get_tag(struct bio *bio, void *tag_buf, unsigned int len)
> +{
> + struct bip *bip = bio->bi_integrity;
> + struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
> + unsigned int nr_sectors;
> +
> + BUG_ON(bip->bip_buf == NULL);
> + BUG_ON(bio_data_dir(bio) != READ);
> +
> + if (bi->tag_size == 0)
> + return -1;
> +
> + nr_sectors = len / bi->tag_size;
> +
> + if (len % 2)
> + nr_sectors++;
> +
> + if (bi->sector_size == 4096)
> + nr_sectors >>= 3;
> +
> + if (nr_sectors * bi->tuple_size > bip->bip_size) {
> + printk(KERN_ERR "%s: tag too big for bio: %u > %u\n",
> + __func__, nr_sectors * bi->tuple_size, bip->bip_size);
> + return -1;
> + }
> +
> + bi->get_tag_fn(bip->bip_buf, tag_buf, nr_sectors);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(bio_integrity_get_tag);
set_tag and get_tag are almost identical. Any chance you want to factor
out that code?
> +/**
> + * bio_integrity_generate - Generate integrity metadata for a bio
> + * @bio: bio to generate integrity metadata for
> + *
> + * Description: Generates integrity metadata for a bio by calling the
> + * block device's generation callback function. The bio must have a
> + * bip attached with enough room to accomodate the generated integrity
^^^^^^^^^^
accommodate
> + * metadata.
> + */
> +static void bio_integrity_generate(struct bio *bio)
> +{
> + struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
Hmm, up until this point you use bi to mean bio_integrity, but now
it means blk_integrity. Confusion will ensue. ;)
> + struct blk_integrity_exchg bix;
struct blk_integrity_exchg is not yet defined in your patch set, so this
will likely break git bisect.
> +int bio_integrity_prep(struct bio *bio)
> +{
...
> + buf = kzalloc(len, GFP_NOIO | q->bounce_gfp);
Does this actually need to be zeroed?
> +void bio_integrity_advance(struct bio *bio, unsigned int bytes_done)
...
> + bip_for_each_vec(iv, bip, i) {
> + if (skip == 0) {
> + bip->bip_idx = i;
> + return;
> + } else if (skip >= iv->bv_len) {
> + skip -= iv->bv_len;
> + } else { /* skip < iv->bv_len) */
> + iv->bv_offset += skip;
> + iv->bv_len -= skip;
> + bip->bip_idx = i;
> + return;
> + }
> + }
> +}
> +void bio_integrity_trim(struct bio *bio, unsigned int offset, unsigned int sectors)
> +{
...
> + /* Mark head */
> + bip_for_each_vec(iv, bip, i) {
> + if (skip == 0) {
> + bip->bip_idx = i;
> + break;
> + } else if (skip >= iv->bv_len) {
> + skip -= iv->bv_len;
> + } else { /* skip < iv->bv_len) */
> + iv->bv_offset += skip;
> + iv->bv_len -= skip;
> + bip->bip_idx = i;
> + break;
> + }
> + }
The above two loops look pretty much the same to me. Can you factor
that out to a helper?
Cheers,
Jeff
next prev parent reply other threads:[~2008-06-10 20:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-07 4:55 [PATCH 0 of 7] Block/SCSI Data Integrity Support Martin K. Petersen
2008-06-07 4:55 ` [PATCH 1 of 7] lib: Add support for the T10 Data Integrity Field CRC Martin K. Petersen
2008-06-07 4:55 ` [PATCH 2 of 7] block: Globalize bio_set and bio_vec_slab Martin K. Petersen
2008-06-10 18:55 ` Jeff Moyer
2008-06-07 4:55 ` [PATCH 3 of 7] block: Find bio sector offset given idx and offset Martin K. Petersen
2008-06-09 16:07 ` Jeff Moyer
2008-06-09 16:15 ` Martin K. Petersen
2008-06-10 19:02 ` Jeff Moyer
2008-06-07 4:55 ` [PATCH 4 of 7] block: bio data integrity support Martin K. Petersen
2008-06-07 14:45 ` Monakhov Dmitri
2008-06-09 15:05 ` Martin K. Petersen
2008-06-10 20:52 ` Jeff Moyer [this message]
2008-06-11 4:05 ` Martin K. Petersen
2008-06-11 17:41 ` Jeff Moyer
2008-06-07 4:55 ` [PATCH 5 of 7] block: Block/request layer " Martin K. Petersen
2008-06-08 4:27 ` Greg KH
2008-06-09 15:06 ` Martin K. Petersen
2008-06-07 4:55 ` [PATCH 6 of 7] scsi: Support devices with protection information (DIF) Martin K. Petersen
2008-06-07 4:55 ` [PATCH 7 of 7] Support for SCSI disk (SBC) Data Integrity Field Martin K. Petersen
2008-06-10 14:41 ` [PATCH 0 of 7] Block/SCSI Data Integrity Support Jeff Moyer
2008-06-10 15:28 ` Martin K. Petersen
2008-06-10 18:49 ` Jeff Moyer
2008-06-10 20:47 ` Martin K. Petersen
2008-06-10 20:53 ` Jeff Moyer
2008-07-17 13:55 ` Mike Snitzer
2008-07-17 15:35 ` Martin K. Petersen
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=x491w359fne.fsf@segfault.boston.devel.redhat.com \
--to=jmoyer@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).