From patchwork Sat Mar 5 07:07:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 8509371 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9CB869F659 for ; Sat, 5 Mar 2016 07:11:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8D36320173 for ; Sat, 5 Mar 2016 07:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6DFA22022A for ; Sat, 5 Mar 2016 07:11:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753518AbcCEHLW (ORCPT ); Sat, 5 Mar 2016 02:11:22 -0500 Received: from mail-ob0-f177.google.com ([209.85.214.177]:33331 "EHLO mail-ob0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750952AbcCEHLU (ORCPT ); Sat, 5 Mar 2016 02:11:20 -0500 Received: by mail-ob0-f177.google.com with SMTP id fz5so69008261obc.0 for ; Fri, 04 Mar 2016 23:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daterainc-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yr5LnFB5hYaVLaIHY7ctLRiKK33vbXRfyf1syZfBGaY=; b=WcHozkh7BY9ed/mlNAhrWnRFM9M1cVlBoXTdPhDrX9ZVvsh45hZsjbkcunAi5fRi75 p5tfbByaUZmkpv+eiRVNs/6IGS1al7laENgmFBWWbVN0RFwunZtxAUeVHO9J1vnRQbKM MtDH44Vsv4ET9jcL5cKmukf8N9kNSHntRyhyREam2qcmWsYrIs3vVWkKJziAN4cYO2hX Zvb3amXWk4Ndq4VbeTpXo6mw50NWnHuCpnOpcKuaYIjYk6lwt+nd1hSDmKALK4Dak4cH eDS1PH8letRGtN8a21cL6X54wvGQSfmO1cA5uMvR7JWenrFFWkZUXaoNfN4JMwYyYZ5i K13Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yr5LnFB5hYaVLaIHY7ctLRiKK33vbXRfyf1syZfBGaY=; b=cb0GQJdZCW69KnhgrlaDbikp5ynG6vRvWDwv5kgG09EHdpWBbFfki/xnRiZ1EeBNKd 0pPHYrw1Ry7pxlLcz17TEAO5xO9W6sZ4adn+ixO7CgBB8vgyzIzhuGvhsBdnYFezHR7w vCVPqSIYTTevsnUEVXTTOjoNvG5AZLJ/wAeSC4MbpW8q9jVGebPaKZb7rWsdbaKpUkMi HdMy2ICq/VjVeSdjQZ4xzV8KcuRZYMDuQGlFSFv5vM2zAlPKuIorWA/8SFf1ojvf2KA+ kjNek9eghqTXMxCVu8l4kX0IEmWBnEU0eiy5ffM/JPtuhWtw3S6UHL/6W94Oi0w+WAno usZA== X-Gm-Message-State: AD7BkJLAkcwpdrFnrWgeKUciepT93VwxJPZbhOaHD0VQGNLCb0npagFK3gvsa++zAHCJ0A== X-Received: by 10.182.144.133 with SMTP id sm5mr8941688obb.69.1457161879998; Fri, 04 Mar 2016 23:11:19 -0800 (PST) Received: from localhost.localdomain (mail.linux-iscsi.org. [67.23.28.174]) by smtp.gmail.com with ESMTPSA id b128sm4495160oig.26.2016.03.04.23.11.19 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 04 Mar 2016 23:11:19 -0800 (PST) From: "Nicholas A. Bellinger" To: target-devel , linux-scsi Cc: Hannes Reinecke , Christoph Hellwig , Mike Christie , Sagi Grimberg , Andy Grover , Nicholas Bellinger , Sagi Grimberg , Mike Christie Subject: [PATCH-v2 2/2] target/iblock: Use -EAGAIN/-ENOMEM to propigate SAM BUSY/TASK_SET_FULL Date: Sat, 5 Mar 2016 07:07:14 +0000 Message-Id: <1457161634-15756-2-git-send-email-nab@daterainc.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1457161634-15756-1-git-send-email-nab@daterainc.com> References: <1457161634-15756-1-git-send-email-nab@daterainc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nicholas Bellinger This patch updates target/iblock backend driver code to check for bio completion status of -EAGAIN / -ENOMEM provided by raw block drivers and scsi devices, in order to generate the following SCSI status to initiators: - SAM_STAT_BUSY - SAM_STAT_TASK_SET_FULL Note these two SAM status codes are useful to signal to Linux SCSI host side that se_cmd should be retried again, or with TASK_SET_FULL case to attempt to lower our internal host LLD queue_depth and scsi_cmnd retry. It also updates target_complete_cmd() to parse status when signalling success to target_completion_wq. Reviewed-by: Hannes Reinecke Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Sagi Grimberg Cc: Andy Grover Cc: Mike Christie Signed-off-by: Nicholas Bellinger --- drivers/target/target_core_iblock.c | 38 +++++++++++++++++++++++++++------- drivers/target/target_core_iblock.h | 1 + drivers/target/target_core_transport.c | 13 ++++++++++-- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c index 026a758..ce754f1 100644 --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c @@ -282,11 +282,28 @@ static void iblock_complete_cmd(struct se_cmd *cmd) if (!atomic_dec_and_test(&ibr->pending)) return; - - if (atomic_read(&ibr->ib_bio_err_cnt)) - status = SAM_STAT_CHECK_CONDITION; - else + /* + * Propigate use these two bio completion values from raw block + * drivers to signal up BUSY and TASK_SET_FULL status to the + * host side initiator. The latter for Linux/iSCSI initiators + * means the Linux/SCSI LLD will begin to reduce it's internal + * per session queue_depth. + */ + if (atomic_read(&ibr->ib_bio_err_cnt)) { + switch (ibr->ib_bio_retry) { + case -EAGAIN: + status = SAM_STAT_BUSY; + break; + case -ENOMEM: + status = SAM_STAT_TASK_SET_FULL; + break; + default: + status = SAM_STAT_CHECK_CONDITION; + break; + } + } else { status = SAM_STAT_GOOD; + } target_complete_cmd(cmd, status); kfree(ibr); @@ -298,7 +315,15 @@ static void iblock_bio_done(struct bio *bio) struct iblock_req *ibr = cmd->priv; if (bio->bi_error) { - pr_err("bio error: %p, err: %d\n", bio, bio->bi_error); + pr_debug_ratelimited("test_bit(BIO_UPTODATE) failed for bio: %p," + " err: %d\n", bio, bio->bi_error); + /* + * Save the retryable status provided and translate into + * SAM status in iblock_complete_cmd(). + */ + if (bio->bi_error == -EAGAIN || bio->bi_error == -ENOMEM) { + ibr->ib_bio_retry = bio->bi_error; + } /* * Bump the ib_bio_err_cnt and release bio. */ @@ -677,8 +702,7 @@ iblock_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents, struct scatterlist *sg; u32 sg_num = sgl_nents; unsigned bio_cnt; - int rw = 0; - int i; + int i, rw = 0; if (data_direction == DMA_TO_DEVICE) { struct iblock_dev *ib_dev = IBLOCK_DEV(dev); diff --git a/drivers/target/target_core_iblock.h b/drivers/target/target_core_iblock.h index 01c2afd..ff3cfdd 100644 --- a/drivers/target/target_core_iblock.h +++ b/drivers/target/target_core_iblock.h @@ -9,6 +9,7 @@ struct iblock_req { atomic_t pending; atomic_t ib_bio_err_cnt; + int ib_bio_retry; } ____cacheline_aligned; #define IBDF_HAS_UDEV_PATH 0x01 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 784dd22..df01997 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -731,11 +731,20 @@ static unsigned char *transport_get_sense_buffer(struct se_cmd *cmd) void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) { struct se_device *dev = cmd->se_dev; - int success = scsi_status == GOOD; + int success; unsigned long flags; cmd->scsi_status = scsi_status; - + switch (cmd->scsi_status) { + case SAM_STAT_GOOD: + case SAM_STAT_BUSY: + case SAM_STAT_TASK_SET_FULL: + success = 1; + break; + default: + success = 0; + break; + } spin_lock_irqsave(&cmd->t_state_lock, flags); cmd->transport_state &= ~CMD_T_BUSY;