From patchwork Thu May 3 17:53:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Duncan X-Patchwork-Id: 10378809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 922086038F for ; Thu, 3 May 2018 17:54:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80C8729210 for ; Thu, 3 May 2018 17:54:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7292929213; Thu, 3 May 2018 17:54:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C6B629210 for ; Thu, 3 May 2018 17:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751075AbeECRyQ (ORCPT ); Thu, 3 May 2018 13:54:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:50993 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751095AbeECRyE (ORCPT ); Thu, 3 May 2018 13:54:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 66BACADF9; Thu, 3 May 2018 17:54:03 +0000 (UTC) From: Lee Duncan To: target-devel@vger.kernel.org Cc: nab@linux-iscsi.org, hare@suse.de, Lee Duncan Subject: [PATCH RFC] target transport: allow st INI reads Date: Thu, 3 May 2018 10:53:40 -0700 Message-Id: <20180503175340.3863-1-lduncan@suse.com> X-Mailer: git-send-email 2.13.6 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a tape drive is exported via LIO using the pscsi module, a read that requests more bytes per block than the tape can supply returns an empty buffer. This is because the pscsi pass-through target module sees the "ILI" illegal length bit set and thinks there is no reason to return the data. Add in a hack to check for tape reads with the INI bit set, treating such cases as if there is no sense data. The tape driver then "does the right thing" when it gets the INI bit and that date. NOTE: I'm not sure if this is the right place to effect this change, nor if it's the right approach, so comments/ suggestions are welcomed! --- drivers/target/target_core_transport.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 836d552b0385..aafd64b514fe 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2187,7 +2187,25 @@ static void target_complete_ok_work(struct work_struct *work) * the struct se_cmd in question. */ if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) { + struct se_device *dev = cmd->se_dev; + unsigned char *sense = cmd->sense_buffer; + WARN_ON(!cmd->scsi_status); + + /* + * hack: check for tape reads with the ILI (illegal + * length indicator) set, and just pass those through + */ + if ((dev->transport->get_device_type(dev) == TYPE_TAPE) && + (cmd->scsi_status == SAM_STAT_CHECK_CONDITION) && + (cmd->data_direction == DMA_FROM_DEVICE)) { + if ((sense[0] == 0xf0) && /* 'valid' and 'fixed format' */ + (sense[2] & 0x20)) { /* 'ILI' */ + pr_debug("Tape ILI Bit detected. Treating as OK\n"); + goto treat_as_normal_read; + } + } + ret = transport_send_check_condition_and_sense( cmd, 0, 1); if (ret)