From patchwork Thu Oct 31 01:00:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Meneghini X-Patchwork-Id: 840372 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4BC718E1A for ; Thu, 31 Oct 2024 01:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730336448; cv=none; b=otcE8Yh5nLBipo2o1Z+1GeDdTlVzIXg2VgdsV2DGBH8vhySIDgEbhdtpQMn4VGUGfb0q4DV/kE9un7767qJ7SSKFzHL8/NlEJiEKC80FmSMjpaQ2BwCn8j6cta0zUL6TFwlt55zsx3Bub1Ue24gObTBvn6xr7Ypr1kEClcixiWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730336448; c=relaxed/simple; bh=LoG6lQ8EcFrrcx+uHSM2692NxO2J62QbqVQvIKaLRpg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=Nyz0MK71rnzL67VwmccDt7BV+OI7rk/woxgRf6pLqGQuK37EbngSR48Ju6vzfqH0G/KNdHAGIuMKX4JoxtBEWnGrt6UPWkcejJo0jYk/lQtmPuF/WuFMTP6w0IrFDyGot8IFXXkSVj3UlTAOfBZIWRN6hfebqBRVOfSo88BRxLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=i8/fXUiV; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="i8/fXUiV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730336444; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zV2CqiFJ/81MvsUoQTp9efLKrMQCNW6MCzItPNj5jFM=; b=i8/fXUiVd4qmAWcEAwrOw9bF2dXVjZ/gpNPGJAlBN81d7rHrTxY/yGuoBkom5ReA1ferMn sP0yKeQFQUGpUANIwotxeX6aylw79tuRszSQdvApCVCF15mHAhRH9eqha59Lq/Iglo3Gph 7TXuANQLMdPUikKMpObtBcs0EvC0GSk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-sGtup4OJOuyOZa3jc8I4fw-1; Wed, 30 Oct 2024 21:00:42 -0400 X-MC-Unique: sGtup4OJOuyOZa3jc8I4fw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 67AB6195609F; Thu, 31 Oct 2024 01:00:41 +0000 (UTC) Received: from jmeneghi-thinkpadp1gen3.rmtusnh.csb (unknown [10.22.88.108]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E1BE91956054; Thu, 31 Oct 2024 01:00:39 +0000 (UTC) From: John Meneghini To: linux-scsi@vger.kernel.org, Kai.Makisara@kolumbus.fi, martin.petersen@oracle.com Cc: James.Bottomley@HansenPartnership.com, loberman@redhat.com Subject: [PATCH 1/3] scsi: st: instrument the pos_unknown code Date: Wed, 30 Oct 2024 21:00:30 -0400 Message-ID: <20241031010032.117296-2-jmeneghi@redhat.com> In-Reply-To: <20241031010032.117296-1-jmeneghi@redhat.com> References: <20241031010032.117296-1-jmeneghi@redhat.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Add debugging printfs to the various code paths that use pos_unknown. This code is a little chatty but nothing has been added to the datapath. It has been used to help debug a number of customer reported problems from the field since the change for commit 9604eea5bd3a ("scsi: st: Add third party poweron reset handling") was added. To enable: echo 1 > /sys/module/st/drivers/scsi:st/debug_flag Signed-off-by: John Meneghini Reviewed-by: Laurence Oberman Tested-by: Laurence Oberman --- drivers/scsi/st.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index d50bad3a2ce9..9c0f9779768e 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -418,6 +418,10 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) STp->pos_unknown |= STp->device->was_reset; + DEBC_printk(STp, "%s: %d: pos_unknown %x was_reset %x ready %x, result %d\n", + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready, result); + if (cmdstatp->have_sense && scode == RECOVERED_ERROR #if ST_RECOVERED_WRITE_FATAL @@ -834,6 +838,10 @@ static int flush_buffer(struct scsi_tape *STp, int seek_next) int backspace, result; struct st_partstat *STps; + DEBC_printk(STp, "%s: %d: pos_unknown %x was_reset %x ready %x\n", + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready); + if (STp->ready != ST_READY) return 0; @@ -1050,6 +1058,10 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) struct inode *inode = file_inode(filp); int mode = TAPE_MODE(inode); + DEBC_printk(STp, "%s: %d: pos_unknown %x was_reset %x ready %x\n", + __func__, __LINE__, STp->pos_unknown, + STp->device->was_reset, STp->ready); + STp->ready = ST_READY; if (mode != STp->current_mode) { @@ -1085,6 +1097,9 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) STps->drv_file = 0; } new_session = 1; + DEBC_printk(STp, "%s: %d: CHKRES_NEW_SESS pos_unknown %x was_reset %x ready %x\n", + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready); } else { STp->cleaning_req |= saved_cleaning; @@ -1101,6 +1116,12 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) STp->ps[0].drv_file = STp->ps[0].drv_block = (-1); STp->partition = STp->new_partition = 0; STp->door_locked = ST_UNLOCKED; + + DEBC_printk(STp, + "%s: %d: CHKRES_NOT_READY pos_unknown %x was_reset %x ready %x\n", + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready); + return CHKRES_NOT_READY; } } @@ -1237,9 +1258,16 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) } } + DEBC_printk(STp, "%s: %d: CHKRES_READY pos_unknown %x was_reset %x ready %x\n", + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready); + return CHKRES_READY; err_out: + DEBC_printk(STp, "%s: %d: pos_unknown %x was_reset %x ready %x retval %d\n", + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, + STp->ready, retval); return retval; } @@ -1352,6 +1380,9 @@ static int st_flush(struct file *filp, fl_owner_t id) if (file_count(filp) > 1) return 0; + DEBC_printk(STp, "%s: %d: pos_unknown %x was_reset %x ready %x\n", + __func__, __LINE__, STp->pos_unknown, STp->device->was_reset, STp->ready); + if (STps->rw == ST_WRITING && !STp->pos_unknown) { result = st_flush_write_buffer(STp); if (result != 0 && result != (-ENOSPC)) From patchwork Thu Oct 31 01:00:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Meneghini X-Patchwork-Id: 840039 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59C2C26281 for ; Thu, 31 Oct 2024 01:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730336449; cv=none; b=KPvDOTcoHgEOTEuhLHwP76Etk/ynGioU18IzRawVv6azga4oIB2/wGw+LImBPBOv/hhbfPEotixHbIB9CZj8xcojcw9H3fwVcyRxosYnDbvyVSLr9MZazarSzZ0EGxMGa1XaX2vuGlTWviQ8Hch4TJ0eXRCLhRy3hWTbGcsKxfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730336449; c=relaxed/simple; bh=1xOrw5x/CcT82SbwOauUh91G6hlyTArReGPNHUab4C4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=Cwn63zmpjwibP2cKjZjluI+SFDRDs++wKOcosGYXaaZndIV2o6EShx8rx2g8otgdxkebHNodBCF2pssD6aC7fAY3sdzHKBsXNEtR+FatZ1hV60CJb5OXAztoxG8RBQqgBRENaR/4Y8vruBsUOmfrM1FYwlax7GZrF5Zb3XKQvWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TVkj5SV0; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TVkj5SV0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730336446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/iz2+fsE8CNUntTe9v/iSv0zGPEHwco22tORbQK2AKI=; b=TVkj5SV06wIhm2RVpOAEcTYB29JAhLMSe0GAb+4bb7az2QeIfIuK0+He7c4pMvfT+Jd9/H hpDN4midnHFn+FqpLGBAH0pv3JBwfqR3fDJBh31hcKPcy1P8B/XzpN4fbv/A26KzbKOS/j gEzGzN5RxckzGQVAcqS1qoZnjlYGy2Q= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-xE0IXlUrPM6tMxIwMLSITg-1; Wed, 30 Oct 2024 21:00:44 -0400 X-MC-Unique: xE0IXlUrPM6tMxIwMLSITg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A2E231955F45; Thu, 31 Oct 2024 01:00:43 +0000 (UTC) Received: from jmeneghi-thinkpadp1gen3.rmtusnh.csb (unknown [10.22.88.108]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AC923195605F; Thu, 31 Oct 2024 01:00:41 +0000 (UTC) From: John Meneghini To: linux-scsi@vger.kernel.org, Kai.Makisara@kolumbus.fi, martin.petersen@oracle.com Cc: James.Bottomley@HansenPartnership.com, loberman@redhat.com Subject: [PATCH 2/3] scsi: st: clear was_reset when CHKRES_NEW_SESSION Date: Wed, 30 Oct 2024 21:00:31 -0400 Message-ID: <20241031010032.117296-3-jmeneghi@redhat.com> In-Reply-To: <20241031010032.117296-1-jmeneghi@redhat.com> References: <20241031010032.117296-1-jmeneghi@redhat.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Be sure to clear was_reset when ever we clear pos_unknown. If we don't then the code in st_chk_result() will turn on pos_unknown again. STp->pos_unknown |= STp->device->was_reset; This results in confusion as future commands fail unexpectedly. Signed-off-by: John Meneghini --- drivers/scsi/st.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 9c0f9779768e..e9d1cb6c8a86 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -1083,6 +1083,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp) if (retval == CHKRES_NEW_SESSION) { STp->pos_unknown = 0; + STp->device->was_reset = 0; STp->partition = STp->new_partition = 0; if (STp->can_partitions) STp->nbr_partitions = 1; /* This guess will be updated later From patchwork Thu Oct 31 01:00:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Meneghini X-Patchwork-Id: 840371 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B74342AA5 for ; Thu, 31 Oct 2024 01:00:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730336453; cv=none; b=HKi0sW8WdTTH8/TjQG2Sc9ptyZSXA5hhbWF5abJP/NDxRkZZC7gUxY87/ohu8SI06xJ7fctA9T08qEYkMw5AnLTTO+sP3lcu4VuwGx2sBfLDaQLSUYCnwA+k4IX8MH6TLNm3oBAb0255282uTFF1PkdYovsL5OUIHqUKs99d7cs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730336453; c=relaxed/simple; bh=zX31+Yy5s+OEYYug7rJ0UMPbtIDSwyZFEhO/watTPvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=behYRBk7DU+X8trfpJ+qpTpbGX+hmO0BHAEdMBd1MY0/abw/t9GP1mBTjAzo9v44IF0EK9RbJjBsXlPYYIgCKstRzrFxrSPV3ypLlG9nGl5UqXGPzyG9IdIsH5yNHZAFG5lUl3iHlBbXs7Gtbiwa99CIQRVGAIuORl9eU+ocPnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CReKTNg+; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CReKTNg+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730336450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=di8pGQdZsDvyC4JdkaVDe+HgICS9D1R4yOLMiu65I58=; b=CReKTNg+gEK3wXdj7g9lG89bYUXYvc3sNrfu9NJUX6B6vFA2g+Pe4sZhgsgAbsaHhtMMHP Vmg9lObrB+XSGFOLU+8AK7u8o7ZkP2HqrIyXGgJKI8RxS6/zTpZ97tgICPbh+kS8XxSgV6 5+WqnqsmDnQVbwQE0pPsqVc/fncyeG0= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-190-Mf5tud4lNxyUnfkPICiL9w-1; Wed, 30 Oct 2024 21:00:46 -0400 X-MC-Unique: Mf5tud4lNxyUnfkPICiL9w-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A76F19560BF; Thu, 31 Oct 2024 01:00:45 +0000 (UTC) Received: from jmeneghi-thinkpadp1gen3.rmtusnh.csb (unknown [10.22.88.108]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E87D01956054; Thu, 31 Oct 2024 01:00:43 +0000 (UTC) From: John Meneghini To: linux-scsi@vger.kernel.org, Kai.Makisara@kolumbus.fi, martin.petersen@oracle.com Cc: James.Bottomley@HansenPartnership.com, loberman@redhat.com Subject: [PATCH 3/3] scsi: st: clear pos_unknown when the por ua is expected Date: Wed, 30 Oct 2024 21:00:32 -0400 Message-ID: <20241031010032.117296-4-jmeneghi@redhat.com> In-Reply-To: <20241031010032.117296-1-jmeneghi@redhat.com> References: <20241031010032.117296-1-jmeneghi@redhat.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 From: Kai Makisara The change for commit 9604eea5bd3a ("scsi: st: Add third party poweron reset handling") was introduced to handle the problem where an unexpected power/on reset resulted in an undetected position lost condition which caused lost data as the driver flushed data and wrote a file mark at the beginning of the tape. To solve this problem code was added which detected the unexpected a power on/reset Unit Attention in st_chk_results(). This correctly set pos_unknown in the driver and prevented further access to the device until the tape is re-positioned or rewound. The problem with this solution is that it is catching POR Unit Attentions that are expected as well as those that are unexpected. This results in an unwanted EIO response to MTIOCGET. The change for commit 3d882cca73be ("scsi: st: Fix input/output error on empty drive reset") attempts to fix this problem by returning success in flush_buffer() when ready != to ST_READY. However, once ST_READY is set, if pos_unknown remains uncleared, MTIOGET can still return EIO. This is confusing as some tape drives will set a POR UA when the system reboots or the driver is reloaded. Fixes: 3d882cca73be ("scsi: st: Fix input/output error on empty drive reset") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219419 Signed-off-by: Kai Makisara Tested-by: John Meneghini --- drivers/scsi/st.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index e9d1cb6c8a86..0260361d19fa 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -3538,6 +3538,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) int i, cmd_nr, cmd_type, bt; int retval = 0; unsigned int blk; + bool cmd_mtiocget; struct scsi_tape *STp = file->private_data; struct st_modedef *STm; struct st_partstat *STps; @@ -3651,6 +3652,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) */ if (mtc.mt_op != MTREW && mtc.mt_op != MTOFFL && + mtc.mt_op != MTLOAD && mtc.mt_op != MTRETEN && mtc.mt_op != MTERASE && mtc.mt_op != MTSEEK && @@ -3764,17 +3766,28 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) goto out; } + cmd_mtiocget = cmd_type == _IOC_TYPE(MTIOCGET) && cmd_nr == _IOC_NR(MTIOCGET); + if ((i = flush_buffer(STp, 0)) < 0) { - retval = i; - goto out; - } - if (STp->can_partitions && - (i = switch_partition(STp)) < 0) { - retval = i; - goto out; + /* flush fails -> modify status accordingly */ + if (cmd_mtiocget && STp->pos_unknown) { + reset_state(STp); + STp->pos_unknown = 1; + } else { /* return error */ + retval = i; + goto out; + } + } else { /* flush_buffer succeeds */ + if (STp->can_partitions) { + i = switch_partition(STp); + if (i < 0) { + retval = i; + goto out; + } + } } - if (cmd_type == _IOC_TYPE(MTIOCGET) && cmd_nr == _IOC_NR(MTIOCGET)) { + if (cmd_mtiocget) { struct mtget mt_status; if (_IOC_SIZE(cmd_in) != sizeof(struct mtget)) { @@ -3788,7 +3801,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK); mt_status.mt_blkno = STps->drv_block; mt_status.mt_fileno = STps->drv_file; - if (STp->block_size != 0) { + if (STp->block_size != 0 && mt_status.mt_blkno >= 0) { if (STps->rw == ST_WRITING) mt_status.mt_blkno += (STp->buffer)->buffer_bytes / STp->block_size;