From patchwork Fri Jun 15 18:23:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Lingshan X-Patchwork-Id: 10467219 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 3BC2860348 for ; Fri, 15 Jun 2018 18:24:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2ACD128E3B for ; Fri, 15 Jun 2018 18:24:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C40228E40; Fri, 15 Jun 2018 18:24:17 +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 A081B28E3B for ; Fri, 15 Jun 2018 18:24:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756366AbeFOSYP (ORCPT ); Fri, 15 Jun 2018 14:24:15 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:52017 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753541AbeFOSYP (ORCPT ); Fri, 15 Jun 2018 14:24:15 -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:02 -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 01/33] TCMU PR: first commit to implement TCMU PR Date: Sat, 16 Jun 2018 02:23:10 +0800 Message-Id: <20180615182342.6239-1-lszhu@suse.com> X-Mailer: git-send-email 2.17.1 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 These commits and the following intend to implement Persistent Reservation operations for TCMU devices. This series of commits would implement such PR operations: PR_Out_Register, PR_Out_Reserve, PR_Out_Clear, PR_Out_Preempt, PR_Out_Release and PR_In_ReadKeys. Next wave of patches will contain the other PR operations. This patch added a struct tcmu_pr_info to store PR information for the handling functions, added command codes and attrs for netlink interfaces. Design note: In order to get consistent Persistent Reservation results from multiple targets hosting the same TCMU device(like Ceph RBD), this solution stores a string on the device itself(like RBD metadata). Everytime when kernel receive a PR request against a TCMU device, it will query this string(a netlink attr carried by a netlink cmd). Then decide whether the PR request should be performed, after processing, it will update this string. For example: When receive a PR Reserve request, kernel will send a netlink message to tcmu-runner, try to get the string, tcmu-runner will response, send the PR info string to kernel. Then kernel will decode the string, find information like key, reservation holder, then process this request. After processing, it will update the string, send the updated string to tcmu-runner, so that tcmu-runner will write it back to the device(like RBD metadata). So we make the device itself as a "single" response point, (with locks protection) we will get a consistent result even more than one initiators sending multiple PR requests via multiple targets. Signed-off-by: Zhu Lingshan --- include/uapi/linux/target_core_user.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/uapi/linux/target_core_user.h b/include/uapi/linux/target_core_user.h index 0be80f72646b..2d5c3e55d3f8 100644 --- a/include/uapi/linux/target_core_user.h +++ b/include/uapi/linux/target_core_user.h @@ -132,9 +132,13 @@ enum tcmu_genl_cmd { TCMU_CMD_ADDED_DEVICE, TCMU_CMD_REMOVED_DEVICE, TCMU_CMD_RECONFIG_DEVICE, + TCMU_CMD_GET_PR_INFO, + TCMU_CMD_SET_PR_INFO, TCMU_CMD_ADDED_DEVICE_DONE, TCMU_CMD_REMOVED_DEVICE_DONE, TCMU_CMD_RECONFIG_DEVICE_DONE, + TCMU_CMD_GET_PR_INFO_DONE, + TCMU_CMD_SET_PR_INFO_DONE, TCMU_CMD_SET_FEATURES, __TCMU_CMD_MAX, }; @@ -151,8 +155,23 @@ enum tcmu_genl_attr { TCMU_ATTR_CMD_STATUS, TCMU_ATTR_DEVICE_ID, TCMU_ATTR_SUPP_KERN_CMD_REPLY, + TCMU_ATTR_PR_INFO, __TCMU_ATTR_MAX, }; #define TCMU_ATTR_MAX (__TCMU_ATTR_MAX - 1) +/* This struct help to store the Persistent Reservation which we + * are handling, it is encoded from or decoded to the string buffer in + * "struct tcmu_dev_pr_info" + */ +struct tcmu_pr_info { + u32 vers; /* on disk format version number */ + u32 seq; /* sequence number bumped every xattr write */ + struct tcmu_scsi2_rsv *scsi2_rsv; /* SCSI2 reservation if any */ + u32 gen; /* PR generation number */ + struct tcmu_pr_rsv *rsv; /* SCSI3 reservation if any */ + u32 num_regs; /* number of registrations */ + struct list_head regs; /* list of registrations */ +}; + #endif