From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 6D9233C73CC for ; Tue, 23 Jun 2026 07:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782199509; cv=none; b=bKhezd2vWUjXtp3qH9bCzXYqdXsRKH/JS4He21lpIPNvRABhpDe9JJLPEr4aF4FGpHpKYnlUYcZcIjKaBGYPKT/wycj8G6KxxusGE5jTc8hMiK98X8oQwiddaEQjJ2Wgq8JWm3AxO4o0JMQyllG52ncSOzeDeB9IukVjRWr+GyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782199509; c=relaxed/simple; bh=pi36dSeQOSTozHEmOCspgGzCWBC2YAX8boNyEEQexAE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bm6aqElAYevLkZIwwZnOl6NHhmmQ9mJ0mQuyaHm6jMYnzCWGeWPwTko2LBLu5C3BPEYV0q1fWDMiwWZfDc4fupvupCsqUKXcaSjYeSrXuTAVLJ9EcWh7SQN9o8K2sScdQC85avk+pI5J3fjclzLMQTBZBKzCLsThBAHp8XQnlvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XKkNfuMV; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XKkNfuMV" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-46019edc13dso2381687f8f.1 for ; Tue, 23 Jun 2026 00:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782199505; x=1782804305; 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=WZwDk65SlHZMpofHwuZQxVBN+KnkiDxjqYzIMhpdz0E=; b=XKkNfuMVKkNqnvOirhmAo+WqVLRFe0/7fWvBuB56r+8xlnHvayUGPoW1tz/Y7FvdBN +hOIHNQltHxi8pK8K9L6OYg10w/Dbv+TinyfVYw8DrGIZTpG9S7E5JmCksX4BFegwWkZ L+cdYVvVtEV9yhbCq9JeLjUqLh/qPOSGJG1S67w5/0/sxBaXc4hdzuEBQNWqWUEGJizw SV1Rrbxs8yiQkd6ZP+OZZDYAQDxyrqAJJL1YmuQDPCf7XWqqOYl7sWuMlBA/UJCc3aRi SHhtnJK4EXc5+a/zRJRk5R9WiL2QA6o38JTBv0cHdNfXqDMhItv2N+W8eGKnbZCtpAvf LnDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782199505; x=1782804305; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WZwDk65SlHZMpofHwuZQxVBN+KnkiDxjqYzIMhpdz0E=; b=D9vblKdPZhHN0aTxoF2Ky5+T8zCr6AFDjHJXH0Dc6Qg6BLI1Y8oH2hnzl6F9DB/hNc IgYX58lS7+dSD7CtE9GXSrMnrjK35INqNtUn9crtNz3uhKlr4t7CeKfFSiEPkHp1fqQB qG29ReZipemk0PFBu+hGUpv3pUznqoWQUsZXTtzwKrqE9r892gVcpaBKXw9ZbNZO7V1t 3ZXA4F3TclFjAQIzDgsresADDZHAMRjkOr3F3VmirgeQ6gbSo9d+jx3+xIJl3v7Ig9xk TTggjjLhYicw/ZZVaGc0zT+zXMULGhCNZ1FlCTeh2sKCC0/dB/p6D3ZV4fVK/vl9I3/t BQAg== X-Forwarded-Encrypted: i=1; AHgh+RpWS5aZLvKyVbelcj+dq0dQCyD7LI6STEQM+uSA0657eGzX/tv6Rw6VZ+rtjC/hiqf4KSEFpd15IMDhY4M=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4Lo7VOhyrI0JqMAbIXjtRzGPAxcYiyUr1TA2bIFyjwseL3z1z HKlwbbWOXta5LHnE6Ze7v+gr8lNpMC/ztiYcxUlUb9r0ZlnSqxFUH7XI X-Gm-Gg: AfdE7cljVwRGQnMXuKS+BVlEFSSI+DTT1wcqZeaApFqmU+F7+f7j+B7q5I4IaWONexe JTvRLXl0qEA8BfV/HnYpuxnzFmzh4UMjNFvkqdGGCZtDHa+vf33uc0T8aocbJzMiuTT9gtR7DE/ 567u13/QHD1m6zrca1EuNXRwUyT/4T6gDynuA4Y3ryGD4dHzasE/+Bdtq7AxQj51x416zNeF+fg +dqLKmdWZws7BKKskdQjv16Jw6p8CTy35lP5OudSX0/w8cGujvrNcS24LdNsEeFDGMd7WZKkYcp /iNOQ3hzdJVCLo2n8+nlQnnKhffBlnQVq6ZKWBkb0kmL1Doj+UrnQZ+uOqufjRT/+zJfnWEANPF BxNwPznymEtNYiTPdVDQhZ7R5bjzI6Vb8LTfCLfo+AEVrZ9TuRYKszfjnCPx6e6Fb1T18QiGf0M fIRzrKyuUu/zYqRdgn3pUwRmgraxx/GaaM X-Received: by 2002:a05:6000:18a9:b0:468:607:e967 with SMTP id ffacd0b85a97d-46ad96ba61dmr2158426f8f.17.1782199504734; Tue, 23 Jun 2026 00:25:04 -0700 (PDT) Received: from yocto.rz.uni-frankfurt.de ([141.2.113.173]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-46666c57afasm34278743f8f.29.2026.06.23.00.25.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 00:25:04 -0700 (PDT) From: Abd-Alrhman Masalkhi To: song@kernel.org, yukuai@fygo.io, magiclinan@didiglobal.com, xiao@kernel.org, axboe@kernel.dk, john.g.garry@oracle.com, martin.petersen@oracle.com, abd.masalkhi@gmail.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] md/raid1: handle atomic writes that require splitting Date: Tue, 23 Jun 2026 07:24:51 +0000 Message-ID: <20260623072456.333437-3-abd.masalkhi@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260623072456.333437-1-abd.masalkhi@gmail.com> References: <20260623072456.333437-1-abd.masalkhi@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If a request already requires splitting when entering raid1_write_request(), the current code allows it to proceed until it eventually reaches the split path. Along the way, the bio may instead fail due to other conditions and return a different status, even though the request was invalid as an atomic write from the beginning. Additionally, an otherwise valid atomic write may later require splitting because bad blocks reduce the writable range or because write-behind constraints reduce the maximum writable size. In these cases, the bio currently completes with either EINVAL or ENOTSUPP, whereas it should complete with EIO instead. Fixes: f2a38abf5f1c ("md/raid1: Atomic write support") Fixes: a4c55c902670 ("md/raid1: simplify raid1_write_request() error handling") Signed-off-by: Abd-Alrhman Masalkhi --- drivers/md/raid1.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 86d4f224ffb1..8386d37343a4 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1511,9 +1511,15 @@ static bool raid1_write_request(struct mddev *mddev, struct bio *bio, int first_clone; bool write_behind = false; bool nowait = bio->bi_opf & REQ_NOWAIT; + bool atomic = bio->bi_opf & REQ_ATOMIC; bool is_discard = op_is_discard(bio->bi_opf); sector_t sector = bio->bi_iter.bi_sector; + if (atomic && max_sectors != bio_sectors(bio)) { + bio_endio_status(bio, BLK_STS_INVAL); + return false; + } + if (mddev_is_clustered(mddev) && mddev->cluster_ops->area_resyncing(mddev, WRITE, sector, bio_end_sector(bio))) { @@ -1592,20 +1598,6 @@ static bool raid1_write_request(struct mddev *mddev, struct bio *bio, } if (is_bad) { int good_sectors; - - /* - * We cannot atomically write this, so just - * error in that case. It could be possible to - * atomically write other mirrors, but the - * complexity of supporting that is not worth - * the benefit. - */ - if (bio->bi_opf & REQ_ATOMIC) { - bio->bi_status = BLK_STS_NOTSUPP; - bio_endio(bio); - goto err_dec_pending; - } - good_sectors = first_bad - sector; if (good_sectors < max_sectors) max_sectors = good_sectors; @@ -1626,6 +1618,11 @@ static bool raid1_write_request(struct mddev *mddev, struct bio *bio, max_sectors = min_t(int, max_sectors, BIO_MAX_VECS * (PAGE_SIZE >> 9)); if (max_sectors < bio_sectors(bio)) { + if (atomic) { + bio_io_error(bio); + goto err_dec_pending; + } + bio = bio_submit_split_bioset(bio, max_sectors, &conf->bio_split); if (!bio) -- 2.43.0