Re: [PATCH] support custom block sizes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 30 Nov 2010 21:04:59 +0200
Alexander Nezhinsky <alexandern@xxxxxxxxxxxx> wrote:

> Added support for user-defined block size (actually "sector size").
> 
> The rationale is for using with devices (notably SSDs) that allow 
> formatting with sector size different from 512B. If such device 
> is formatted to a greater value, but tgt reports its sector size
> to be 512B, all commands referencing device sectors and/or extents
> will address wrong locations, some of which will be even out of
> the device's capacity.
> 
> This patch follows the patch posted here:
> http://lists.wpkg.org/pipermail/stgt/2009-December/003469.html
> and elaborates the suggested functionality a bit further.
> 
> The default block size is maintained by sbc (block devices).
> It has its own default value 512B. This default may be overridden
> by using the following extra param in tgt command line:
> --sbc blocksize=4096
> (sizes 512,1024..8096 are supported).

Let's remove this option because we can configure this per lun.


> After this all block devices will report the passed block sz value
> during scsi inquiries.
> Block size can be set for individual luns as well using
> --params blocksize=4096,...
> among the parameters of new logical unit through tgtadm.
> This may be used in scripts as follows:
> --params blocksize=`blockdev --getss /dev/sdd`
> In this case lun specific setting overrides sbc default.
> Tha actual per lun is displayed through -m target -o show.
> 
> Signed-off-by: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>
> ---
>  usr/sbc.c    |   51 +++++++++++++++++++++++++++++++++++++++++++--------
>  usr/target.c |   35 +++++++++++++++++++++++++++++++----
>  usr/tgtd.h   |    1 +
>  usr/util.c   |   19 +++++++++++++++++++
>  usr/util.h   |    1 +
>  5 files changed, 95 insertions(+), 12 deletions(-)
> 
> diff --git a/usr/sbc.c b/usr/sbc.c
> index 1f0a6ff..88cd893 100644
> --- a/usr/sbc.c
> +++ b/usr/sbc.c
> @@ -41,7 +41,9 @@
>  #include "spc.h"
>  #include "tgtadm_error.h"
>  
> -#define BLK_SHIFT	9
> +#define DEFAULT_BLK_SHIFT 9
> +
> +static unsigned int blk_shift = DEFAULT_BLK_SHIFT;
>  
>  static int sbc_mode_page_update(struct scsi_cmd *cmd, uint8_t *data, int *changed)
>  {
> @@ -123,7 +125,7 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
>  
>  	cmd->scsi_cmd_done = target_cmd_io_done;
>  
> -	cmd->offset = (scsi_rw_offset(cmd->scb) << BLK_SHIFT);
> +	cmd->offset = (scsi_rw_offset(cmd->scb) << cmd->dev->blk_shift);
>  	ret = cmd->dev->bst->bs_cmd_submit(cmd);
>  	if (ret) {
>  		key = HARDWARE_ERROR;
> @@ -163,6 +165,7 @@ static int sbc_release(int host_no, struct scsi_cmd *cmd)
>  static int sbc_read_capacity(int host_no, struct scsi_cmd *cmd)
>  {
>  	uint32_t *data;
> +	unsigned int bshift;
>  	uint64_t size;
>  	uint8_t *scb = cmd->scb;
>  	unsigned char key = ILLEGAL_REQUEST;
> @@ -177,11 +180,12 @@ static int sbc_read_capacity(int host_no, struct scsi_cmd *cmd)
>  		goto overflow;
>  
>  	data = scsi_get_in_buffer(cmd);
> -	size = cmd->dev->size >> BLK_SHIFT;
> +	bshift = cmd->dev->blk_shift;
> +	size = cmd->dev->size >> bshift;
>  
>  	data[0] = (size >> 32) ?
>  		__cpu_to_be32(0xffffffff) : __cpu_to_be32(size - 1);

Can we use put_unaligned_be32 instead? I like to kill __cpu_to_
macros.
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux