From patchwork Wed Oct 30 15:57:38 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: 13856812 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 5D32A2141BD; Wed, 30 Oct 2024 15:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730303890; cv=none; b=awk828LYXl9g+3WK8oYjh1R9Ceq1JNQS17vwq7b2MbL+ySa+9XlEC3jWwOMTrEZ6z11Qr+0NNqWNw22A9CXnI95750m0fFRTQPv9IWZUYnuDWo8rbBB3Vki3prG7PWWULck8hScgN6awxBmgM+VUy6qIIgZtqcc0DOBWxs+QA5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730303890; c=relaxed/simple; bh=6MLbOFxGNNLBsEeUlGAXzKJfREo9mmcLXriQUfx9u6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mt9pbAhM1prefNqe6JrG4QGEsZMkfK/oZr/kiQRIANKp7sb8LICtNt4o82PUqXH+zuEZ0qeNlMMWLfWkNsI0Og5yzbMJwz7bhCR6RPmtwVQgN1QopnbM4JHEmDnGxjGzxKGSYgSD7D780WYJ5kHFF4FTbVwppfvAaZZMGuYyaic= 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=aDdBLmrj; arc=none smtp.client-ip=209.85.210.175 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="aDdBLmrj" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-720b173a9ebso519917b3a.0; Wed, 30 Oct 2024 08:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730303887; x=1730908687; 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=1Ul6bf5oFgoo++/QZF7+fo4tu6EaEqfB4zMIyb1p9Fg=; b=aDdBLmrjRAV1VJc44Qgwj1+HBGksfmTAUBgqqlQRB7QTMB91wXcVASy83Gfv/hONLa i6bcjwK2VCYyBE98lXWcMAgypbhY+ykSBbpbMfulmjXHiGwQDStpfeeSmFRVzItgJjAb SKZY3QJdcNGeM4jQ2c7sP+JZlDwvlzC6cTHOlrvgAa3WbGlvf5QXkuFtI72eFKXtr1Tc xhDuJG9iIKvTJeK0/SuHAMjvWvABOKQi/C2xSzHQvYViF63+WWKCyV+ZNnxA/6NFLsck LExxLvYGwgjdqx+putqO8K0Kxj2sHqi+kOZL36xF6LSvvoM8i3qPS9RwomI/jIPj1DUa iULg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730303887; x=1730908687; 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=1Ul6bf5oFgoo++/QZF7+fo4tu6EaEqfB4zMIyb1p9Fg=; b=DC0hFLLJkLh3XlKSKunwyGoN/nZThVkW7B+ZNFv1ung3nvypPRufUx3D03edrwe2mS aj4hXs6GZYwOglnIKtXgUw70Z9KftKp9Lam1DLgBDhIT1kZ59EoAjzZHJilkyiOWwEME lmvgFmQEJwRQjeekTHgduIIho7+fNAUxT0HPJHCnwYW8eB9+VK6DF6iXrld8oQBfisnO 3SqwYWcVy4Lz+uW0xdgNGWF1Gnlr3O4koKlxTGiiu5q1d6ZZXs8pG/By87AQ78Bz85nY MMpKc82yvHdaBZpHdozwW7oRyfoZfU7orle13fbBtSboA+a+1PQfmD6ojFYFhG9lQWmt nVxg== X-Forwarded-Encrypted: i=1; AJvYcCUbXvK7dWL0YW9EmNEfNtBpEqwKC7Fy/rP4V/2mgFgLtpnjHZZsVCpjw2ahGSwlnWchYg1PzdK9NOZE@vger.kernel.org, AJvYcCUwVv9U2K45eZ6NcKjloWzULStmBUNGmlK9qmaQdx4egV1QVDX8FwMhnAnqmj5P0g996D2yoeWsg9BJ6CQ0@vger.kernel.org, AJvYcCW+z9L+BF5ASU31PeKzgKvOmR0kJko+prV7egPPFUydifvEYdq+z9p7fzVwrQzdYdGt4ydRg1UpQubTON2S@vger.kernel.org X-Gm-Message-State: AOJu0YwYxns4a9G59e5OsTYLbvvui8HV+Fp+UIR5gyz7wr6R2v0KJhCB Jc26f37HvEX78wsLE3Ewd4MZaOf1euce/qksE+0Gy6os9X2+Tt+YadM6rQ== X-Google-Smtp-Source: AGHT+IGKGZlS/e2tooSc2exV5oRtb9Ih5JmhMr9zJXD1y+6ScM32dz3x4uWBEm9f/ZIR5uISOqFQwg== X-Received: by 2002:a05:6a00:a29:b0:71e:7604:a76 with SMTP id d2e1a72fcca58-720b9bb3e7emr240914b3a.1.1730303886655; Wed, 30 Oct 2024 08:58:06 -0700 (PDT) Received: from dw-tp.ibmuc.com ([203.81.241.194]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f2d5bsm9407519a12.57.2024.10.30.08.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 08:58:06 -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 v3 1/4] ext4: Add statx support for atomic writes Date: Wed, 30 Oct 2024 21:27:38 +0530 Message-ID: <3338514d98370498d49ebc297a9b6d48a55282b8.1730286164.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-xfs@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. Co-developed-by: Ojaswin Mujoo Signed-off-by: Ojaswin Mujoo Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/ext4.h | 9 +++++++++ fs/ext4/inode.c | 14 ++++++++++++++ fs/ext4/super.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 44b0d418143c..6ee49aaacd2b 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 in bytes */ + unsigned int s_awu_min; + unsigned int s_awu_max; + /* Ext4 fast commit sub transaction ID */ atomic_t s_fc_subtid; @@ -3855,6 +3859,11 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh) return buffer_uptodate(bh); } +static inline bool ext4_can_atomic_write(struct super_block *sb) +{ + return EXT4_SB(sb)->s_awu_min > 0; +} + extern int ext4_block_write_begin(handle_t *handle, struct folio *folio, loff_t pos, unsigned len, get_block_t *get_block); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 54bdd4884fe6..fcdee27b9aa2 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_can_atomic_write(inode->i_sb)) { + awu_min = sbi->s_awu_min; + awu_max = sbi->s_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..ebe1660bd840 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4425,6 +4425,36 @@ 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->s_awu_min = max(sb->s_blocksize, + bdev_atomic_write_unit_min_bytes(bdev)); + sbi->s_awu_max = min(sb->s_blocksize, + bdev_atomic_write_unit_max_bytes(bdev)); + if (sbi->s_awu_min && sbi->s_awu_max && + sbi->s_awu_min <= sbi->s_awu_max) { + ext4_msg(sb, KERN_NOTICE, "Supports (experimental) DIO atomic writes awu_min: %u, awu_max: %u", + sbi->s_awu_min, sbi->s_awu_max); + } else { + sbi->s_awu_min = 0; + sbi->s_awu_max = 0; + } +} + static void ext4_fast_commit_init(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); @@ -5336,6 +5366,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 Wed Oct 30 15:57:39 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: 13856813 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 347992144A9; Wed, 30 Oct 2024 15:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730303895; cv=none; b=YgHTqqQN50IQBDpzAvWV4aaE9yF4gs6sI/kDCVFQuPfkzVejBAJ5hmXhgfrXgM7uBzGMNan2G1KXex9F1OjzD6pyUQH8IrmxN6rSgFThIem3qnpp6/6kzD2tCrIwintRNgGS58MUF8o9RkE/Kt909GMoX3Y8w61dAyxzoKIesj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730303895; c=relaxed/simple; bh=jtHSk3Bdf7QEVK6brq3Guj2iz2HsAL8mfJaVXrdn3YM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+v79cjmORzbjEStyVjdhJxrQQXtTE9/itogcicdKjm5x69mB0GKV2nAk83Hb5JET8U9D/KA3jyG14W5A9lLL93Jl/+Yps58HmC9Z9+tADjn4XrlBRH89MDw3WFAr5hJLUGVBnx8z6yrNpQAN1sBAbka2SVs+l7F+OeDh0NNxgI= 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=ZUMBPh9/; arc=none smtp.client-ip=209.85.215.178 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="ZUMBPh9/" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-7d4fa972cbeso32957a12.2; Wed, 30 Oct 2024 08:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730303892; x=1730908692; 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=yEjmZvZuZCYGHLblrXah7vS9Oj6EM5ySVORIRl0DI0M=; b=ZUMBPh9/8YqXTabK0BK/YaXPNBSFxRZQ+LmoBVxAoN6xHiBFh7DE6zaJ7trCLnmsIq Bq5J8NlOhF9WMGg1BDCK5kJkckOq5Tbw1w3WtcDFT+kQMP2OG2jRPSjrs98lUqUEQlEJ kDv/uAlIJ3kytisAzrVn0uQ9YRpIKiSGX8ab0Ws6NpQ269uzi22uAF+gj+BJaVQRNg3H GgRlsHkeybQU2rILNJ/x5avz/N9X28bkvA2DslQhXMfqPA+LgxhDxeknYTawIojH1Xbr UyNwXtR11BVGNs1QWs8oLqqskKpLResbbDWRteaQtk4p8vP1nvZw296jvyc+5fP6EBt8 yFVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730303892; x=1730908692; 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=yEjmZvZuZCYGHLblrXah7vS9Oj6EM5ySVORIRl0DI0M=; b=AMnsLHxuHmSSIjRiSNCfN9kIwm3IEpglD8/LYHGEish0GzIqXIfSS/u+QSTnJrne3F /JmpkgDpUEpmCRWIb4pTTzwWc6j5hh1/7E6P0q6MpZwHtyhmakGzNHOflogM9gpJ/cuO T4QtUU/VrP5tant0dDNVcLeVn59KIFtbMplKF/oLw14P3yCuGOlUgi4zjFa+m+NLgy3G FGMpIhyC27bXEwtQeuXMpVBZCOvS/buZqmmmZSBGcYwUlsAhobBx70i7hH8Rd5yra9GS 5lMX5PoKq3hy6pUeXXRY0ubKHxrnoIAKm5bRaSO+rN8/ttOZXtqla32ctIPrzwfK4XcN Q0yA== X-Forwarded-Encrypted: i=1; AJvYcCWDRwx4UQpKDE8x4IYVl02gqcSfJkXDV5d9nTQkeJ5vTiTCX5ZpWC6FUB/ACF4CeArZ0qsWesy9s2vPWKHX@vger.kernel.org, AJvYcCWnW2z5kdb/IdE+I/FaX/vQpWeW/OPFrW1vByR3Xgf7b/7rTY3+ym1PC/+duiJXvoitnF6N7H/jFLs/BRKf@vger.kernel.org, AJvYcCXFhDUepjrEmTO+rTYztxKZhofgup8wiUEE2EYhrspGxKhc199G0bC3NH/0IpraKSwPZ92K49y7aUy3@vger.kernel.org X-Gm-Message-State: AOJu0YzhTzM/I4lidwcNfEAp60K+EGhJk/LShRgwkTbx1pJtbM5iKPri WXrXJZqrOOERwCjwXdIAXuwTeTdy0l/8ZMinMVZs/PyzI6cBQi2SmCwdeg== X-Google-Smtp-Source: AGHT+IFEla8dSlLTzR+Z7uqPoCGGg3twqAEwqUIkBJ6jIt9bVpE2kVwAltPEVZ8rw70v1jdIHTIWLA== X-Received: by 2002:a05:6a21:394c:b0:1d8:a49b:ee71 with SMTP id adf61e73a8af0-1d9a840a378mr22285292637.29.1730303891944; Wed, 30 Oct 2024 08:58:11 -0700 (PDT) Received: from dw-tp.ibmuc.com ([203.81.241.194]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f2d5bsm9407519a12.57.2024.10.30.08.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 08:58:11 -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 v3 2/4] ext4: Check for atomic writes support in write iter Date: Wed, 30 Oct 2024 21:27:39 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Let's validate the given constraints for atomic write request. Otherwise it will fail with -EINVAL. Currently atomic write is only supported on DIO, so for buffered-io it will return -EOPNOTSUPP. Reviewed-by: John Garry Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Darrick J. Wong --- fs/ext4/file.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index f14aed14b9cf..a7b9b9751a3f 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 (len < EXT4_SB(inode->i_sb)->s_awu_min || + len > EXT4_SB(inode->i_sb)->s_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 Wed Oct 30 15:57:40 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: 13856814 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 9F2122144A9; Wed, 30 Oct 2024 15:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730303900; cv=none; b=MoPxe9u0hp3XW8Qpt4CLgwRcTmJpVMLQEb0YH+OwAfmID/syy6UB6jjP5fMfhLpsGjcjyHGlmrhN/HwBxL3DuP5p1/DbHLgI7adGy9u+uPjfCr8Z89ioH1Augj51sEPkcXpWhOEXzY2A1c0z6abGUcSP/gFScG3EJL9JV2QR1uo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730303900; c=relaxed/simple; bh=C5cMhwPytVR2EzbChVNdP2H1ztmLjkB0HGNKbS+SibA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jFsd9DK1DN7ekFBPDcdapnQEVmKKiKLIdAUAcVAEO5aYqHkMWMKnW9frP07+vIItf0Ti3mcAfkRY9dWriqPKG1+4Eyzg56tG0iOvtWY2a8BXSxg2zb0XKMt2uEfEYiz/aWn8LH+a/FsHkCEBt3ffNf6xEmNl8fPk0duXlikfoAU= 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=S32mXr4n; arc=none smtp.client-ip=209.85.215.179 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="S32mXr4n" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7ed9f1bcb6bso36031a12.1; Wed, 30 Oct 2024 08:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730303897; x=1730908697; 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=MAbLcLIUb8LSCLMQH+IQ3Pz3Cez3fTJykr77/x0LTCE=; b=S32mXr4nEGTQqlD2STasA0DeWNRE8X6RQmHLFWxe29JQZXN17JvkJeQ0yLcFXGG6c5 P2M1lR+6vNYcDx0M76p5xOqeWIJNoi2daUJKuvZqnSWq5k8aJtVYVLnTkHgZUC8vWgkj noaSacvy+H29ChLC1IINjvYTwjnw4EcPZf0txNvlHkLHI5k5q7Xej7fxPi1MSQ2DxHSy DlPJpj4EoVjb6CRX/OfXgHflqhQPWlTsuusSYvYwhgdkdTmdlfF6W1Yd6sHm75oixa0D fbH+TrsxGMENyr42seHtLRRrG4pU2oZ2gjc+6y27jIA1DkjrEeRYwHAAjMNWIgYO0syJ 4z/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730303897; x=1730908697; 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=MAbLcLIUb8LSCLMQH+IQ3Pz3Cez3fTJykr77/x0LTCE=; b=l1GwQnI0ykelUSGrdnuIfB+N5TfTdYE0ibIv+hF5BP6RZfVFLaoOlm1EzHgHf6XVbS m+Je/hgRhS/jtqbx/JnNr62uAikDpSEV42e8UQP+zrpj76hmlZl6x/XRdGk5sicgwS9P FN2OXC8e5BJ+nX0u2Z4F6yulDuo/pTmA33y9DA6J9QifdBbOjTKwMakNoj7weMfVsxcS cx0/+iQxkRjHTmvQkLXPCKdC5YPgVrbFO95FMdB5Cq/pOwDAVDYr1escdWYOgiR6R7hl INf1oS8ujO6FeGNzx+ccCO/QnJnmz7nKCgOh05iIM1HUd/V1QvOtwwxy3PUMIN7JyPqu VZeQ== X-Forwarded-Encrypted: i=1; AJvYcCVxEoEcnPoWlZlI6YdR9zeOnnAlXRomOx8ziOxhiJFZoHrtAtNNg7CE2hY82HshVvZWBzha3r6knJ3Psfst@vger.kernel.org, AJvYcCWLgIg88W3qEQdEduzp+PM7KcMT5hs61LUGACn08Sdw+QiVevB4vOrtO5DgXrWRPDSvWVhYr1sgtNvddj8E@vger.kernel.org, AJvYcCWpGCkH+fAiomFfZLdcaFQuYFX/5ZbEbBDd77dDSkwqRYf59S3go0mVwk39R+u5cFON3JPgQRQ/ku26@vger.kernel.org X-Gm-Message-State: AOJu0YxX6jFx35kY0rBvC2IgzlnBz9ZfWAGjhJi+vbhqnZ0poj21kphS f8UhOc6w7ejz3oD/OaQLB0aYq+1FPbgNpvCzL7WuxhSBdyph+9CuYJyMDQ== X-Google-Smtp-Source: AGHT+IExGVU2eIhzLtlF5oC+IwQZch6SQphmFxCHEMGjkPilr1PdurYZniIoRt/eIMWw+CYH760DmA== X-Received: by 2002:a05:6a21:164e:b0:1d9:87e3:120c with SMTP id adf61e73a8af0-1d9a851e807mr20475787637.32.1730303897299; Wed, 30 Oct 2024 08:58:17 -0700 (PDT) Received: from dw-tp.ibmuc.com ([203.81.241.194]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f2d5bsm9407519a12.57.2024.10.30.08.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 08:58:16 -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 v3 3/4] ext4: Support setting FMODE_CAN_ATOMIC_WRITE Date: Wed, 30 Oct 2024 21:27:40 +0530 Message-ID: <6324c2a6d7cda24d72cb271e2a46a0b0df721d0a.1730286164.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-xfs@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()). Set this capability on a regular file if ext4 can do atomic write. Reviewed-by: John Garry Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Darrick J. Wong --- fs/ext4/file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index a7b9b9751a3f..8116bd78910b 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 (S_ISREG(inode->i_mode) && ext4_can_atomic_write(inode->i_sb)) + filp->f_mode |= FMODE_CAN_ATOMIC_WRITE; + filp->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT; return dquot_file_open(inode, filp); } From patchwork Wed Oct 30 15:57:41 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: 13856815 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 D37BF2144A9; Wed, 30 Oct 2024 15:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730303905; cv=none; b=grvpFR5Utd67y2zZQ7hGLDXVsBpotRHpz/X8sMuq/KXbE7elSeoobZdQn1C3/VbhY6NcGBDZwo1K0NLtjO/lFeDlWTz+2t/J9fVpXACwKO3NmAu79Gb2s421UERzaBqzKfLJmkUP+EvVHmlAz2QBRpKm6yPnO2Ch38iw4wXEqXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730303905; c=relaxed/simple; bh=LzN5+Qpd7fuL14+fAVQDSNU6E/uPPJd4jhyHUUHdrXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uHWh66QC85zZh5Qbt331lRrsKhhHgw6CtTdH8uEDf9fuUbpm7rDYGX/c9wR21ECSLIMvP3F7b2UZdpjxgcg+2/UADVhKtYFTJfP/4F9HbCptkFgvriat2qg/LtnabNI1syf9lwg6ozdqQN5XSUP3piv8uH0cOJ3bYgnpsDq7j/Q= 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=jgFyGQfQ; arc=none smtp.client-ip=209.85.215.169 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="jgFyGQfQ" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7ea6a4f287bso31057a12.3; Wed, 30 Oct 2024 08:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730303903; x=1730908703; 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=pGqbYAHXK4Jd6LmiaTB3lDHwM2K50OqruyDt1hmpDOc=; b=jgFyGQfQuNT3bYW3Rj1ew3UOSOKYaaVW9yBIyAH+FR1gDRZdyvMvj3i7pkRLqgmlbK +odCCjVEdzhdTLNP3Ycl0jyZRyJe2NrOgI8L1b1m/u0Dq1R0YYxzlMwktkVpTQtCfutc eaVHnu8EKvVGFrR4l2SyOLl0rnJDzTErMkJsJGpSi68mUb4iFfuGvunylR/HO9OiGSbk hThFewh3iT3W7fHpKd30kQVsw53Vwj6GhKetTAv4hrwPm3BcFQwatVdWh15LfPppQ8O5 Wqf1IW93w3EijoGhl13ZT4NMtOY19GbtGopPGlNMoLtekoUsMCUzSw8fY4phbnGlqpml 2VHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730303903; x=1730908703; 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=pGqbYAHXK4Jd6LmiaTB3lDHwM2K50OqruyDt1hmpDOc=; b=su7FjUi6MSnXcd+N2Hz9eLjiFKi376WH4RxRaAgNkpjim6GrrPcDPYvNrULl69mbWY u1L+DsOc04bUcNVYwUhuBY8AkvPFgJMBxnsA9WZdjwvT7tdHJLXpXpg3lojqoYr69Nx0 68TPaVPXTtjtx4QAeuhlLc545Ma02UZWUYOhAKal1JHDkzdwx5bQacDMoDBwTJBAOmFb LK/aEgllqkBGJQvuF3+mfOftPQ/4V4NYU4/yn7DZAkGEjxHLedy1NzRDZ57nfiBt/2py FP3w+8esqT7DWuqnSvQzb1K2NLj/E8djv6uHHOZdSKa1j2K3zw2k4mkRDCXBoxZbk6NH VawA== X-Forwarded-Encrypted: i=1; AJvYcCViTmr0ApLpfZvuwrXxYcBBBZPjdU3bA2vmtOmsVEwa8fwwmIwMm19tXufUdZ1oVN0528h1ryuy172basSj@vger.kernel.org, AJvYcCWIVN9hp6eXz9YYvHMO119/R7g83LiVZCKv5rLxs/v7RTCiZrCIFIHg1Y5LHlYENaWj4qPuq2Br791R@vger.kernel.org, AJvYcCXIxx5h4MQgToiK+xn2FgzcOtE5t/rnP8x/buhpjoZe5S5DpqKtao217Erq4ILNQjyuWRd4B9HUqrZejMaX@vger.kernel.org X-Gm-Message-State: AOJu0Ywpa4NVrMWm8DWGpvqIDqlnzRq/RxmWKNkQLDmN++6NNvTDh0nu ifJt6mp2hh1IApmfC/lVU//EW/37M+fYnDKz5MqaYV314yYGq3WD/CCQDA== X-Google-Smtp-Source: AGHT+IERpMAKdiB7Q+yEULyTmcaK7Y2OEMDYKNAg4w67ROuwPqoJMrUWG93TXtbM1zJgoABdgJmOjQ== X-Received: by 2002:a05:6a20:d528:b0:1d9:f95:9f97 with SMTP id adf61e73a8af0-1d9a83c22b1mr19163886637.16.1730303902714; Wed, 30 Oct 2024 08:58:22 -0700 (PDT) Received: from dw-tp.ibmuc.com ([203.81.241.194]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc89f2d5bsm9407519a12.57.2024.10.30.08.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 08:58: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 v3 4/4] ext4: Do not fallback to buffered-io for DIO atomic write Date: Wed, 30 Oct 2024 21:27:41 +0530 Message-ID: <3c6f41ebed5ca2a669fb05ccc38e8530d0e3e220.1730286164.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 atomic writes is currently only supported for single fsblock and only for direct-io. We should not return -ENOTBLK for atomic writes since we want the atomic write request to either complete fully or fail otherwise. We should not fallback to buffered-io in case of DIO atomic write requests. Let's also catch if this ever happens by adding some WARN_ON_ONCE before buffered-io handling for direct-io atomic writes. More details of the discussion [1]. [1]: https://lore.kernel.org/linux-xfs/cover.1729825985.git.ritesh.list@gmail.com/T/#m9dbecc11bed713ed0d7a486432c56b105b555f04 Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/file.c | 7 +++++++ fs/ext4/inode.c | 14 +++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 8116bd78910b..61787a37e9d4 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -599,6 +599,13 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) ssize_t err; loff_t endbyte; + /* + * There is no support for atomic writes on buffered-io yet, + * we should never fallback to buffered-io for DIO atomic + * writes. + */ + WARN_ON_ONCE(iocb->ki_flags & IOCB_ATOMIC); + offset = iocb->ki_pos; err = ext4_buffered_write_iter(iocb, from); if (err < 0) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fcdee27b9aa2..26b3c84d7f64 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3449,12 +3449,16 @@ static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length, { /* * Check to see whether an error occurred while writing out the data to - * the allocated blocks. If so, return the magic error code so that we - * fallback to buffered I/O and attempt to complete the remainder of - * the I/O. Any blocks that may have been allocated in preparation for - * the direct I/O will be reused during buffered I/O. + * the allocated blocks. If so, return the magic error code for + * non-atomic write so that we fallback to buffered I/O and attempt to + * complete the remainder of the I/O. + * For atomic writes we will simply fail the I/O request if we coudn't + * write anything. For non-atomic writes, any blocks that may have been + * allocated in preparation for the direct I/O will be reused during + * buffered I/O. */ - if (flags & (IOMAP_WRITE | IOMAP_DIRECT) && written == 0) + if (!(flags & IOMAP_ATOMIC) && (flags & (IOMAP_WRITE | IOMAP_DIRECT)) + && written == 0) return -ENOTBLK; return 0;