From patchwork Thu Oct 5 19:41:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13410689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 618A2E9273B for ; Thu, 5 Oct 2023 19:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232063AbjJETmy (ORCPT ); Thu, 5 Oct 2023 15:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbjJETmc (ORCPT ); Thu, 5 Oct 2023 15:42:32 -0400 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD55D122; Thu, 5 Oct 2023 12:42:21 -0700 (PDT) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-692ada71d79so1169973b3a.1; Thu, 05 Oct 2023 12:42:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696534941; x=1697139741; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fOMydPF2VcwRgPLFEqLOV65CCfeEvsEsIGHpmPfdEcY=; b=ZyNOa5OPzHONg28/VjxWXf98ZJSOqjjMDng6+hlr7nv3rWjHwwoR/LSM1SBIYpQTYH HPITVQfOkzlFeeLz+A2hO2xJxX83DJY0P+BN6BxS7Jcj55r1l7m7SXy57GdsBH4ZKHc5 JldVA/v2LWirSSkJfPpLIw2iDRi9XDL4PfjauOcCu9ALp7ZNjsBKnke+eAb+s9wq5NW+ lALkAYF2bSMR+gqylk3EaMc7A8i5ggtBrau9xyP8aDC2txFOytjlD6hdnPSg6xPoq7QX ig0wVQPq/i6YEHYCxc9a1coxtuXsbhcu8HWimaacRsJnEFMe3H6pySi1l2bVlD5aqVl3 +t+w== X-Gm-Message-State: AOJu0Yx9EoL3pwUi06jqgJDG5+4mNvQsnEiJtc339K+Qp5Z0Q0pytoyA 73+8u3HRCEYEJ6+UU9Q9DVk= X-Google-Smtp-Source: AGHT+IHJemajbUI3eRYS5Uq9s4QjGLDeYckQB+yGUUfVzpZ+2r7ZZgAxOl6HcN2nPPYposG48CdPcg== X-Received: by 2002:a05:6a21:4887:b0:163:ab2b:bddd with SMTP id av7-20020a056a21488700b00163ab2bbdddmr5329767pzc.27.1696534941045; Thu, 05 Oct 2023 12:42:21 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:ca3e:70ef:bad:2f]) by smtp.gmail.com with ESMTPSA id u4-20020a170902e5c400b001a9b29b6759sm2129596plf.183.2023.10.05.12.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 12:42:20 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , "James E.J. Bottomley" Subject: [PATCH v2 14/15] scsi_debug: Implement GET STREAM STATUS Date: Thu, 5 Oct 2023 12:41:00 -0700 Message-ID: <20231005194129.1882245-15-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog In-Reply-To: <20231005194129.1882245-1-bvanassche@acm.org> References: <20231005194129.1882245-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Implement the GET STREAM STATUS SCSI command. Report that the first three stream indexes correspond to permanent streams. Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index d56989e94c4a..801448570960 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -481,6 +481,8 @@ static int resp_write_scat(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_start_stop(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_readcap16(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_get_lba_status(struct scsi_cmnd *, struct sdebug_dev_info *); +static int resp_get_stream_status(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip); static int resp_report_tgtpgs(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_unmap(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_rsup_opcodes(struct scsi_cmnd *, struct sdebug_dev_info *); @@ -555,6 +557,9 @@ static const struct opcode_info_t sa_in_16_iarr[] = { {0, 0x9e, 0x12, F_SA_LOW | F_D_IN, resp_get_lba_status, NULL, {16, 0x12, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0xc7} }, /* GET LBA STATUS(16) */ + {0, 0x9e, 0x16, F_SA_LOW | F_D_IN, resp_get_stream_status, NULL, + {16, 0x16, 0, 0, 0xff, 0xff, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, + 0, 0} }, /* GET STREAM STATUS */ }; static const struct opcode_info_t vl_iarr[] = { /* VARIABLE LENGTH */ @@ -2241,7 +2246,7 @@ static int resp_ctrl_m_pg(unsigned char *p, int pcontrol, int target) return sizeof(ctrl_m_pg); } -enum { MAXIMUM_NUMBER_OF_STREAMS = 4 }; +enum { MAXIMUM_NUMBER_OF_STREAMS = 4, PERMANENT_STREAM_COUNT = 3 }; /* IO Advice Hints Grouping mode page */ static int resp_grouping_m_pg(unsigned char *p, int pcontrol, int target) @@ -4236,6 +4241,43 @@ static int resp_get_lba_status(struct scsi_cmnd *scp, return fill_from_dev_buffer(scp, arr, SDEBUG_GET_LBA_STATUS_LEN); } +static int resp_get_stream_status(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip) +{ + u16 starting_stream_id, stream_id; + const u8 *cmd = scp->cmnd; + u32 alloc_len, offset; + u8 arr[256]; + + starting_stream_id = get_unaligned_be16(cmd + 4); + alloc_len = get_unaligned_be32(cmd + 10); + + if (alloc_len < 8) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1); + return check_condition_result; + } + + if (starting_stream_id >= MAXIMUM_NUMBER_OF_STREAMS) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, -1); + return check_condition_result; + } + + for (offset = 8, stream_id = starting_stream_id; + offset + 8 <= min_t(u32, alloc_len, sizeof(arr)) && + stream_id < MAXIMUM_NUMBER_OF_STREAMS; + offset += 8, stream_id++) { + struct scsi_stream_status *stream_status = (void *)arr + offset; + + stream_status->perm = stream_id < PERMANENT_STREAM_COUNT; + put_unaligned_be16(stream_id, + &stream_status->stream_identifier); + stream_status->rel_lifetime = stream_id + 1; + } + put_unaligned_be32(offset - 8, arr + 0); /* PARAMETER DATA LENGTH */ + + return fill_from_dev_buffer(scp, arr, min(offset, alloc_len)); +} + static int resp_sync_cache(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) {