From patchwork Wed Jun 28 19:06:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 114025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9150282vqr; Wed, 28 Jun 2023 12:13:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4dExLiMSqY5znAbt5xDz4CWWjcRV6gMt7gXAnGdcu2WQ4xAebrhMgKS1c6J++h6IaHSqVt X-Received: by 2002:a05:651c:220a:b0:2b6:9e4d:119e with SMTP id y10-20020a05651c220a00b002b69e4d119emr592245ljq.2.1687979615078; Wed, 28 Jun 2023 12:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687979615; cv=none; d=google.com; s=arc-20160816; b=zJXznSmHaaTIqT2kR4rMnGATMClOAhHNkp4sOTNykaDber99XQlN7UnAiSAqhPsj1z hRnQzPueN4WOFbC8oBYxoIb2KeiafZcWpmIj4TVcsIMQYOOjdAmeOL/zIaHgbMaYWy5h uxAfgK5YKPmn9w9pM3RsmoPcFyMTsHCDvjT97bzCKJnqmPBzSOo4yAQN1Jpe37nwoEic sCeyKHJ7JdfRdvuNoK5Njx+ZuIbZxo4tJhQPXefoJECHAI/VSBkTzwILm6QmGF6jKVHj q7soVeIydVuuyWMlJjnORG0n86TTEMnYAmq0K+8sTLWlFEJSZcj9/ZavpxCiZhV/vMEC cCtg== 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=1+mgtaI49ANVecSJsMlgWiAuBSlWzk7jhi+QFImWVd0=; fh=PtLHm9B0+hM1tQPeQT3fpvfpYSsUVoUxZslaqHBKa8M=; b=jGJO87IbwU7PdA2ff/Ic3Wepld/pcqq1Di5UULOr5zT0aIujOiQpSgOkJGduHCOZbD smdihIV9lNGA3pzIfuydxanAMWpRmjwX81kxHuPfIHPgR9jDghjHulGn5xxBDCMOQs7T GmG7VbKnB1Yrbk+9iqFkTlcvwYWjBZwmXvyvOKFh6XoriPlYNISiDLsLc1KQ5eSnubwF Z0YAPe9e7wV6ecsdcDHED1L1o6Ylcvx+j7wAn8E44OWJRlFoCP6q0p0XvSc1lRIfuX7z TXJOspc+HyVKRQx6YJit+0TDJSHmphMiHVTMEJH0zNeSX1QpgjGsmPfK7OTAh49PE/aB 9I4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=PkKpRHm8; 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 lu13-20020a170906facd00b009929d998ab3si494915ejb.734.2023.06.28.12.13.09; Wed, 28 Jun 2023 12:13:35 -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=PkKpRHm8; 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 S232124AbjF1THY (ORCPT + 99 others); Wed, 28 Jun 2023 15:07:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232138AbjF1THA (ORCPT ); Wed, 28 Jun 2023 15:07:00 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 653B6212E for ; Wed, 28 Jun 2023 12:06:55 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2b5c231c23aso2952511fa.0 for ; Wed, 28 Jun 2023 12:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1687979213; x=1690571213; 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=1+mgtaI49ANVecSJsMlgWiAuBSlWzk7jhi+QFImWVd0=; b=PkKpRHm88ty23JmdD6Stv68WY2ScVPPFNR0Y4NXYM3+ohmSQ8JoLfz3P6aKYHyfa3J XtO6/D3dg4RfSDjOC99oQIU0dCtIL8m47OtuB/Qw2NlYnKF3fucYg95jzZESwcJHMZ8w 4FUQ9WeZccmv9k805txFr46dsytAXQBoWqRgDbvNvdp8iDeD59ulFumL4NNN6mIY6K1s q8zmTlCYHivwHdQJQRrdFlCEMi/J5TzNG0SWvsXwcZmgB1aFXmyzy+Uy1xGxCkpeRjTh ZzLqbjKQzATcgk4ldAWg9NOiP90rN4aeFHdOjlLAxqbqBxMX0oBKytS/ofFpMkZmCBn8 rgXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687979213; x=1690571213; 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=1+mgtaI49ANVecSJsMlgWiAuBSlWzk7jhi+QFImWVd0=; b=gFuFtGoLKXlMyaRFFH/VM6Q8WYp80Ji2Wvie5txXMZObaMGHLG0/XPN6nrQQk4uKCu AD/J2+SSOljqtuLiLSwGwLVEgHiMiJEMVkc3oWCVF60Fl3SIondi+y6ej9cNvyKZpUzV ZvmoeH/sBp+pJ7Q557mKlF3R/KJOlzviTCHVuZ7RVwCU0B5ypPGPNjk5/c01NCoBM3CC wH3buNo4XbE5qDHp4/uBHRxPBG6mA51i+ycws0EGEn14+IMBxratjMGmP9nkxNHpS3k8 8QWlG4P/bb/d9+dTh8rLSyFMZE/Jsn+bsWeSFxZnW3UHEfBkBt9aCy+AE3sYU6W6UZoT HsPg== X-Gm-Message-State: AC+VfDxPpaP6zcu45DpiQsWpZzJWQU/t1yfnOuLgVU7olukXs9cqZcFR Oa5Ufzj8bZpyJiYZXWEvbeTMew== X-Received: by 2002:a2e:86c6:0:b0:2b6:c3b8:3a94 with SMTP id n6-20020a2e86c6000000b002b6c3b83a94mr915163ljj.42.1687979213445; Wed, 28 Jun 2023 12:06:53 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id ot6-20020a170906ccc600b0098df7d0e096sm5683211ejb.54.2023.06.28.12.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 12:06:53 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: Hans Holmberg , Aravind Ramesh , Jens Axboe , linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Matias Bjorling , Andreas Hindborg , linux-kernel@vger.kernel.org (open list), Damien Le Moal , gost.dev@samsung.com, Minwoo Im Subject: [PATCH v4 1/4] ublk: change ublk IO command defines to enum Date: Wed, 28 Jun 2023 21:06:46 +0200 Message-ID: <20230628190649.11233-2-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628190649.11233-1-nmi@metaspace.dk> References: <20230628190649.11233-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?1769974912535924848?= X-GMAIL-MSGID: =?utf-8?q?1769974912535924848?= From: Andreas Hindborg This change is in preparation for zoned storage support. Signed-off-by: Andreas Hindborg --- include/uapi/linux/ublk_cmd.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index 4b8558db90e1..471b3b983045 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -229,12 +229,23 @@ 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 +enum ublk_op { + UBLK_IO_OP_READ = 0, + UBLK_IO_OP_WRITE = 1, + UBLK_IO_OP_FLUSH = 2, + UBLK_IO_OP_DISCARD = 3, + UBLK_IO_OP_WRITE_SAME = 4, + UBLK_IO_OP_WRITE_ZEROES = 5, + UBLK_IO_OP_ZONE_OPEN = 10, + UBLK_IO_OP_ZONE_CLOSE = 11, + UBLK_IO_OP_ZONE_FINISH = 12, + UBLK_IO_OP_ZONE_APPEND = 13, + UBLK_IO_OP_ZONE_RESET = 15, + __UBLK_IO_OP_DRV_IN_START = 32, + __UBLK_IO_OP_DRV_IN_END = 96, + __UBLK_IO_OP_DRV_OUT_START = __UBLK_IO_OP_DRV_IN_END, + __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 Wed Jun 28 19:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 114027 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9154281vqr; Wed, 28 Jun 2023 12:20:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oYZva7cDEkAyN1HUGncjtOvy2qEev/M3RaYIqa83PsZagQ3U992aEu7lO7uEEj+OYaXDs X-Received: by 2002:a05:6a00:1d18:b0:668:70af:b5c1 with SMTP id a24-20020a056a001d1800b0066870afb5c1mr850623pfx.1.1687980037068; Wed, 28 Jun 2023 12:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687980037; cv=none; d=google.com; s=arc-20160816; b=UaGTO/P2y9w6bhS69bHkqJxm77B2v60h7/i8+ALTc66CciFvFGN+tlhhklU6fEq8lT ZvC9QAmrMH/r0rv6Iw0DihnjtiBycYf4xVIvm6s1NStJrA71xnuGP2ejZsSM6rHAN+r/ pPc/UU2AO8iVDsrYueMWbGLi/pDR3sTkgrgCY98b3SUcrZ0Rmlw62/VEbRvLWamTI4qx OaNPvDAcSsbFuuiSZo2MUV5REMYabaL8Xb2yWtWu5qPN5LMeqF7mf+c3/MqsWQaeRaV1 haDwJlnPLsoCzJpEW58YnDGsqp4hid3HztQX02xXbBQLUPp8ohOkkxLso4Y/63RUrUCt BmXg== 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=QL2rSnLNVvXtnKVS/60xfeay+8umeUcihwVxY5tjP98=; fh=PtLHm9B0+hM1tQPeQT3fpvfpYSsUVoUxZslaqHBKa8M=; b=HzUKpM0feQRbSrT3XE80t2K6O0800/44E8jTWvxwOCk5KHYmfGMDd1aKci7K8/dkQp 9/MjnpL6JwBlEvpzuC6djR8qase2KVJ/Nv7VMTknAX7acQhmIEEgmj8A1iQIaH9F9ae1 PkBP3stCqWeFlV/DamvqOdyU+e+04j6m34d5PyJljpFkafYSaCCmUxerijxdWsflQwoD O0DWcw4tFc/dCpQw1XrquMNKJRhMXN/QDoWW/gVfbq8YDiCBtEu955hAuOPnFzjvhwn5 Sx2A4FzU4CAodFiKN4B4/s0J16IoDlIfBkwTyrvqvf31K7NOWVQyYBn2zPT4y5b4FXAV +9tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b="N/l8Ikg1"; 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 cm16-20020a056a00339000b006761adef5desi6830892pfb.230.2023.06.28.12.20.23; Wed, 28 Jun 2023 12:20:37 -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="N/l8Ikg1"; 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 S231726AbjF1THL (ORCPT + 99 others); Wed, 28 Jun 2023 15:07:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbjF1TG7 (ORCPT ); Wed, 28 Jun 2023 15:06:59 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556802134 for ; Wed, 28 Jun 2023 12:06:56 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-99286af0260so17651766b.2 for ; Wed, 28 Jun 2023 12:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1687979215; x=1690571215; 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=QL2rSnLNVvXtnKVS/60xfeay+8umeUcihwVxY5tjP98=; b=N/l8Ikg1L9otvySPGQDLDjHIJK0ZEZHD7iOlMTOao9itYccG7s15NluGTE1ZOWd1/r lV4Sxvo1cFnCXpuV8MLHEgY3gY4xwoqvSkcxFXgQbxEY5VBWWn+W7SlZwnTUD8UGqRY9 gQL67nR+wH4ZLkOOjqOsN2Dl79jVqr6Y3yhpq6DhSvV/Rjfql9wrdoZmDxAnAhIOuyZN 8bT8iq6SSgnHS0VtBaf//U2UGM+sEmFp5YrCNOZk+wjMyjIp/nQR0TkHGFxcGTKf8bfQ taqy445nhmULOrmGlwiUBwT+j0VmIrIrdPhYQte3FlfvzxJO3IMrdw/PJ9mGTXD4TM5p RKWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687979215; x=1690571215; 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=QL2rSnLNVvXtnKVS/60xfeay+8umeUcihwVxY5tjP98=; b=UF/UrdciROPgwDNgAK/14eLP7CFNJFyjp9FiFxjMsc2Arw8Do0Asf9qVpVumllnSu0 RUSWo7wcuE0m86ZkgZLLPpxjKrmkANEo7lYCx3Wq3tIvtX7Y2RaQEE26Ude2J/pFzAaB IcndVNZl5wVf50RTM7JbNOD6c3BzLz6ONX/q4g5Vg2FEk3vZZlEgGQpmckjTEtmnNqq9 DgljGZXCMkroH+0C0HaJ4STCbewKmwHZKM82V8jcaaOyAQ+9v31z9xxGboozLemFIPx5 7r6CzczNwV912CMNf+SJAWOjMdn3aIYYNwwu3ZbU8k9z/lNztf3bfDbj3rxiG0dsjaMj CL8g== X-Gm-Message-State: AC+VfDzMZkri1KgLZ0JiwdATWY1aDIfoyErtAPpKUPqM1+T7lg4q36MG 0xvHGW+UsjYrho0gPPhLelFhng== X-Received: by 2002:a17:907:360e:b0:96a:4ea0:a1e7 with SMTP id bk14-20020a170907360e00b0096a4ea0a1e7mr34442458ejc.50.1687979214735; Wed, 28 Jun 2023 12:06:54 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id ec10-20020a170906b6ca00b009893650453fsm6057136ejb.173.2023.06.28.12.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 12:06:54 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: Hans Holmberg , Aravind Ramesh , Jens Axboe , linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Matias Bjorling , Andreas Hindborg , linux-kernel@vger.kernel.org (open list), Damien Le Moal , gost.dev@samsung.com, Minwoo Im Subject: [PATCH v4 2/4] ublk: move types to shared header file Date: Wed, 28 Jun 2023 21:06:47 +0200 Message-ID: <20230628190649.11233-3-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628190649.11233-1-nmi@metaspace.dk> References: <20230628190649.11233-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?1769975355255035356?= X-GMAIL-MSGID: =?utf-8?q?1769975355255035356?= 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 | 45 +------------------------------- drivers/block/ublk_drv.h | 55 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 44 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..e519dc0d9fe7 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,11 +63,6 @@ #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; @@ -140,45 +136,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..f81e62256456 --- /dev/null +++ b/drivers/block/ublk_drv.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _UBLK_DRV_H +#define _UBLK_DRV_H + +#include +#include +#include + +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; +}; + +#endif From patchwork Wed Jun 28 19:06:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 114024 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9149411vqr; Wed, 28 Jun 2023 12:12:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tBwtVh80nAsNo+YnmXEztTVvMKhl1v6BSngrFJYPCVJQj7tS2pMwyZza5F0v2JXYrYa/D X-Received: by 2002:a17:906:73cc:b0:98d:eaa8:8c27 with SMTP id n12-20020a17090673cc00b0098deaa88c27mr9372275ejl.1.1687979526044; Wed, 28 Jun 2023 12:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687979526; cv=none; d=google.com; s=arc-20160816; b=U46GG1HUaWBkVlM7IS3pU8duZpLSRHx2lFflaVfISY7ghyHiAeudwXImixY/wd5tPV gF+1vjr5iQInneDOF/MSQCzUuWxV4ZEnMRYXkuy73L3UmYi+9AbrlhH8ktbKJ65dPwvg ChawUTgcQI8IB3zyAM5e6YaSW0Tbl8d4rJlR0BPf+QEHwCyNkBqbLULFdc9VMiaKvTZO k8ARJRtehob091jtc5AbLoD8aTjTfMxJB5ZXWXCuLPRCgr4rQUrpV9UIYflw8c22WGb+ 7P3EbxCivZuIoNWQcT5dDUY5N5e+IfiRff3KWasaYl+fz8/57rDMjpIhmYJiGy3SZPz7 lAuQ== 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=pg7qlCroyjqfExyu0Mf7wmo/LFcyzu8Rds2rnmf83TY=; fh=PtLHm9B0+hM1tQPeQT3fpvfpYSsUVoUxZslaqHBKa8M=; b=j9P+RWATq9HyHSYPo0/lRxFZrZp1Fcrw9BxlGuOzhJhsyBC3F0PsaibJFRZj8hAitS HM0H39WRsGHE+c3bggdhNgpix/NfDzZxa917D/aADzP2Jv6/GeWSfX4HHX1E9Vb1iEjt R+0WoQCRjZRXJnXCV5mhw/vJWL/wAzeXSvHqEzkpbklwzcLeDG0ClQ4/FU1dOikuoGOn PuGUvVrRKYHSB27OgSacTEJT2fksyRcg54/z07CH77mnMYio6e4A9UncHd6vp92iibdo 0yjkSZfjEAJJOHg6cDkxlsHDtV7dBR3EXBVGYf33Fb3ZD61iGx9i1/Y1FmcveuTQXbcB r0WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=vVn82u2e; 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 gr6-20020a170906e2c600b0098886d50308si5459778ejb.490.2023.06.28.12.11.40; Wed, 28 Jun 2023 12:12:06 -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=vVn82u2e; 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 S232027AbjF1THU (ORCPT + 99 others); Wed, 28 Jun 2023 15:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232144AbjF1THA (ORCPT ); Wed, 28 Jun 2023 15:07:00 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B6C6213D for ; Wed, 28 Jun 2023 12:06:57 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-991f956fb5aso18171866b.0 for ; Wed, 28 Jun 2023 12:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1687979216; x=1690571216; 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=pg7qlCroyjqfExyu0Mf7wmo/LFcyzu8Rds2rnmf83TY=; b=vVn82u2esZzVa5ZwtSPC/bCJhdLMHBQdCVjMNWzggQ9tMXOBCnrEC1XcWzz+Zxo0LC TicovbfO2FpRpQXUaNDTNLavQ0REUkhMu3JxyKfHC61baP4wPnHlXRGDfP6IuA7+4OK5 D2Xrc/CmCPUhXEnfZV/LaumLhogYf/JLuK1KxhqZHbC4Pkc+wtThCGdnu+8uXh0ZLK4s NIqgElyqPwWu15FeXtNwGwFTWSRYETXDlvSzTZw2VuHX5FjkRGtCnKXqtacRIw2KqtVX Xe2gv4B52yt9LqcGPxLYNlmwmZm7SJA7P07avT36HYpSZucRL+RwuWjpO5eK4rG+GbPH dLmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687979216; x=1690571216; 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=pg7qlCroyjqfExyu0Mf7wmo/LFcyzu8Rds2rnmf83TY=; b=NaQ1AmR5D0kzB7Xd0SlPnKhV1Bc3dSvVx+VONilpe0iVq0txDz1xWwRD4ZJG9FRQSJ Vqb79s0mpJ+B89QeaM39ANxGC5PWVeQy25PNH3kdpI/hkJ6eOqY3togNZG1mtvsIvd9P YeAm7OdqO+y/r0188a2B0XhHIfNuA52ItlRv3eFxIwcYSTqpa7FAtqzo915uM0CpAq1q zhPZqCADVzpIFE7DqmM750TozvJnaRg4ZxTZRCAovVQcVDAwPgzSoZjVbrxnKZHnerab 7NcRWqm0GdbXUHkEhCccRt7fM1pLtSOFzGazymvcSZhDcc0eKlTxz0dfchW8gJNCh9T4 cQhg== X-Gm-Message-State: AC+VfDwipjhesR++Z0PkdgmDDC7GebUWt/Cue3hUVeU0kUj/6XNThnG/ zXgiSJJpU1lyyV1WJCZMgGMMCQ== X-Received: by 2002:a17:907:7d9e:b0:991:bd74:ea3e with SMTP id oz30-20020a1709077d9e00b00991bd74ea3emr8214488ejc.4.1687979215931; Wed, 28 Jun 2023 12:06:55 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id j8-20020a1709062a0800b00992316f0690sm1938987eje.74.2023.06.28.12.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 12:06:55 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: Hans Holmberg , Aravind Ramesh , Jens Axboe , linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Matias Bjorling , Andreas Hindborg , linux-kernel@vger.kernel.org (open list), Damien Le Moal , gost.dev@samsung.com, Minwoo Im Subject: [PATCH v4 3/4] ublk: enable zoned storage support Date: Wed, 28 Jun 2023 21:06:48 +0200 Message-ID: <20230628190649.11233-4-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628190649.11233-1-nmi@metaspace.dk> References: <20230628190649.11233-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?1769974819276332900?= X-GMAIL-MSGID: =?utf-8?q?1769974819276332900?= 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 Note: This commit changes the ublk kernel module name from `ublk_drv.ko` to `ublk.ko` in order to link multiple translation units into the module. Signed-off-by: Andreas Hindborg --- MAINTAINERS | 1 + drivers/block/Kconfig | 4 + drivers/block/Makefile | 4 +- drivers/block/ublk_drv-zoned.c | 144 +++++++++++++++++++++++++++++++++ drivers/block/ublk_drv.c | 64 +++++++++++++-- drivers/block/ublk_drv.h | 15 ++++ include/uapi/linux/ublk_cmd.h | 14 ++++ 7 files changed, 239 insertions(+), 7 deletions(-) create mode 100644 drivers/block/ublk_drv-zoned.c diff --git a/MAINTAINERS b/MAINTAINERS index ace71c90751c..db8a8deb5926 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21555,6 +21555,7 @@ S: Maintained F: Documentation/block/ublk.rst F: drivers/block/ublk_drv.c F: drivers/block/ublk_drv.h +F: drivers/block/ublk_drv-zoned.c F: include/uapi/linux/ublk_cmd.h UCLINUX (M68KNOMMU AND COLDFIRE) diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index 5b9d4aaebb81..c58dfd035557 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -402,6 +402,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 + def_bool y + 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 101612cba303..bc1649e20ec2 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -37,6 +37,8 @@ obj-$(CONFIG_BLK_DEV_RNBD) += rnbd/ obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk/ -obj-$(CONFIG_BLK_DEV_UBLK) += ublk_drv.o +obj-$(CONFIG_BLK_DEV_UBLK) += ublk.o +ublk-$(CONFIG_BLK_DEV_UBLK) += ublk_drv.o +ublk-$(CONFIG_BLK_DEV_UBLK_ZONED) += ublk_drv-zoned.o swim_mod-y := swim.o swim_asm.o diff --git a/drivers/block/ublk_drv-zoned.c b/drivers/block/ublk_drv-zoned.c new file mode 100644 index 000000000000..ea86bf4b3681 --- /dev/null +++ b/drivers/block/ublk_drv-zoned.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 Andreas Hindborg + */ +#include +#include +#include + +#include "ublk_drv.h" + +void ublk_set_nr_zones(struct ublk_device *ub) +{ + const struct ublk_param_basic *p = &ub->params.basic; + + if (ub->dev_info.flags & UBLK_F_ZONED && p->chunk_sectors) + ub->ub_disk->nr_zones = p->dev_sectors / p->chunk_sectors; +} + +void ublk_dev_param_zoned_apply(struct ublk_device *ub) +{ + const struct ublk_param_zoned *p = &ub->params.zoned; + + if (ub->dev_info.flags & UBLK_F_ZONED) { + disk_set_max_active_zones(ub->ub_disk, p->max_active_zones); + disk_set_max_open_zones(ub->ub_disk, p->max_open_zones); + } +} + +int ublk_revalidate_disk_zones(struct gendisk *disk) +{ + return blk_revalidate_disk_zones(disk, NULL); +} + +/* 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; + } + + bufsize = 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; + struct blk_zone *buffer; + size_t buffer_length; + + if (!(ub->dev_info.flags & UBLK_F_ZONED)) + 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); + int err = 0; + 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)) + return PTR_ERR(req); + + 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; + + err = blk_rq_map_kern(disk->queue, req, buffer, buffer_length, + GFP_KERNEL); + if (err) { + blk_mq_free_request(req); + kvfree(buffer); + return err; + } + + status = blk_execute_rq(req, 0); + err = blk_status_to_errno(status); + blk_mq_free_request(req); + if (err) { + kvfree(buffer); + return err; + } + + for (unsigned int i = 0; i < zones_in_request; i++) { + struct blk_zone *zone = buffer + i; + + err = cb(zone, i, data); + if (err) + return err; + + done_zones++; + sector += zone_size_sectors; + + /* A zero length zone means don't ask for more zones */ + if (!zone->len) { + kvfree(buffer); + return done_zones; + } + } + } + + kvfree(buffer); + return done_zones; +} diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index e519dc0d9fe7..88fa39853c61 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.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; @@ -209,6 +210,9 @@ 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); + + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED)) + ublk_set_nr_zones(ub); } static void ublk_dev_param_discard_apply(struct ublk_device *ub) @@ -269,6 +273,9 @@ static int ublk_apply_params(struct ublk_device *ub) if (ub->params.types & UBLK_PARAM_TYPE_DISCARD) ublk_dev_param_discard_apply(ub); + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && (ub->params.types & UBLK_PARAM_TYPE_ZONED)) + ublk_dev_param_zoned_apply(ub); + return 0; } @@ -439,6 +446,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 @@ -553,7 +561,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, @@ -637,6 +646,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)) { @@ -655,6 +665,35 @@ 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; + iod->addr = io->addr; + return BLK_STS_OK; + default: + return BLK_STS_IOERR; + } + case REQ_OP_ZONE_APPEND: + 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; } @@ -708,7 +747,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 */ @@ -1835,6 +1875,15 @@ 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); + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && + ub->dev_info.flags & UBLK_F_ZONED) { + disk_set_zoned(disk, BLK_ZONED_HM); + blk_queue_required_elevator_features(disk->queue, ELEVATOR_F_ZBD_SEQ_WRITE); + ret = ublk_revalidate_disk_zones(disk); + if (ret) + goto out_put_disk; + } + get_device(&ub->cdev_dev); ub->dev_info.state = UBLK_S_DEV_LIVE; ret = add_disk(disk); @@ -1997,6 +2046,9 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) if (ub->dev_info.flags & UBLK_F_USER_COPY) ub->dev_info.flags &= ~UBLK_F_NEED_GET_DATA; + if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED)) + ub->dev_info.flags &= ~UBLK_F_ZONED; + /* We are not ready to support zero copy */ ub->dev_info.flags &= ~UBLK_F_SUPPORT_ZERO_COPY; diff --git a/drivers/block/ublk_drv.h b/drivers/block/ublk_drv.h index f81e62256456..7242430fd6b9 100644 --- a/drivers/block/ublk_drv.h +++ b/drivers/block/ublk_drv.h @@ -50,6 +50,21 @@ struct ublk_rq_data { struct llist_node node; struct kref ref; + enum ublk_op operation; + __u64 sector; + __u32 nr_sectors; }; +void ublk_set_nr_zones(struct ublk_device *ub); +void ublk_dev_param_zoned_apply(struct ublk_device *ub); +int ublk_revalidate_disk_zones(struct gendisk *disk); + +#ifdef CONFIG_BLK_DEV_UBLK_ZONED +int ublk_report_zones(struct gendisk *disk, sector_t sector, + unsigned int nr_zones, report_zones_cb cb, + void *data); +#else +#define ublk_report_zones NULL +#endif + #endif diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index 471b3b983045..436525afffe8 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -176,6 +176,11 @@ /* Copy between request and user buffer by pread()/pwrite() */ #define UBLK_F_USER_COPY (1UL << 7) +/* + * Enable zoned device support + */ +#define UBLK_F_ZONED (1ULL << 8) + /* device state */ #define UBLK_S_DEV_DEAD 0 #define UBLK_S_DEV_LIVE 1 @@ -242,6 +247,7 @@ enum ublk_op { UBLK_IO_OP_ZONE_APPEND = 13, UBLK_IO_OP_ZONE_RESET = 15, __UBLK_IO_OP_DRV_IN_START = 32, + UBLK_IO_OP_REPORT_ZONES = __UBLK_IO_OP_DRV_IN_START, __UBLK_IO_OP_DRV_IN_END = 96, __UBLK_IO_OP_DRV_OUT_START = __UBLK_IO_OP_DRV_IN_END, __UBLK_IO_OP_DRV_OUT_END = 160, @@ -342,6 +348,12 @@ struct ublk_param_devt { __u32 disk_minor; }; +struct ublk_param_zoned { + __u32 max_open_zones; + __u32 max_active_zones; + __u8 reserved[24]; +}; + struct ublk_params { /* * Total length of parameters, userspace has to set 'len' for both @@ -353,11 +365,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 From patchwork Wed Jun 28 19:06:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Hindborg X-Patchwork-Id: 114028 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp9157622vqr; Wed, 28 Jun 2023 12:27:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5HnvsI5Nqq2ouJd+eYGeniJedNCi8fv8ypOgCnVsD60adfqjkCwcGuDDmvgv8Jv2YePeml X-Received: by 2002:a05:6a21:3394:b0:126:aa77:a11f with SMTP id yy20-20020a056a21339400b00126aa77a11fmr15571931pzb.6.1687980430384; Wed, 28 Jun 2023 12:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687980430; cv=none; d=google.com; s=arc-20160816; b=oBys02peSteUwnlQeINOLw1irvyKahC5fniDCehsKgorvVQPucWWRvebu+6jOA4tSu zSUOeo7gSgQ56dG90cFcGcSvFdDpyuilYS8GPq8zRIwKyNivHXDUuDfFjjuQBQU+/XDw njJdke4Xi9hx4Mg7Bgq2mHGFwXDyWR726sFhqM59s/lrHnGjk8IzhnuKpVMvt3tDwvbt 01/BSSDuXGc2biNf0qtzbsUavCShp3HpnCAdbfGZmhWorlKhfyH3kLuxpJvwaQlae6xl uKadklBOI/hE7a1I887XW8mxyWcLYY27Tn3/beVaOYEw47VF44eKrJp2pSQYhWHDWV8j GuUw== 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=k09MsLBHwTc+y9WYz50c8Y73VYgCsBkw4p9DqkCCN/M=; fh=PtLHm9B0+hM1tQPeQT3fpvfpYSsUVoUxZslaqHBKa8M=; b=u5hTswmeJT+RC37LL2TvNUbKfwNT4UHIMoqEX6z841mYA9uxBvuPEbsUbO/TeCMuVW 4t1kyRjHoBVMb2udoz8/SEneG2VnGOEo4nsHjv3iDIfyocAYGgWqT//mYR8aJnxHcOyI hvcttpQb12oOVr1bvg/bnLDGA7XJD7WnfslHbVHFGY1sgXCEGnfFOtrrxnyAkDTyFFzf TW5YF27OPoQSqoQrMw78/YYi5sO8XAvwOl6liohsWnBRAAvY3UHNmkxBdjSQbSYCvjKQ iG81cTItcTQBamVU2AoTV9sqMDfzqFLDHlv0vbRZ5wCSaJNqfYHdcbzbhefK45RCFKtV /4jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=AMrm8MGS; 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 bs66-20020a632845000000b0055b2c94e7b1si1141227pgb.190.2023.06.28.12.26.55; Wed, 28 Jun 2023 12:27:10 -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=AMrm8MGS; 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 S232169AbjF1TH1 (ORCPT + 99 others); Wed, 28 Jun 2023 15:07:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbjF1THC (ORCPT ); Wed, 28 Jun 2023 15:07:02 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3E3526AB for ; Wed, 28 Jun 2023 12:06:58 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-51d9128494cso4556238a12.0 for ; Wed, 28 Jun 2023 12:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1687979217; x=1690571217; 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=k09MsLBHwTc+y9WYz50c8Y73VYgCsBkw4p9DqkCCN/M=; b=AMrm8MGS8YsjLjsAEPiKS0/uHUYlIE1gZyHmH/mHOzZRfp3DgrhhgqGOc7Y1du/0Ns +vrRD7Ix5cumjIVFj0Az8G3vMK7rGO6lgJLmLNw7UkFpQ8uQpzM5L78cp3UPSeLkBKkp 2ndQ+7cCB1PoaCz4ekU6RKY0+lnwP8SvXJrBSeBahEYWsy0CP5TTUnGJzzVD7Bab8cwd 0e4RqEYNzHRJOHjdxXtf+RLOPCaaP/KK9bx3sP94URvC41wNbwKDSJKppPK39KiJ5Net b3I+hpw0s1i2H0FeZkEqrxV7Pkx6sj+4+D2XKanPcpHe+rV2Jg/yvA9ONYOTThU+nfx6 YCQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687979217; x=1690571217; 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=k09MsLBHwTc+y9WYz50c8Y73VYgCsBkw4p9DqkCCN/M=; b=lx2RgbBRr1CXnAGKJhnlLxKeFgi7g2hmFB3SbsE/fUiY4frj+GV/wKNrf0gpkfsGaq 1UX5IuAknTu94t6Yg0/ZQ0BSfYXQkBbyOgFWExuzC29uIDVy3bSZkrdZAHJ15spmWcZV u5WscWZ0JSkL90y/gpNSir40qlmgk09TRVUAyhFeGcjeEHc9Sms3LuJfL+MchxleZ6hu 9EpUze7vMohYyBLQ1jKsANndZF3newZtYVKR4VkHGAu7rfcEc171LI94eF8SXeWq8Pg3 qUbdCdoi/vf8/vlyfIgwM3ufaJJPwMsmbHv3CYWLVsjokBhgSPmBj0EIuADaPMeXw/rU lWqg== X-Gm-Message-State: AC+VfDw7QqRhxygo7gAdTAug35C2hFHr1ciQHqhr7aFC6CYaVQOSRjVG w+rTG3Aq5fg63mSxk7RPDj46Ww== X-Received: by 2002:a05:6402:892:b0:51d:d41b:26a5 with SMTP id e18-20020a056402089200b0051dd41b26a5mr1285108edy.14.1687979217241; Wed, 28 Jun 2023 12:06:57 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id e2-20020a170906080200b0098503ba0db4sm6150511ejd.149.2023.06.28.12.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 12:06:56 -0700 (PDT) From: Andreas Hindborg To: Ming Lei Cc: Hans Holmberg , Aravind Ramesh , Jens Axboe , linux-block@vger.kernel.org (open list:BLOCK LAYER), Christoph Hellwig , Matias Bjorling , Andreas Hindborg , linux-kernel@vger.kernel.org (open list), Damien Le Moal , gost.dev@samsung.com, Minwoo Im Subject: [PATCH v4 4/4] ublk: add zone append Date: Wed, 28 Jun 2023 21:06:49 +0200 Message-ID: <20230628190649.11233-5-nmi@metaspace.dk> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628190649.11233-1-nmi@metaspace.dk> References: <20230628190649.11233-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?1769975768081105632?= X-GMAIL-MSGID: =?utf-8?q?1769975768081105632?= From: Andreas Hindborg Add zone append feature to ublk. This feature uses the `addr` field of `struct ublksrv_io_cmd`. Therefore ublk must be used with the user copy feature (UBLK_F_USER_COPY) for zone append to be available. Without this feature, ublk will fail zone append requests. Suggested-by: Ming Lei Signed-off-by: Andreas Hindborg --- drivers/block/ublk_drv-zoned.c | 11 +++++++++ drivers/block/ublk_drv.c | 43 ++++++++++++++++++++++++++++++---- drivers/block/ublk_drv.h | 1 + include/uapi/linux/ublk_cmd.h | 3 ++- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/drivers/block/ublk_drv-zoned.c b/drivers/block/ublk_drv-zoned.c index ea86bf4b3681..007e8fc7ff25 100644 --- a/drivers/block/ublk_drv-zoned.c +++ b/drivers/block/ublk_drv-zoned.c @@ -16,6 +16,16 @@ void ublk_set_nr_zones(struct ublk_device *ub) ub->ub_disk->nr_zones = p->dev_sectors / p->chunk_sectors; } +int ublk_dev_param_zoned_validate(const struct ublk_device *ub) +{ + const struct ublk_param_zoned *p = &ub->params.zoned; + + if (! p->max_zone_append_sectors) + return -EINVAL; + + return 0; +} + void ublk_dev_param_zoned_apply(struct ublk_device *ub) { const struct ublk_param_zoned *p = &ub->params.zoned; @@ -23,6 +33,7 @@ void ublk_dev_param_zoned_apply(struct ublk_device *ub) if (ub->dev_info.flags & UBLK_F_ZONED) { 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); } } diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 88fa39853c61..6a949669b47e 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -107,6 +107,11 @@ struct ublk_uring_cmd_pdu { */ #define UBLK_IO_FLAG_NEED_GET_DATA 0x08 +/* + * Set when IO is Zone Append + */ +#define UBLK_IO_FLAG_ZONE_APPEND 0x10 + struct ublk_io { /* userspace buffer address from io cmd */ __u64 addr; @@ -230,6 +235,8 @@ static void ublk_dev_param_discard_apply(struct ublk_device *ub) static int ublk_validate_params(const struct ublk_device *ub) { + int ret = 0; + /* basic param is the only one which must be set */ if (ub->params.types & UBLK_PARAM_TYPE_BASIC) { const struct ublk_param_basic *p = &ub->params.basic; @@ -260,6 +267,13 @@ static int ublk_validate_params(const struct ublk_device *ub) if (ub->params.types & UBLK_PARAM_TYPE_DEVT) return -EINVAL; + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && + (ub->params.types & UBLK_PARAM_TYPE_ZONED)) { + ret = ublk_dev_param_zoned_validate(ub); + if (ret) + return ret; + } + return 0; } @@ -690,6 +704,11 @@ static blk_status_t ublk_setup_iod(struct ublk_queue *ubq, struct request *req) return BLK_STS_IOERR; } case REQ_OP_ZONE_APPEND: + if (!(ubq->dev->dev_info.flags & UBLK_F_USER_COPY)) + return BLK_STS_IOERR; + 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 */ @@ -1112,6 +1131,12 @@ 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); + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED)) { + if (io->flags & UBLK_IO_FLAG_ZONE_APPEND) + req->__sector = ub_cmd->addr; + io->flags &= ~UBLK_IO_FLAG_ZONE_APPEND; + } + if (req && likely(!blk_should_fake_timeout(req->q))) ublk_put_req_ref(ubq, req); } @@ -1411,7 +1436,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; } @@ -1534,11 +1560,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; @@ -1867,6 +1896,12 @@ 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; + ub->dev_info.state = UBLK_S_DEV_LIVE; + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && + ub->dev_info.flags & UBLK_F_ZONED) { + disk_set_zoned(disk, BLK_ZONED_HM); + } + ret = ublk_apply_params(ub); if (ret) goto out_put_disk; @@ -1877,7 +1912,6 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd) if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && ub->dev_info.flags & UBLK_F_ZONED) { - disk_set_zoned(disk, BLK_ZONED_HM); blk_queue_required_elevator_features(disk->queue, ELEVATOR_F_ZBD_SEQ_WRITE); ret = ublk_revalidate_disk_zones(disk); if (ret) @@ -1885,7 +1919,6 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd) } get_device(&ub->cdev_dev); - ub->dev_info.state = UBLK_S_DEV_LIVE; ret = add_disk(disk); if (ret) { /* diff --git a/drivers/block/ublk_drv.h b/drivers/block/ublk_drv.h index 7242430fd6b9..f55e1c25531d 100644 --- a/drivers/block/ublk_drv.h +++ b/drivers/block/ublk_drv.h @@ -56,6 +56,7 @@ struct ublk_rq_data { }; void ublk_set_nr_zones(struct ublk_device *ub); +int ublk_dev_param_zoned_validate(const struct ublk_device *ub); void ublk_dev_param_zoned_apply(struct ublk_device *ub); int ublk_revalidate_disk_zones(struct gendisk *disk); diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index 436525afffe8..4b6ad0b28598 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -351,7 +351,8 @@ struct ublk_param_devt { struct ublk_param_zoned { __u32 max_open_zones; __u32 max_active_zones; - __u8 reserved[24]; + __u32 max_zone_append_sectors; + __u8 reserved[20]; }; struct ublk_params {