From patchwork Fri Jun 15 18:23:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Lingshan X-Patchwork-Id: 10467241 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 D885D601C2 for ; Fri, 15 Jun 2018 18:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9DD028E3B for ; Fri, 15 Jun 2018 18:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE9B028E41; Fri, 15 Jun 2018 18:24:35 +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 6239D28E3B for ; Fri, 15 Jun 2018 18:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756437AbeFOSYd (ORCPT ); Fri, 15 Jun 2018 14:24:33 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:56353 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756355AbeFOSYc (ORCPT ); Fri, 15 Jun 2018 14:24:32 -0400 Received: from vstart.localdomain (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Fri, 15 Jun 2018 12:24:22 -0600 From: Zhu Lingshan To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, nab@linux-iscsi.org, mchristi@redhat.com, martin.petersen@oracle.com Cc: hare@suse.de, lduncan@suse.com, ddiss@suse.de, lszhu@suse.de, Zhu Lingshan Subject: [PATCH 07/33] TCMU PR: add functions to handle SCSI2 Reservation Date: Sat, 16 Jun 2018 02:23:16 +0800 Message-Id: <20180615182342.6239-7-lszhu@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180615182342.6239-1-lszhu@suse.com> References: <20180615182342.6239-1-lszhu@suse.com> 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 This patch added two functions: tcmu_pr_info_scsi2_rsv_encode() and tcmu_pr_info_scsi2_rsv_decode() to encode and decode SCSI2 Reservations. Signed-off-by: Zhu Lingshan --- drivers/target/target_core_user.c | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index ccb1607edd0a..50723ac0ed22 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -94,6 +94,9 @@ #define TCMU_GLOBAL_MAX_BLOCKS_DEF (512 * 1024) #define TCMU_PR_INFO_XATTR_VERS 1 +#define TCMU_PR_INFO_XATTR_VAL_SCSI2_RSV_ABSENT "No SPC-2 Reservation holder" + +#define TCMU_PR_IT_NEXUS_MAXLEN 484 static u8 tcmu_kern_cmd_reply_supported; @@ -200,6 +203,14 @@ struct tcmu_cmd { #define TCMU_CMD_BIT_EXPIRED 0 unsigned long flags; }; + +/* + * I-T nexus for SCSI2 (RESERVE/RELEASE) reservation. + */ +struct tcmu_scsi2_rsv { + char it_nexus[TCMU_PR_IT_NEXUS_MAXLEN]; + }; + /* * To avoid dead lock the mutex lock order should always be: * @@ -1875,6 +1886,60 @@ tcmu_pr_info_vers_decode(char *str, u32 *vers) return 0; } +static int +tcmu_pr_info_scsi2_rsv_decode(char *str, struct tcmu_scsi2_rsv **_scsi2_rsv) +{ + struct tcmu_scsi2_rsv *scsi2_rsv; + + if (!_scsi2_rsv) { + WARN_ON(1); + return -EINVAL; + } + if (!strncmp(str, TCMU_PR_INFO_XATTR_VAL_SCSI2_RSV_ABSENT, + sizeof(TCMU_PR_INFO_XATTR_VAL_SCSI2_RSV_ABSENT))) { + scsi2_rsv = NULL; + } else { + size_t n; + + scsi2_rsv = kzalloc(sizeof(*scsi2_rsv), GFP_KERNEL); + if (!scsi2_rsv) + return -ENOMEM; + + n = strlcpy(scsi2_rsv->it_nexus, str, + TCMU_PR_IT_NEXUS_MAXLEN); + if (n >= TCMU_PR_IT_NEXUS_MAXLEN) { + kfree(scsi2_rsv); + return -EINVAL; + } + } + + pr_debug("processed pr_info SCSI2 rsv: %s\n", str); + + *_scsi2_rsv = scsi2_rsv; + return 0; +} + +static int +tcmu_pr_info_scsi2_rsv_encode(char *buf, size_t buf_remain, + struct tcmu_scsi2_rsv *scsi2_rsv) +{ + int rc; + + if (!scsi2_rsv) { + /* no reservation */ + rc = snprintf(buf, buf_remain, "%s\n", + TCMU_PR_INFO_XATTR_VAL_SCSI2_RSV_ABSENT); + } else { + rc = snprintf(buf, buf_remain, "%s\n", scsi2_rsv->it_nexus); + } + if ((rc < 0) || (rc >= buf_remain)) { + pr_err("failed to encode SCSI2 reservation\n"); + return -EINVAL; + } + + return rc; +} + static int tcmu_configure_device(struct se_device *dev) { struct tcmu_dev *udev = TCMU_DEV(dev);