Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp749941lqg; Fri, 1 Mar 2024 23:44:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUK5FeafHaTVdRjyg5P3dfaoNklQmxt/DfkFQCdrC9o696rZkmYZyGvqhISXJ4otmpCB3KYacqaRDas8/ujzZt/400Q9Q/ze8JPr4ExdA== X-Google-Smtp-Source: AGHT+IHx64Mwk3lU/4FiVPMKrXEcglOr8a6i3j42y4JT7oUrNq432b2a9M5habXLKUXVgln1eUoP X-Received: by 2002:a05:6808:3994:b0:3c1:d1a7:eff5 with SMTP id gq20-20020a056808399400b003c1d1a7eff5mr5975134oib.15.1709365469182; Fri, 01 Mar 2024 23:44:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709365469; cv=pass; d=google.com; s=arc-20160816; b=mu1wztTVFS/MZbN3OIzdWEGj6CWU6HjTnFuYpLABXxtwiv5GNZrs85+uv/DI7M3p12 zpUa7iMYiNb3SlKg9i8hk0KCncy/o7npbCOtJz7XoYg5Z/34K4Lp+o5Td0KdGEIc5w3m Skm4VgK/Qh3D4egKlLCDrAsNJsrXpPG9SqpLj23t/vJR1wWxMQhr6ToOmSMDVDa6cLTn 0MRcIq+BqluxHxkjIguUrd2kokz53hl4Go94vurT6UJUCLK/7QEDweHIO1lQFnbOFinl Fmxu+okSQL5Bqz1EtSB/03s2sUXYW/moOHascYoibG6nCAN7ndeI6lLaVum/y3OVjXOr D8nw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MmvvXS9J0hotjKmd7nXk3BFkDw31hUfZsHqAnm1NWAk=; fh=hH2LUuYdn3AJhjdwoMCDzkNUKmE3Bf3pwLiaI6ZegM8=; b=YLJ+d9Twc6/4STWT18OZepl3tOWSp1aIClGByzraTHKwSHxyGoegQcfig+aVvblgyg VtQTtQyUQ+I4aCz4Rko3fRYT40X+HaUsLE04aaI0rqbr/e4k9FrECU/IKj4NzKaXEqSL pvkKTJsOGd0WmgYSbHwNzveXsjthGHgzScWH4msOZSQXDzXxbSwy9ZE7sdAvSgUKV6PD 2ETJ3Sw8kmjsQNLpNud9ntdhEYR2n+o/d7WhmFrSfzozvCl2xV0LbROHZ6tQ/dlRZFHC tZ4nt4ri0RvGwoO4pV24Cc+HSsVrbJxl8OK/JIt4FWBrK6Yh4wVrMLfr9Wk5sru5QeN8 Z05A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HPoK+sXQ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-89349-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89349-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h25-20020a632119000000b005dc816e3080si5110979pgh.12.2024.03.01.23.44.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 23:44:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89349-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HPoK+sXQ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-89349-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89349-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CE627283895 for ; Sat, 2 Mar 2024 07:44:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 528F618E1C; Sat, 2 Mar 2024 07:42:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HPoK+sXQ" Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) (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 D703218059; Sat, 2 Mar 2024 07:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709365367; cv=none; b=LduN4ABZ7QPeLyuWnaNM6Fd9V0tDe+qj2ArUMFS+FyySUeNVO4Zt6tJdQ/Prap70nMjcDms5UWcwGYtW4VDIoibINT3nwRg6XuZUwcS6PKqb8XZmH3DBlLsVPCU55PtaAEmro9XCDHoOILU0KdvC+pNup+JrvdElU8AQxNrVZzA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709365367; c=relaxed/simple; bh=XccdQgbUgEfTrYjCxrgPLToybofUT8Nn97GdxSvqImc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=euFd6ucb+Yg7+BUygYNh+zE0Z3hHAoTcnLbOWgzRjwcezAP3fNeB0QlI0wXDmZECGJVN1pqk2kwjvo6S0dAomOaFDvUFT5HfGMFOuYOfH69Qc5WP0veNUVNdN5g3jopwlBpsQyD6sPhl7zig89zhIAPW9i4vA8DmxsaWsECKL/U= 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=HPoK+sXQ; arc=none smtp.client-ip=209.85.160.43 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 Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-21fa872dce3so1203047fac.2; Fri, 01 Mar 2024 23:42:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709365364; x=1709970164; 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=MmvvXS9J0hotjKmd7nXk3BFkDw31hUfZsHqAnm1NWAk=; b=HPoK+sXQwBYyISFknHPxG2QoERx2lq6Z6PW8pXOvNowJfSN7lx1bi8iUCrwsLc6798 wPtk3zfoVD5J+m/+tCi97AWAzm1fM7meGU11Ibi9tIc8wWa8qiZ2Uy4tyS5WjkDXm3H6 AX6cck9M89+rpOGqVXC8azvLZXMVLLmLAT8YKHlkOybREroH1bbtSVCemXdQI1t6BvxC CtWkmGZVUHhS4jFmcikCKEc2pQaThBm+PlJTcnw0M80svpnH6r+LNA3G/uwbkTqg1+Tq cqUuUqrBzollsz9pn4/MUPkxOY2GXbV4FyBYJP/HqMkHR9MrWpJ8yG+vDaicMIFrW2zh KTMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709365364; x=1709970164; 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=MmvvXS9J0hotjKmd7nXk3BFkDw31hUfZsHqAnm1NWAk=; b=bbbHZlhrRZuFvtCn4+L1klm9C/l7Zsqzm1htGL0ZAkjGOKa2lqXVlZanu3uj/IePki Y2o0J14RkCoEgoxMgQQ+JvvjsoQQCIApYC13mfoWHItoKWLuMUcAWkvGkmCcg3HuXgDY 5Vk3IpNo9xXMuMjJvqLhniNSGI78UobEvUp0XHKjRqVIWnbsDhhL+ezObwRg4EsuZlWp FFKyNwNkKyT74iomZTmYYVXLE6iS+oSpPTF9UdMurXuIVNi1UgIyZwOu9ZTNxkrirPhs CFNxuP49b+D5/fTRETD3f225rhgl681X9WgdRW3LUbjacOtq0wSUDbNI88T075R8Pv+2 MMMw== X-Forwarded-Encrypted: i=1; AJvYcCWJbF9GyZP5xAvVrZfcLakDkOhLu3ggy9z91aZChNng5dLcOhNL4O8uDMEwLXAZ2ASfVqbHt4NxqzcC8HUD0Bb067MMtitKsnMSjb5YKJgvdG5nmzgdNxP3hALQIjPiTsQfXh72wI3Vcg== X-Gm-Message-State: AOJu0YxX/kTkiwqBu7sB1jzBnsG6HotwOuG4Yc8wT3BIraQ8NuH5JAGB s+c0QYXKsD1iMxSRXIzxG04kwwtC7c5Y82dKOUiieWZAfk5QB+GfRMEremw/ X-Received: by 2002:a05:6870:c142:b0:220:bf55:b12a with SMTP id g2-20020a056870c14200b00220bf55b12amr3871797oad.38.1709365364048; Fri, 01 Mar 2024 23:42:44 -0800 (PST) Received: from dw-tp.. ([49.205.218.89]) by smtp.gmail.com with ESMTPSA id x11-20020aa784cb000000b006e45c5d7720sm4138206pfn.93.2024.03.01.23.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 23:42:43 -0800 (PST) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Ojaswin Mujoo , Jan Kara , Theodore Ts'o , Matthew Wilcox , "Darrick J . Wong" , Luis Chamberlain , John Garry , linux-kernel@vger.kernel.org, "Ritesh Harjani (IBM)" Subject: [RFC 5/8] ext4: Adds direct-io atomic writes checks Date: Sat, 2 Mar 2024 13:12:02 +0530 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: <555cc3e262efa77ee5648196362f415a1efc018d.1709361537.git.ritesh.list@gmail.com> References: <555cc3e262efa77ee5648196362f415a1efc018d.1709361537.git.ritesh.list@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 This patch adds ext4 specific checks for supporting atomic writes using fsawu (filesystem atomic write unit). We can enable this support with either - 1. bigalloc on a 4k pagesize system or 2. bs < ps system with -b 3. filesystems with LBS (large block size) support (future) Let's use generic_atomic_write_valid() helper for alignment restrictions checking. Co-developed-by: Ojaswin Mujoo Signed-off-by: Ojaswin Mujoo Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/file.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 54d6ff22585c..8e309a9a0bd6 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -400,6 +400,21 @@ static const struct iomap_dio_ops ext4_dio_write_ops = { .end_io = ext4_dio_write_end_io, }; +static bool ext4_dio_atomic_write_checks(struct kiocb *iocb, + struct iov_iter *from) +{ + struct super_block *sb = file_inode(iocb->ki_filp)->i_sb; + loff_t pos = iocb->ki_pos; + unsigned int fsawu_min, fsawu_max; + + if (!ext4_can_atomic_write_fsawu(sb)) + return false; + + ext4_atomic_write_fsawu(sb, &fsawu_min, &fsawu_max); + + return generic_atomic_write_valid(pos, from, fsawu_min, fsawu_max); +} + /* * The intention here is to start with shared lock acquired then see if any * condition requires an exclusive inode lock. If yes, then we restart the @@ -427,13 +442,19 @@ static ssize_t ext4_dio_write_checks(struct kiocb *iocb, struct iov_iter *from, loff_t offset; size_t count; ssize_t ret; - bool overwrite, unaligned_io; + bool overwrite, unaligned_io, atomic_write; restart: ret = ext4_generic_write_checks(iocb, from); if (ret <= 0) goto out; + atomic_write = iocb->ki_flags & IOCB_ATOMIC; + if (atomic_write && !ext4_dio_atomic_write_checks(iocb, from)) { + ret = -EINVAL; + goto out; + } + offset = iocb->ki_pos; count = ret; @@ -576,8 +597,15 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) iomap_ops = &ext4_iomap_overwrite_ops; ret = iomap_dio_rw(iocb, from, iomap_ops, &ext4_dio_write_ops, dio_flags, NULL, 0); - if (ret == -ENOTBLK) - ret = 0; + + /* Fallback to buffered-io for non-atomic DIO */ + if (ret == -ENOTBLK) { + if (iocb->ki_flags & IOCB_ATOMIC) + ret = -EIO; + else + ret = 0; + } + if (extend) { /* * We always perform extending DIO write synchronously so by -- 2.43.0