From patchwork Tue Apr 2 19:58:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10882267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5E111390 for ; Tue, 2 Apr 2019 19:58:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5C5728684 for ; Tue, 2 Apr 2019 19:58:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 967FA288D3; Tue, 2 Apr 2019 19:58:30 +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 EE4012875F for ; Tue, 2 Apr 2019 19:58:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726352AbfDBT63 (ORCPT ); Tue, 2 Apr 2019 15:58:29 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37841 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbfDBT63 (ORCPT ); Tue, 2 Apr 2019 15:58:29 -0400 Received: by mail-pl1-f195.google.com with SMTP id w23so3848099ply.4 for ; Tue, 02 Apr 2019 12:58:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N133rg5a0m02/y1a5R/nOMoMg4CIDO7f7/L3j02IvMo=; b=TEO3wqcn8E+IJRaZykUz7JCsR6/vZDDd/uaS93wMZfUT/DV2zQpBcLlBs95lqE30sN vRt0XmiWqMwN3Ti1TpvdJL6xL9nMKmb9LEzUeKqf0vkfUZbg3jSOx3pvjb5erwIqEGNg ODz144/3AEhg5FgtZA8XxHOgTyBltedDejx+b9wLzYcaaYSnHG0vpnkKrc9DQLpTbuK/ 2jUutPnsNPa6Dy9wHmxnfn/YgwdEH6Gc4kojt4qxvNLG5K4rl4NJI2JYeL02+Xzsy9ft SOmkaqaz1GpiR7lnmxGrF4oQLP27rGAAy7XoQcgdSrgPGaKuvXZPAL8aWwPHdEEiBAC2 nDQA== X-Gm-Message-State: APjAAAVO8N2YWdA0hFXAxDx9q/Y4B1POq0SbXdbvRBFbuMPE1IxAsmbW 7qCV4TiZBk2WGD2UJzwOnOc= X-Google-Smtp-Source: APXvYqxZPnls0NPQd7yx3G4Idw7kv2jDAPKwJKKn3IQRvRGCe8PkWrrG9yCerH3NuqI2T0ibgjZgEQ== X-Received: by 2002:a17:902:a607:: with SMTP id u7mr14635175plq.66.1554235108418; Tue, 02 Apr 2019 12:58:28 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id o5sm49055490pfa.135.2019.04.02.12.58.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 12:58:27 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Mike Christie , Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Mike Christie , Hannes Reinecke , Nicholas Bellinger Subject: [PATCH 02/11] target/core: Rework the SPC-2 reservation handling code Date: Tue, 2 Apr 2019 12:58:06 -0700 Message-Id: <20190402195815.254796-3-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190402195815.254796-1-bvanassche@acm.org> References: <20190402195815.254796-1-bvanassche@acm.org> MIME-Version: 1.0 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 Instead of tracking the initiator that established an SPC-2 reservation, track the session through which the SPC-2 reservation has been established. This patch does not change any functionality. Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Nicholas Bellinger Signed-off-by: Bart Van Assche --- drivers/target/target_core_configfs.c | 5 ++-- drivers/target/target_core_pr.c | 33 +++++++++++++++------------ drivers/target/target_core_pr.h | 1 + drivers/target/target_core_tmr.c | 2 +- include/target/target_core_base.h | 4 ++-- include/target/target_core_fabric.h | 1 + 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 3fe79875b3ac..db2558fe8d46 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -1624,11 +1624,12 @@ static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev, static ssize_t target_core_dev_pr_show_spc2_res(struct se_device *dev, char *page) { + struct se_session *sess = dev->reservation_holder; struct se_node_acl *se_nacl; ssize_t len; - se_nacl = dev->dev_reserved_node_acl; - if (se_nacl) { + if (sess) { + se_nacl = sess->se_node_acl; len = sprintf(page, "SPC-2 Reservation: %s Initiator: %s\n", se_nacl->se_tpg->se_tpg_tfo->fabric_name, diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 1597a9ebadca..03767693f580 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c @@ -111,10 +111,10 @@ target_scsi2_reservation_check(struct se_cmd *cmd) break; } - if (!dev->dev_reserved_node_acl || !sess) + if (!dev->reservation_holder || !sess) return 0; - if (dev->dev_reserved_node_acl != sess->se_node_acl) + if (dev->reservation_holder->se_node_acl != sess->se_node_acl) return TCM_RESERVATION_CONFLICT; if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS_WITH_ISID) { @@ -200,6 +200,16 @@ static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd) return 0; } +void target_release_reservation(struct se_device *dev) +{ + dev->reservation_holder = NULL; + dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS; + if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS_WITH_ISID) { + dev->dev_res_bin_isid = 0; + dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS_WITH_ISID; + } +} + sense_reason_t target_scsi2_reservation_release(struct se_cmd *cmd) { @@ -217,21 +227,16 @@ target_scsi2_reservation_release(struct se_cmd *cmd) return TCM_RESERVATION_CONFLICT; spin_lock(&dev->dev_reservation_lock); - if (!dev->dev_reserved_node_acl || !sess) + if (!dev->reservation_holder || !sess) goto out_unlock; - if (dev->dev_reserved_node_acl != sess->se_node_acl) + if (dev->reservation_holder->se_node_acl != sess->se_node_acl) goto out_unlock; if (dev->dev_res_bin_isid != sess->sess_bin_isid) goto out_unlock; - dev->dev_reserved_node_acl = NULL; - dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS; - if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS_WITH_ISID) { - dev->dev_res_bin_isid = 0; - dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS_WITH_ISID; - } + target_release_reservation(dev); tpg = sess->se_tpg; pr_debug("SCSI-2 Released reservation for %s LUN: %llu ->" " MAPPED LUN: %llu for %s\n", @@ -275,13 +280,13 @@ target_scsi2_reservation_reserve(struct se_cmd *cmd) tpg = sess->se_tpg; spin_lock(&dev->dev_reservation_lock); - if (dev->dev_reserved_node_acl && - (dev->dev_reserved_node_acl != sess->se_node_acl)) { + if (dev->reservation_holder && + dev->reservation_holder->se_node_acl != sess->se_node_acl) { pr_err("SCSI-2 RESERVATION CONFLIFT for %s fabric\n", tpg->se_tpg_tfo->fabric_name); pr_err("Original reserver LUN: %llu %s\n", cmd->se_lun->unpacked_lun, - dev->dev_reserved_node_acl->initiatorname); + dev->reservation_holder->se_node_acl->initiatorname); pr_err("Current attempt - LUN: %llu -> MAPPED LUN: %llu" " from %s \n", cmd->se_lun->unpacked_lun, cmd->orig_fe_lun, @@ -290,7 +295,7 @@ target_scsi2_reservation_reserve(struct se_cmd *cmd) goto out_unlock; } - dev->dev_reserved_node_acl = sess->se_node_acl; + dev->reservation_holder = sess; dev->dev_reservation_flags |= DRF_SPC2_RESERVATIONS; if (sess->sess_bin_isid != 0) { dev->dev_res_bin_isid = sess->sess_bin_isid; diff --git a/drivers/target/target_core_pr.h b/drivers/target/target_core_pr.h index 198fad5c89dc..a31c93e4e19c 100644 --- a/drivers/target/target_core_pr.h +++ b/drivers/target/target_core_pr.h @@ -58,6 +58,7 @@ extern struct kmem_cache *t10_pr_reg_cache; extern void core_pr_dump_initiator_port(struct t10_pr_registration *, char *, u32); +extern void target_release_reservation(struct se_device *dev); extern sense_reason_t target_scsi2_reservation_release(struct se_cmd *); extern sense_reason_t target_scsi2_reservation_reserve(struct se_cmd *); extern int core_scsi3_alloc_aptpl_registration( diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 3a1bb799a9ab..344df737f3a3 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -390,7 +390,7 @@ int core_tmr_lun_reset( if (!preempt_and_abort_list && (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS)) { spin_lock(&dev->dev_reservation_lock); - dev->dev_reserved_node_acl = NULL; + dev->reservation_holder = NULL; dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS; spin_unlock(&dev->dev_reservation_lock); pr_debug("LUN_RESET: SCSI-2 Released reservation\n"); diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 19a5bf4214fc..7c9716fe731e 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -795,8 +795,8 @@ struct se_device { spinlock_t se_tmr_lock; spinlock_t qf_cmd_lock; struct semaphore caw_sem; - /* Used for legacy SPC-2 reservationsa */ - struct se_node_acl *dev_reserved_node_acl; + /* Used for legacy SPC-2 reservations */ + struct se_session *reservation_holder; /* Used for ALUA Logical Unit Group membership */ struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem; /* Used for SPC-3 Persistent Reservations */ diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 8ed90407f062..063f133e47c2 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -142,6 +142,7 @@ void transport_register_session(struct se_portal_group *, struct se_node_acl *, struct se_session *, void *); ssize_t target_show_dynamic_sessions(struct se_portal_group *, char *); void transport_free_session(struct se_session *); +void target_spc2_release(struct se_node_acl *nacl); void target_put_nacl(struct se_node_acl *); void transport_deregister_session_configfs(struct se_session *); void transport_deregister_session(struct se_session *);