linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@sandisk.com>
To: "Bryant G. Ly" <bryantly@linux.vnet.ibm.com>,
	<JBottomley@odin.com>, <martin.petersen@oracle.com>,
	<tyreld@linux.vnet.ibm.com>, <akpm@linux-foundation.org>,
	<kvalo@codeaurora.org>, <davem@davemloft.net>,
	<gregkh@linuxfoundation.org>, <mchehab@osg.samsung.com>,
	<jslaby@suse.com>, <joe@perches.com>, <bp@suse.de>
Cc: <linux-kernel@vger.kernel.org>, <linux-scsi@vger.kernel.org>,
	<target-devel@vger.kernel.org>, bgly <bgly@us.ibm.com>,
	Joe Perches <joe@perches.com>
Subject: Re: [PATCH] ibmvscsis: Initial commit of IBM VSCSI Tgt Driver
Date: Tue, 24 May 2016 09:25:05 -0700	[thread overview]
Message-ID: <3303bc98-ade7-62f0-71c7-11e7ef42b42d@sandisk.com> (raw)
In-Reply-To: <1464097978-88457-1-git-send-email-bryantly@linux.vnet.ibm.com>

On 05/24/2016 06:52 AM, Bryant G. Ly wrote:
> +config SCSI_IBMVSCSIS
> +  	tristate "IBM Virtual SCSI Server support"
> +  	depends on PPC_PSERIES && SCSI_SRP && TARGET_CORE
> +  	help
> +  	  This is the IBM POWER Virtual SCSI Target Server
> +
> +          The userspace component needed to initialize the driver and
> +  	  documentation can be found:
> +
> +          https://github.com/powervm/ibmvscsis
> +
> +          To compile this driver as a module, choose M here: the
> +  	  module will be called ibmvstgt.
> +

This driver has confused Linux users before. Most people know SRP as a 
SCSI transport layer that is used for communication between servers. 
This driver however uses the SRP protocol for communication between 
guests and/or the host that run on the same server. Please add this 
information to the above help text, together with a reference to the VIO 
protocol documentation in the POWER architecture manual.

> +#include <generated/utsrelease.h>

Every Linux user can query the kernel version by running the uname 
command. Is it really useful to print the kernel version (UTS_RELEASE) 
when this driver is loaded?

> +#include "ibmvscsi.h"

The above include directive indirectly includes a whole bunch of SCSI 
initiator driver header files. We do not want that initiator header 
files are included in the source code of a target driver. If it is 
necessary to share definitions of symbolic constants between the 
initiator and the target driver please move these into a new header file.

> +static inline long h_send_crq(struct ibmvscsis_adapter *adapter,
> +			u64 word1, u64 word2)
> +{
> +	long rc;
> +	struct vio_dev *vdev = adapter->dma_dev;
> +
> +	pr_debug("ibmvscsis: ibmvscsis_send_crq(0x%x, 0x%016llx, 0x%016llx)\n",
> +			vdev->unit_address, word1, word2);
> +

As Joe Perches already asked, please define pr_fmt() instead of 
including the kernel module name in every pr_debug() statement.

> +static char system_id[64] = "";
> +static char partition_name[97] = "UNKNOWN";

Where do these magic constants come from and what is their meaning? 
Please consider to introduce symbolic names for these constants.

> +static ssize_t ibmvscsis_tpg_enable_show(struct config_item *item,
> +				char *page)
> +{
> +	struct se_portal_group *se_tpg = to_tpg(item);
> +	struct ibmvscsis_tport *tport = container_of(se_tpg,
> +						struct ibmvscsis_tport, se_tpg);
> +
> +	return snprintf(page, PAGE_SIZE, "%d\n", (tport->enabled) ? 1 : 0);
> +}

Have you considered to use MODULE_VERSION() instead of introducing a 
sysfs attribute to export the module version? An advantage of 
MODULE_VERSION() is that it allows to query the module version without 
having to load a kernel module.

> +static void ibmvscsis_modify_std_inquiry(struct se_cmd *se_cmd)
> +{
> +	struct se_device *dev = se_cmd->se_dev;
> +	unsigned char *buf = NULL;
> +	u32 cmd_len = se_cmd->data_length;
> +
> +	if (cmd_len <= INQ_DATA_OFFSET)
> +		return;
> +
> +	buf = transport_kmap_data_sg(se_cmd);
> +	if (buf) {
> +		memcpy(&buf[8], "IBM	     ", 8);
> +		if (dev->transport->get_device_type(dev) == TYPE_ROM)
> +			memcpy(&buf[16], "VOPTA           ", 16);
> +		else
> +			memcpy(&buf[16], "3303      NVDISK", 16);
> +		memcpy(&buf[32], "0001", 4);
> +		transport_kunmap_data_sg(se_cmd);
> +	}
> +}

Shouldn't a sense code be returned to the initiator if this function fails?

> +	default:
> +		pr_err("ibmvscsis: unknown task mgmt func %d\n",
> +						srp_tsk->tsk_mgmt_func);
> +		cmd->se_cmd.se_tmr_req->response =
> +					TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED;
> +		rc = -1;
> +		break;
> +	}
> +
> +	if (!rc) {

Please consider changing the above "break" into "goto fail" such that 
the if (!rc) can be left out and such that the indentation of the code 
below if (!rc) can be reduced.

> +static int ibmvscsis_queuecommand(struct ibmvscsis_adapter *adapter,
> +				  struct iu_entry *iue)
> +{
> +	struct srp_cmd *cmd = iue->sbuf->buf;
> +	struct scsi_cmnd *sc;
> +	struct ibmvscsis_cmnd *vsc;
> +	int ret;
> +
> +	pr_debug("ibmvscsis: ibmvscsis_queuecommand\n");
> +
> +	vsc = kzalloc(sizeof(*vsc), GFP_KERNEL);

Allocating memory in the command processing path in a SCSI driver 
usually causes suboptimal performance. Other LIO target drivers 
preallocate such buffers before I/O starts.

> +static uint64_t ibmvscsis_unpack_lun(const uint8_t *lun, int len)
> +{
> +	uint64_t res = NO_SUCH_LUN;
> +	int addressing_method;
> +
> +	if (unlikely(len < 2)) {
> +		pr_err("Illegal LUN length %d, expected 2 bytes or more\n",
> +			len);
> +		goto out;
> +	}
> +
> +	switch (len) {
> +	case 8:
> +		if ((*((__be64 *)lun) & cpu_to_be64(0x0000FFFFFFFFFFFFLL)) != 0)
> +			goto out_err;
> +		break;
> +	case 4:
> +		if (*((__be16 *)&lun[2]) != 0)
> +			goto out_err;
> +		break;
> +	case 6:
> +		if (*((__be32 *)&lun[2]) != 0)
> +			goto out_err;
> +		break;
> +	case 2:
> +		break;
> +	default:
> +		goto out_err;
> +	}
> +
> +	addressing_method = (*lun) >> 6; /* highest two bits of byte 0 */
> +	switch (addressing_method) {
> +	case SCSI_LUN_ADDR_METHOD_PERIPHERAL:
> +	case SCSI_LUN_ADDR_METHOD_FLAT:
> +	case SCSI_LUN_ADDR_METHOD_LUN:
> +		res = *(lun + 1) | (((*lun) & 0x3f) << 8);
> +		break;
> +
> +	case SCSI_LUN_ADDR_METHOD_EXTENDED_LUN:
> +	default:
> +		pr_err("Unimplemented LUN addressing method %u\n",
> +			addressing_method);
> +		break;
> +	}
> +
> +out:
> +	return res;
> +out_err:
> +	pr_err("Support for multi-level LUNs has not yet been implemented\n");
> +	goto out;
> +}

In the above function there is nothing that is specific to the VIO 
mechanism. Please consider to merge this function with scsilun_to_int(), 
e.g. by introducing a new function that accepts a SCSI LUN and the 
addressing method as arguments and by making scsilun_to_int() call that 
function with SCSI_LUN_ADDR_METHOD_PERIPHERAL as one of its arguments.

> +struct inquiry_data {
> +	u8 qual_type;
> +	u8 rmb_reserve;
> +	u8 version;
> +	u8 aerc_naca_hisup_format;
> +	u8 addl_len;
> +	u8 sccs_reserved;
> +	u8 bque_encserv_vs_multip_mchngr_reserved;
> +	u8 reladr_reserved_linked_cmdqueue_vs;
> +	char vendor[8];
> +	char product[16];
> +	char revision[4];
> +	char vendor_specific[20];
> +	char reserved1[2];
> +	char version_descriptor[16];
> +	char reserved2[22];
> +	char unique[158];
> +};

Is this the inquiry data response format from SPC? If so, this is a 
structure definition that is useful for the SCSI initiator core and also 
for other LIO target drivers. There might be a more appropriate header 
file for this definition.

> +enum scsi_lun_addr_method {
> +	SCSI_LUN_ADDR_METHOD_PERIPHERAL   = 0,
> +	SCSI_LUN_ADDR_METHOD_FLAT         = 1,
> +	SCSI_LUN_ADDR_METHOD_LUN          = 2,
> +	SCSI_LUN_ADDR_METHOD_EXTENDED_LUN = 3,
> +};

Same comment here.

> diff --git a/drivers/scsi/libsrp.c b/drivers/scsi/libsrp.c
> new file mode 100644
> index 0000000..0e32abd
> --- /dev/null
> +++ b/drivers/scsi/libsrp.c
> @@ -0,0 +1,387 @@
> +/*******************************************************************************
> + * SCSI RDMA Protocol lib functions

My understanding of the VIO mechanism is that the invocation of 
H_COPY_RDMA is synchronous. This means that this operation only finishes 
after the data has been transferred. If I interpret the code in libsrp.c 
and libsrp.h correctly then this code can only be used by SRP drivers 
use synchronous data transfers and not by SRP drivers that use 
asynchronous data transfers. This means that this code is not useful for 
any of the SRP drivers that are already upstream (ib_srp and ib_srpt). 
Hence my proposal to move the libsrp.c and libsrp.h source files from 
drivers/scsi and include/scsi to the same directory as the ibmvscsis driver.

Thanks,

Bart.

  parent reply	other threads:[~2016-05-24 16:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-24 13:52 [PATCH] ibmvscsis: Initial commit of IBM VSCSI Tgt Driver Bryant G. Ly
2016-05-24 14:14 ` Joe Perches
2016-05-24 14:30 ` Greg KH
2016-05-24 16:25 ` Bart Van Assche [this message]
2016-05-24 16:34   ` Greg KH
2016-05-24 16:44     ` Bart Van Assche
2016-05-24 16:50       ` Greg KH
2016-05-24 20:00   ` Bryant G Ly
2016-06-10 19:03     ` Bart Van Assche
2016-06-14  6:23       ` Nicholas A. Bellinger
2016-06-14 14:55         ` Christoph Hellwig
2016-05-25 14:17 ` IBM VSCSI Target Driver Initial Patch Sets Bryant G. Ly
2016-05-25 14:17   ` [PATCH 2/3] ibmvscsis: Addressing Bart's comments Bryant G. Ly
2016-05-25 14:17   ` [PATCH 3/3] ibmvscsis: clean up functions Bryant G. Ly
2016-05-25 14:44     ` Joe Perches

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=3303bc98-ade7-62f0-71c7-11e7ef42b42d@sandisk.com \
    --to=bart.vanassche@sandisk.com \
    --cc=JBottomley@odin.com \
    --cc=akpm@linux-foundation.org \
    --cc=bgly@us.ibm.com \
    --cc=bp@suse.de \
    --cc=bryantly@linux.vnet.ibm.com \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=jslaby@suse.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mchehab@osg.samsung.com \
    --cc=target-devel@vger.kernel.org \
    --cc=tyreld@linux.vnet.ibm.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).