On Mon, Jan 30 2012 at 7:31pm -0500, Martin K. Petersen <martin.petersen@xxxxxxxxxx> wrote: > From: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx> > > The WRITE SAME command supported on some SCSI devices allows the same > block to be efficiently replicated throughout a block range. Only a > single logical block is transferred from the host and the storage device > writes the same data to all blocks described by the I/O. > > This patch implements support for WRITE SAME in the block layer. The > blkdev_issue_write_same() function can be used by filesystems and block > drivers to replicate a buffer across a block range. This can be used to > efficiently initialize software RAID devices, etc. > > Signed-off-by: Martin K. Petersen <martin.petersen@xxxxxxxxxx> ... > diff --git a/block/blk-lib.c b/block/blk-lib.c > index 2b461b4..19f4754 100644 > --- a/block/blk-lib.c > +++ b/block/blk-lib.c > @@ -115,6 +115,85 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, > EXPORT_SYMBOL(blkdev_issue_discard); > > /** > + * blkdev_issue_write_same - queue a write same operation > + * @bdev: target blockdev > + * @sector: start sector > + * @nr_sects: number of sectors to write > + * @gfp_mask: memory allocation flags (for bio_alloc) > + * @buffer: pointer to buffer containing data to write > + * @length: buffer length. Must be equal to bdev logical block size. > + * > + * Description: > + * Issue a write same request for the sectors in question. > + */ > +int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, > + sector_t nr_sects, gfp_t gfp_mask, void *buffer, > + unsigned int length) > +{ > + DECLARE_COMPLETION_ONSTACK(wait); > + struct request_queue *q = bdev_get_queue(bdev); > + unsigned int max_write_same_sectors; > + struct bio_batch bb; > + struct bio *bio; > + int ret = 0; > + > + if (!q) > + return -ENXIO; > + > + max_write_same_sectors = q->limits.max_write_same_sectors; > + > + if (max_write_same_sectors == 0) > + return -EOPNOTSUPP; > + > + BUG_ON(length != bdev_logical_block_size(bdev)); Why require @length to be passed in if we can easily determine the only correct length, via bdev_logical_block_size, locally? Mike -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html