From nobody Mon Nov 25 12:50:07 2024 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 CADB017C9B8; Sun, 27 Oct 2024 18:17:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730053071; cv=none; b=r5e+7xHKSSxDVzoL8po0BQElpvfn/pY2v0jg9fR/IQuOccd9q1Oi6fdN4J038DObQZ1a9hRN58vm82Hp8PK/UWORV4R87nKfrlXYElyxb3PGLVqJOGPbbtGks+3JnHqx+GOG36Wxy0lPW35rRDOQF7KtrwqCKv1eIhBq+7FdQho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730053071; c=relaxed/simple; bh=E4kn5FAkWbJ6k/m72AWp2fMttsJ6jfRJvG48Jo6+ghw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fdDRtQRYqHzvBeBDTbvrWrflyQPo4cgdT9z2ZALZ5VIxaeG/zNcc5Rm68RmhkhQxEfssl+MLtJnxRzK+MVsFCcn7xrecB3hYYfNKWD7JaXrm15x8otp7cLw0x23mw5j5l/S4ykDYorPHesU34/bcw37D1pHqjWLdnByzO462+JI= 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=VflNNE5p; arc=none smtp.client-ip=209.85.215.172 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="VflNNE5p" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7ed9f1bcb6bso2316457a12.1; Sun, 27 Oct 2024 11:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730053068; x=1730657868; 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=PpHmwu2LSyHM8Uyjkn2fhaNMGmMYwEF858nXYCRWd/w=; b=VflNNE5pwCrMpHKJQQ88pxVMcU9KuH635wuRyQUZ1aEVNWhba+ofNXG+DarW5LYTcV oU+2gOT9q26pUOuVRBbFrZuVEXLC9lIJxLbtpmub0Ke7Na3Le/GHn7UNJEy1zrNA8SqR zekox7oOOdiPj2A0u2dwJPcAIx7TBvMFPb1G2uuMA5gqrNLmobSKBYDnAV4l4CemSDhq r40IeFuNqVAMg6sW7EaeUHYkkH6DI0/RuOaA/GGgIbptRexjXT2e28g+WUAxcQg0JE84 /0x+esy8vMM2vNYRLQDkP3iimBvQrROYmMxI4CUMozHY2fTY/5YIOLQc32dspeC5b7uR MV4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730053068; x=1730657868; 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=PpHmwu2LSyHM8Uyjkn2fhaNMGmMYwEF858nXYCRWd/w=; b=IPmYsJzIUizJAIAIrcwJC9nfi8HLXwOmTSe4QYO77yILo8EnZ9OvbIV7i9GHXUbeGq 2vsm5+uh3AtfhSb7Bc7lrOK3w+zGC1+SALmOVHKjywa9vDKvi7VDtOqIWzneNdjgf582 gU/oVLZVkj987NIUBXwBf72m6/NYY96JV55QfcdRdmEcM8PnIm4IpS6xN6/5sY6FaAQV 7dfPvhTuGX2J6dypvbr65gRT1lws+pyFwrsc3QCS1t+xFq/ihRtPQoGKk+8euJZ8cwmX N5prSlreKkZw/BUyip6vIhB+Dla6xTT1OA2S01leNz56Mn0HUd02EEz7Twr+64dDkPOm saeg== X-Forwarded-Encrypted: i=1; AJvYcCUaf9uFAGoI1h4XcbzSuvH3Gx0YiVog+KVZBmJ67kb+8QVvz9/MDaPOMkbdN3nptlfID/ygRKPZzAKg5H2X@vger.kernel.org, AJvYcCX2ZJ2xc20sKZliNmsNa6M9FvlpX0YIW+AQYMhsC2MlchHIBWtbWdLxTxG8PR8hrGA8exbB1rINOe7PYR2y@vger.kernel.org, AJvYcCXWkN/yVfyo7FIMpaK2fy/eLZbayw82I0qZLBPgWBrb0RMN1hYi60lesgLdQTCVsJNT1o9vAaxMTTuZ@vger.kernel.org X-Gm-Message-State: AOJu0YynD3LXvP0y549dKlW8luObIO+OKVAxnCZ6AYNWPRvEP9FLXod6 Rqtd8fdu5397Q2hDGzoe4FcBrlHDBdkk1GS3TH+nvAsCcVy7MWOsnujzUg== X-Google-Smtp-Source: AGHT+IGvGfEMuByImWk7dMpw3CXY3ZTVR8Qehtc38AAIoQWocV5rGOtQODxOlH0cp6oPATUnfEa+ZQ== X-Received: by 2002:a05:6a20:43a0:b0:1cf:476f:2d10 with SMTP id adf61e73a8af0-1d9a853b55amr8075328637.49.1730053068069; Sun, 27 Oct 2024 11:17:48 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.83.19]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc867d0c1sm4306492a12.33.2024.10.27.11.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 11:17:47 -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 v2 1/4] ext4: Add statx support for atomic writes Date: Sun, 27 Oct 2024 23:47:25 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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; =20 + /* 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; =20 @@ -3855,6 +3859,11 @@ static inline int ext4_buffer_uptodate(struct buffer= _head *bh) return buffer_uptodate(bh); } =20 +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 stru= ct path *path, } } =20 + if (S_ISREG(inode->i_mode) && (request_mask & STATX_WRITE_ATOMIC)) { + struct ext4_sb_info *sbi =3D EXT4_SB(inode->i_sb); + unsigned int awu_min, awu_max; + + if (ext4_can_atomic_write(inode->i_sb)) { + awu_min =3D sbi->s_awu_min; + awu_max =3D sbi->s_awu_max; + } else { + awu_min =3D awu_max =3D 0; + } + + generic_fill_statx_atomic_writes(stat, awu_min, awu_max); + } + flags =3D ei->i_flags & EXT4_FL_USER_VISIBLE; if (flags & EXT4_APPEND_FL) stat->attributes |=3D STATX_ATTR_APPEND; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 16a4ce704460..d6e3201a48be 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4425,6 +4425,36 @@ static int ext4_handle_clustersize(struct super_bloc= k *sb) return 0; } =20 +/* + * ext4_atomic_write_init: Initializes filesystem min & max atomic write u= nits. + * @sb: super block + * TODO: Later add support for bigalloc + */ +static void ext4_atomic_write_init(struct super_block *sb) +{ + struct ext4_sb_info *sbi =3D EXT4_SB(sb); + struct block_device *bdev =3D sb->s_bdev; + + if (!bdev_can_atomic_write(bdev)) + return; + + if (!ext4_has_feature_extents(sb)) + return; + + sbi->s_awu_min =3D max(sb->s_blocksize, + bdev_atomic_write_unit_min_bytes(bdev)); + sbi->s_awu_max =3D min(sb->s_blocksize, + bdev_atomic_write_unit_max_bytes(bdev)); + if (sbi->s_awu_min && sbi->s_awu_max && + sbi->s_awu_min <=3D sbi->s_awu_max) { + ext4_msg(sb, KERN_NOTICE, "Supports atomic writes awu_min: %u, awu_max: = %u", + sbi->s_awu_min, sbi->s_awu_max); + } else { + sbi->s_awu_min =3D 0; + sbi->s_awu_max =3D 0; + } +} + static void ext4_fast_commit_init(struct super_block *sb) { struct ext4_sb_info *sbi =3D EXT4_SB(sb); @@ -5336,6 +5366,7 @@ static int __ext4_fill_super(struct fs_context *fc, s= truct super_block *sb) =20 spin_lock_init(&sbi->s_bdev_wb_lock); =20 + ext4_atomic_write_init(sb); ext4_fast_commit_init(sb); =20 sb->s_root =3D NULL; --=20 2.46.0 From nobody Mon Nov 25 12:50:07 2024 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 AFE2A17BB32; Sun, 27 Oct 2024 18:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730053075; cv=none; b=DQNWT3MA0s0lRi4XM+/gYDXt7IH3wMsENdYZ/CKaCkTsLk6LSugv0VQWACZ+912PPlpLqah+zoDdc4G2/iPj2aP/s+mMZwyBH0VxAAjdSH98hv2wo4VkRTSHDH8iinL6fAgz4ulM+gGayuN/WlPOt8JTm4AYFhV3MNoEl8PsRrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730053075; c=relaxed/simple; bh=lFlE2lzdud9Wm5BYL/80r7Eoxs5vlCkkI0BDXowyjxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KLq77IwaoWaXqy/5K+fhbUJ/Nf7t5B7n8YFUB6x1MlNyWcop5yK4i5KHQejp8UMGL7OCAlN1oJv60FYrmtYd8IS//67ox/ofmI/XU65WUoUxV/lLXV0uo9hovf58KQR8U8nTUMI+uc2hqbK1gMNSd6tW42MccQEtrwiT8zcq2GE= 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=EVrV57y3; arc=none smtp.client-ip=209.85.215.174 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="EVrV57y3" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-656d8b346d2so2312371a12.2; Sun, 27 Oct 2024 11:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730053072; x=1730657872; 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=bIG/VePA94ngMhv++GpkFcjTMUbZokWtpy9DDHaG6pI=; b=EVrV57y3xP3kAno7p7o7JXpNDBlP0CUTm0+2GsWFWRNW/tNhaqKhH0EIuagKWzFcv0 DLwrnCXrwYxZrRSh/ve8INgeixlgXbgSmDBPAZSNaMUMnTFL9e5sGSyX3rdbsyeqToMo y+RhtWJb9XaWrb0Hfm1UcE21fvIKdsMrCGqdFjatcL3I+HqeRjIktzYOeu9yBDqbbbUu kGWJq2zG2MG4NN+4o9aSfba216NKxJWiTc472/X4JyuLm4QhELMYOcB2IqUf7RP2b+Co 0xvkU3HTB3gwqSNSBTMOwOIsIsvx/BROo8gLNZ78RSokOF0HnlhbZU04tlS1gOPQVq+L s30A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730053072; x=1730657872; 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=bIG/VePA94ngMhv++GpkFcjTMUbZokWtpy9DDHaG6pI=; b=EmaNz9YYy7E5JVIcP1xw1yGpBdxjc3Y1wqlZT7nv6/9bdUizgwhrMk62cOsF59Qr0P P/jLY5oA3OJ5zjVgCjeIZOS8alR1cieYHauAYWVgma09AR8NxLecgbVa4uPQTiVwC4bl TENd6Cs6vvG9LzAXKf3m4s0/V2EWBt8Fm9A5ShNzmZyKgwYzYOTpjq4SqjHHV32L8052 reZDgewtlGMSvwadPV0GRAAJLHl/7jdQ3SpucNgxeKqKXSfy9kIoyCRhxSwu6oVtmJbv LDr6v5ZexSRaeEX6WeUuOYiVcidzip62PTaVNF38unKG4FDZE0+XUKfsFewfv+4vpj+/ kxDQ== X-Forwarded-Encrypted: i=1; AJvYcCUjaRNBk84ZJEygLSZ/BJ6GKSyQrRplPmn429hdy+/P+2DZIgEp1duZ80YXspCpA1UOi9d/rW7Vd0z8J7GP@vger.kernel.org, AJvYcCWI5uxkc5x8tk0i1bL5F/3rdoIkv4kdcV1S31oMkk/fUtOiB7tWi+fnEK0X1RUQRUt9EsXc5GHEoe/k@vger.kernel.org, AJvYcCWR/EuxQNyKnmOGJp06B4PGCKQT8hg8MCIm3LmUALUw6WE5WDgMH7gz4yzMPofYkAui7WF74V9VoCWexB5z@vger.kernel.org X-Gm-Message-State: AOJu0YzQ5ZU2sNPXPgQTD3nWsOYdfciR2bDcxwTQ6YiVclIahypP+Zq3 cc2id+x8yHZOnssGEzgHFHMrs81WW7EPuBsndpXqP5c7mdOw0svHaDAEzQ== X-Google-Smtp-Source: AGHT+IG/BR3q47H84KcJI2JvB5THMdtv3sxmNpwtaQz8MQ9YIWXUarEAK1UqcT36wBQMt0varbGCEg== X-Received: by 2002:a05:6a20:d98:b0:1d9:1858:2f75 with SMTP id adf61e73a8af0-1d9a84b8ca8mr7765626637.38.1730053072101; Sun, 27 Oct 2024 11:17:52 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.83.19]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc867d0c1sm4306492a12.33.2024.10.27.11.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 11:17:51 -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 v2 2/4] ext4: Check for atomic writes support in write iter Date: Sun, 27 Oct 2024 23:47:26 +0530 Message-ID: <78ce051e4a7e9a453a46720da76771c21691b162.1729944406.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: John Garry --- 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_it= er *from) if (IS_DAX(inode)) return ext4_dax_write_iter(iocb, from); #endif + + if (iocb->ki_flags & IOCB_ATOMIC) { + size_t len =3D 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 =3D generic_atomic_write_valid(iocb, from); + if (ret) + return ret; + } + if (iocb->ki_flags & IOCB_DIRECT) return ext4_dio_write_iter(iocb, from); else --=20 2.46.0 From nobody Mon Nov 25 12:50:07 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 9FEC6185923; Sun, 27 Oct 2024 18:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730053079; cv=none; b=SQAa5d4pE1wdH5nQ5ZuyPhnazObVq+UTM/B5xoQmBROvndF22XQA/Ec+i/ATs/IKmsHSJdNnPv1sRRpJG1cNnSKICShT/9Ex4jv4oulItlRMVIGtWBQuPsI5LKgBRhC+UULqjQygjtmJMlQLm+MAtqUdGyQnny7ng8MxJ4MEvW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730053079; c=relaxed/simple; bh=+Kq9Z5tndx7d8My1EDcLmC5OkXd+eYGSXICBqfZJQm4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r0uZxkaGQXXMX3ru4vnq9Dy+5Aw0JdDUQru2iZipqc7s549mIxg463Q8xEnau0H1+/6+jhWvjF751YYra4DptBEI0efPNvIQw9Qwn7PSeP3YYVEY68R2r01mlYBUcR9CEslHvKrpjD81jc5KttE0KQgsciUxOwZkWv9QUgjHXag= 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=b2TJoZjF; arc=none smtp.client-ip=209.85.214.181 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="b2TJoZjF" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20cf3e36a76so34742365ad.0; Sun, 27 Oct 2024 11:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730053076; x=1730657876; 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=i+h3NnvEkUh4JyGQi7rGno9Md2mADF6L0JRgif7uwPg=; b=b2TJoZjF+IoKU86tTS0dZnpEn8yjVB0PliAiw094netDiLzNx9pimt1rG7IpVfm/WV tzdGkrBZCfs3SrfcGoXO0K8RsfjQEGl24wR1bH8UDSIubnMnqeYK2N51droPW5tM+ykx rnK23RTibDRbc9J3ojZXFz7C+UgbcmNt/Xb44i4WgW2unna703olggI/rx3qaRRC3C3g 3xRNmVe57DYYT++fM+4m0ggOHTp76ZjDjn1GTfWHRXSxFmgfoGAYsfxZtewUHhthBJHf bHi7ar4tt4urvRyfA2n2pzu+Lz0wK+AxI1Q6OquGPFl37QpnCKOOoKnz68ipkGlTQTrY moXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730053076; x=1730657876; 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=i+h3NnvEkUh4JyGQi7rGno9Md2mADF6L0JRgif7uwPg=; b=i/M4Ww0sYoadtZjLPXb9YFbOw0u3gkJuyjcG4Iu5AuK2nx/SdRetpBwr85gCIZKAox t1RBI3K9dPKR6tiC4Ls2NaJbLkUynqjDmqp334K3SV5Q6T+e7NvBjDqqsyyd7xqaVjmR MqNOJbXp9QBgcDxNSwUt6VromYD0ENbIYfZixygR1EZVM3o+Oy1AgFFXO52SFCIa9iT/ J54FWxed1bzkdhiqhUGp7Pl1XXqQEj2/+OK9onhh+bTA1q2KapQfoITme1/hX5QBJ25j bzsiYUv8yEaLk/+N73QwAA69pBOElIn8OVirQ02M3Or+lbpmiPCzLUjssn2rklH2BtKm 3rog== X-Forwarded-Encrypted: i=1; AJvYcCU9Q73KgFh6DCmrdv/iR7YMai/3F+wfeHRtUBHo83OBrMH4gK8uxjpWKgkduC6k98qixXTLlvcw565TKtbD@vger.kernel.org, AJvYcCUrpvZlCatyQz3hxqz7aKMVGHFwzESWa+YlFj+Veqrft6PbR0BQXrT3raJpQd+my3EONeohqYKmsqZ67+Np@vger.kernel.org, AJvYcCXUfCuhCbGXFSTbqfpEwtrVU6vu9t56yk/yiBYHKsvyuH2HKQNrVK0nLFi+Xl1qfw1xBuH0IP4Pw8fc@vger.kernel.org X-Gm-Message-State: AOJu0YzxyW99MCgs4jdvT3vkh2fDekhoZwY15bC6zytS5kb/n5r+pxLc mlfG0N/msjLkM8wpa65rb1PdFbQzM85VPQJYsjQpPrPRIWMZS9qt755D9w== X-Google-Smtp-Source: AGHT+IE6qvy6/jDGpnieNnqa5gpNIZJ/VGzknEc5hpU86jWBQ91TiI3g8sAzXPXYI8QZZG0akBE44Q== X-Received: by 2002:a05:6a21:6282:b0:1cc:9f25:54d4 with SMTP id adf61e73a8af0-1d9a84d9ddfmr8080021637.38.1730053076059; Sun, 27 Oct 2024 11:17:56 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.83.19]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc867d0c1sm4306492a12.33.2024.10.27.11.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 11:17:55 -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 v2 3/4] ext4: Support setting FMODE_CAN_ATOMIC_WRITE Date: Sun, 27 Oct 2024 23:47:27 +0530 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: John Garry --- 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 f= ile *filp) return ret; } =20 + if (S_ISREG(inode->i_mode) && ext4_can_atomic_write(inode->i_sb)) + filp->f_mode |=3D FMODE_CAN_ATOMIC_WRITE; + filp->f_mode |=3D FMODE_NOWAIT | FMODE_CAN_ODIRECT; return dquot_file_open(inode, filp); } --=20 2.46.0 From nobody Mon Nov 25 12:50:07 2024 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.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 ADD15175D4F; Sun, 27 Oct 2024 18:18:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730053083; cv=none; b=b126QtEfOAeXfsMhe9hX7ukoZzth01Rx7RV6VRiFmUHN7l3RQMlRYzMxr0yh3z5/wYK5K13HzZeYvUzzWmCP8DConvYa2m34MMlYOAzpTz9+kXuD9pfwaWndQAcrkWSZUAq5zNPMV4tePY/POAJQhvFs+/AnD2hw5ja77jReGMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730053083; c=relaxed/simple; bh=kzZEMQtGjT3xUvEAgHBfB/Plmy9itmDznejbLu1l7yo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VGUuerI4ovDzMal0G7468tJn1pYhPa8yI4O0jaV9crGjZtTbiU4UkpIZ5kl7MYVId2+S9GAeVr0M+WXDgMMEJLqsL1z2JlhBPlM3apIEJGjVL9GspRNisC8OGtwOHzBmj4lxLwkBdfCaMpQHTVaums3AD1u8nHruK4pdVjKG3pw= 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=fe02/s6E; arc=none smtp.client-ip=209.85.214.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="fe02/s6E" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-207115e3056so29127435ad.2; Sun, 27 Oct 2024 11:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730053080; x=1730657880; 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=NHyJQcVgH8e0oFFdgLIXEiGBIAl5grLOxXR97atkfWU=; b=fe02/s6EK3Dhoqh6+i/38MfVtPrauywLohVUm7lxjHgdg5k0PKRrK3rqmZnu4Fmf/w UDjF7tLKR5eHP2RbL0bhqueCHnFlc8JZJEIfoM+gXcSiZX96MQjqFg5UymE5dIV4qNVN TihQ5D/sreHl/DQCVXl3TZLGLNxUNwpHIC1KJHAVNw/tCBP6GeQ5D965Dwg2GsA8rVaP +wqwy48eUduxxqCRlkaMjbRsArS+MbQoybmR1RbgmjSzPU2FlxLtTEssL5yGZlYC8NDf bFFGaBXtsI0MvuWVMVzFnIF/tlgdHmXGHrKw3Py5UQyeS8lTdbsjsJUe2fkHDrzocF5t x94g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730053080; x=1730657880; 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=NHyJQcVgH8e0oFFdgLIXEiGBIAl5grLOxXR97atkfWU=; b=Ua+CcUL7wtn+ynzz2JsAd/weN0NpLakXAmQH3QSOHmBWPueRgl+jcY/8IDPmj3Bgzq QIpl0pTJUAuaFK25m28dUAXwZZir/L/s4tFrMaug5hNKkRG9lJhHsIUVcLyegtRaUwDE BEGucmqsW+Fqkf8BelShYV9zAyTJlm8vUjc/WJYWyW7edeuBxEZQ2Hnix0bxy5yA3yQ7 FHJmV0y5KpOpGahHIyXoPgUQgveT3dBrRx3W5E7O3IFt1QvfiuToMoclhBo9EJfyAKUX B804jgMvg/bExhAsz57rfi5I/UaM2tGQ5Mjs8AeGSdrnF53gKkK02JKi7ahcCBP340yM JZ+w== X-Forwarded-Encrypted: i=1; AJvYcCVOvSWlG1eDHIkVzKTU6pyZtX5rZ+prUcRkjiLkJ6YW5F95FCpRmdhqW3HU3Qfz9xgoTS62OP80T/QqkvDg@vger.kernel.org, AJvYcCW0/BAHdEKAn9vgFbzSePVikXFo4DY683rG/W9Q7nfCer3lGde7HHSfd6Bqx2G71cP12+9EbSWNKyMYulI3@vger.kernel.org, AJvYcCWfJ9zjK2/dZKuSVyoH6KrAebFrE23TAf2hEKCvzPrY/R+AQCdUt7R7m/r5vMX7W4uXSdzV/p7mS/Yb@vger.kernel.org X-Gm-Message-State: AOJu0YzCbU5JMUda6BhjXyOC8aTcGM4NHSdcKTMqszUgQYsIf6ym+mA/ Vq/h95630qWS+VmVYrvY5RjfhknTWFJnL0/07ppnSoJi0ktZ27e9g6sHIQ== X-Google-Smtp-Source: AGHT+IHlK1DQGgtyzFZ/u5B+HQUDv5dmC5qOpcScmo4peyuali8RqyvqysJpa6H37hq37KZO+0Zbnw== X-Received: by 2002:a17:903:2309:b0:20c:5e86:9b5e with SMTP id d9443c01a7336-210c687399amr73289195ad.3.1730053080009; Sun, 27 Oct 2024 11:18:00 -0700 (PDT) Received: from dw-tp.ibmuc.com ([171.76.83.19]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc867d0c1sm4306492a12.33.2024.10.27.11.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 11:17:59 -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 v2 4/4] ext4: Do not fallback to buffered-io for DIO atomic write Date: Sun, 27 Oct 2024 23:47:28 +0530 Message-ID: <80da397c359adaf54b87999eff6a63b331cfbcfc.1729944406.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" iomap can return -ENOTBLK if pagecache invalidation fails. Let's make sure if -ENOTBLK is ever returned for atomic writes than we fail the write request (-EIO) instead of fallback to buffered-io. Reviewed-by: Darrick J. Wong Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/file.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 8116bd78910b..22d31b4fdff3 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -576,8 +576,18 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb,= struct iov_iter *from) iomap_ops =3D &ext4_iomap_overwrite_ops; ret =3D iomap_dio_rw(iocb, from, iomap_ops, &ext4_dio_write_ops, dio_flags, NULL, 0); - if (ret =3D=3D -ENOTBLK) + if (ret =3D=3D -ENOTBLK) { ret =3D 0; + /* + * iomap can return -ENOTBLK if pagecache invalidation fails. + * Let's make sure if -ENOTBLK is ever returned for atomic + * writes than we fail the write request instead of fallback + * to buffered-io. + */ + if (iocb->ki_flags & IOCB_ATOMIC) + ret =3D -EIO; + } + if (extend) { /* * We always perform extending DIO write synchronously so by -- 2.46.0