From patchwork Tue Apr 2 19:58:07 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: 10882269 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 06FC21390 for ; Tue, 2 Apr 2019 19:58:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E501A28684 for ; Tue, 2 Apr 2019 19:58:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8D61288D3; Tue, 2 Apr 2019 19:58:31 +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 6357128684 for ; Tue, 2 Apr 2019 19:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726372AbfDBT6b (ORCPT ); Tue, 2 Apr 2019 15:58:31 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45247 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbfDBT6a (ORCPT ); Tue, 2 Apr 2019 15:58:30 -0400 Received: by mail-pl1-f193.google.com with SMTP id bf11so6775313plb.12 for ; Tue, 02 Apr 2019 12:58:30 -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=9LZpHuwewRP1ARYeGJ/sRqmTw/BjrwRVwTj1Sym1XJw=; b=blH3zjXCqvVBX8fTNbV6vl4YVehI8RlxqJBcCO50PA37nQnCkmpqgKL3nxyzwj+bv4 Ncxqtn8cfiVsz50oapWy8S7B1C5vkiKeJpmW8Y/hmkB8Za4qCOESX7bc17heHkbwYYqA 3NmTD2RTBO1JR2Z3USnq63g4gTgYFWMuFfDobHWQ6rHUyCRzQTSFhrrWXl/R9aS6spKA YymbHI4d8p2XoAlhD1wVOE9tQ5r4mi2nLlzjd8Sdb0tyHpJhAUqYN+KzztePY/iRE54v xF6TjHf0gSlRKmdFwl98xm0/P07HM7tLFkK5r1n4zCYUnex30W/1Qrie3tZbxFp+uU3T C5MQ== X-Gm-Message-State: APjAAAXNiNf96TyRclSs11quZdUDqdTrA+pEIz1/nCcPOzxniUvyq8k5 PGGs/WwSvzAGSoukym6892Y= X-Google-Smtp-Source: APXvYqwQpcL73HIDQ9096LXbyHxIG+CHkLKWxPGDzpLtfLIPcvtqQtsLGDn8bcBuWqf2+TKOkCxV5A== X-Received: by 2002:a17:902:12f:: with SMTP id 44mr72755709plb.208.1554235110112; Tue, 02 Apr 2019 12:58:30 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 12:58:29 -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 03/11] target/core: Release SPC-2 reservation upon initiator logout Date: Tue, 2 Apr 2019 12:58:07 -0700 Message-Id: <20190402195815.254796-4-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 While testing with the libiscsi tool I noticed after the tool had stopped and hence after it had logged out that an SPC-2 reservation was still active: $ (cd /sys/kernel/config/target/core && find -name res_holder|xargs grep -aH .) ./pscsi_0/vdev3/pr/res_holder:Passthrough ./iblock_0/vdev2/pr/res_holder:No SPC-3 Reservation holder ./fileio_1/vdev1/pr/res_holder:SPC-2 Reservation: iSCSI Initiator: iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-test-2 ./fileio_0/vdev0/pr/res_holder:No SPC-3 Reservation holder This is a bug. SPC-2 reservations must be cleared when an initiator logs out. This patch fixes that bug. A quote from SPC-2 illustrates this: "Reservations managed using the reserve/release method do not persist across some recovery actions (e.g., hard resets). When a target performs one of these recovery actions, the application client(s) have to rediscover the configuration and re-establish the required reservations." Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Nicholas Bellinger Signed-off-by: Bart Van Assche --- drivers/target/target_core_transport.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index e3f7e21e6614..93ef5c6362d6 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -550,6 +550,15 @@ void transport_deregister_session_configfs(struct se_session *se_sess) } EXPORT_SYMBOL(transport_deregister_session_configfs); +static int target_sess_release_reservation(struct se_device *dev, void *data) +{ + struct se_session *sess = data; + + if (dev->reservation_holder == sess) + target_release_reservation(dev); + return 0; +} + void transport_free_session(struct se_session *se_sess) { struct se_node_acl *se_nacl = se_sess->se_node_acl; @@ -592,6 +601,7 @@ void transport_free_session(struct se_session *se_sess) sbitmap_queue_free(&se_sess->sess_tag_pool); kvfree(se_sess->sess_cmd_map); } + target_for_each_device(target_sess_release_reservation, se_sess); percpu_ref_exit(&se_sess->cmd_count); kmem_cache_free(se_sess_cache, se_sess); }