From patchwork Mon Jun 17 19:44:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uday Shankar X-Patchwork-Id: 13701328 Received: from mail-wr1-f98.google.com (mail-wr1-f98.google.com [209.85.221.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC64011CAB for ; Mon, 17 Jun 2024 19:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718653501; cv=none; b=phiryY5MVfYo+IgW0AoCcBcm2SX8xry8hvozZKDijd1JOA6LfjXLNRpTtkLmCUrtTH79grTf5iTU3zhUEgUIZ3olKJSC33tR7Ge5E10uf+yFTtkesgRPdgBum2ZwgBQ+nptil1WMe+/O50p2D0m2xOyht/o3fOtU+jMN+84RfG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718653501; c=relaxed/simple; bh=q3OT82/5hPbQeWQRe7ZoRAYo/DmtuhC4FJtiSJ2ZuNg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z363WBCDddo2grDnNbtbPJHNo2V8Q6dc8ggJBbvvU4or21sRR7TojfzbmXsR8sL9XAVJAOs2DGwlqvtmmIDbS2aG2fd9Kb9SC6gklP1lmF8KhXoLHeub5tAx4Lf3b4mc4aB/HRZik+Ju4moOg9CHXpDPvrnryPTNaUXcYDVVJcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=dgAGDNvp; arc=none smtp.client-ip=209.85.221.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="dgAGDNvp" Received: by mail-wr1-f98.google.com with SMTP id ffacd0b85a97d-35f23f3da44so4214617f8f.0 for ; Mon, 17 Jun 2024 12:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1718653497; x=1719258297; darn=vger.kernel.org; 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=x2TV2BQQ7MB9qUDCbVKF9ekWJjR1zvRJg3acNlnp8OI=; b=dgAGDNvpTJhmzqAUx8dmdr8J1A112cFesFhsetLSCsuoJ++qA6+iOlpRdO2lQayk8Q Yhnn8IvCnkb8iEheEq2jnvGfGKyVyzWmEw7Lp6F52QpE0pxdLZHBGYXhM32Cr0YH9OXz V/YZq6w8Xb9EDW7rtBK7x4MFK/URvc1FCgIM9++g06cuAsJxZsv3Jf1MIwKtRS+TuD+2 CN1JhrYAK+Q+lJnMf2aSExwwO1xrtpAz6NZwvwYsxEMmnk5f1wyN63u5dGntTxNTssfH w3LIXZjcX+BhiiOlrBgd6UwBmaaMHuKrHoRjgawJD/6k8Pr71viWj4hUKggsr0w5myy9 9LiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718653497; x=1719258297; 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=x2TV2BQQ7MB9qUDCbVKF9ekWJjR1zvRJg3acNlnp8OI=; b=XIMTA+T+Ad+KC8JaA+U2Z0QROIxgWnfYDp1nJmf/Df3sUZCe9/HZJhJQQ4jGSMHnM5 PPfJOdAbnV9bVblCkE+GOBqAYsRPZUpmcsQjKec72eJbzjmQz6KJ7ZV4HVFGg0+QXawt 7+97YoTvmjtxEOdSgmf8aGYqO5Ahdv/MK1Ds4rnByKhCqA6/mcUoIIkP1NOTdNxuYbrr TRVDsNDUrX3tE4B7EjZKE/hiohHRHbcxlsXGP7a2qwSB3tO4RfY0XgNzxWU/VJPeXSoh p6u7mNaaO5gi9cd5muX6Ogl24AahNJDIZRFvuvfQhYbbKoloNp2eMcvnU/Cc2U2oPkDn OHuQ== X-Forwarded-Encrypted: i=1; AJvYcCUy3jgmuUAXpvjRYL+j3RMvBi16kTD+h2Yubfz6KiITZdZQg/MYjqAtpoT/4dqbIWaG/om4iFHj+SsCvbGsTKCbYNwU6LJRvlWlyiI= X-Gm-Message-State: AOJu0Ywxk0PLkcioyx080/bNTqYpIOwsIOl3/3qJ7cA5qZS6og9NBzwU aRpqUtj6vQ5n8iqCLEgjDAD33GwuCzzbmwNzsoQxeFVxkQJDquxJYOIGRdES3G56Hd4/rK0Zx5C mwdsuKB0XGW+k5vuEW2SJXJtZKrQg4Y89xYYifeaZVYvi8bVe X-Google-Smtp-Source: AGHT+IFoYx4fI/YGIm6N7q5kadC+ob/MIKwVAar81Ko+FTLLdZI7GiQypxjb9KJxUUwlblAHYD6fSYC9IQSl X-Received: by 2002:adf:cf0a:0:b0:360:7a44:12d9 with SMTP id ffacd0b85a97d-3607a7c20aemr8261296f8f.42.1718653497163; Mon, 17 Jun 2024 12:44:57 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id ffacd0b85a97d-360750b75c5sm457968f8f.17.2024.06.17.12.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 12:44:57 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-ushankar.dev.purestorage.com (dev-ushankar.dev.purestorage.com [10.7.70.36]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id E7462340644; Mon, 17 Jun 2024 13:44:55 -0600 (MDT) Received: by dev-ushankar.dev.purestorage.com (Postfix, from userid 1557716368) id D76B6E401A9; Mon, 17 Jun 2024 13:44:55 -0600 (MDT) From: Uday Shankar To: Ming Lei , Jens Axboe Cc: Uday Shankar , linux-block@vger.kernel.org Subject: [PATCH 1/4] ublk: check recovery flags for validity Date: Mon, 17 Jun 2024 13:44:48 -0600 Message-Id: <20240617194451.435445-2-ushankar@purestorage.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617194451.435445-1-ushankar@purestorage.com> References: <20240617194451.435445-1-ushankar@purestorage.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Only certain combinations of recovery flags are valid. For example, setting UBLK_F_USER_RECOVERY_REISSUE without also setting UBLK_F_USER_RECOVERY is currently silently equivalent to not setting any recovery flags. Check for such issues and fail add_dev if they are detected. Signed-off-by: Uday Shankar --- drivers/block/ublk_drv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 4e159948c912..2752a9afe9d4 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -59,6 +59,9 @@ | UBLK_F_USER_COPY \ | UBLK_F_ZONED) +#define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \ + | UBLK_F_USER_RECOVERY_REISSUE) + /* All UBLK_PARAM_TYPE_* should be included here */ #define UBLK_PARAM_TYPE_ALL \ (UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DISCARD | \ @@ -2341,6 +2344,18 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) else if (!(info.flags & UBLK_F_UNPRIVILEGED_DEV)) return -EPERM; + /* forbid nonsense combinations of recovery flags */ + switch (info.flags & UBLK_F_ALL_RECOVERY_FLAGS) { + case 0: + case UBLK_F_USER_RECOVERY: + case (UBLK_F_USER_RECOVERY | UBLK_F_USER_RECOVERY_REISSUE): + break; + default: + pr_warn("%s: invalid recovery flags %llx\n", __func__, + info.flags & UBLK_F_ALL_RECOVERY_FLAGS); + return -EINVAL; + } + /* * unprivileged device can't be trusted, but RECOVERY and * RECOVERY_REISSUE still may hang error handling, so can't From patchwork Mon Jun 17 19:44:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uday Shankar X-Patchwork-Id: 13701327 Received: from mail-lf1-f99.google.com (mail-lf1-f99.google.com [209.85.167.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 286EA187565 for ; Mon, 17 Jun 2024 19:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718653501; cv=none; b=fvWCOqi66H2v8BWlGjZXHQODNrEJH8nRNGbZWPFzUMcoODEpoCkeMoKzpee/zQmTRSqJLUwbPAlPFknaeuvELTC1pHEjkr6rA8gGPvcwAIXMEMeC4nb2ilw+RUSw34mODvWQDPYdC/1v0Pr77gUvJ0edm09zGrha4MFnirC4txg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718653501; c=relaxed/simple; bh=zHh5cInX6LbAD9zKOLYTffSQaG4k+QriHA4NDndLIeo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ircbh5BYWFf/9gWaQt/EDevc7Gii2MbFkvos2K/kIs4vDcKBVkFf2kK1WWwUpdBh1ve+/xbzonapqyddgNf+8aUNTeqMEhIcSkpsLgJAakZ2Vc/Lc5M/ZVa8FtcMY5RAATctpuI0eR2R1tkgLuVRtqhG9KeHLpmIcnd9WsCzyYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=XZ3N4HBI; arc=none smtp.client-ip=209.85.167.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="XZ3N4HBI" Received: by mail-lf1-f99.google.com with SMTP id 2adb3069b0e04-52b7ffd9f6eso4651564e87.3 for ; Mon, 17 Jun 2024 12:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1718653497; x=1719258297; darn=vger.kernel.org; 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=JRG4KmmpYlaV0TAj9hrThh+HxSU+Y2tSkTCvMoWEui8=; b=XZ3N4HBItIuT8O68gRVld51MCZ9UvtaQHnLGkCTOHj1l2F4dqdCejCkGlvWdNSxUZN Jxk6LPtAn0/CnPklg/CAYqEwBKxgaGoMMHfjPz+eBqE/lPVbhu+L9n9IwlaAtu0Gy0M1 bST8fiaCmamgE92umzWEOfU53+oa+6iyv+WWAy8O30iDoMaFgx2QV/jsKc9dizh4l1pM X/fuNLPJm5Dsw37Dx+MEIZ1ZcwyK4Vh8cgHLVtNl9FLVVZg1bCAybG5+4VTDk8WpFpEZ Hb5zVuN8rnR8uMgkiqzh+4btMqs2djKj+ckfYS4YWL1gCbfA0e8SUxWAmA1jyX+RSfWT WAvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718653497; x=1719258297; 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=JRG4KmmpYlaV0TAj9hrThh+HxSU+Y2tSkTCvMoWEui8=; b=oWzBvH8wAvVyOWUUHla7EAXueqI7CAN+7VScLSLg3Yt/cPEo1xkU8TK0LQ30/JsbkV fKMQIQeCZusLj9YbGZstvR9tbc7f4Qir2pe6UZmYvBM/A6RgP1+m2/6R9C2TtNN0Dp8G rsEUxmMhGtNIptX6jl9sQwZwPxpisq5/gPZCFE62a0uE1QP23PqD4AaDYF9wWugvNTSK hNlolMHfD5UFz3b/9upof7iXwE0/sP1qM0qRw7qYKw1cACOR2hmxVGlmHEE3leezuLmn dfsYx0MFIaEAZIjlCXEIICq7i1q5b4B2QF89omCOimzzqbO8Tl38K9L8lzRjFDjzagSW 1k/g== X-Forwarded-Encrypted: i=1; AJvYcCUGQrGFbG0lZhfZpM9Ljju4Shki+Sto+GuGbGCi8BErPPj22Iffto8tfdmcd51s6CIJAduuUUXhKtVXCIkPXcQmaeY/atmw7TsxqO8= X-Gm-Message-State: AOJu0YxYHGeY+1H43Hkv6DXCznWpswpIjAlo4liZzwwxqOQ3HLvTe4Nm 1WwV9drTJ6NC6x4HonJOlvv+4p4iTpyFE318w4DKY6NzaqzaWmJ3cVOtV9H2nI2g29TuYcTUUfk ly7D3xNmdAmEyZYYrzjUqn9C6hjKDZJey X-Google-Smtp-Source: AGHT+IF+QlL0V5HbkCBcsh05FT8zTC679DjWT9hTmYB+z8ASdbQxMa0mcuh9Zm5Eg9zithYY6OZe7A+wR/SK X-Received: by 2002:a05:6512:3992:b0:52c:c22d:3d4b with SMTP id 2adb3069b0e04-52cc22d3f85mr549683e87.54.1718653497217; Mon, 17 Jun 2024 12:44:57 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.129]) by smtp-relay.gmail.com with ESMTPS id a640c23a62f3a-a6f56f18f09sm13017566b.248.2024.06.17.12.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 12:44:57 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-ushankar.dev.purestorage.com (dev-ushankar.dev.purestorage.com [10.7.70.36]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id E612A340509; Mon, 17 Jun 2024 13:44:55 -0600 (MDT) Received: by dev-ushankar.dev.purestorage.com (Postfix, from userid 1557716368) id E13EFE4143F; Mon, 17 Jun 2024 13:44:55 -0600 (MDT) From: Uday Shankar To: Ming Lei , Jens Axboe Cc: Uday Shankar , linux-block@vger.kernel.org Subject: [PATCH 2/4] ublk: refactor recovery configuration flag helpers Date: Mon, 17 Jun 2024 13:44:49 -0600 Message-Id: <20240617194451.435445-3-ushankar@purestorage.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617194451.435445-1-ushankar@purestorage.com> References: <20240617194451.435445-1-ushankar@purestorage.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ublk currently supports the following behaviors on ublk server exit: A: outstanding I/Os get errors, subsequently issued I/Os get errors B: outstanding I/Os get errors, subsequently issued I/Os queue C: outstanding I/Os get reissued, subsequently issued I/Os queue and the following behaviors for recovery of preexisting block devices by a future incarnation of the ublk server: 1: ublk devices stopped on ublk server exit (no recovery possible) 2: ublk devices are recoverable using start/end_recovery commands The userspace interface allows selection of combinations of these behaviors using flags specified at device creation time, namely: default behavior: A + 1 UBLK_F_USER_RECOVERY: B + 2 UBLK_F_USER_RECOVERY|UBLK_F_USER_RECOVERY_REISSUE: C + 2 We can't easily change the userspace interface to allow independent selection of one of {A, B, C} and one of {1, 2}, but we can refactor the internal helpers which test for the flags. Replace the existing helpers with the following set: ublk_nosrv_should_reissue_outstanding: tests for behavior C ublk_nosrv_should_queue_io: tests for behavior B ublk_nosrv_should_stop_dev: tests for behavior 1 Signed-off-by: Uday Shankar --- drivers/block/ublk_drv.c | 55 +++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 2752a9afe9d4..e8cca58a71bc 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -652,22 +652,35 @@ static inline int ublk_queue_cmd_buf_size(struct ublk_device *ub, int q_id) PAGE_SIZE); } -static inline bool ublk_queue_can_use_recovery_reissue( - struct ublk_queue *ubq) +/* + * Should I/O outstanding to the ublk server when it exits be reissued? + * If not, outstanding I/O will get errors. + */ +static inline bool ublk_nosrv_should_reissue_outstanding(struct ublk_device *ub) { - return (ubq->flags & UBLK_F_USER_RECOVERY) && - (ubq->flags & UBLK_F_USER_RECOVERY_REISSUE); + return (ub->dev_info.flags & UBLK_F_USER_RECOVERY) && + (ub->dev_info.flags & UBLK_F_USER_RECOVERY_REISSUE); } -static inline bool ublk_queue_can_use_recovery( - struct ublk_queue *ubq) +/* + * Should I/O issued while there is no ublk server queue? If not, I/O + * issued while there is no ublk server will get errors. + */ +static inline bool ublk_nosrv_should_queue_io(struct ublk_device *ub) { - return ubq->flags & UBLK_F_USER_RECOVERY; + return ub->dev_info.flags & UBLK_F_USER_RECOVERY; } -static inline bool ublk_can_use_recovery(struct ublk_device *ub) +/* + * Should ublk devices be stopped (i.e. no recovery possible) when the + * ublk server exits? If not, devices can be used again by a future + * incarnation of a ublk server via the start_recovery/end_recovery + * commands. + */ +static inline bool ublk_nosrv_should_stop_dev(struct ublk_device *ub) { - return ub->dev_info.flags & UBLK_F_USER_RECOVERY; + return (!(ub->dev_info.flags & UBLK_F_USER_RECOVERY)) && + (!(ub->dev_info.flags & UBLK_F_USER_RECOVERY_REISSUE)); } static void ublk_free_disk(struct gendisk *disk) @@ -1043,7 +1056,7 @@ static void __ublk_fail_req(struct ublk_queue *ubq, struct ublk_io *io, { WARN_ON_ONCE(io->flags & UBLK_IO_FLAG_ACTIVE); - if (ublk_queue_can_use_recovery_reissue(ubq)) + if (ublk_nosrv_should_reissue_outstanding(ubq->dev)) blk_mq_requeue_request(req, false); else ublk_put_req_ref(ubq, req); @@ -1071,7 +1084,7 @@ static inline void __ublk_abort_rq(struct ublk_queue *ubq, struct request *rq) { /* We cannot process this rq so just requeue it. */ - if (ublk_queue_can_use_recovery(ubq)) + if (ublk_nosrv_should_queue_io(ubq->dev)) blk_mq_requeue_request(rq, false); else blk_mq_end_request(rq, BLK_STS_IOERR); @@ -1216,10 +1229,10 @@ static enum blk_eh_timer_return ublk_timeout(struct request *rq) struct ublk_device *ub = ubq->dev; if (ublk_abort_requests(ub, ubq)) { - if (ublk_can_use_recovery(ub)) - schedule_work(&ub->quiesce_work); - else + if (ublk_nosrv_should_stop_dev(ub)) schedule_work(&ub->stop_work); + else + schedule_work(&ub->quiesce_work); } return BLK_EH_DONE; } @@ -1248,7 +1261,7 @@ static blk_status_t ublk_queue_rq(struct blk_mq_hw_ctx *hctx, * Note: force_abort is guaranteed to be seen because it is set * before request queue is unqiuesced. */ - if (ublk_queue_can_use_recovery(ubq) && unlikely(ubq->force_abort)) + if (ublk_nosrv_should_queue_io(ubq->dev) && unlikely(ubq->force_abort)) return BLK_STS_IOERR; if (unlikely(ubq->canceling)) { @@ -1469,10 +1482,10 @@ static void ublk_uring_cmd_cancel_fn(struct io_uring_cmd *cmd, ublk_cancel_cmd(ubq, io, issue_flags); if (need_schedule) { - if (ublk_can_use_recovery(ub)) - schedule_work(&ub->quiesce_work); - else + if (ublk_nosrv_should_stop_dev(ub)) schedule_work(&ub->stop_work); + else + schedule_work(&ub->quiesce_work); } } @@ -1577,7 +1590,7 @@ static void ublk_stop_dev(struct ublk_device *ub) mutex_lock(&ub->mutex); if (ub->dev_info.state == UBLK_S_DEV_DEAD) goto unlock; - if (ublk_can_use_recovery(ub)) { + if (ublk_nosrv_should_queue_io(ub)) { if (ub->dev_info.state == UBLK_S_DEV_LIVE) __ublk_quiesce_dev(ub); ublk_unquiesce_dev(ub); @@ -2674,7 +2687,7 @@ static int ublk_ctrl_start_recovery(struct ublk_device *ub, int i; mutex_lock(&ub->mutex); - if (!ublk_can_use_recovery(ub)) + if (ublk_nosrv_should_stop_dev(ub)) goto out_unlock; /* * START_RECOVERY is only allowd after: @@ -2725,7 +2738,7 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub, __func__, ub->dev_info.nr_hw_queues, header->dev_id); mutex_lock(&ub->mutex); - if (!ublk_can_use_recovery(ub)) + if (ublk_nosrv_should_stop_dev(ub)) goto out_unlock; if (ub->dev_info.state != UBLK_S_DEV_QUIESCED) { From patchwork Mon Jun 17 19:44:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uday Shankar X-Patchwork-Id: 13701326 Received: from mail-lf1-f99.google.com (mail-lf1-f99.google.com [209.85.167.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29C38187567 for ; Mon, 17 Jun 2024 19:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718653501; cv=none; b=LLXIy1WvZJUWPLRMHhZRPDOLaOKxiHk7n3P6q72fTwtbMD1/ip692QD5MoWlyoPsFT/l+V4PaJ6bEePMxRoSWfCuzBp88dslwfH4TnA+SbShh0bkcLW6OUSkhisOQ41G8bHZPVbvAduEQwSVVJDc7Nv+WJ2ijuC50eZYO54dKnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718653501; c=relaxed/simple; bh=2+LwCHEVwTKte1Sqyy+VNnEqZA9WS1/s0+xVs/pbhiw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Rlb8CabSMLQLs6WJlr+ZSRXO3cha6sO5OXAOEjbsNga1uytz4mWrFvpzGaLe46wKxM6b0/rmBoQYALzLyWZ4uDOnHrbU0ICgVkASDDTAKjD1/5wsdBBs/DLeyDHZQ86Cw+NqepNxe62ewogK0hpRcbxtSunN/wMH6VowVLuC7qM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=KkXohA/D; arc=none smtp.client-ip=209.85.167.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="KkXohA/D" Received: by mail-lf1-f99.google.com with SMTP id 2adb3069b0e04-52bc29c79fdso6476756e87.1 for ; Mon, 17 Jun 2024 12:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1718653497; x=1719258297; darn=vger.kernel.org; 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=K7qhPXyAkeQjB7Mf6zuo0q5cuZeT1DLbeNHHlB7kG+A=; b=KkXohA/DvPoMb6YvQTtdZUcDEjyQ/bLW8emVAFB5EmR/qK97Q1Wqjh4IYBdX/f0EaK 1O8saF4my/Qefla+0WRhn3uE8N/1evQzOSgKtnuur8YvffnoptmHTVxsarbsnMs4PC++ /wFZSU+DJPSDB1hoMxuutYvav7AmPb851LZkiCiMiRpadAJskeFIqKhk9vxSDOdlyK1i e33qkAgPtKRidPO/ltTm1hfOog0Fknk3pfFl0PHymN5WGOeiY/HDc/M+K1ZaisdPeIh/ bGRu7rzhQgGrdminhAp4Bfxy0LdvQJ+JV/t4MkX3/55kI80v6bmZbsWnf4Z7DV5GUBlj zrtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718653497; x=1719258297; 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=K7qhPXyAkeQjB7Mf6zuo0q5cuZeT1DLbeNHHlB7kG+A=; b=q3TdlBw3Zeh8Clg/qZn0DK7oWysyhxhq7YGSXtCtuWoyhcD9ujTunUeGRLK83WweTt AJ3X4NozVv3iImZv5f2ry5UJvKnB4cef5NptFF0cgtiunoaqej1gdttRlQOTmzqCaSUH SDVi4Pi86fSkqIYnKtjHekd2R0zl7gTpdAtolPSZZtd4EbG54pQEVSFHCmttF9UVVnfz 2wzHKBQFqCUZjvMCUYmzUA7/JPabkCgDl5xkFkTAQoOO6kT1bXQKWr01WZ/urWmGiNlp xeNO77p1AfgellBpcsFTr9xd+tFhMoipqBGwwMHiHnfMnUecLc1mOY4FOTXmnt98M7Qe Shvg== X-Forwarded-Encrypted: i=1; AJvYcCUNeR9dZXLFScGtlRGK07GVnB2flPGABJE9XHs54AF+8qoByLmperhAfchjAOx35YX6dBqOFTdxg5FmMshWmA2gKQfKOOTjlGbWiUs= X-Gm-Message-State: AOJu0YxphZt/ooRR4CHK5UEMMGeYtKEOPRVvY0HHmLywMj0EboNfNs1e WZpnSP2s1lZv2CSpLer5vUYgSGb1Pl85c0ga11jwwvXyELkp2X5kCoYsRP1BghvBW0DzhfPF7Ur Mh1xUtKr7ZKKvTFCxJrFfffXjAqQAZmKd4Suh6CdR6dipk4n9 X-Google-Smtp-Source: AGHT+IFXBpoa/4oXdqrSvu3k47reQw7dFd15KWYnB4XNzjtajTuXuVi4ykjkH4aNUjF/GA9PXItgVhwnnG75 X-Received: by 2002:a05:6512:3d10:b0:52c:8ed1:21fe with SMTP id 2adb3069b0e04-52ca6e924cbmr10582961e87.53.1718653497256; Mon, 17 Jun 2024 12:44:57 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([2620:125:9017:12:36:3:5:0]) by smtp-relay.gmail.com with ESMTPS id a640c23a62f3a-a6f56d8c61bsm12994066b.83.2024.06.17.12.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 12:44:57 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-ushankar.dev.purestorage.com (dev-ushankar.dev.purestorage.com [IPv6:2620:125:9007:640:7:70:36:0]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id F07993407A1; Mon, 17 Jun 2024 13:44:55 -0600 (MDT) Received: by dev-ushankar.dev.purestorage.com (Postfix, from userid 1557716368) id EAE73E41412; Mon, 17 Jun 2024 13:44:55 -0600 (MDT) From: Uday Shankar To: Ming Lei , Jens Axboe Cc: Uday Shankar , linux-block@vger.kernel.org Subject: [PATCH 3/4] ublk: merge stop_work and quiesce_work Date: Mon, 17 Jun 2024 13:44:50 -0600 Message-Id: <20240617194451.435445-4-ushankar@purestorage.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617194451.435445-1-ushankar@purestorage.com> References: <20240617194451.435445-1-ushankar@purestorage.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Save some lines by merging stop_work and quiesce_work into nosrv_work, which looks at the recovery flags and does the right thing when the "no ublk server" condition is detected. Signed-off-by: Uday Shankar Reviewed-by: Ming Lei --- drivers/block/ublk_drv.c | 64 ++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 39 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index e8cca58a71bc..0496fa372cc1 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -182,8 +182,7 @@ struct ublk_device { unsigned int nr_queues_ready; unsigned int nr_privileged_daemon; - struct work_struct quiesce_work; - struct work_struct stop_work; + struct work_struct nosrv_work; }; /* header of ublk_params */ @@ -1229,10 +1228,7 @@ static enum blk_eh_timer_return ublk_timeout(struct request *rq) struct ublk_device *ub = ubq->dev; if (ublk_abort_requests(ub, ubq)) { - if (ublk_nosrv_should_stop_dev(ub)) - schedule_work(&ub->stop_work); - else - schedule_work(&ub->quiesce_work); + schedule_work(&ub->nosrv_work); } return BLK_EH_DONE; } @@ -1482,10 +1478,7 @@ static void ublk_uring_cmd_cancel_fn(struct io_uring_cmd *cmd, ublk_cancel_cmd(ubq, io, issue_flags); if (need_schedule) { - if (ublk_nosrv_should_stop_dev(ub)) - schedule_work(&ub->stop_work); - else - schedule_work(&ub->quiesce_work); + schedule_work(&ub->nosrv_work); } } @@ -1548,20 +1541,6 @@ static void __ublk_quiesce_dev(struct ublk_device *ub) ub->dev_info.state = UBLK_S_DEV_QUIESCED; } -static void ublk_quiesce_work_fn(struct work_struct *work) -{ - struct ublk_device *ub = - container_of(work, struct ublk_device, quiesce_work); - - mutex_lock(&ub->mutex); - if (ub->dev_info.state != UBLK_S_DEV_LIVE) - goto unlock; - __ublk_quiesce_dev(ub); - unlock: - mutex_unlock(&ub->mutex); - ublk_cancel_dev(ub); -} - static void ublk_unquiesce_dev(struct ublk_device *ub) { int i; @@ -1610,6 +1589,25 @@ static void ublk_stop_dev(struct ublk_device *ub) ublk_cancel_dev(ub); } +static void ublk_nosrv_work(struct work_struct *work) +{ + struct ublk_device *ub = + container_of(work, struct ublk_device, nosrv_work); + + if (ublk_nosrv_should_stop_dev(ub)) { + ublk_stop_dev(ub); + return; + } + + mutex_lock(&ub->mutex); + if (ub->dev_info.state != UBLK_S_DEV_LIVE) + goto unlock; + __ublk_quiesce_dev(ub); + unlock: + mutex_unlock(&ub->mutex); + ublk_cancel_dev(ub); +} + /* device can only be started after all IOs are ready */ static void ublk_mark_io_ready(struct ublk_device *ub, struct ublk_queue *ubq) { @@ -2124,14 +2122,6 @@ static int ublk_add_chdev(struct ublk_device *ub) return ret; } -static void ublk_stop_work_fn(struct work_struct *work) -{ - struct ublk_device *ub = - container_of(work, struct ublk_device, stop_work); - - ublk_stop_dev(ub); -} - /* align max io buffer size with PAGE_SIZE */ static void ublk_align_max_io_size(struct ublk_device *ub) { @@ -2156,8 +2146,7 @@ static int ublk_add_tag_set(struct ublk_device *ub) static void ublk_remove(struct ublk_device *ub) { ublk_stop_dev(ub); - cancel_work_sync(&ub->stop_work); - cancel_work_sync(&ub->quiesce_work); + cancel_work_sync(&ub->nosrv_work); cdev_device_del(&ub->cdev, &ub->cdev_dev); ublk_put_device(ub); ublks_added--; @@ -2412,8 +2401,7 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) goto out_unlock; mutex_init(&ub->mutex); spin_lock_init(&ub->lock); - INIT_WORK(&ub->quiesce_work, ublk_quiesce_work_fn); - INIT_WORK(&ub->stop_work, ublk_stop_work_fn); + INIT_WORK(&ub->nosrv_work, ublk_nosrv_work); ret = ublk_alloc_dev_number(ub, header->dev_id); if (ret < 0) @@ -2548,9 +2536,7 @@ static inline void ublk_ctrl_cmd_dump(struct io_uring_cmd *cmd) static int ublk_ctrl_stop_dev(struct ublk_device *ub) { ublk_stop_dev(ub); - cancel_work_sync(&ub->stop_work); - cancel_work_sync(&ub->quiesce_work); - + cancel_work_sync(&ub->nosrv_work); return 0; } From patchwork Mon Jun 17 19:44:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uday Shankar X-Patchwork-Id: 13701325 Received: from mail-wm1-f97.google.com (mail-wm1-f97.google.com [209.85.128.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF4E4187542 for ; Mon, 17 Jun 2024 19:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718653501; cv=none; b=ddbPTmewwkQgZKEJvj3Jx8l3vLP39us3ql4iD7W2PoibTvihkQ+7IbWS05y1uPDsuxt2PKFooAwzmAFLqqrz42CIFehipJrBF4lNWK7FRe/RTmm/ySVu3wqQBDM2movf/kPv8DY80e6p2jNtQAiL8gj+VeKh0rItkXUI7gq0lug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718653501; c=relaxed/simple; bh=lrMGTTg5aJZSzO9i2PprZIkUkeJlHaO7FEbcoSn7euI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fqddQzRoC7INALMDFRtQSP+N1EnNYF2NgtZRLYEvsPiPnEOV4qK1kAKS5BV5o0NLKYrLoPbQ/lXAwqYMdqzpVAPsyt7Xwt9/82+o6vt3aleqEfjNbhjKxiNgqlM+lFs22qrLPLXelveWAcFF4bx3fw9qOcU9b+i3YNyTGudBQ2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com; spf=fail smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=VP4HeccA; arc=none smtp.client-ip=209.85.128.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="VP4HeccA" Received: by mail-wm1-f97.google.com with SMTP id 5b1f17b1804b1-4218314a6c7so39701275e9.0 for ; Mon, 17 Jun 2024 12:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1718653497; x=1719258297; darn=vger.kernel.org; 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=Aghx42yP//ci2m0muis70ts+owHj1yS8R/2aMs8x6/Y=; b=VP4HeccAk3CNeueiHhlsCvw/L1qarTFHc4WY270e0EeJbFlIi6e1Euc5KIDMheRxRU dwtkky/2v4v14U2r10TbOQSlwKGDHB3q6GurppvyheP/pI8Dy/OEcUXc3BK/eaukzVSO t2i7isTOk59WxXnlnwsADSdCf7ExIdO6TCLGzcexQ3CVO9FtCdrmouWVA32ESYr4+Hai wG8UJNoQ6QX9Gl0JbczkjZFHZIEGH/KNKCQy+u/DjOSgCtMexlbPwalWexiVTKcNdkqI o1/VYnhku6BpgY62MgelvdgRSem55lL35q+npCNGec14gPlXdBgF5kx06+F3d7fEnJCT t0+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718653497; x=1719258297; 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=Aghx42yP//ci2m0muis70ts+owHj1yS8R/2aMs8x6/Y=; b=wI2g4JA4Tr+yIVlIWTmWL7/YU5cIsi4r/6Gc1Da35hmlGB0aen1OFVH1idQsTzGfO4 Au4ast4JlhH7BfBo7YET7VVwr7yh/Rqsm7JjN/x0FHqiSkXDRmLZwFVwftx5lArKtDd2 ViJUOfO+VKF3ljWdlJ74+mOqbfElWF8MBdmHZYdHsTq5GcmUGMtGX/QzEEcHedQSgUsu ZJ0TaKBWyceFJODBRd/oBZIDKGuThKD4osZqY9CnXK3oGCi75xfCQM3mMJbfFtF/mhyP mpdMEi3Pu/mZovPauALLoM2Q3TGkkia2Egz5k1sBa0V2eVwVJ5E6q+pAOnQzy2pMWZgC qWnw== X-Forwarded-Encrypted: i=1; AJvYcCW42KUSrjYHM5J2u1kG3OKqx+mj5Mx/sP/2ci9BOV+x4weJaCR3aJ/pfIw794vin7uK66O521ZZHE6/HF4SNxhKFyqQxlg0xIqj1pE= X-Gm-Message-State: AOJu0YwgnT5YmhdAGoCxOzNe3DpbRJcq7XUYgb+hxjDkdYbaHWvPSiNU Uf7+Hoc+Eb27lTumAD9+pXzbA5Bw2LXS5sOS3aoKyflTDkOkJkXu/zz5SjvFhcOvfJeyGZ8vztN +IKwBarmYgMvJ73isNjoDXkFfpyKCryJj X-Google-Smtp-Source: AGHT+IGd/Z5Fsm8rIEFLUr+qBfyVoAISYuE+A/Dm7LN8v8nb6y80kXzlK7WNLnWx+Lj9p4DfCQUTpBDZFoVw X-Received: by 2002:a05:600c:1c9a:b0:422:6449:1307 with SMTP id 5b1f17b1804b1-4230484f994mr103939685e9.32.1718653497282; Mon, 17 Jun 2024 12:44:57 -0700 (PDT) Received: from c7-smtp-2023.dev.purestorage.com ([208.88.159.128]) by smtp-relay.gmail.com with ESMTPS id 5b1f17b1804b1-42286fe92bbsm5716225e9.13.2024.06.17.12.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 12:44:57 -0700 (PDT) X-Relaying-Domain: purestorage.com Received: from dev-ushankar.dev.purestorage.com (dev-ushankar.dev.purestorage.com [IPv6:2620:125:9007:640:7:70:36:0]) by c7-smtp-2023.dev.purestorage.com (Postfix) with ESMTP id 03076340A21; Mon, 17 Jun 2024 13:44:56 -0600 (MDT) Received: by dev-ushankar.dev.purestorage.com (Postfix, from userid 1557716368) id 0043BE41412; Mon, 17 Jun 2024 13:44:55 -0600 (MDT) From: Uday Shankar To: Ming Lei , Jens Axboe Cc: Uday Shankar , linux-block@vger.kernel.org Subject: [PATCH 4/4] ublk: support device recovery without I/O queueing Date: Mon, 17 Jun 2024 13:44:51 -0600 Message-Id: <20240617194451.435445-5-ushankar@purestorage.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617194451.435445-1-ushankar@purestorage.com> References: <20240617194451.435445-1-ushankar@purestorage.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ublk currently supports the following behaviors on ublk server exit: A: outstanding I/Os get errors, subsequently issued I/Os get errors B: outstanding I/Os get errors, subsequently issued I/Os queue C: outstanding I/Os get reissued, subsequently issued I/Os queue and the following behaviors for recovery of preexisting block devices by a future incarnation of the ublk server: 1: ublk devices stopped on ublk server exit (no recovery possible) 2: ublk devices are recoverable using start/end_recovery commands The userspace interface allows selection of combinations of these behaviors using flags specified at device creation time, namely: default behavior: A + 1 UBLK_F_USER_RECOVERY: B + 2 UBLK_F_USER_RECOVERY|UBLK_F_USER_RECOVERY_REISSUE: C + 2 The behavior A + 2 is currently unsupported. Add support for this behavior under the new flag UBLK_F_USER_RECOVERY_NOQUEUE. Signed-off-by: Uday Shankar --- drivers/block/ublk_drv.c | 53 +++++++++++++++++++++++++++-------- include/uapi/linux/ublk_cmd.h | 18 ++++++++++++ 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 0496fa372cc1..4fec8b48d30e 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -57,10 +57,12 @@ | UBLK_F_UNPRIVILEGED_DEV \ | UBLK_F_CMD_IOCTL_ENCODE \ | UBLK_F_USER_COPY \ - | UBLK_F_ZONED) + | UBLK_F_ZONED \ + | UBLK_F_USER_RECOVERY_NOQUEUE) #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \ - | UBLK_F_USER_RECOVERY_REISSUE) + | UBLK_F_USER_RECOVERY_REISSUE \ + | UBLK_F_USER_RECOVERY_NOQUEUE) /* All UBLK_PARAM_TYPE_* should be included here */ #define UBLK_PARAM_TYPE_ALL \ @@ -679,7 +681,14 @@ static inline bool ublk_nosrv_should_queue_io(struct ublk_device *ub) static inline bool ublk_nosrv_should_stop_dev(struct ublk_device *ub) { return (!(ub->dev_info.flags & UBLK_F_USER_RECOVERY)) && - (!(ub->dev_info.flags & UBLK_F_USER_RECOVERY_REISSUE)); + (!(ub->dev_info.flags & UBLK_F_USER_RECOVERY_REISSUE)) && + (!(ub->dev_info.flags & UBLK_F_USER_RECOVERY_NOQUEUE)); +} + +static inline bool ublk_dev_in_recoverable_state(struct ublk_device *ub) +{ + return ub->dev_info.state == UBLK_S_DEV_QUIESCED || + ub->dev_info.state == UBLK_S_DEV_FAIL_IO; } static void ublk_free_disk(struct gendisk *disk) @@ -1243,6 +1252,11 @@ static blk_status_t ublk_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *rq = bd->rq; blk_status_t res; + if (ubq->dev->dev_info.state == UBLK_S_DEV_FAIL_IO) { + return BLK_STS_TARGET; + } + WARN_ON_ONCE(ubq->dev->dev_info.state != UBLK_S_DEV_LIVE); + /* fill iod to slot in io cmd buffer */ res = ublk_setup_iod(ubq, rq); if (unlikely(res != BLK_STS_OK)) @@ -1602,7 +1616,15 @@ static void ublk_nosrv_work(struct work_struct *work) mutex_lock(&ub->mutex); if (ub->dev_info.state != UBLK_S_DEV_LIVE) goto unlock; - __ublk_quiesce_dev(ub); + + if (ublk_nosrv_should_queue_io(ub)) { + __ublk_quiesce_dev(ub); + } else { + blk_mq_quiesce_queue(ub->ub_disk->queue); + ub->dev_info.state = UBLK_S_DEV_FAIL_IO; + blk_mq_unquiesce_queue(ub->ub_disk->queue); + } + unlock: mutex_unlock(&ub->mutex); ublk_cancel_dev(ub); @@ -2351,6 +2373,7 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd) case 0: case UBLK_F_USER_RECOVERY: case (UBLK_F_USER_RECOVERY | UBLK_F_USER_RECOVERY_REISSUE): + case UBLK_F_USER_RECOVERY_NOQUEUE: break; default: pr_warn("%s: invalid recovery flags %llx\n", __func__, @@ -2682,14 +2705,18 @@ static int ublk_ctrl_start_recovery(struct ublk_device *ub, * and related io_uring ctx is freed so file struct of /dev/ublkcX is * released. * + * and one of the following holds + * * (2) UBLK_S_DEV_QUIESCED is set, which means the quiesce_work: * (a)has quiesced request queue * (b)has requeued every inflight rqs whose io_flags is ACTIVE * (c)has requeued/aborted every inflight rqs whose io_flags is NOT ACTIVE * (d)has completed/camceled all ioucmds owned by ther dying process + * + * (3) UBLK_S_DEV_FAIL_IO is set, which means the queue is not + * quiesced, but all I/O is being immediately errored */ - if (test_bit(UB_STATE_OPEN, &ub->state) || - ub->dev_info.state != UBLK_S_DEV_QUIESCED) { + if (test_bit(UB_STATE_OPEN, &ub->state) || !ublk_dev_in_recoverable_state(ub)) { ret = -EBUSY; goto out_unlock; } @@ -2727,18 +2754,22 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub, if (ublk_nosrv_should_stop_dev(ub)) goto out_unlock; - if (ub->dev_info.state != UBLK_S_DEV_QUIESCED) { + if (!ublk_dev_in_recoverable_state(ub)) { ret = -EBUSY; goto out_unlock; } ub->dev_info.ublksrv_pid = ublksrv_pid; pr_devel("%s: new ublksrv_pid %d, dev id %d\n", __func__, ublksrv_pid, header->dev_id); - blk_mq_unquiesce_queue(ub->ub_disk->queue); - pr_devel("%s: queue unquiesced, dev id %d.\n", - __func__, header->dev_id); - blk_mq_kick_requeue_list(ub->ub_disk->queue); + ub->dev_info.state = UBLK_S_DEV_LIVE; + if (ublk_nosrv_should_queue_io(ub)) { + blk_mq_unquiesce_queue(ub->ub_disk->queue); + pr_devel("%s: queue unquiesced, dev id %d.\n", + __func__, header->dev_id); + blk_mq_kick_requeue_list(ub->ub_disk->queue); + } + ret = 0; out_unlock: mutex_unlock(&ub->mutex); diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h index c8dc5f8ea699..c4512b3a3c52 100644 --- a/include/uapi/linux/ublk_cmd.h +++ b/include/uapi/linux/ublk_cmd.h @@ -147,8 +147,18 @@ */ #define UBLK_F_NEED_GET_DATA (1UL << 2) +/* + * - Block devices are recoverable if ublk server exits and restarts + * - Outstanding I/O when ublk server exits is met with errors + * - I/O issued while there is no ublk server queues + */ #define UBLK_F_USER_RECOVERY (1UL << 3) +/* + * - Block devices are recoverable if ublk server exits and restarts + * - Outstanding I/O when ublk server exits is reissued + * - I/O issued while there is no ublk server queues + */ #define UBLK_F_USER_RECOVERY_REISSUE (1UL << 4) /* @@ -184,10 +194,18 @@ */ #define UBLK_F_ZONED (1ULL << 8) +/* + * - Block devices are recoverable if ublk server exits and restarts + * - Outstanding I/O when ublk server exits is met with errors + * - I/O issued while there is no ublk server is met with errors + */ +#define UBLK_F_USER_RECOVERY_NOQUEUE (1ULL << 9) + /* device state */ #define UBLK_S_DEV_DEAD 0 #define UBLK_S_DEV_LIVE 1 #define UBLK_S_DEV_QUIESCED 2 +#define UBLK_S_DEV_FAIL_IO 3 /* shipped via sqe->cmd of io_uring command */ struct ublksrv_ctrl_cmd {