From patchwork Tue Jul 4 16:52:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 115870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1357748vqx; Tue, 4 Jul 2023 10:09:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlGBUbt6mpwRJYLG4brawqzkW6CHTF+2fDolrGLX9qloPyING8Sjac1GabPOFEjX2BW1c2fG X-Received: by 2002:a17:903:2304:b0:1a2:a904:c42e with SMTP id d4-20020a170903230400b001a2a904c42emr20994996plh.24.1688490554711; Tue, 04 Jul 2023 10:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688490554; cv=none; d=google.com; s=arc-20160816; b=ENfa3HVpFBMYyc8cdP6ViuA1BWYlyjKCcBUfu7VeKWnsQNRg/xd9xGIf9yWSdBiY69 L8zHKAe3BNCoLI/txu0bCi/6t65rOiUEnZ5ZYkdCMsy1Ae/pnfRdNU4/I610GMbg8Fbg uFdgut31yaoipyrqPWMa3hlD/HFZ0Vakc+5HMw4bUnc8shHd34jNmPJV3ZwycwuNawWw wnWFpFXG0563FjHB6ZeKYye4+zanauSQ09zJFIMdz89d03vK20DqvF87YEOQQ9gV89jg tlLIXTKfWeLaLMmAYq1gfH0GxiiAk9iPRzDSMaV0wGuqyxOg41Kz45IMEzUWUCrcLNI5 F0yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ajr5DYl9C6qOy7ts63BGAnBwuXR1t1xb9L8MNCWnMcM=; fh=JwN0p46ZlpvloRQl/55YovaDle/zmEWTwso8DKF8XUk=; b=isG3VfFP7rUMS+Iur4CBZXieX9i1yf1ooMYsC5jDcSU4mdY4QJ363F0XKBzQEbmoRN 6QefWhid8TorsiRvwaQPVtsgXhXDlPCO4pFlgQllD/aGTZZOb/Y+Buu1gInPynr+Mtt1 dbEP7c186x/FBLV1UXjfT+iQvC7YZQOyIExpd5fj0swgClTyMbW9I/A4Ye8XwqG9ftZA 7vB45dln99v2YSf013o8gOEWfOS3UGbfkPMhJpyJhzh3tyJHZIIlwCg0frs1L0suGgn+ 6TTBNoYUoPxl1i46wG2l2zL9D+2YoAjJ0bqxLW8Jab3Xy2H58MQLmSR7mL4qxhPoEaPm EBHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=ELcA0gKS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a170902f60d00b001b3dd46d4fesi21516183plg.66.2023.07.04.10.08.59; Tue, 04 Jul 2023 10:09:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=ELcA0gKS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231481AbjGDQwT (ORCPT + 99 others); Tue, 4 Jul 2023 12:52:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230466AbjGDQwQ (ORCPT ); Tue, 4 Jul 2023 12:52:16 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D09B1AD for ; Tue, 4 Jul 2023 09:52:15 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-51de9c2bc77so4975762a12.3 for ; Tue, 04 Jul 2023 09:52:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1688489534; x=1691081534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ajr5DYl9C6qOy7ts63BGAnBwuXR1t1xb9L8MNCWnMcM=; b=ELcA0gKS9JSx9R9qjiLpvMhVbjMHSmx5lrUB94ix+gOFrnfps5pbmDmG98waBqqayS sLoP2JP1w+4strsaZol5otwIl+x73ByHuDTl8YyYMUo1JtdU2L35bZ/kT05v1brDrLRe ti7ETokvmT6vw18s0039eK6WcpQDJJr2INKRskGSKJlDmXWuuJVkddx3a/UWeCzFZdbX tWG5CFlpFMEtkW+uDiHE4vudJtbGje3FJdJCF0uF3hYb7opZ0R3yrW9t9fRGYkK35U0Q cZKgwmhLsxE61ALTpNq6fEXjuXvY5Irpg8bh0XCYxl+Bu1B/xeKt8jF/kS/JawRlNZBu YZZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688489534; x=1691081534; 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=Ajr5DYl9C6qOy7ts63BGAnBwuXR1t1xb9L8MNCWnMcM=; b=GEwZwMdKnBsIQ680Pw2c8BRvAEI/unU9TUG+HjorcKY8LxTlMgPJudRz12hEEcyPTT hUYCPZ3y16tG5hWa3UNn0E5MhbRNF2DjWsWqAmLKWBZBZ5x/ARqtcLwqIPiU2mmHfB5L w8fPEshCkwUP2cLp85swappH/O14xT86TAUDozMqAWN5B446ilcdSNTHOaqbh/64YKqW ur8qZygmmuRuCh0xGNByJk29rNR29qIwlancowdFe5+KUP5GdtBYACF8T3Pzxr57/dXq Xm+FLz9coW36LfIMxVv0bWskW4vQ8+c6vtvnUT5uRfNEXP6wNwB7uEgq5QwuasQeZo+P Z5og== X-Gm-Message-State: ABy/qLYMyKquV9Ed9vcuDA1ZByE9EA4p5lQ0Gh/3JbqJFVnvp40WV8eW 8yNp1GjeT8stAtkMjBPq/Y4nUQ== X-Received: by 2002:a17:906:b294:b0:991:d05c:f065 with SMTP id q20-20020a170906b29400b00991d05cf065mr10489010ejz.52.1688489533683; Tue, 04 Jul 2023 09:52:13 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id n20-20020a170906725400b0099275c59bc9sm8510947ejk.33.2023.07.04.09.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 09:52:13 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: linux-kernel@vger.kernel.org (open list), Matias Bjorling , Hans Holmberg , Jens Axboe , Minwoo Im , Aravind Ramesh , gost.dev@samsung.com, linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Damien Le Moal , Andreas Hindborg Subject: [PATCH v5 1/5] ublk: add opcode offsets for DRV_IN/DRV_OUT Date: Tue, 4 Jul 2023 18:52:05 +0200 Message-ID: <20230704165209.514591-2-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230704165209.514591-1-nmi@metaspace.dk> References: <20230704165209.514591-1-nmi@metaspace.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770510671605577196?= X-GMAIL-MSGID: =?utf-8?q?1770510671605577196?= From: Andreas Hindborg Ublk zoned storage support relies on DRV_IN handling for zone report. Prepare for this change by adding offsets for the DRV_IN/DRV_OUT commands. Also add parenthesis to existing opcodes for better macro hygiene. Signed-off-by: Andreas Hindborg --- include/uapi/linux/ublk_cmd.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index 4b8558db90e1..a32810c8ef2b 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -229,12 +229,16 @@ struct ublksrv_ctrl_dev_info { __u64 reserved2; }; -#define UBLK_IO_OP_READ 0 -#define UBLK_IO_OP_WRITE 1 -#define UBLK_IO_OP_FLUSH 2 -#define UBLK_IO_OP_DISCARD 3 -#define UBLK_IO_OP_WRITE_SAME 4 -#define UBLK_IO_OP_WRITE_ZEROES 5 +#define UBLK_IO_OP_READ (0) +#define UBLK_IO_OP_WRITE (1) +#define UBLK_IO_OP_FLUSH (2) +#define UBLK_IO_OP_DISCARD (3) +#define UBLK_IO_OP_WRITE_SAME (4) +#define UBLK_IO_OP_WRITE_ZEROES (5) +#define __UBLK_IO_OP_DRV_IN_START (32) +#define __UBLK_IO_OP_DRV_IN_END (96) +#define __UBLK_IO_OP_DRV_OUT_START (__UBLK_IO_OP_DRV_IN_END) +#define __UBLK_IO_OP_DRV_OUT_END (160) #define UBLK_IO_F_FAILFAST_DEV (1U << 8) #define UBLK_IO_F_FAILFAST_TRANSPORT (1U << 9) From patchwork Tue Jul 4 16:52:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 115866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1350732vqx; Tue, 4 Jul 2023 09:59:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5z1n/HwtczB/UVo+tPlcd1K3c7AqxetxpvuWqu3FjibLZg3HHm5tqYj0f78OOAidbLgzs7 X-Received: by 2002:a05:6830:120d:b0:6b2:e8dc:e468 with SMTP id r13-20020a056830120d00b006b2e8dce468mr13732791otp.37.1688489955969; Tue, 04 Jul 2023 09:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688489955; cv=none; d=google.com; s=arc-20160816; b=og4BtK86to9k8wOjBBCfSm3tZbO7GJL6+BF3e6IOat6fMzbELJEnzyHFOqg56KnrRm m3Hzn2lXsDQPAxpq3lWX5kb045lCJv4FIlYopQwcqs3KtwizMFCXDFa4L/z330KvVW4+ FFHZCkuS7lHjF5BkFYDLUY+MDVaXaba5ROcoUvnclE4/bVOu2+tht+8b6BtDwCvdktSn jPXUI0wmy9+sebeIrSL/j/YqjmjKowcfXXXDZ/n7F/H5+RhpihACLzRNX5qJiyj/JSYm jrwKrKJRjf7/RjLqsCrcMSTzG1LE05RuQdzRBev58gaADa0LemPzW3Ew7CIZfzolgE4i nieQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QmeNaedvzJG5TN3SYyJwsVgz2v8XaFGPq/mxdzNq3MQ=; fh=JwN0p46ZlpvloRQl/55YovaDle/zmEWTwso8DKF8XUk=; b=ydzqasGv8tEauMFZh29Yb1yP8AY/5rDfj9Tf5I0IKaA25rJLcvbJQar880PtcDS9jn JRg1S8WQbyugh76h038yK0tu0OEZ+1zan+jSu3Ylqurj/HHG+3aODpB6u9diyEugucjG gKzuMYVc60EqRgpqtWBTRY5xBSauqy5P980EWer7X3+7RBAqUIY8wkRiLvrYnzhAW3sS Fwz3b5vduDXoQJdQfI8Wg2DP247VUWg9TmmMVmuupegWahUv6mwnidSkJd4c3XsHR16P 37Tyo6Me3U3DEXtQhynndmJ+zPSx2YiwtHSaR1dAzmizc2oKmXCuCUwEE1zsCZVFTkA8 we4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=hsY9Plq6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i18-20020a63e452000000b005538b4e729csi21836689pgk.171.2023.07.04.09.58.59; Tue, 04 Jul 2023 09:59:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=hsY9Plq6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231521AbjGDQwY (ORCPT + 99 others); Tue, 4 Jul 2023 12:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231453AbjGDQwT (ORCPT ); Tue, 4 Jul 2023 12:52:19 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EA071AC for ; Tue, 4 Jul 2023 09:52:17 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-51dfa0771cdso4387741a12.2 for ; Tue, 04 Jul 2023 09:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1688489536; x=1691081536; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QmeNaedvzJG5TN3SYyJwsVgz2v8XaFGPq/mxdzNq3MQ=; b=hsY9Plq6xsZwALy6I424gNrBfMMGHepEgIEhkVotKU8rhkli2WV14MmfZ669RuEkRf gnBL6RSfyJq6J5qlB3haPLuxh9sNaZHNwmypq/Q89rIN4uZZISIJkOnpHxdxxPsAk1Mr JX4i/Ys9YJ5r97psNoKs92oayg/XECLqYfKdDOchU9l4DlPJVsnydN+pi905UAHT5sga W8B4reNoYndKs/4loeHOQYvPUnXKq7TOJpnYVZHe23hiIpjWUw4xwgxEW+GsfGRxY7jk hYIGsFuoLjTgej5fvpGM/EnDKmqyAFqLZ24MQ0lzia6ebVtMFbU8E7uhT9wftvbClbw/ hgSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688489536; x=1691081536; 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=QmeNaedvzJG5TN3SYyJwsVgz2v8XaFGPq/mxdzNq3MQ=; b=lWVmer1cgUI7w7qguQKbLg6Ki0HVZ7FBOMpMNUYj3aZJ96pQEeQ1WC7QHJbjrUjwmi 7SfkOnCJKODHb5ULXRm2BlFXBeS3/3z/Oroufrh0ABJMSeU7cm5Fvoi7ToiVTmEflexQ vkH+Q84TP5kpDwDLAyqgHdEF/FhXaTreTVgrJLy+ST8TSwfrmn/AETVzcAlWG8TsTxXu daVjZ3xAFLBcLYe9B1Opie40I98uMkplLdFvRqLQb5xCedNQaKayhIE5o7e0VBdVkQN+ Zkhrzn1xf30gs/K12hR8FErQLK3zo4XONkOef4PqdSYR+G2r9FlU29MRNgb3FdY4/yRg fywA== X-Gm-Message-State: ABy/qLaoNOZEw/SxKuyRIMZpILuu/2dpHkod80+IGBALtmtrFsgTANB4 y4pueQxeZGy/lu5Q4U/s58d8BA== X-Received: by 2002:a17:907:20a4:b0:973:9f60:c57e with SMTP id pw4-20020a17090720a400b009739f60c57emr9620153ejb.2.1688489535956; Tue, 04 Jul 2023 09:52:15 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id n5-20020a170906088500b0098963eb0c3dsm13479053eje.26.2023.07.04.09.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 09:52:15 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: linux-kernel@vger.kernel.org (open list), Matias Bjorling , Hans Holmberg , Jens Axboe , Minwoo Im , Aravind Ramesh , gost.dev@samsung.com, linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Damien Le Moal , Andreas Hindborg Subject: [PATCH v5 2/5] ublk: move types to shared header file Date: Tue, 4 Jul 2023 18:52:06 +0200 Message-ID: <20230704165209.514591-3-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230704165209.514591-1-nmi@metaspace.dk> References: <20230704165209.514591-1-nmi@metaspace.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770510044437374438?= X-GMAIL-MSGID: =?utf-8?q?1770510044437374438?= From: Andreas Hindborg This change is in preparation for ublk zoned storage support. Signed-off-by: Andreas Hindborg Reviewed-by: Damien Le Moal --- MAINTAINERS | 1 + drivers/block/ublk_drv.c | 92 +--------------------------------- drivers/block/ublk_drv.h | 103 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 91 deletions(-) create mode 100644 drivers/block/ublk_drv.h diff --git a/MAINTAINERS b/MAINTAINERS index 27ef11624748..ace71c90751c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21554,6 +21554,7 @@ L: linux-block@vger.kernel.org S: Maintained F: Documentation/block/ublk.rst F: drivers/block/ublk_drv.c +F: drivers/block/ublk_drv.h F: include/uapi/linux/ublk_cmd.h UCLINUX (M68KNOMMU AND COLDFIRE) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 1c823750c95a..bca0c4e1cfd8 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -45,6 +45,7 @@ #include #include #include +#include "ublk_drv.h" #define UBLK_MINORS (1U << MINORBITS) @@ -62,63 +63,11 @@ #define UBLK_PARAM_TYPE_ALL (UBLK_PARAM_TYPE_BASIC | \ UBLK_PARAM_TYPE_DISCARD | UBLK_PARAM_TYPE_DEVT) -struct ublk_rq_data { - struct llist_node node; - - struct kref ref; -}; struct ublk_uring_cmd_pdu { struct ublk_queue *ubq; }; -/* - * io command is active: sqe cmd is received, and its cqe isn't done - * - * If the flag is set, the io command is owned by ublk driver, and waited - * for incoming blk-mq request from the ublk block device. - * - * If the flag is cleared, the io command will be completed, and owned by - * ublk server. - */ -#define UBLK_IO_FLAG_ACTIVE 0x01 - -/* - * IO command is completed via cqe, and it is being handled by ublksrv, and - * not committed yet - * - * Basically exclusively with UBLK_IO_FLAG_ACTIVE, so can be served for - * cross verification - */ -#define UBLK_IO_FLAG_OWNED_BY_SRV 0x02 - -/* - * IO command is aborted, so this flag is set in case of - * !UBLK_IO_FLAG_ACTIVE. - * - * After this flag is observed, any pending or new incoming request - * associated with this io command will be failed immediately - */ -#define UBLK_IO_FLAG_ABORTED 0x04 - -/* - * UBLK_IO_FLAG_NEED_GET_DATA is set because IO command requires - * get data buffer address from ublksrv. - * - * Then, bio data could be copied into this data buffer for a WRITE request - * after the IO command is issued again and UBLK_IO_FLAG_NEED_GET_DATA is unset. - */ -#define UBLK_IO_FLAG_NEED_GET_DATA 0x08 - -struct ublk_io { - /* userspace buffer address from io cmd */ - __u64 addr; - unsigned int flags; - int res; - - struct io_uring_cmd *cmd; -}; - struct ublk_queue { int q_id; int q_depth; @@ -140,45 +89,6 @@ struct ublk_queue { #define UBLK_DAEMON_MONITOR_PERIOD (5 * HZ) -struct ublk_device { - struct gendisk *ub_disk; - - char *__queues; - - unsigned int queue_size; - struct ublksrv_ctrl_dev_info dev_info; - - struct blk_mq_tag_set tag_set; - - struct cdev cdev; - struct device cdev_dev; - -#define UB_STATE_OPEN 0 -#define UB_STATE_USED 1 -#define UB_STATE_DELETED 2 - unsigned long state; - int ub_number; - - struct mutex mutex; - - spinlock_t mm_lock; - struct mm_struct *mm; - - struct ublk_params params; - - struct completion completion; - unsigned int nr_queues_ready; - unsigned int nr_privileged_daemon; - - /* - * Our ubq->daemon may be killed without any notification, so - * monitor each queue's daemon periodically - */ - struct delayed_work monitor_work; - struct work_struct quiesce_work; - struct work_struct stop_work; -}; - /* header of ublk_params */ struct ublk_params_header { __u32 len; diff --git a/drivers/block/ublk_drv.h b/drivers/block/ublk_drv.h new file mode 100644 index 000000000000..2a4ab721d513 --- /dev/null +++ b/drivers/block/ublk_drv.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _UBLK_DRV_H +#define _UBLK_DRV_H + +#include +#include +#include + +/* + * io command is active: sqe cmd is received, and its cqe isn't done + * + * If the flag is set, the io command is owned by ublk driver, and waited + * for incoming blk-mq request from the ublk block device. + * + * If the flag is cleared, the io command will be completed, and owned by + * ublk server. + */ +#define UBLK_IO_FLAG_ACTIVE 0x01 + +/* + * IO command is completed via cqe, and it is being handled by ublksrv, and + * not committed yet + * + * Basically exclusively with UBLK_IO_FLAG_ACTIVE, so can be served for + * cross verification + */ +#define UBLK_IO_FLAG_OWNED_BY_SRV 0x02 + +/* + * IO command is aborted, so this flag is set in case of + * !UBLK_IO_FLAG_ACTIVE. + * + * After this flag is observed, any pending or new incoming request + * associated with this io command will be failed immediately + */ +#define UBLK_IO_FLAG_ABORTED 0x04 + +/* + * UBLK_IO_FLAG_NEED_GET_DATA is set because IO command requires + * get data buffer address from ublksrv. + * + * Then, bio data could be copied into this data buffer for a WRITE request + * after the IO command is issued again and UBLK_IO_FLAG_NEED_GET_DATA is unset. + */ +#define UBLK_IO_FLAG_NEED_GET_DATA 0x08 + + +struct ublk_device { + struct gendisk *ub_disk; + + char *__queues; + + unsigned int queue_size; + struct ublksrv_ctrl_dev_info dev_info; + + struct blk_mq_tag_set tag_set; + + struct cdev cdev; + struct device cdev_dev; + +#define UB_STATE_OPEN 0 +#define UB_STATE_USED 1 +#define UB_STATE_DELETED 2 + unsigned long state; + int ub_number; + + struct mutex mutex; + + spinlock_t mm_lock; + struct mm_struct *mm; + + struct ublk_params params; + + struct completion completion; + unsigned int nr_queues_ready; + unsigned int nr_privileged_daemon; + + /* + * Our ubq->daemon may be killed without any notification, so + * monitor each queue's daemon periodically + */ + struct delayed_work monitor_work; + struct work_struct quiesce_work; + struct work_struct stop_work; +}; + +struct ublk_rq_data { + struct llist_node node; + + struct kref ref; +}; + +struct ublk_io { + /* userspace buffer address from io cmd */ + __u64 addr; + unsigned int flags; + int res; + + struct io_uring_cmd *cmd; +}; + +#endif From patchwork Tue Jul 4 16:52:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 115873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1365500vqx; Tue, 4 Jul 2023 10:24:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlHAcfHNH1ITR+8r2+8OcYoqRTLpHXR10K6mMhc0lNzBehJE2UF3SFZ9c3rIf6FBrV8QcCjh X-Received: by 2002:a17:902:7b95:b0:1b7:facb:2e79 with SMTP id w21-20020a1709027b9500b001b7facb2e79mr9949956pll.18.1688491459066; Tue, 04 Jul 2023 10:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688491459; cv=none; d=google.com; s=arc-20160816; b=YJkPjeAAVaXhMKu8NkJzyzSwW9EljMeZb0OglsOZ+iwrf/S4YLZ2c2sxwPTl0Xc7RH 0HLOGLP9GwfEBniANicadMbufWUv/7gLWhqoh1W6/6BhuRYZx46dtLvYM6W8AKjBOaMm +f5ARoG+Lpb/qiCh7qnj6j6/bGOpUEiMalltlzoYHLcAgdBwKUr7DAA0uLBJnv3sE3CZ zaEVdjPvt62GA8DR3xj1IcHW5bMRyOVs9mrQKg2blrrZRtVWX1Zb3Vssny7B6a3lH1wN E2WLTPCbCDmIou4uQOoONZOwHIR3ToPMBk/PCvMPW+lxbxGbhB9YlDxd9u3O3GeOrti/ 44uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XN7i8sOpMipC40cVjppg9yu+Ps/zil9DAOK5KLDUw0M=; fh=JwN0p46ZlpvloRQl/55YovaDle/zmEWTwso8DKF8XUk=; b=eUs/oHUuMVFLEokshJfmNhQAo7xas816LRKJpTjP+rhqz26+a2lX4gnuMHCx75DB4N H/lBXWJqHVDt+q8nSE658iMS0ZgIS/DKjpzHCRPUFj1gm5p4Mm68Nh1Nf6gqriBT10Xc MVcrQWQXHEyoyNY5xKEm7uKLIbLI06Q8zyyZ1HGgXcp7kCkGsfLotABrgWi3xL3dYepJ 7iV2+tR29cXIlFdneLNBcxRVNwmFbSnX8e+Ii4Ffi7xkxlaGpUFv0v/FgbYn6vSo88K0 Tt2KiPMA5DsPRB+wVuGogVyFlZDU+FXiSPbU7ewz4y1MTuEBscAORpaNxijEx/3reCHl ZNvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=YnGaH5q+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a170902f08c00b001b7eb86ae1asi18540079pla.204.2023.07.04.10.24.06; Tue, 04 Jul 2023 10:24:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=YnGaH5q+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231733AbjGDQw1 (ORCPT + 99 others); Tue, 4 Jul 2023 12:52:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231483AbjGDQwU (ORCPT ); Tue, 4 Jul 2023 12:52:20 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED95BE42 for ; Tue, 4 Jul 2023 09:52:18 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-51d946d2634so6912239a12.3 for ; Tue, 04 Jul 2023 09:52:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1688489537; x=1691081537; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XN7i8sOpMipC40cVjppg9yu+Ps/zil9DAOK5KLDUw0M=; b=YnGaH5q+0mIaDQVxcj8VDtedKRiYHSnb62uFMjDO2iLG4NGLiHnr37a9E/mkOlwqZO kgloe5K90mNkLAHoxxm2I/boPTp3Og+Q21xzBYrOhPZ4W1OH0zlmbMA1R4z9IGn7j6zb Gmoxe2x4OEcQCw1KRgL1BPGouhgFIy9UmxP8RqbYvWq4xHTuW0Ij+nz9bjjx+E2oQIWw Ihbu7uO3ua087o1mZ0W8ShexOzdxsWkljy3b2yTBwq+NwhL/J/hqXUKq/gfb7V0DZg+b CMJORX2P6hCknhGJNGt6vfSBBw/eINF8eKZyE14NSWhLwwM2dr0XozOc/efnuPu0foU/ 6bLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688489537; x=1691081537; 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=XN7i8sOpMipC40cVjppg9yu+Ps/zil9DAOK5KLDUw0M=; b=HRvXJhaixa/rD+xadv0MbNICXMWwyrrt5zKiWEAJsT0vC/Q3affkjJJPPnSKmt1pzG r5HHrvGfkJ8rNspOhKzZWGt5b9+LolOGyaqX5MOCMbPfWxd8S25Gy5KCJvE+iXDQsTuh b83oP2WX9AAVkgJwX4iY1l3hkroVTfzQ9qgfCCYYSL/fsnGzzgNCgSIxS6SmCQyPKJ+w 0DnF3qjbq7JtEFcb79oBcXjlbN0N5uP+obEFjoqEZumpGGMZP2sbJsQXy+wGH/xST58B 4d8IZ+/9iREAAGuwo3lYyGEwzyAAkOWodOZh1iV+FvmZzs1o4alTOUSRRbp/L0w9AFJ9 ZaGg== X-Gm-Message-State: ABy/qLal8ZVYAX4Zm4TB70WHhak7fevd4YIEcqwo1y7wZC0QgPEBee5o xQVr7BfaKVAB45unFyPyXnhsIw== X-Received: by 2002:aa7:c489:0:b0:51d:eb90:4928 with SMTP id m9-20020aa7c489000000b0051deb904928mr10924266edq.30.1688489537566; Tue, 04 Jul 2023 09:52:17 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id g25-20020aa7c859000000b0050cc4461fc5sm11872717edt.92.2023.07.04.09.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 09:52:17 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: linux-kernel@vger.kernel.org (open list), Matias Bjorling , Hans Holmberg , Jens Axboe , Minwoo Im , Aravind Ramesh , gost.dev@samsung.com, linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Damien Le Moal , Andreas Hindborg Subject: [PATCH v5 3/5] ublk: rename driver files to prepare for multiple translation units Date: Tue, 4 Jul 2023 18:52:07 +0200 Message-ID: <20230704165209.514591-4-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230704165209.514591-1-nmi@metaspace.dk> References: <20230704165209.514591-1-nmi@metaspace.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770511620058497519?= X-GMAIL-MSGID: =?utf-8?q?1770511620058497519?= From: Andreas Hindborg The zoned storage support for ublk adds a translation unit to the module. In order to be able to keep the existing name for the module, rename the currently only translation unit. Also rename the header to align with the C file name. Signed-off-by: Andreas Hindborg --- MAINTAINERS | 4 ++-- drivers/block/Makefile | 1 + drivers/block/{ublk_drv.c => ublk.c} | 2 +- drivers/block/{ublk_drv.h => ublk.h} | 0 4 files changed, 4 insertions(+), 3 deletions(-) rename drivers/block/{ublk_drv.c => ublk.c} (99%) rename drivers/block/{ublk_drv.h => ublk.h} (100%) diff --git a/MAINTAINERS b/MAINTAINERS index ace71c90751c..1f193cd43958 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21553,8 +21553,8 @@ M: Ming Lei L: linux-block@vger.kernel.org S: Maintained F: Documentation/block/ublk.rst -F: drivers/block/ublk_drv.c -F: drivers/block/ublk_drv.h +F: drivers/block/ublk.c +F: drivers/block/ublk.h F: include/uapi/linux/ublk_cmd.h UCLINUX (M68KNOMMU AND COLDFIRE) diff --git a/drivers/block/Makefile b/drivers/block/Makefile index 101612cba303..38f2229623a8 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -38,5 +38,6 @@ obj-$(CONFIG_BLK_DEV_RNBD) += rnbd/ obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk/ obj-$(CONFIG_BLK_DEV_UBLK) += ublk_drv.o +ublk_drv-$(CONFIG_BLK_DEV_UBLK) += ublk.o swim_mod-y := swim.o swim_asm.o diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk.c similarity index 99% rename from drivers/block/ublk_drv.c rename to drivers/block/ublk.c index bca0c4e1cfd8..a0453619bf67 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk.c @@ -45,7 +45,7 @@ #include #include #include -#include "ublk_drv.h" +#include "ublk.h" #define UBLK_MINORS (1U << MINORBITS) diff --git a/drivers/block/ublk_drv.h b/drivers/block/ublk.h similarity index 100% rename from drivers/block/ublk_drv.h rename to drivers/block/ublk.h From patchwork Tue Jul 4 16:52:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 115872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1365268vqx; Tue, 4 Jul 2023 10:23:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEa5KDMnHOzVIaALXmE9HrVfmBCIUv7QCv8UB/TyDFy2nzGNMMfF7uaaKN6KHFp+KY366r X-Received: by 2002:a17:90b:3105:b0:260:9cad:c581 with SMTP id gc5-20020a17090b310500b002609cadc581mr10468175pjb.3.1688491421678; Tue, 04 Jul 2023 10:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688491421; cv=none; d=google.com; s=arc-20160816; b=Gs4A/cd2SEYvyEbJcJXQ8JUeFNXf1TuJ0qeN1/OPNdCrIirDXTZnroM2V/YIIoXTSn Y6SHoDCaKBzSAxnsrXFEnVo12gn8niMjoWqmrkB1GO+Xv7UPvw1hEKzocF8m1eA2RzBL LZvCoKNYAEOzUM/7NiYlUOUIXH5CXACFSnQBA2rW6R6XWjxjZO3KQ/I1vbe5BM1/y5RS uuFV76WYIl7MEPvxOSlPBhJG4dGgIgvV4bMlL+eina3EftC/qKKuaxJR8dXXRviVmTzW anG6VbPf2rjHpPDNjk9FOMkZKJyU6tHPUrfIsec0GpFtm3uyKYKmSrxSVgUXe8Lef0LC 9w8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kerXQTH1dAySlTElaGBSfiCF85mcj9UpEbZgolqgBfs=; fh=JwN0p46ZlpvloRQl/55YovaDle/zmEWTwso8DKF8XUk=; b=vkce74W87tlpA5o77FO6TqIExemibMAxLfEXAmeDo1EkDzck6xgPy/Rr6hgzFplmBe qGuWIMDWsw1Nc851d2r9PV5zoqkhbxsE2qytakg0I7gWuyrPmae8XQS41JahZ1Uonypc CB1EMT6CVqNVDhJGVKSS9kw0gU7yrgwY5Nt+MhPgYt7BzkEQV9BRM5u6H/E9jhS/yIUV Bxgi84x2TJUkTRyq96LLV30MC2jmTIK+tclg1Od0shMkBYXtYGvoH39/oERRWTaqEmli 6Fmpp47YNo9pMHqhzoty5iBJKvwE8TpmChuBd2qPcJ11jKdxRztLq1bn0Jk+hE9OEzEz L5dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=P8TZLt+1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n124-20020a632782000000b0054febdc8ea2si22853989pgn.87.2023.07.04.10.23.28; Tue, 04 Jul 2023 10:23:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=P8TZLt+1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231775AbjGDQw2 (ORCPT + 99 others); Tue, 4 Jul 2023 12:52:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbjGDQwX (ORCPT ); Tue, 4 Jul 2023 12:52:23 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2899710D5 for ; Tue, 4 Jul 2023 09:52:21 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-98377c5d53eso678294366b.0 for ; Tue, 04 Jul 2023 09:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1688489539; x=1691081539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kerXQTH1dAySlTElaGBSfiCF85mcj9UpEbZgolqgBfs=; b=P8TZLt+1iMw/L7r0tZACsMST9Y8BUHGj1lAZtCsqY0Npj4VwghEArRmx/9vTR+lx3H Zmsn906MCbl2K6oAIhjvpUvDL6XsbJkD0xd6p10uPhZnTj0H/waRssXsK2kafcMK3Jpr eC1rtmCHpjyxOhkOW7YE6ZwY6CIpn/MGxh2dOjqlTntRiWoEO3fhoT+3AEC8B8e97rdd SrgxFbfzEqnQfsd0Qdss1xyLs2chavG2Tskkds/qxENIaeB17c6rNwj5c6TYf1Jy6/Bw Tby0JvFq/Jc7Mwaf6JrmJ/2aSHgw52LABuLY+aQi/X2YmLIUlmBTdml3y2P4zaDhluBc 9kIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688489539; x=1691081539; 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=kerXQTH1dAySlTElaGBSfiCF85mcj9UpEbZgolqgBfs=; b=jnje0DD66DWGiLAqQAWNon/wievS30+ZSHUbRE3lCoWM+1afpeNtUDS8c8qEUtnWcF Qzrx2E5CmxTmWPHiI6PdfBwgLMVzbHv86l0JO2FJC4AmFI5diRAsGRnXzGt7e8jMoYO0 Nzd7Rzmiwf3d5ViEOohXxlpxsGnqnihaqPFdBwaIq5D/ASxio0TgLCNpQrZwCvNahaU1 3nVdT/qAnrD8SXOxrkRCZUa8D69uJ+goseTnvAucylZxF0IVrsamZrqgmmec1Wp78wdT HUIFAoff/3cfAYB48J/ngPUPsXllBMjp20GSEwrnFnTEMDN78mE1TL/aQfearnlH0IzR GKZA== X-Gm-Message-State: ABy/qLYX4MeJteuQGnbTJ1a6HxYeDSuyLeF3t+I+btidSMVoOEHz2pL5 EXGmf3dKdgmtpdSVj9QLaEPqnw== X-Received: by 2002:a17:907:2ce6:b0:965:6075:d0e1 with SMTP id hz6-20020a1709072ce600b009656075d0e1mr12305216ejc.72.1688489539778; Tue, 04 Jul 2023 09:52:19 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id k12-20020a1709063e0c00b0098e2eaec394sm12378270eji.101.2023.07.04.09.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 09:52:19 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: linux-kernel@vger.kernel.org (open list), Matias Bjorling , Hans Holmberg , Jens Axboe , Minwoo Im , Aravind Ramesh , gost.dev@samsung.com, linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Damien Le Moal , Andreas Hindborg Subject: [PATCH v5 4/5] ublk: add helper to check if device supports user copy Date: Tue, 4 Jul 2023 18:52:08 +0200 Message-ID: <20230704165209.514591-5-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230704165209.514591-1-nmi@metaspace.dk> References: <20230704165209.514591-1-nmi@metaspace.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770511580573463560?= X-GMAIL-MSGID: =?utf-8?q?1770511580573463560?= From: Andreas Hindborg This will be used by ublk zoned storage support. Signed-off-by: Andreas Hindborg Reviewed-by: Damien Le Moal --- drivers/block/ublk.c | 2 +- drivers/block/ublk.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/block/ublk.c b/drivers/block/ublk.c index a0453619bf67..0b1ec102aaae 100644 --- a/drivers/block/ublk.c +++ b/drivers/block/ublk.c @@ -1947,7 +1947,7 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) UBLK_F_URING_CMD_COMP_IN_TASK; /* GET_DATA isn't needed any more with USER_COPY */ - if (ub->dev_info.flags & UBLK_F_USER_COPY) + if (ublk_dev_is_user_copy(ub)) ub->dev_info.flags &= ~UBLK_F_NEED_GET_DATA; /* We are not ready to support zero copy */ diff --git a/drivers/block/ublk.h b/drivers/block/ublk.h index 2a4ab721d513..fcbcc6b02aa0 100644 --- a/drivers/block/ublk.h +++ b/drivers/block/ublk.h @@ -100,4 +100,9 @@ struct ublk_io { struct io_uring_cmd *cmd; }; +static inline bool ublk_dev_is_user_copy(const struct ublk_device *ub) +{ + return ub->dev_info.flags & UBLK_F_USER_COPY; +} + #endif From patchwork Tue Jul 4 16:52:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 115864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1349165vqx; Tue, 4 Jul 2023 09:55:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6//pUqwy8gfUrBkzJ0NgrT55Cd5Ze//KfRN8WaIzsyu5m58lW2OiNW0GTeITc1DxQOpVCh X-Received: by 2002:a05:6a20:8e22:b0:126:5459:25d9 with SMTP id y34-20020a056a208e2200b00126545925d9mr27002342pzj.29.1688489732785; Tue, 04 Jul 2023 09:55:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688489732; cv=none; d=google.com; s=arc-20160816; b=Pa/rmEgcUYeV23gN5lf3bIqenyRCibI5IujROmO+gn6IwBNSFrWtUWYrdwTmF+WF+B Ol1lYZlqd9In31i0Dw/XTxsXDsaeak5FdOskyjJq2hmU5xIIXc8fBhSHwZW6jARDAdCf lgZMOyKd7WG4ESa3Wmi6IFLCHzHQIAfdLNPr5ThRBblLOp2W6uuL5w3skwDr2zToBdP1 79t+bfq3h/4+o5V6+olB/mkqP8xxOqZJM7nNfvO/kcZyaHLfVuCBOqxtXHuFJcWfbJ6w erhq5cOcb7a8Zesd1U1g1x4WTVNCUH3EummQoFShSbyuzgRym9u5jvlDAw6z9uU1Hsl1 NSQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+IbxDPtV+Ude4FwnmirBRUCqAsNikpq+PKfinxScon4=; fh=JwN0p46ZlpvloRQl/55YovaDle/zmEWTwso8DKF8XUk=; b=ZVGUfsBUCyJQNX5Xb7VsBkjzEugrQhiQFIN9qPFRxf8ifGIFODT/+TQhqK0tM69qDs 620btE2xbNAWjhDsvUeHKdcPfXCND7v+A7uuz2FzMYm48geURU+jrmAfbW6vqIljOPMw 9Y1F0Z1sYO3rtlzGclJ/YwZsKgmB1M01OF3xgIjIMs/iYNixuLup2BBp/OTSNKXOtMF0 NQ4KcutH3iZy8mbZAcgI5UK/Y8R1eqQltAcANT/QBJWx7tXDP3L/7/RJLW3Y615PNpDO N/eK8JrvTknqRUZeWzdAEXwU2xhxFlbAFx11oTDFTCDhRfiEd70av2pyFmMxK8LAlM3I mu1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=Qf4Eevxq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n188-20020a6327c5000000b005536fc5187asi20779192pgn.47.2023.07.04.09.55.15; Tue, 04 Jul 2023 09:55:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=Qf4Eevxq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231715AbjGDQwb (ORCPT + 99 others); Tue, 4 Jul 2023 12:52:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231693AbjGDQwZ (ORCPT ); Tue, 4 Jul 2023 12:52:25 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D94F1AC for ; Tue, 4 Jul 2023 09:52:23 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fb41682472so8819756e87.2 for ; Tue, 04 Jul 2023 09:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1688489541; x=1691081541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+IbxDPtV+Ude4FwnmirBRUCqAsNikpq+PKfinxScon4=; b=Qf4EevxqFwYjDF2rm85BVu5Pe6LQkltmxGuS0nohZAdqUvZJNBwgqkbiaTu5q1fm9u XiD/fBPm3FEzX//cQaAE1uvLeXenpjSmb/WI6q94srhJTQYiwvBL0bVy1MmqpLpUvLh3 LC42GOqV2dIubP51oBPaWvJBSy/tPMuyj2w93XERFIQGFXXRLxSN0AZs7yiYQz1wxIgd h4w8bqWZb4zAx5/00MHBlsV4p+mDIx7pLH/o2DkU7XlR38wazNNJL4yodqGizxRphpNG ren1t+uDd7ecmySBD/tYSf2wytOh3+5faoG1PHuZopxCTL9yjOSTQ4KtS0/yWvN1jhd7 LKmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688489541; x=1691081541; 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=+IbxDPtV+Ude4FwnmirBRUCqAsNikpq+PKfinxScon4=; b=VXHv6Agq387Q2GyoOlBeb8m4T0MUeW6GmXkfpsaD5cSsmmSV5GHkQeyHCy6PrsWG84 kFSTBgx1zNPAvrdaxCKdG8XIv8PZAtQfysV+s4lL7fFNM6qMFXd1/4ShoMqCxpNL73VG DTr6XHdGnBUhTzcfMB13TtC0UCtWqxkhDNaWr3LxTKQ7paZ2Y4R7h2XzO5dIxzUeyWGG pZ38WZqrjvVeKhHVUiSdjAYKeBzcmuLchHTavSwGF6NTyMLjQi0eX2+63/iaF9vRX3Kn aHxlO/kWxwwOt5LFTERFV+bVjpOcO+1exqBipE7Z8MVoaD59u+1KevGcOCf8f4eQMR+4 8Dig== X-Gm-Message-State: ABy/qLY/rPAa2v3APijnKS2aMsg3FIwxlP9oIdtVnIanguALW1bYGdJH tYKRG5EUZ5r5+jyDxMFJNfqBCA== X-Received: by 2002:a05:6512:3586:b0:4fb:7642:88d3 with SMTP id m6-20020a056512358600b004fb764288d3mr9963050lfr.27.1688489541078; Tue, 04 Jul 2023 09:52:21 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id k22-20020a056402049600b0051e0bf5807bsm3688514edv.49.2023.07.04.09.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 09:52:20 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: linux-kernel@vger.kernel.org (open list), Matias Bjorling , Hans Holmberg , Jens Axboe , Minwoo Im , Aravind Ramesh , gost.dev@samsung.com, linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Damien Le Moal , Andreas Hindborg Subject: [PATCH v5 5/5] ublk: enable zoned storage support Date: Tue, 4 Jul 2023 18:52:09 +0200 Message-ID: <20230704165209.514591-6-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230704165209.514591-1-nmi@metaspace.dk> References: <20230704165209.514591-1-nmi@metaspace.dk> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770509810308318709?= X-GMAIL-MSGID: =?utf-8?q?1770509810308318709?= From: Andreas Hindborg Add zoned storage support to ublk: report_zones and operations: - REQ_OP_ZONE_OPEN - REQ_OP_ZONE_CLOSE - REQ_OP_ZONE_FINISH - REQ_OP_ZONE_RESET - REQ_OP_ZONE_APPEND The zone append feature uses the `addr` field of `struct ublksrv_io_cmd` to communicate ALBA back to the kernel. Therefore ublk must be used with the user copy feature (UBLK_F_USER_COPY) for zoned storage support to be available. Without this feature, ublk will not allow zoned storage support. Signed-off-by: Andreas Hindborg --- MAINTAINERS | 1 + drivers/block/Kconfig | 5 + drivers/block/Makefile | 1 + drivers/block/ublk-zoned.c | 225 ++++++++++++++++++++++++++++++++++ drivers/block/ublk.c | 92 +++++++++++--- drivers/block/ublk.h | 72 +++++++++++ include/uapi/linux/ublk_cmd.h | 28 +++++ 7 files changed, 410 insertions(+), 14 deletions(-) create mode 100644 drivers/block/ublk-zoned.c diff --git a/MAINTAINERS b/MAINTAINERS index 1f193cd43958..8277f3e3e8e9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21553,6 +21553,7 @@ M: Ming Lei L: linux-block@vger.kernel.org S: Maintained F: Documentation/block/ublk.rst +F: drivers/block/ublk-zoned.c F: drivers/block/ublk.c F: drivers/block/ublk.h F: include/uapi/linux/ublk_cmd.h diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index 5b9d4aaebb81..2d76e9693c2d 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -373,6 +373,7 @@ config BLK_DEV_RBD config BLK_DEV_UBLK tristate "Userspace block driver (Experimental)" select IO_URING + select BLK_DEV_UBLK_ZONED if BLK_DEV_ZONED help io_uring based userspace block driver. Together with ublk server, ublk has been working well, but interface with userspace or command data @@ -402,6 +403,10 @@ config BLKDEV_UBLK_LEGACY_OPCODES suggested to enable N if your application(ublk server) switches to ioctl command encoding. +config BLK_DEV_UBLK_ZONED + bool + depends on BLK_DEV_UBLK && BLK_DEV_ZONED + source "drivers/block/rnbd/Kconfig" endif # BLK_DEV diff --git a/drivers/block/Makefile b/drivers/block/Makefile index 38f2229623a8..6c700936d427 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -39,5 +39,6 @@ obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk/ obj-$(CONFIG_BLK_DEV_UBLK) += ublk_drv.o ublk_drv-$(CONFIG_BLK_DEV_UBLK) += ublk.o +ublk_drv-$(CONFIG_BLK_DEV_UBLK_ZONED) += ublk-zoned.o swim_mod-y := swim.o swim_asm.o diff --git a/drivers/block/ublk-zoned.c b/drivers/block/ublk-zoned.c new file mode 100644 index 000000000000..6ddde2ac63e3 --- /dev/null +++ b/drivers/block/ublk-zoned.c @@ -0,0 +1,225 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 Andreas Hindborg + */ +#include +#include +#include + +#include "ublk.h" + + +static int get_nr_zones(const struct ublk_device *ub) +{ + const struct ublk_param_basic *p = &ub->params.basic; + + if (p->chunk_sectors) + return p->dev_sectors / p->chunk_sectors; + else + return 0; +} + +int ublk_set_nr_zones(struct ublk_device *ub) +{ + const struct ublk_param_basic *p = &ub->params.basic; + + if (ublk_dev_is_zoned(ub) && !p->chunk_sectors) + return -EINVAL; + + if (ublk_dev_is_zoned(ub)) { + ub->ub_disk->nr_zones = get_nr_zones(ub); + if (!ub->ub_disk->nr_zones) + return -EINVAL; + } + + return 0; +} + +void ublk_disk_set_zoned(struct ublk_device *ub) +{ + if (ublk_dev_is_zoned(ub)) { + disk_set_zoned(ub->ub_disk, BLK_ZONED_HM); + blk_queue_required_elevator_features(ub->ub_disk->queue, + ELEVATOR_F_ZBD_SEQ_WRITE); + } +} + +void ublk_zoned_commit_completion(const struct ublksrv_io_cmd *ub_cmd, + struct ublk_io *io, struct request *req) +{ + if (io->flags & UBLK_IO_FLAG_ZONE_APPEND) + req->__sector = ub_cmd->addr; + io->flags &= ~UBLK_IO_FLAG_ZONE_APPEND; +} + +int ublk_revalidate_disk_zones(struct ublk_device *ub) +{ + int ret = 0; + + if (ublk_dev_is_zoned(ub)) + ret = blk_revalidate_disk_zones(ub->ub_disk, NULL); + + return ret; +} + +int ublk_dev_param_zoned_validate(const struct ublk_device *ub) +{ + const struct ublk_param_zoned *p = &ub->params.zoned; + int nr_zones; + + if (ublk_dev_is_zoned(ub) && !(ublk_dev_params_zoned(ub))) + return -EINVAL; + + if (!ublk_dev_is_zoned(ub) && ublk_dev_params_zoned(ub)) + return -EINVAL; + + if (!ublk_dev_params_zoned(ub)) + return 0; + + if (!p->max_zone_append_sectors) + return -EINVAL; + + nr_zones = get_nr_zones(ub); + + if (p->max_active_zones > nr_zones) + return -EINVAL; + + if (p->max_open_zones > nr_zones) + return -EINVAL; + + return 0; +} + +int ublk_dev_param_zoned_apply(struct ublk_device *ub) +{ + const struct ublk_param_zoned *p = &ub->params.zoned; + + if (ublk_dev_is_zoned(ub) && !(ublk_dev_params_zoned(ub))) + return -EINVAL; + + if (!ublk_dev_is_zoned(ub) && ublk_dev_params_zoned(ub)) + return -EINVAL; + + if (!ublk_dev_params_zoned(ub)) + return 0; + + disk_set_max_active_zones(ub->ub_disk, p->max_active_zones); + disk_set_max_open_zones(ub->ub_disk, p->max_open_zones); + blk_queue_max_zone_append_sectors(ub->ub_disk->queue, p->max_zone_append_sectors); + + return 0; +} + +/* Based on virtblk_alloc_report_buffer */ +static void *ublk_alloc_report_buffer(struct ublk_device *ublk, + unsigned int nr_zones, + unsigned int zone_sectors, size_t *buflen) +{ + struct request_queue *q = ublk->ub_disk->queue; + size_t bufsize; + void *buf; + + nr_zones = min_t(unsigned int, nr_zones, + get_capacity(ublk->ub_disk) >> ilog2(zone_sectors)); + + bufsize = nr_zones * sizeof(struct blk_zone); + bufsize = + min_t(size_t, bufsize, queue_max_hw_sectors(q) << SECTOR_SHIFT); + bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT); + + while (bufsize >= sizeof(struct blk_zone)) { + buf = __vmalloc(bufsize, GFP_KERNEL | __GFP_NORETRY); + if (buf) { + *buflen = bufsize; + return buf; + } + bufsize >>= 1; + } + + *buflen = 0; + return NULL; +} + +int ublk_report_zones(struct gendisk *disk, sector_t sector, + unsigned int nr_zones, report_zones_cb cb, void *data) +{ + struct ublk_device *ub = disk->private_data; + unsigned int zone_size_sectors = disk->queue->limits.chunk_sectors; + unsigned int first_zone = sector >> ilog2(zone_size_sectors); + unsigned int done_zones = 0; + unsigned int max_zones_per_request; + int ret; + struct blk_zone *buffer; + size_t buffer_length; + + if (!ublk_dev_is_zoned(ub)) + return -EOPNOTSUPP; + + nr_zones = min_t(unsigned int, ub->ub_disk->nr_zones - first_zone, + nr_zones); + + buffer = ublk_alloc_report_buffer(ub, nr_zones, zone_size_sectors, + &buffer_length); + if (!buffer) + return -ENOMEM; + + max_zones_per_request = buffer_length / sizeof(struct blk_zone); + + while (done_zones < nr_zones) { + unsigned int remaining_zones = nr_zones - done_zones; + unsigned int zones_in_request = min_t( + unsigned int, remaining_zones, max_zones_per_request); + struct request *req; + struct ublk_rq_data *pdu; + blk_status_t status; + + memset(buffer, 0, buffer_length); + + req = blk_mq_alloc_request(disk->queue, REQ_OP_DRV_IN, 0); + if (IS_ERR(req)) { + ret = PTR_ERR(req); + goto out; + } + + pdu = blk_mq_rq_to_pdu(req); + pdu->operation = UBLK_IO_OP_REPORT_ZONES; + pdu->sector = sector; + pdu->nr_sectors = remaining_zones * zone_size_sectors; + + ret = blk_rq_map_kern(disk->queue, req, buffer, buffer_length, + GFP_KERNEL); + if (ret) { + blk_mq_free_request(req); + goto out; + } + + status = blk_execute_rq(req, 0); + ret = blk_status_to_errno(status); + blk_mq_free_request(req); + if (ret) + goto out; + + for (unsigned int i = 0; i < zones_in_request; i++) { + struct blk_zone *zone = buffer + i; + + ret = cb(zone, i, data); + if (ret) + goto out; + + done_zones++; + sector += zone_size_sectors; + + /* A zero length zone means don't ask for more zones */ + if (!zone->len) { + ret = done_zones; + goto out; + } + } + } + + ret = done_zones; + +out: + kvfree(buffer); + return ret; +} diff --git a/drivers/block/ublk.c b/drivers/block/ublk.c index 0b1ec102aaae..c97a8f14f8a9 100644 --- a/drivers/block/ublk.c +++ b/drivers/block/ublk.c @@ -57,12 +57,13 @@ | UBLK_F_USER_RECOVERY_REISSUE \ | UBLK_F_UNPRIVILEGED_DEV \ | UBLK_F_CMD_IOCTL_ENCODE \ - | UBLK_F_USER_COPY) + | UBLK_F_USER_COPY \ + | UBLK_F_ZONED) /* All UBLK_PARAM_TYPE_* should be included here */ -#define UBLK_PARAM_TYPE_ALL (UBLK_PARAM_TYPE_BASIC | \ - UBLK_PARAM_TYPE_DISCARD | UBLK_PARAM_TYPE_DEVT) - +#define UBLK_PARAM_TYPE_ALL \ + (UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DISCARD | \ + UBLK_PARAM_TYPE_DEVT | UBLK_PARAM_TYPE_ZONED) struct ublk_uring_cmd_pdu { struct ublk_queue *ubq; @@ -137,7 +138,7 @@ static inline unsigned ublk_pos_to_tag(loff_t pos) UBLK_TAG_BITS_MASK; } -static void ublk_dev_param_basic_apply(struct ublk_device *ub) +static int ublk_dev_param_basic_apply(struct ublk_device *ub) { struct request_queue *q = ub->ub_disk->queue; const struct ublk_param_basic *p = &ub->params.basic; @@ -162,6 +163,8 @@ static void ublk_dev_param_basic_apply(struct ublk_device *ub) set_disk_ro(ub->ub_disk, true); set_capacity(ub->ub_disk, p->dev_sectors); + + return ublk_set_nr_zones(ub); } static void ublk_dev_param_discard_apply(struct ublk_device *ub) @@ -191,6 +194,9 @@ static int ublk_validate_params(const struct ublk_device *ub) if (p->max_sectors > (ub->dev_info.max_io_buf_bytes >> 9)) return -EINVAL; + + if (ublk_dev_is_zoned(ub) && !p->chunk_sectors) + return -EINVAL; } else return -EINVAL; @@ -209,20 +215,24 @@ static int ublk_validate_params(const struct ublk_device *ub) if (ub->params.types & UBLK_PARAM_TYPE_DEVT) return -EINVAL; - return 0; + return ublk_dev_param_zoned_validate(ub); } static int ublk_apply_params(struct ublk_device *ub) { + int ret; + if (!(ub->params.types & UBLK_PARAM_TYPE_BASIC)) return -EINVAL; - ublk_dev_param_basic_apply(ub); + ret = ublk_dev_param_basic_apply(ub); + if (ret) + return ret; if (ub->params.types & UBLK_PARAM_TYPE_DISCARD) ublk_dev_param_discard_apply(ub); - return 0; + return ublk_dev_param_zoned_apply(ub); } static inline bool ublk_support_user_copy(const struct ublk_queue *ubq) @@ -392,6 +402,7 @@ static const struct block_device_operations ub_fops = { .owner = THIS_MODULE, .open = ublk_open, .free_disk = ublk_free_disk, + .report_zones = ublk_report_zones, }; #define UBLK_MAX_PIN_PAGES 32 @@ -506,7 +517,8 @@ static inline bool ublk_need_map_req(const struct request *req) static inline bool ublk_need_unmap_req(const struct request *req) { - return ublk_rq_has_data(req) && req_op(req) == REQ_OP_READ; + return ublk_rq_has_data(req) && + (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_DRV_IN); } static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req, @@ -590,6 +602,7 @@ static blk_status_t ublk_setup_iod(struct ublk_queue *ubq, struct request *req) { struct ublksrv_io_desc *iod = ublk_get_iod(ubq, req->tag); struct ublk_io *io = &ubq->ios[req->tag]; + struct ublk_rq_data *pdu = blk_mq_rq_to_pdu(req); u32 ublk_op; switch (req_op(req)) { @@ -608,6 +621,37 @@ static blk_status_t ublk_setup_iod(struct ublk_queue *ubq, struct request *req) case REQ_OP_WRITE_ZEROES: ublk_op = UBLK_IO_OP_WRITE_ZEROES; break; + case REQ_OP_ZONE_OPEN: + ublk_op = UBLK_IO_OP_ZONE_OPEN; + break; + case REQ_OP_ZONE_CLOSE: + ublk_op = UBLK_IO_OP_ZONE_CLOSE; + break; + case REQ_OP_ZONE_FINISH: + ublk_op = UBLK_IO_OP_ZONE_FINISH; + break; + case REQ_OP_ZONE_RESET: + ublk_op = UBLK_IO_OP_ZONE_RESET; + break; + case REQ_OP_DRV_IN: + ublk_op = pdu->operation; + switch (ublk_op) { + case UBLK_IO_OP_REPORT_ZONES: + iod->op_flags = ublk_op | ublk_req_build_flags(req); + iod->nr_sectors = pdu->nr_sectors; + iod->start_sector = pdu->sector; + return BLK_STS_OK; + default: + return BLK_STS_IOERR; + } + case REQ_OP_ZONE_APPEND: + ublk_op = UBLK_IO_OP_ZONE_APPEND; + io->flags |= UBLK_IO_FLAG_ZONE_APPEND; + break; + case REQ_OP_ZONE_RESET_ALL: + case REQ_OP_DRV_OUT: + /* We do not support zone append or reset_all yet */ + fallthrough; default: return BLK_STS_IOERR; } @@ -661,7 +705,8 @@ static inline void __ublk_complete_rq(struct request *req) * * Both the two needn't unmap. */ - if (req_op(req) != REQ_OP_READ && req_op(req) != REQ_OP_WRITE) + if (req_op(req) != REQ_OP_READ && req_op(req) != REQ_OP_WRITE && + req_op(req) != REQ_OP_DRV_IN) goto exit; /* for READ request, writing data in iod->addr to rq buffers */ @@ -1025,6 +1070,8 @@ static void ublk_commit_completion(struct ublk_device *ub, /* find the io request and complete */ req = blk_mq_tag_to_rq(ub->tag_set.tags[qid], tag); + ublk_zoned_commit_completion(ub_cmd, io, req); + if (req && likely(!blk_should_fake_timeout(req->q))) ublk_put_req_ref(ubq, req); } @@ -1324,7 +1371,8 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd, ^ (_IOC_NR(cmd_op) == UBLK_IO_NEED_GET_DATA)) goto out; - if (ublk_support_user_copy(ubq) && ub_cmd->addr) { + if (ublk_support_user_copy(ubq) && + !(io->flags & UBLK_IO_FLAG_ZONE_APPEND) && ub_cmd->addr) { ret = -EINVAL; goto out; } @@ -1447,11 +1495,14 @@ static inline bool ublk_check_ubuf_dir(const struct request *req, int ubuf_dir) { /* copy ubuf to request pages */ - if (req_op(req) == REQ_OP_READ && ubuf_dir == ITER_SOURCE) + if ((req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_DRV_IN) && + ubuf_dir == ITER_SOURCE) return true; /* copy request pages to ubuf */ - if (req_op(req) == REQ_OP_WRITE && ubuf_dir == ITER_DEST) + if ((req_op(req) == REQ_OP_WRITE || + req_op(req) == REQ_OP_ZONE_APPEND) && + ubuf_dir == ITER_DEST) return true; return false; @@ -1780,6 +1831,8 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd) ub->dev_info.ublksrv_pid = ublksrv_pid; ub->ub_disk = disk; + ublk_disk_set_zoned(ub); + ret = ublk_apply_params(ub); if (ret) goto out_put_disk; @@ -1788,8 +1841,12 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd) if (ub->nr_privileged_daemon != ub->nr_queues_ready) set_bit(GD_SUPPRESS_PART_SCAN, &disk->state); - get_device(&ub->cdev_dev); ub->dev_info.state = UBLK_S_DEV_LIVE; + ret = ublk_revalidate_disk_zones(ub); + if (ret) + goto out_put_disk; + + get_device(&ub->cdev_dev); ret = add_disk(disk); if (ret) { /* @@ -1950,6 +2007,13 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) if (ublk_dev_is_user_copy(ub)) ub->dev_info.flags &= ~UBLK_F_NEED_GET_DATA; + /* Zoned storage support requires user copy feature */ + if (ublk_dev_is_zoned(ub) && + (!IS_ENABLED(CONFIG_BLK_DEV_ZONED) || !ublk_dev_is_user_copy(ub))) { + ret = -EINVAL; + goto out_free_dev_number; + } + /* We are not ready to support zero copy */ ub->dev_info.flags &= ~UBLK_F_SUPPORT_ZERO_COPY; diff --git a/drivers/block/ublk.h b/drivers/block/ublk.h index fcbcc6b02aa0..b78ab43cea82 100644 --- a/drivers/block/ublk.h +++ b/drivers/block/ublk.h @@ -45,6 +45,10 @@ */ #define UBLK_IO_FLAG_NEED_GET_DATA 0x08 +/* + * Set when IO is Zone Append + */ +#define UBLK_IO_FLAG_ZONE_APPEND 0x10 struct ublk_device { struct gendisk *ub_disk; @@ -89,6 +93,9 @@ struct ublk_rq_data { struct llist_node node; struct kref ref; + __u32 operation; + __u64 sector; + __u32 nr_sectors; }; struct ublk_io { @@ -100,9 +107,74 @@ struct ublk_io { struct io_uring_cmd *cmd; }; +static inline int ublk_dev_params_zoned(const struct ublk_device *ub) +{ + return ub->params.types & UBLK_PARAM_TYPE_ZONED; +} + +static inline bool ublk_dev_is_zoned(const struct ublk_device *ub) +{ + return ub->dev_info.flags & UBLK_F_ZONED; +} + static inline bool ublk_dev_is_user_copy(const struct ublk_device *ub) { return ub->dev_info.flags & UBLK_F_USER_COPY; } +#ifndef CONFIG_BLK_DEV_ZONED + +static inline int ublk_set_nr_zones(struct ublk_device *ub) +{ + return 0; +} + +static inline void ublk_disk_set_zoned(struct ublk_device *ub) +{ +} + +static inline int ublk_dev_param_zoned_validate(const struct ublk_device *ub) +{ + if (ublk_dev_params_zoned(ub)) + return -EINVAL; + return 0; +} + +static inline int ublk_dev_param_zoned_apply(struct ublk_device *ub) +{ + if (ublk_dev_params_zoned(ub)) + return -EINVAL; + return 0; +} + +static inline void +ublk_zoned_commit_completion(const struct ublksrv_io_cmd *ub_cmd, + struct ublk_io *io, struct request *req) +{ +} + +static inline int ublk_revalidate_disk_zones(struct ublk_device *ub) +{ + return 0; +} + +#define ublk_report_zones (NULL) + +#else + +int ublk_set_nr_zones(struct ublk_device *ub); +void ublk_disk_set_zoned(struct ublk_device *ub); +int ublk_dev_param_zoned_validate(const struct ublk_device *ub); +int ublk_dev_param_zoned_apply(struct ublk_device *ub); +void ublk_zoned_commit_completion(const struct ublksrv_io_cmd *ub_cmd, + struct ublk_io *io, struct request *req); +int ublk_revalidate_disk_zones(struct ublk_device *ub); +int ublk_report_zones(struct gendisk *disk, sector_t sector, + unsigned int nr_zones, report_zones_cb cb, + void *data); + +#endif + + + #endif diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index a32810c8ef2b..13b76e665aed 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -176,6 +176,12 @@ /* Copy between request and user buffer by pread()/pwrite() */ #define UBLK_F_USER_COPY (1UL << 7) +/* + * User space sets this flag when setting up the device to request zoned storage support. Kernel may + * deny the request by returning an error. + */ +#define UBLK_F_ZONED (1ULL << 8) + /* device state */ #define UBLK_S_DEV_DEAD 0 #define UBLK_S_DEV_LIVE 1 @@ -235,7 +241,20 @@ struct ublksrv_ctrl_dev_info { #define UBLK_IO_OP_DISCARD (3) #define UBLK_IO_OP_WRITE_SAME (4) #define UBLK_IO_OP_WRITE_ZEROES (5) +#define UBLK_IO_OP_ZONE_OPEN (10) +#define UBLK_IO_OP_ZONE_CLOSE (11) +#define UBLK_IO_OP_ZONE_FINISH (12) +#define UBLK_IO_OP_ZONE_APPEND (13) +#define UBLK_IO_OP_ZONE_RESET (15) #define __UBLK_IO_OP_DRV_IN_START (32) +/* Construct a zone report. The report request is carried in `struct ublksrv_io_desc`. The + * `start_sector` field must be the first sector of a zone and shall indicate the first zone of the + * report. The `nr_sectors` shall indicate how many zones should be reported (divide by zone size to + * get number of zones in the report) and must be an integer multiple of the zone size. The report + * shall be delivered as a `struct blk_zone` array. To report fewer zones than requested, zero the + * last entry of the returned array. + */ +#define UBLK_IO_OP_REPORT_ZONES (__UBLK_IO_OP_DRV_IN_START) #define __UBLK_IO_OP_DRV_IN_END (96) #define __UBLK_IO_OP_DRV_OUT_START (__UBLK_IO_OP_DRV_IN_END) #define __UBLK_IO_OP_DRV_OUT_END (160) @@ -335,6 +354,13 @@ struct ublk_param_devt { __u32 disk_minor; }; +struct ublk_param_zoned { + __u32 max_open_zones; + __u32 max_active_zones; + __u32 max_zone_append_sectors; + __u8 reserved[20]; +}; + struct ublk_params { /* * Total length of parameters, userspace has to set 'len' for both @@ -346,11 +372,13 @@ struct ublk_params { #define UBLK_PARAM_TYPE_BASIC (1 << 0) #define UBLK_PARAM_TYPE_DISCARD (1 << 1) #define UBLK_PARAM_TYPE_DEVT (1 << 2) +#define UBLK_PARAM_TYPE_ZONED (1 << 3) __u32 types; /* types of parameter included */ struct ublk_param_basic basic; struct ublk_param_discard discard; struct ublk_param_devt devt; + struct ublk_param_zoned zoned; }; #endif