From patchwork Fri Oct 25 03:45:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13849998 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 02FF318C913; Fri, 25 Oct 2024 03:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827975; cv=none; b=tazsiGEtvQjwLu67uWABsPW7z1RPS8L8W2Kr12zHu5GO3mbVzOoV1XJl693NckxlNWoJs1kP0+0X+kTpxzBfsGLvuGXKIi026CMgrK4Z6OAPbzzv5YZNv3RZ5sgIfkHjXQD0u+h/RmPWwJyDL/iHBPb4e/lvVrYt74VMKiaIUJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827975; c=relaxed/simple; bh=xVExj8sHZH5uULT4cvGiGnRyhNwkdZz65CKNZZT4fx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nndFFY0FUiQFXU8IzHUIgg6LBXbGc907KqVZUyDtLkIq4dSE66HOoVHOxHfPHDiJ7bpBRfLZLvuGRLIaz1OCCnBLUtOnoOvkyBrHOIwsFvIjqqwPNhkvbahB7hqgTHjpxMFmhWy4PyPjpPTcNaZSi5qTJ8Zbb3RwR8nk4OsSFHA= 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=ba9r2xWb; arc=none smtp.client-ip=209.85.216.54 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="ba9r2xWb" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2e3686088c3so1185841a91.0; Thu, 24 Oct 2024 20:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729827971; x=1730432771; 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=6GQ8gMBVajrbBrY4WQuOAAu3ETMW067CiWzIB7SBFck=; b=ba9r2xWb7Yk2aQ4dm72jSFKBQUhbDht7Ow5N0ye855FQcWPn5uBF1mI0rGh9PqgQbs nqC764LVhGQdUDCNVLJFb0ym2ZEqTLJGOVSsn9KYXO9zZKzRKtmLGTOZJEGo/N22AuOH pjHVYZKHYk5eTKYc/dRIdq9lk9hHyxnSsDI/F2SMv5Y4VVypLlw2JAqFEGKcwLQwrcRr mQ1+oq6OoW87INKpUI1AYe5ZBQMc+qV8iS9T1N1DGDWaaJWU2lZQDMti5ssfs3pwA6nw 5ZePqNAy3YrT89dA/PiWfMojuvIxRQqOPMUd45P/6w6WQCunpXQi943cr7r1a0gBIjco 8FgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729827971; x=1730432771; 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=6GQ8gMBVajrbBrY4WQuOAAu3ETMW067CiWzIB7SBFck=; b=uXIL1dtm831c1o0oCC7KnGZIFkF4MN6nJKPqVY45PASfw0caoTDmtLIEIyvTko0HxV Gg1fbhBJfjyx2bHQ6FO6TqxGkmnDEEyar0QG+ju0Y47I2XeG3nhxy6B/PVlFXjy1o4b/ yqYvQwXpxNCYtQoonCkaJ0c5vXn9TsVFOf9cemPWU2flPVDyIyeg3TbTdlMyjU5/3zQB uRDxbL8ipyiPruniKJRRoIMi0dMdJ6KI0a5o4aKLfiXEmji8yvMhtAt9w8+omOzh1yGk 5YDl6rl5DU2b04BQNCcc/R9KRZq2KU0CxhLI2XF80iYysH6X/L5nOzacZVgFNiXiHKY6 V/DQ== X-Forwarded-Encrypted: i=1; AJvYcCUBCYRHtEjpOXqfFKZw1+G8cv7FSYs/wainxbVewdcCILCZEpje+6JwRIgz77AVOKvgcEI4oAMWJYVy@vger.kernel.org, AJvYcCUu1AO/ejpFyjeHTXWwqRQC7kG4/A2vM2Sq1mjHXqKbVVQsx69LqOH59jVbUtzKhwIUGZXAtJwKlrZAidaA@vger.kernel.org, AJvYcCV1v7R7MTBfHWsrsGv/OoMgpkdNmLNYRVZxamp4UO2bbMNYgInkIs6PxdVjjZ13yUPSyRYGGfo0xrtFR838@vger.kernel.org X-Gm-Message-State: AOJu0YxZ/75UDvGEevvRZ0Gghkaty6t4adwIAiNfu+K2Lf6K43bBVCZ/ +LU810mB8X8nbv0LX1touyHQsaHoUG60R4Lj3G7n8x+Q3amGp9BIOMqaxA== X-Google-Smtp-Source: AGHT+IGbumeN2+sOtoVqOaL0IlcYe6rLvQcQmR2eIUejioxGB/ADbwp3sejP1Cn23n+oTyZ4VY+6IA== X-Received: by 2002:a17:90a:c405:b0:2d8:e7db:9996 with SMTP id 98e67ed59e1d1-2e76b5e6d17mr9204923a91.13.1729827971122; Thu, 24 Oct 2024 20:46:11 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.85.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5df40265fsm3463176a91.0.2024.10.24.20.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:10 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , Jan Kara , "Darrick J . Wong" , Christoph Hellwig , John Garry , Ojaswin Mujoo , Dave Chinner , linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Ritesh Harjani (IBM)" Subject: [PATCH 1/6] ext4: Add statx support for atomic writes Date: Fri, 25 Oct 2024 09:15:50 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch adds base support for atomic writes via statx getattr. On bs < ps systems, we can create FS with say bs of 16k. That means both atomic write min and max unit can be set to 16k for supporting atomic writes. Later patches adds support for bigalloc as well so that ext4 can also support doing atomic writes for bs = ps systems. Co-developed-by: Ojaswin Mujoo Signed-off-by: Ojaswin Mujoo Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/ext4.h | 7 ++++++- fs/ext4/inode.c | 14 ++++++++++++++ fs/ext4/super.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 44b0d418143c..a41e56c2c628 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1729,6 +1729,10 @@ struct ext4_sb_info { */ struct work_struct s_sb_upd_work; + /* Atomic write unit values */ + unsigned int fs_awu_min; + unsigned int fs_awu_max; + /* Ext4 fast commit sub transaction ID */ atomic_t s_fc_subtid; @@ -1820,7 +1824,8 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) */ enum { EXT4_MF_MNTDIR_SAMPLED, - EXT4_MF_FC_INELIGIBLE /* Fast commit ineligible */ + EXT4_MF_FC_INELIGIBLE, /* Fast commit ineligible */ + EXT4_MF_ATOMIC_WRITE /* Supports atomic write */ }; static inline void ext4_set_mount_flag(struct super_block *sb, int bit) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 54bdd4884fe6..897c028d5bc9 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5578,6 +5578,20 @@ int ext4_getattr(struct mnt_idmap *idmap, const struct path *path, } } + if (S_ISREG(inode->i_mode) && (request_mask & STATX_WRITE_ATOMIC)) { + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); + unsigned int awu_min, awu_max; + + if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_ATOMIC_WRITE)) { + awu_min = sbi->fs_awu_min; + awu_max = sbi->fs_awu_max; + } else { + awu_min = awu_max = 0; + } + + generic_fill_statx_atomic_writes(stat, awu_min, awu_max); + } + flags = ei->i_flags & EXT4_FL_USER_VISIBLE; if (flags & EXT4_APPEND_FL) stat->attributes |= STATX_ATTR_APPEND; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 16a4ce704460..f5c075aff060 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4425,6 +4425,37 @@ static int ext4_handle_clustersize(struct super_block *sb) return 0; } +/* + * ext4_atomic_write_init: Initializes filesystem min & max atomic write units. + * @sb: super block + * TODO: Later add support for bigalloc + */ +static void ext4_atomic_write_init(struct super_block *sb) +{ + struct ext4_sb_info *sbi = EXT4_SB(sb); + struct block_device *bdev = sb->s_bdev; + + if (!bdev_can_atomic_write(bdev)) + return; + + if (!ext4_has_feature_extents(sb)) + return; + + sbi->fs_awu_min = max(sb->s_blocksize, + bdev_atomic_write_unit_min_bytes(bdev)); + sbi->fs_awu_max = min(sb->s_blocksize, + bdev_atomic_write_unit_max_bytes(bdev)); + if (sbi->fs_awu_min && sbi->fs_awu_max && + sbi->fs_awu_min <= sbi->fs_awu_max) { + ext4_set_mount_flag(sb, EXT4_MF_ATOMIC_WRITE); + ext4_msg(sb, KERN_NOTICE, "Supports atomic writes awu_min: %u, awu_max: %u", + sbi->fs_awu_min, sbi->fs_awu_max); + } else { + sbi->fs_awu_min = 0; + sbi->fs_awu_max = 0; + } +} + static void ext4_fast_commit_init(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); @@ -5336,6 +5367,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) spin_lock_init(&sbi->s_bdev_wb_lock); + ext4_atomic_write_init(sb); ext4_fast_commit_init(sb); sb->s_root = NULL; From patchwork Fri Oct 25 03:45:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13849999 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 AD7BE18CC17; Fri, 25 Oct 2024 03:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827978; cv=none; b=g8Hz/v1e4SGo3XAC6MLVp4Mux/URVqTHLxMk1enIc3HsfR4YK/y63HePpgMXm4+ZADs8FMGRlOg3XBKA9z1FwpgYzhPeisSqTwRAjqzWPseDq9HuIiZBb+dn0UgvmgOkT46YIGX1edwzekPxGZug4/hIPZQkPs1U5PtrmieyHi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827978; c=relaxed/simple; bh=XyQDkox2MNNQIUWJcrRwxKGQOX+v3b2r2qve2e5EU6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UCbnx7D2ConmhHxCFrKjXFM72gr5JGnsPBbc+qh+YP53i0yBKIBHOjyg2OmABQWb55xsGInBg3PfUsOFd4BsZqO9j/RkKxY/Bdj2oyc85wN/WqCk+rrElTcku5Iha4q5w2MkB05m24FVARU6lZb7LzTtyVhiJQfrFbyLxE/S0j8= 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=jko3EvRd; arc=none smtp.client-ip=209.85.216.41 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="jko3EvRd" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2e2e8c8915eso1189008a91.3; Thu, 24 Oct 2024 20:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729827975; x=1730432775; 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=yVU94oDYUdmKWru5SiVzYI7iG6i76KSCiLJO+AKPsq0=; b=jko3EvRduHL2C9f9pE3rNgVyahVW9GuPpmBChuK9GPNxKSSVfjZtfIY67H+YzK5r/S nO0ZS6+rcBUris4vcPNEeezJJgz9ejQySwG791+Is6kG4tSEM1SC2DacWMewom6C7Gzs +8aYKa7MymeKRStr5BDSl0aVmLQf9gjquo0K7EuytiANlRLiLMl2iCdxzFwewS9I6QmA Ein9nFuPNeHEBnfGcOppmeyUxHVbqWgfZUimT3zgaRFm2Rs3A8WhGAjifroXIGWDGaxA DfjGTg9SAv2wnOhD4gk3QNvA3IQMiau6P/GavfC8wC2dzA4Htukefc7aOuK+WUmRYBHZ C1cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729827975; x=1730432775; 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=yVU94oDYUdmKWru5SiVzYI7iG6i76KSCiLJO+AKPsq0=; b=AFnHL4pPT5SntghcKPR+NGFG5SLFI22DqFt/+/EkMny+urJ3jLOAzxUslNjGOVJtsc 600UIqipqg/9C7nDYUTbOhSWOFT68BEtA0JN5pUiKONoFEfXPshWD3ROemPQnHjytfZY j3xpwCXFCaSblF7DT2FJPcwA2snaafqFuDOp9qyLS4Ig91tM0Rk9OF59RvSsyS/8MryW tj+xVyZIJZeBDt2KsT1/c1d2jeacVhaJNf3KI37quH5/MedhgnhOdUdzjHrWjObPMSvs ZYA5+CpE6YRb3cgraI881VokaKt8tOJ6KBhUNfDA7coENuu9MMNvK+x9TVlZaZy08tTN NEzg== X-Forwarded-Encrypted: i=1; AJvYcCVBCHQHx1yITAdnOzo6uB/+gVq2NFKmtFnEgQdbz04X68fVy1NGu+REDaKRDMQDm9F+j8CgI6ivKbk11Mhc@vger.kernel.org, AJvYcCW6C8T+o7sPwhIaomM+5NVwb5dhkcFABCi+HiPp20GanrNGhZYExweKG9luyJgpFrmgGveWU9jrA0PsK1hw@vger.kernel.org, AJvYcCWjvKJZeMZdBBvnmn0FWMwjNLq5c3mf1vwymn2FrdDo8hzxj0CBBxT2+IWKoMWFf0tOr4mKuPKNayPm@vger.kernel.org X-Gm-Message-State: AOJu0YzbD7mlkjTDHTBTr+lVpMn8Lhh5dno452/ZQH4Z8/8ZH/2069+u QhwhudEXtHZJTnkui6Fa1MuR+/lFQFLoVl97W8wISFcnLuqJz8YxDy80CQ== X-Google-Smtp-Source: AGHT+IGqOWaUl4lVz3uchUPFtaT+KvqbvQ9YtJGxEE2y8Thqyp7fXT75Mw97YNUWj0FXvt/BEpbLdA== X-Received: by 2002:a17:90a:a597:b0:2e2:ef25:ed35 with SMTP id 98e67ed59e1d1-2e76b1f9cc9mr9194949a91.0.1729827975078; Thu, 24 Oct 2024 20:46:15 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.85.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5df40265fsm3463176a91.0.2024.10.24.20.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:14 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , Jan Kara , "Darrick J . Wong" , Christoph Hellwig , John Garry , Ojaswin Mujoo , Dave Chinner , linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Ritesh Harjani (IBM)" Subject: [PATCH 2/6] ext4: Check for atomic writes support in write iter Date: Fri, 25 Oct 2024 09:15:51 +0530 Message-ID: <319766d2fd03bd47f773d320577f263f68ba67a1.1729825985.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Let's validate using generic_atomic_write_valid() in ext4_file_write_iter() if the write request has IOCB_ATOMIC set. Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/file.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index f14aed14b9cf..b06c5d34bbd2 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -692,6 +692,20 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (IS_DAX(inode)) return ext4_dax_write_iter(iocb, from); #endif + + if (iocb->ki_flags & IOCB_ATOMIC) { + size_t len = iov_iter_count(from); + int ret; + + if (!IS_ALIGNED(len, EXT4_SB(inode->i_sb)->fs_awu_min) || + len > EXT4_SB(inode->i_sb)->fs_awu_max) + return -EINVAL; + + ret = generic_atomic_write_valid(iocb, from); + if (ret) + return ret; + } + if (iocb->ki_flags & IOCB_DIRECT) return ext4_dio_write_iter(iocb, from); else From patchwork Fri Oct 25 03:45:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13850000 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 BD41418C002; Fri, 25 Oct 2024 03:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827982; cv=none; b=jU/WLku2A3ByKQtA8jTK2r+LZNcTRlBZKOv8D+RlRhHbiA/3GzOQKBmT4G4MIlFYo/wCQWZ+LHdUqjipVYTl/18ag7LP8sXKV7R5rvKvFJzO5VWAn5r1O+peo9WWx4BCdx+hpPOn7hITgBI0BILBUF0gQXZeEuZ4DuSt+dvWzdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827982; c=relaxed/simple; bh=Q3hxmOKe82lS5vX342pUSY/mMSr9097HfbfclBSB2OI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IY/7lZvOfcpAI2xGn6CnsW3ZLeb34UROevXNEx4F7qxXvfLEVuVnsZvLnW+OiHO/IjUUr+sAz9xVHb9cMeiNEw6yyh+B5g6EKrE4iK+7ANPjz4Qesv17LvWXIyAcNNOdONgh11shZmgtmpDP+uonipLpnW9KOPyVZkNAqWIDgG4= 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=XGkqBSfK; arc=none smtp.client-ip=209.85.216.51 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="XGkqBSfK" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2e2e2d09decso1857320a91.1; Thu, 24 Oct 2024 20:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729827979; x=1730432779; 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=BKwoVnXKo4H7aU7EFii2WWb3tQsQ8MP2woOEWaoMknQ=; b=XGkqBSfKH0tCsncfEvIDwwdKKngL5WCnuGvrclrNl0b6OrZjtZgtO5fe34yECQE80Z Rzm1pGVeeXedUVK8tYEaioyLmjcqpbDZRHFCpfmTKOZj93KrGFbih4L9wYfaCuC2SeAN 7epnm17tpBvkrmKcOHG+OF5QpVdXGmmHTrdAXwwSA9sfZ8apu1ixeMYB1vF4aN43497f Tlu/7xk1rV++2csAqXkvMLW3JYxq5q4usgdQ80dP+AKgcI+8tkNTI0DEgwJTttmgFtz+ onzqyY8QBbQpEcT2dfxagBQRGPjGKG8nXj8PkT7u/mVkj2SEJmvOo+oHCJSGoNfrtPhw xXuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729827979; x=1730432779; 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=BKwoVnXKo4H7aU7EFii2WWb3tQsQ8MP2woOEWaoMknQ=; b=gzH0dMTOzOuE/DvmFXEm0nj0pQCK5Kk/huRBgHdLWDc2xczb/I7N0fi5mEtyLLqJ67 CgXbhKDh02TcqLSLstHXiW98NjHU/dmYEsSV5ZHSKCF+P+vt7EKHWBDnnnf4NM/JmXwz lOabFGw9e7UmhqpaQhHnUD+cv16JSd25rZSiC56Skl4MA/va2DGRBBpCitpGaJvyt5xQ D5KpD6+wZhFK0XSuQBliMW0M8WeElY0TEoqvTymxuR7z6aMRJoeKK2Mm9uJ9HK7X/OT2 MZVu6jw27/DI3eZMPQZb75hFS8MEO7stdpI13Rt7pxYm1Q/oK//GlTTNFovrir4ew58S xxnA== X-Forwarded-Encrypted: i=1; AJvYcCVNdl3qfFgQJ7ULhwRWYIUg6qDsHGZg9hWvIQntySeo1DJ8h10bGQEqS+jR+YakKrVG0bNg2dT66xuIsOr5@vger.kernel.org, AJvYcCW2dpKXksM0T0A0UL+FumX0Mu1B7L66BGd8wA/pBHx+wNKjNO7ssxyJhsb9DxTV9skQcnZuf5K8ErjSCnth@vger.kernel.org, AJvYcCWlJutMMBINFqDHsgglFy4ohKKM72nyfg4F1bSiCO9+jix8J8kxF7TOFVw7reHfAwUccYXiJOcBh5qe@vger.kernel.org X-Gm-Message-State: AOJu0Yz+vuyEFk1mjpzev8QBqI3p/2yE5hrd0VVylbysNBaFtNOJYZUl ouS0YYSVZ5Vy2QC9UlPAzGlkZnVgUNNMRWCr1gmuk2DQRZ8RdEc9NXet0A== X-Google-Smtp-Source: AGHT+IGfwm+lE3tGHnzqEpua6Rp6W0zNi1Ts7IPa81Fl2Mn9wcJO3JSxDkNBrHaYeL2o2l/KFD6JAw== X-Received: by 2002:a17:90b:4b46:b0:2e2:c744:2eea with SMTP id 98e67ed59e1d1-2e77e640bdemr6447296a91.13.1729827979024; Thu, 24 Oct 2024 20:46:19 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.85.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5df40265fsm3463176a91.0.2024.10.24.20.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:18 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , Jan Kara , "Darrick J . Wong" , Christoph Hellwig , John Garry , Ojaswin Mujoo , Dave Chinner , linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Ritesh Harjani (IBM)" Subject: [PATCH 3/6] ext4: Support setting FMODE_CAN_ATOMIC_WRITE Date: Fri, 25 Oct 2024 09:15:52 +0530 Message-ID: <921ffd8731b666b8510e56dd1981a995f57873e0.1729825985.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 FS needs to add the fmode capability in order to support atomic writes during file open (refer kiocb_set_rw_flags()). Let's check if inode can support atomic writes then enable FMODE_CAN_ATOMIC_WRITE. Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/ext4.h | 7 +++++++ fs/ext4/file.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index a41e56c2c628..78475ff14aa2 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3863,6 +3863,13 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh) extern int ext4_block_write_begin(handle_t *handle, struct folio *folio, loff_t pos, unsigned len, get_block_t *get_block); + +static inline bool ext4_inode_can_atomicwrite(struct inode *inode) +{ + return ext4_test_mount_flag(inode->i_sb, EXT4_MF_ATOMIC_WRITE) && + S_ISREG(inode->i_mode); +} + #endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG /* Bad CRC detected */ diff --git a/fs/ext4/file.c b/fs/ext4/file.c index b06c5d34bbd2..f9516121a036 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -898,6 +898,9 @@ static int ext4_file_open(struct inode *inode, struct file *filp) return ret; } + if (ext4_inode_can_atomicwrite(inode)) + filp->f_mode |= FMODE_CAN_ATOMIC_WRITE; + filp->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT; return dquot_file_open(inode, filp); } From patchwork Fri Oct 25 03:45:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13850001 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 BA15118C323; Fri, 25 Oct 2024 03:46:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827986; cv=none; b=hoKAV9r7Jv7T8j1W/Hx5ONPlVOxRD1/oE2VusWdseJEE50Y5xaJZ7a6A3vL8YLyeV0rhEZBAYCrNlzxjqI3uefl1VL/Ge+iM/Ysid2hYKhalS2gn4eMQdzkdt3trKL3uOHG/Vm3kz7xV9ybo0lxIoS8ezr//6GXcfWaSXClO/tE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827986; c=relaxed/simple; bh=7njsC75dLsWIK9qESLdPiLocC7EO9gCvzxffObpwHmI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GiRj4+3OP77PZcrjARAmFcrqyjeedD03W4dXjKYlDtZJaJNb0bP4wB3YWBTeuQq9v12Qh/lltj5gXhwkk3fh2f7s7thujSTBkmUr6gkWK4a5+t89H8rx0Qf0uYzgIhkYjBCn3jXo2tJUw5fyOC6JDIJwJ+0WrCaNbML5ddcQB4s= 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=gCJzK91l; arc=none smtp.client-ip=209.85.216.44 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="gCJzK91l" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2e56df894d4so1229320a91.3; Thu, 24 Oct 2024 20:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729827983; x=1730432783; 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=cduxLudvcfBef+EgChYG/ixsnBTuOQS7aur2v1V1W24=; b=gCJzK91lpeEMIcMKhKeimD7jchhLQufAOHG+zMZV+DPlBB7/SSzE6pU8kDJkU+azEE fm3iplmFMCpOMAJKbua/6Decm7DADEUkj2C98kGuW63PEWSMmBbxn8fHCze1/jmWKZXo 9Ndz+ab6py5vj2CTlwSnU2iAm+RqBky7Sn3j1dJNQiTmDqD6caINYV48FZdaDse9WQnf wizTqLv/YYePiaJFO9p5dkP8CFJbM6jal7blfKY2uuBzp4/k4RRcDryQ0M3Aew0rwOL0 bFz7wKggFmVik5Yf83dNMeHoQaKcAy4xhEYo1OP9t43zn0WRRQKlrDe33aEZzZKohR4U NEIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729827983; x=1730432783; 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=cduxLudvcfBef+EgChYG/ixsnBTuOQS7aur2v1V1W24=; b=Njhi5GqvAE10Giqv5jjrlFdfZTb26bfqTy4K6lnTvNLPI1Xd/jUGLx/fXe1FBXUKz6 c92D5xK5v9M1mPrBGllTcRzEIOiCfdedL9FJ8xrBXqc5uDXum6POFceZhlRZxCzzNBuB G19MIRkAWxboNObuHWVrpy9EJ/pCgSUGPbDCv/uQuUTGhBthg9JcMcK3Wt1+t1HxahXs MlE6ZfcmKfgxxkj377E1Skfej9q8vo3WW6XIYr0o04fwaJ5ZAOEW0IOOGbrPpezcOVyl biL6QeoZB/eri1rlSFhomr8dUuLesAi9LDjiNIkahhyUhOwjTknopfJKXfwK7IkSsBTz wAew== X-Forwarded-Encrypted: i=1; AJvYcCUkcZ7Hhp2BEpqX6IEfQPOVno8NCm5d5XHV3zlX0FgSdxD1xz5/Qf+WCiimVLm5WylUlRyobZh0n0Y4@vger.kernel.org, AJvYcCWSNowk21b5jt5RjF51twET/xy4gC4r03Sw4zL1Ml1OySNfdKlpu7qkTjIoaj7gEuVK6jDQOYMBIn1Zp3pr@vger.kernel.org, AJvYcCX+ezzbiPD6qTKb4VG+/Gq43UcIkwXHc2qUob0BfrNySIjG0K5ZFN8uNFX99LGjRusjKNCUI/gya1OjBvMz@vger.kernel.org X-Gm-Message-State: AOJu0YxbIkzOTWY3VfUX0gvZwxPH8Ot9jfHxWLlvY+YkgKMYqNV12H6X LgZduZPD9tr7cavqGDoZCnTxjGOrbyg1LkZNvHCZ3vZ8yn7NdNJglY3/+A== X-Google-Smtp-Source: AGHT+IEjH24CFA3MuF5TEhAscE+jXi9wvl+LVofCfeMk2E5MSUa/RSa+YoJgyuc7YA/+/aO2sLq8Kw== X-Received: by 2002:a17:90b:120d:b0:2e2:b6ef:1611 with SMTP id 98e67ed59e1d1-2e76b60aed0mr8926834a91.18.1729827983075; Thu, 24 Oct 2024 20:46:23 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.85.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5df40265fsm3463176a91.0.2024.10.24.20.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:22 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , Jan Kara , "Darrick J . Wong" , Christoph Hellwig , John Garry , Ojaswin Mujoo , Dave Chinner , linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Ritesh Harjani (IBM)" Subject: [PATCH 4/6] ext4: Warn if we ever fallback to buffered-io for DIO atomic writes Date: Fri, 25 Oct 2024 09:15:53 +0530 Message-ID: <7c4779f1f0c8ead30f660a2cfbdf4d7cc08e405a.1729825985.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 iomap will not return -ENOTBLK in case of dio atomic writes. But let's also add a WARN_ON_ONCE and return -EIO as a safety net. Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Darrick J. Wong --- fs/ext4/file.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index f9516121a036..af6ebd0ac0d6 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -576,8 +576,16 @@ 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) + if (ret == -ENOTBLK) { ret = 0; + /* + * iomap will never return -ENOTBLK if write fails for atomic + * write. But let's just add a safety net. + */ + if (WARN_ON_ONCE(iocb->ki_flags & IOCB_ATOMIC)) + ret = -EIO; + } + if (extend) { /* * We always perform extending DIO write synchronously so by From patchwork Fri Oct 25 03:45:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13850002 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 BD3DF19939D; Fri, 25 Oct 2024 03:46:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827991; cv=none; b=OeTTT5Y9MD9uFo6rJKpXVD9JbQR4iIhr+98gaYF0b+xtmMN+bMeiDb8bxh9u1zfToRo+lJFn60XNDEjorNan06wO1DZw7+qLX6oEdyPmhobMA/MynXG6KCLbeHqtiz+Bdo+3t6p7kQLtNjG+XEl4ZUpAv+8rBhw/WF1dUw2XZIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827991; c=relaxed/simple; bh=o63aZeBXY/zTOtze20RJSIco9C0hmLZ44l45ynxwh6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iktd7zc4sqBarM4YKLFmMA5TQ7I151XK91C7gG9N9ALVtiMbXV5r/85cZ4Db4kBSXCOZ2tGsbjjd7Pm55ofW1NB6jKzaf10mSqUoG1PLsQb4Aek5CpK0o6zd6HdMRCN5eDpPHvlkOPF2o2jVncIbEIjeGE142Lds2dXSr0srXNU= 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=KP92pPtM; arc=none smtp.client-ip=209.85.216.51 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="KP92pPtM" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2e2bb1efe78so1049477a91.1; Thu, 24 Oct 2024 20:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729827987; x=1730432787; 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=dCbMmlCDwdFDP22giaXn0ktZZ41Vb2DrHB5O9DWkb54=; b=KP92pPtMu1wXC3ERCQC+THy8mXCde/pwl3tk4ZiIlr8irwRIw+LYxxV2MsEEz7WHxF 3Dh5Z8O6JTDnoS2Z66owjRdg+z4QupEFhoZwuMOj4Cy/uk/zhHhWWNnYura81uaFwncK 08a+pgHjl9BIjeaNc1eFKxJaMke+b9KmJjxyrvD3u7bizyqNWw7nGzlfj+b2X7AFrNU6 OysT9BWkxwXUi7yWV9sPiq/raep/Y3wMGDcWqNRm3LiSdMcgvae3L1F6KUt/LYhwWl+F OlBP7Qq+Y4lnALPmn6YjvWnSgGjp8MDBe6mLMNOaigDOkeGyL+zMq0TltDTFu61tSypi Rd8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729827987; x=1730432787; 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=dCbMmlCDwdFDP22giaXn0ktZZ41Vb2DrHB5O9DWkb54=; b=ZfZoCDqVN7GWfqmer4zfReDpuhOPIM5pVAbuECgup/jliOMSu+0MzVrw5dkKtnlP0Q /W1DUyJItI5rK/DP0WkR6rYmjD7rPFDzqIVOCkb7ron1wqrTIIUMerI66qjbXLmbaElR P8t8AQkKmTUEtSupTE1baoa+P9/DVm7kITQBAWWKzKsX6bTuhOXITmpVcSAmzlVMW3Kv iaYzJ8Xii6/vsYlPeRscKOTMaNpF07R630CRWrdDCgyzhHGYkU2PrJMVRiov0LVDolnO FUWvPDWn54Il4b/p4YwlqfOK3yWZncxug5St/rBwYzhym45oInsHz3AEDBlGBKM7s9ol wURg== X-Forwarded-Encrypted: i=1; AJvYcCUfYXDiHqXalFO47rOhUrZbohYbX1Y8FjApu+9C2kTitB5V9CBrxdBllW+rJb61cKHfI3H5ja8oCJFnLSDZ@vger.kernel.org, AJvYcCUmGiC4JXqWkLyq9b9aO9DWFdwDshjjExq82frY3Se4nPiw9EUDznoLAbNikjkHN7j3XlfIRMz/u8fOZPc/@vger.kernel.org, AJvYcCWQYvyf7ReB/iX+gdazERdwB/qFxF7lQ0wg1h4bX+yW+LZx0azjxz8tEeyLEHDD3sspeqxiUQV3F4H3@vger.kernel.org X-Gm-Message-State: AOJu0YyuD0zNIGJyOq+IC1+8UYlnRRki+yk9lLwkgWcimVshPncpq1MU pMQ5i91FnHlN9eCvunaf4PdOoZT+B740p2zlHeqIQBmEEUx1ULNwc45MoA== X-Google-Smtp-Source: AGHT+IFAKwYiwV48LqiQb/bilCzX5cHKd8+sfJVkn41DgjX3ae+16SD3YIvvPuCMBqBidCdSRVY9rw== X-Received: by 2002:a17:90a:b003:b0:2e3:bc3e:feef with SMTP id 98e67ed59e1d1-2e77e5a707cmr6356526a91.3.1729827987017; Thu, 24 Oct 2024 20:46:27 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.85.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5df40265fsm3463176a91.0.2024.10.24.20.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:26 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , Jan Kara , "Darrick J . Wong" , Christoph Hellwig , John Garry , Ojaswin Mujoo , Dave Chinner , linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Ritesh Harjani (IBM)" Subject: [PATCH 5/6] iomap: Lift blocksize restriction on atomic writes Date: Fri, 25 Oct 2024 09:15:54 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Filesystems like ext4 can submit writes in multiples of blocksizes. But we still can't allow the writes to be split. Hence let's check if the iomap_length() is same as iter->len or not. This shouldn't affect XFS since it anyways checks for this in xfs_file_write_iter() to not support atomic write size request of more than FS blocksize. Signed-off-by: Ritesh Harjani (IBM) --- fs/iomap/direct-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index ed4764e3b8f0..1d33b4239b3e 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -306,7 +306,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, size_t copied = 0; size_t orig_count; - if (atomic && length != fs_block_size) + if (atomic && length != iter->len) return -EINVAL; if ((pos | length) & (bdev_logical_block_size(iomap->bdev) - 1) || From patchwork Fri Oct 25 03:45:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 13850003 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 62E5D1ACDF0; Fri, 25 Oct 2024 03:46:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827994; cv=none; b=WMt6PSKivEVZM8+kRIM7Pt6Gp7dhUU4qfKU1Qx5olTdVY/wDil37rmD7fnNJMhRzPgSG8cXe/lBtP5gdmLsPhKv4288rPlZokVwVojV5op7yCd5XiwWzYyivpe5o+sgUbUFwRs7twKSJV25yIh3vBO8uyzvmfMyqXM2rMd5alPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729827994; c=relaxed/simple; bh=+jbFavYt3S3M0UFG+Y++ADSwSWXABL573iBs3QaczNQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c1mCNfDLyXHfF6YuiTE/c/k1q77PtsloR6m1PUFGvqTM96xJtwUZh5zMWgp6yVVteWkTJ8NV/TX3DRp820DWGu4SxEHqPX53KIXiimJgK3wltzqWhl7xA2wI95QqkIng1ZcR4hz5ORu6c9NOZyvfEjDtmyPRDHKZq0zfteZqdqg= 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=ChVnDbTf; arc=none smtp.client-ip=209.85.210.171 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="ChVnDbTf" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-71e953f4e7cso1142968b3a.3; Thu, 24 Oct 2024 20:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729827991; x=1730432791; 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=SV8eyMIG0H3BsY07DI6PZhHnOjAhFRubne0dZ3+5bLE=; b=ChVnDbTfmGIPomXH3WduPk/qUQCxYuqG95MP46kzW0xeIZGBInLZPiUZYxhcY6ci6z 4LwiExHtP43MM2jCfJNRgEIa2gvnF2wLi52FyaWwMJE5QUHGmRqpkC4s+HNdN8w/gPSJ LCO3cEuR7boehgFJpa4NETpqB3NJkLb5R4PKzl9fbZz3NI5k8nfBNOeUaJV8g6D9E4Sh TChcb6M5IDQbWxTKpskGcwrk40zjnGvKEw3IH1IxIUamScAQVpiQXojYefcmDzuaj+C7 JDwkzMjcudYXVS0k2u34stvLP+wYoe6dMNh8KAKRd1j5r4bD0QoRpRpmGmWsdLx2zLwh fR6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729827991; x=1730432791; 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=SV8eyMIG0H3BsY07DI6PZhHnOjAhFRubne0dZ3+5bLE=; b=NyPdox3RvDLGj4DYI9zdC+t2ue1SlVsW7ss3IYFyy+X9o+yJMgY+skQnoAE1poCTnZ 1ZZNFzJkOBLd5xmnY3ray4J02hw2XTmdwti3KJuUY6pS/yTj6vETjYqUSDg7qOPoIyzi rdzmuBjgih9ccmt7R0Znb9adLuhxNcJpA/TH1AT++BbERo8pUVflj4zBiWXA2OU3vxMa 0uP9sT0dxbQbeC+qQmKe3B78TudArn0Yj2qTEQUq1pVqFutGjGDe0cIZ7+hfWFtNugHJ ewQRJXy9AoVMD/SckJQ/1KEIva6xdLv+we7fgEhciWpzCJQRQfoolgrmgypwpZ9oNJ0A 6ByQ== X-Forwarded-Encrypted: i=1; AJvYcCVV6MUPGo+wOdFGU8x7UBSa+vGpv8WVkifmaFIRA3/AkleXHQIbcgvaysFDX6VJioG4XKFrXMbIwGoA@vger.kernel.org, AJvYcCVetRgFO1FHpMm0iTS5XOV57TKBG5njWHQ0HNNGSEHQO1Y8I1LegiLVyhiXhZwNeZbHK8WAfR51sZ1wNVmy@vger.kernel.org, AJvYcCVwLSSbLcBdyZepaDT733kuUph/F4bHdaiyI8QEVCoYw8NPeVfQK56HOv2g1z4gqUf1g7r5NaUyjJVDOI6u@vger.kernel.org X-Gm-Message-State: AOJu0Ywe2gwe2ACvMYREE+4iNVm1KnILwc5fGi9oZ8/fHo8NFLsfO7fF zAVLRNeK6tZpxe0ApGRvljnYA28rLNnEFD1WZi9N5mXqQVvFosC1coep2g== X-Google-Smtp-Source: AGHT+IHNv3nj9RCbYdpMn4CGatYSbVnL4coPHNxRpjeEP5ig4aeDgBKitBPLznyv9qpb0xdXrjrzzg== X-Received: by 2002:a05:6a21:6801:b0:1d9:76a3:a208 with SMTP id adf61e73a8af0-1d978bd6201mr10915868637.47.1729827991027; Thu, 24 Oct 2024 20:46:31 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.85.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5df40265fsm3463176a91.0.2024.10.24.20.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 20:46:30 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , Jan Kara , "Darrick J . Wong" , Christoph Hellwig , John Garry , Ojaswin Mujoo , Dave Chinner , linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Ritesh Harjani (IBM)" Subject: [PATCH 6/6] ext4: Add atomic write support for bigalloc Date: Fri, 25 Oct 2024 09:15:55 +0530 Message-ID: <37baa9f4c6c2994df7383d8b719078a527e521b9.1729825985.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 EXT4 supports bigalloc feature which allows the FS to work in size of clusters (group of blocks) rather than individual blocks. This patch adds atomic write support for bigalloc so that systems with bs = ps can create FS using - mkfs.ext4 -F -O bigalloc -b 4096 -C 16384 EXT4 can then adjust it's atomic write unit max value to cluster size. This can then support atomic write of size anywhere between [blocksize, clustersize]. Note: bigalloc can support writes of the pattern [0 16k] followed by [0 8k]. However, if there is a write pattern detected of type [0 8k] followed by [0 16k], then we return an error (-EINVAL). It is ok to return an error here to avoid splitting of atomic write request. This is ok because anyways atomic write requests has many constraints to follow for e.g. writes of form which does not follow natural alignment [4k, 12k] ([start, end]) can also return -EINVAL (check generic_atomic_write_valid()). Hence the current patch adds the base support needed to support atomic writes with bigalloc. This is helpful for systems with 4k pagesize to support atomic writes. Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/inode.c | 13 +++++++++++++ fs/ext4/super.c | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 897c028d5bc9..2dee8514d2f8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3423,6 +3423,19 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, */ map.m_len = fscrypt_limit_io_blocks(inode, map.m_lblk, map.m_len); + /* + * [0 16k] followed by [0 8k] can work with bigalloc. However, + * For now we don't support atomic writes of the pattern + * [0 8k] followed by [0 16k] in case of bigalloc. This is because it + * can cause the atomic writes to split in the iomap layer. + * Atomic writes anyways has many constraints, so as a base support to + * enable atomic writes using bigalloc, it is ok to return an error for + * an unsupported write request. + */ + if (flags & IOMAP_ATOMIC) { + if (map.m_len < (length >> blkbits)) + return -EINVAL; + } ext4_set_iomap(inode, iomap, &map, offset, length, flags); return 0; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index f5c075aff060..eba16989ce36 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4428,12 +4428,14 @@ static int ext4_handle_clustersize(struct super_block *sb) /* * ext4_atomic_write_init: Initializes filesystem min & max atomic write units. * @sb: super block - * TODO: Later add support for bigalloc */ static void ext4_atomic_write_init(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); struct block_device *bdev = sb->s_bdev; + unsigned int blkbits = sb->s_blocksize_bits; + unsigned int clustersize = sb->s_blocksize; + if (!bdev_can_atomic_write(bdev)) return; @@ -4441,9 +4443,12 @@ static void ext4_atomic_write_init(struct super_block *sb) if (!ext4_has_feature_extents(sb)) return; + if (ext4_has_feature_bigalloc(sb)) + clustersize = 1U << (sbi->s_cluster_bits + blkbits); + sbi->fs_awu_min = max(sb->s_blocksize, bdev_atomic_write_unit_min_bytes(bdev)); - sbi->fs_awu_max = min(sb->s_blocksize, + sbi->fs_awu_max = min(clustersize, bdev_atomic_write_unit_max_bytes(bdev)); if (sbi->fs_awu_min && sbi->fs_awu_max && sbi->fs_awu_min <= sbi->fs_awu_max) {