From nobody Sun Nov 24 21:48:24 2024 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.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 36B9D1537C3; Fri, 1 Nov 2024 06:51:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730443882; cv=none; b=h/a1J1Hw8xGdDMd8tTVOgIeTuCJu1kyLftv4zJMz6MSeqNwMF5VTJU1iZEAVeIxA8sh7xm8mwkXCbwcM1omudn7RCSFfmPYICKDr9TA0tLwzS6/OAqEq1GP+Js9IhgoBHXoG+1SFUtKGtcp2bzAvB6455sCWc1jpX3/DobMmFOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730443882; c=relaxed/simple; bh=XzIQSlbT8rZmBw3jJxXtpbWGqfQwKAZXOe5cMvAo3qI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WtPoxAPd5bVssPWoQjmqRyCQ19Ry/tggCRFfBemAa7SfSGMv+kaPr6QAHh17yjxWBzR95KDezhLq++FwhyweQpVXVpe5KPgbMIvOUdFWjfqMhGsjeYs5/8a+fwgtsVEGh9isChuIFzotNO/E+maUBxbv1hFttatUBPH5F0AYTQs= 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=KkxNDBZw; arc=none smtp.client-ip=209.85.210.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="KkxNDBZw" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-71e4e481692so1483305b3a.1; Thu, 31 Oct 2024 23:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730443878; x=1731048678; 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=PNXaDbmxIS4sXKRquKzQnAi7UjzkGcD7RoMFUnjDnvo=; b=KkxNDBZwM3AX8lcYhuKdnVOGqHGUL5Z1UUQ2Mok60FwlB9FCC+vu6DYI+U6/2bxU71 x/ER0yitVhhGEIOlnwLc+K/v29rC8+3zQTV0+Rtg3bANk+Gv/31Zrp1Tc3X+ltYz4vwy +2xamQy/6aobj4SlwWYbyCLeAa8xUm5ZNh2XxOVACfHYBrRmM00chcHc4MYjMN68eF+4 ALhFTN8zRI8hn+DalC8oVIbCG7JO6T6DvOWN417RnQFmadaMRkRf6vWkBasYwtI4pLd6 0TjQJvpT1AyNO5uc/HOVi/nIHPQk/XPKXrvym3iTufa4NaWxuG4CCBciqpgoo4OREfQY 69JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730443878; x=1731048678; 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=PNXaDbmxIS4sXKRquKzQnAi7UjzkGcD7RoMFUnjDnvo=; b=k8+UyU1x8h6XopAASSgF3YoxYkAZzDUxbttOVS1C1cxo6+81qy2I3+Da0Xbs1s/J+I GnMzS2WJuVFTM9vTxknxhYy/RAE+Ow8V9ayFd41//XC/hH9k6ECoN+eLDAZKg92fKBE+ GTKs1T+apEhdDWN06n0aa9LoB8Qbl6f0DP9Q48XoYsICURjhO3DYuC72bXMEd7PWN9lh spM1rSqxqDNkIOww+nT72REwJBt7f/C56NdLLfqNlFDLPRaqncD9Tpy+SBKfvU2k1xrN G48BBvMJgg8IWsTG1o5SXcOoNIRpPNodLSYrP9j1RfMvG75g67SWzbEizhyvyK9f60WX tJvg== X-Forwarded-Encrypted: i=1; AJvYcCVGhcng7ltrXOkVvMbsL6WcQY7qgkT5uT5x6E/ECVSzJEHH0paOwfurxo31b8+EAAVTH1ivIcWJ2eB3UK6h@vger.kernel.org, AJvYcCXPpoUh6HtNSckEuYIOq5y4PyPmwuoR6paMEvJ3ia7K1/NVxGwOK0y0HVJIDLode0DgFgCxA4ofa4s/@vger.kernel.org, AJvYcCXWzOKWuRHUuI53CKakwmm/Fch5KbWq0HNKHqhthxqY70gPSP/swZMMhkaqiKynej5xKueL+9ElZ9dSMlAu@vger.kernel.org X-Gm-Message-State: AOJu0YydVKkEepWdKVFNYiHanrLnjQbvE5yP5xB4EwNCcx8IVqIqw1OZ J55yrYLy3o4MskkgehgT/gScuES64M60ScDVY2IQd7XdDiweXrtkdgwKcA== X-Google-Smtp-Source: AGHT+IHpeWg1bGGPI18ov4OULTnEjFNA06hTJbNl6qrrOrsjsc4z2X/5qMaK+Q2uB8S6AAZYjiog+A== X-Received: by 2002:a05:6a00:3d51:b0:71e:cd0:cc99 with SMTP id d2e1a72fcca58-720c98a1bfamr4162715b3a.4.1730443878422; Thu, 31 Oct 2024 23:51:18 -0700 (PDT) Received: from dw-tp.ibmuc.com ([203.81.243.23]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1b8971sm2196209b3a.12.2024.10.31.23.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 23:51:17 -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 v4 1/4] ext4: Add statx support for atomic writes Date: Fri, 1 Nov 2024 12:20:51 +0530 Message-ID: <0517cef1682fc1f344343c494ac769b963f94199.1730437365.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" 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) Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara Reviewed-by: John Garry --- fs/ext4/ext4.h | 10 ++++++++++ fs/ext4/inode.c | 12 ++++++++++++ fs/ext4/super.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 44b0d418143c..494d443e9fc9 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,12 @@ static inline int ext4_buffer_uptodate(struct buffer= _head *bh) return buffer_uptodate(bh); } =20 +static inline bool ext4_inode_can_atomic_write(struct inode *inode) +{ + + return S_ISREG(inode->i_mode) && EXT4_SB(inode->i_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..3e827cfa762e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5578,6 +5578,18 @@ int ext4_getattr(struct mnt_idmap *idmap, const stru= ct path *path, } } =20 + if ((request_mask & STATX_WRITE_ATOMIC) && S_ISREG(inode->i_mode)) { + struct ext4_sb_info *sbi =3D EXT4_SB(inode->i_sb); + unsigned int awu_min =3D 0, awu_max =3D 0; + + if (ext4_inode_can_atomic_write(inode)) { + awu_min =3D sbi->s_awu_min; + awu_max =3D sbi->s_awu_max; + } + + 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..ebe1660bd840 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 (experimental) DIO 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 Sun Nov 24 21:48:24 2024 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.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 7807C159583; Fri, 1 Nov 2024 06:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730443886; cv=none; b=nW9CGPK+PEfIVPaJZm0BiT0SqC9m9S5Azw0By6nj6uSCEKwANBN74XM3AQXkqu8Fl8YORUY7Vq4X9FrJvs6ZvJKBhGcIgTFpWqmvnuCmF0TY4ntbh/IeV/0P3s1YHq+gvuYuTVxuF9xS7oRIOtsW6DtgUKGKAdTGZRxo+pHdfgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730443886; c=relaxed/simple; bh=hGvkUyhcQGnwiS/hGGptwrLsDFEWCTYbhDinuGUy2Co=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U8SKWmhU7oG1/jhKzKB46PVdEbgK0ayih9WFE2CeAFeTFrQjhcSZP76HfdTVlPJWOgoJuAcJwE28tBw3fexu1a/2etzlsHAV3JR9b10f1340cdE40M0PV1+45Od3u8FpEXZWPPteQSZPKNNCRLUuMtNCKFgHpoq7IWytXWpGJ9Y= 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=QAEB13Ls; arc=none smtp.client-ip=209.85.210.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="QAEB13Ls" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-72070d341e5so1514741b3a.1; Thu, 31 Oct 2024 23:51:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730443883; x=1731048683; 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=4m95drDy3WKTcNebz6Rmv1HMtAg3PdxEM0SnqJC05to=; b=QAEB13LsYls/xIB3iM31dknhVxRl492rskEc7xKXD97oj2v8qYOnBKAU8GKSSUYEJl X7WhM5FTsn8byQg7WywO/Uch70LFQeQalxA1iGqxAO8mmVZb12Wws+a9/pHgZBFf34YH 4/h8+XPCy3F5yF+VZA/EDrmBeGHMKViYCOGdOCZaSjZOcPHAteC9C5Dgqs2ELj1VRfnj jkNl4gGLkolbsW1AtvO5ic2pwsI89t5HY7PGJ15TY0a4eWbH+dfTPSCZZs1n5sgKa3gR LHaQDQ7NvKP8w7V+WnvxggqE+PnjpxEhjSDP5LPtZ6p1ctjqzaiwXTO8XmJCRlt2actI lQzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730443883; x=1731048683; 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=4m95drDy3WKTcNebz6Rmv1HMtAg3PdxEM0SnqJC05to=; b=tsBr97W74V5UNLQmFX/LNuFO1N4pAqAw1W4RE+XgYJJoZpocuDad76RIiAy5HEgnH2 yMEFM1DsgkuTXFiuvLlZ/krNYagfMLIACoRo0LiUrnN4ZXp2w5/tETFc5oibl2KjBGUs cCTwDv/L1qw13RN00VNe0xlD9bYHwxcozID4EZtKVvVmjASKq2zHpGB5+2kC9/EbTHd5 PZECH790g4XoZeD11bTyWdcUiaEB0xloN+BO9WRPvKwW32jGw1gDLwoG+Bn0LDZ704WU AsLpi5J6/o6/jiY/ywQOIUfRogO3tW0M4sLk1iaAJsuIlxdDH/z/CPiIwLi9cYn0eAWf o6lg== X-Forwarded-Encrypted: i=1; AJvYcCUGFjb7nmT71FrsJvNHQrC2jDvNb3KoKUmmmLCA6fcAJQQ6+GDobHchUTgo/FQxQcg05d3cpzkd/fHf@vger.kernel.org, AJvYcCVpyW1A/IooTrrCck3rLwuQinOaGp+wTc0rbQ0l5vYSmZm/lgVvuLXk8FpDuH5f/9QOBo6sJau20/lPUHYl@vger.kernel.org, AJvYcCWYIEBk1qnpfsR7HnfFKiWssCODIgTh9PZFheQAIKdPuPLoEOVNYFxgQmN+fMxabFGW+AHKnumrrDQp5hDX@vger.kernel.org X-Gm-Message-State: AOJu0Yyu9OzIrs1d9OAjy/gtj16fHhcfeEY9FOiL+ecQTDYs6wc3xIuY JJG5xRNFH7mp14vpx8DLssdFVWiE0ZJmfOwhiz/9r9IIjdDagXf7JtIRMw== X-Google-Smtp-Source: AGHT+IGO9V8DDq+6aDg1Ap7nZ8qTZYy+ILppgxnOCcguh9dqMJOYU0c6JOYuhapMAJ0Dj0o8WXccgg== X-Received: by 2002:a05:6a20:6d06:b0:1d9:db56:39bf with SMTP id adf61e73a8af0-1db91e8271dmr6092387637.49.1730443883166; Thu, 31 Oct 2024 23:51:23 -0700 (PDT) Received: from dw-tp.ibmuc.com ([203.81.243.23]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1b8971sm2196209b3a.12.2024.10.31.23.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 23:51: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 v4 2/4] ext4: Check for atomic writes support in write iter Date: Fri, 1 Nov 2024 12:20:52 +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" 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 Reviewed-by: Darrick J. Wong Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Jan Kara --- 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 -- 2.46.0 From nobody Sun Nov 24 21:48:24 2024 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (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 2BA0C1662F7; Fri, 1 Nov 2024 06:51:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730443891; cv=none; b=pULQO3PGKgdAiyhxZU3axMyLU6bbMWFj2V06BhwHF7NXY4v0IRoRZnlYt5exwNWLsTG+woDZO8en1Q/8QrSmmrwDqvLPBgTnD8imzcFTwdLa6r3PqXApISj6sNPfm191gWURWtcl4AIBfXKVhk/mlS65ULX7iGFNDwt+/f8i2yE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730443891; c=relaxed/simple; bh=vaVgVv7YrZV3cIEBmlq17X937fsAcWlptFhuhHNeyxU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cex6XkJ21BTdDJdw3IgA5nhWSxW8epWkVzNFeR9EK8mB78GWG5sEuN71VOMKUfsSQ587AVYJQTMtz0BoVAOZ2VMaAr5FStfcRiXOnoUJvfQT6HTa+70RF3IonUET8RjfdPekTY2RcoxxrsTN9oVzDtJ8RK/aWqEKFewbWO4Ns3g= 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=hJy3YhB+; arc=none smtp.client-ip=209.85.160.49 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="hJy3YhB+" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-2887326be3dso824331fac.1; Thu, 31 Oct 2024 23:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730443888; x=1731048688; 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=NhxFZHmBzzbN7OKvAvqCU+zoNbHp35oZYGK+yoxfA8k=; b=hJy3YhB+8ugHGBvGR8u7nt42KBiNv1Fdv33cdS8GJssay1dAuB+44jZToCn3Fw55tH H/+TzNmng2NFY0SLxi65uOjst0simwgRw/UnJ2a7d2ASRnBOKEWD0DIyA2qru+biYpDO SqKhCfj2aPiuqU2ylwgzyK6VREwjOaoa2omjKJum5KjbZg7zTt3NhGI4MdorSFYa8QqS gs0UhTZJep+9a4RY4IApY8zMouuLZT+A6mAbGbbQ7qXZYzP7iqIovSqI8hqkxe60wrj3 U+++7oErks+5Q5W/wya9Y8LQf2gltWdUQ/AMWMTL0arhwG/5LQ4oyWC26kRNUCAGMvTh GZYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730443888; x=1731048688; 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=NhxFZHmBzzbN7OKvAvqCU+zoNbHp35oZYGK+yoxfA8k=; b=vjfRqGvWq+A7txG7jNKkLtythfSLv9MSrQYnqdgGcQzEy6NpeYGtU07XDKNHiRzXz4 XpROgi+S9YLyHgsTg6ZJ76+kSjXsEB9RdrZbmQVUG8ys65VB5CbzDkDuVlq2pas5FICl 6qUI4+CR/jwcUS+U+BbGHyFDzPGn3F/mg0kKrI/w9k7N+p/fqcBD3IPlmETbOKbUurlB HHQ02mJxKpP9aRjZ/fkn1SZmoaX4qaophVCWS/3LDcDDrRq6tnmnVuEV07wuQNyL6WWu PTqVQTP3s0SyKdhLLwW41BRevg8hv4d51TuT7lTPcC6ySsmCtWdKJ7T83Mc44FjSpCnq opwQ== X-Forwarded-Encrypted: i=1; AJvYcCVhho7+9IUEMXIc+pejNCpZQBX4F1J8eGM6XUiSebD+ltiWcmBS8/rpRlWOScKuKQCyJ7vtfE3lk2gX@vger.kernel.org, AJvYcCWFtzdYNTrHMEdt6NwRrQPt38nN+kGrqRnqNMNjuYK16odgNLpR55YZpOX4/LhmPhaXM1jyza+NZGEdDYw8@vger.kernel.org, AJvYcCXkiWmCvh3EG8XYPJOGev3QtpPWHtbs9V1dAZXwBGSXVBjWqgXajvlZQY1JaLn/6kI9Hv7i/kvYheXjmx5S@vger.kernel.org X-Gm-Message-State: AOJu0YwwyENnJ5zGHJ+AFKLDTwtdWDfnvb27DhO+N0qdhs39zWMOoVrf lu9rCU7v1qN4zbrEhz+HxNjFtywpEWpaO3WXLenreFfWyZYIoyxiGUPsJQ== X-Google-Smtp-Source: AGHT+IG2PpCGU18j4TG27jx7tqg8xRN7m1guvNIHyfgGBbDGQRzUtv9/AF48cKYSYlXTbK8C/jXcXg== X-Received: by 2002:a05:6871:3598:b0:288:4313:a3f8 with SMTP id 586e51a60fabf-2948449bccfmr5276844fac.13.1730443887734; Thu, 31 Oct 2024 23:51:27 -0700 (PDT) Received: from dw-tp.ibmuc.com ([203.81.243.23]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1b8971sm2196209b3a.12.2024.10.31.23.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 23:51:27 -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 v4 3/4] ext4: Support setting FMODE_CAN_ATOMIC_WRITE Date: Fri, 1 Nov 2024 12:20:53 +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. Reviewed-by: John Garry Reviewed-by: Darrick J. Wong Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Jan Kara --- fs/ext4/file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index a7b9b9751a3f..96d936f5584b 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; } + if (ext4_inode_can_atomic_write(inode)) + filp->f_mode |=3D FMODE_CAN_ATOMIC_WRITE; + filp->f_mode |=3D FMODE_NOWAIT | FMODE_CAN_ODIRECT; return dquot_file_open(inode, filp); } -- 2.46.0 From nobody Sun Nov 24 21:48:24 2024 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.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 7B24C1714BC; Fri, 1 Nov 2024 06:51:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730443896; cv=none; b=Li9OmYdE/yWogxSLt2BwBeZ92ST1BsvVl79IZ1q6XEiJujlc3WFYwDtlNszwdr2JHt3QO6extIHjvFuWCMOYG0WedKy1818q3AhXkYA26rRDXF/mg+NOqKA7lPSK3hbQDeQ5FGbtoFKDUgSRV1TDii+s2OQxnc5rYimuxuwue+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730443896; c=relaxed/simple; bh=vNVkQK5HqfJrI3jmXZheJg3/RyjZh6GM0HcqoIQ82F0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LA8PzZwf5MAF27mEK0RVvKr7Jd2er9HwaYv4iBzzG3J0cDGofId8QmE7LeAV2LNLIa21vPTiN8oRbnNGScPWEELTU/v4FCtJDbd8807c26LH//dazifGPJQe33x+HBBFvaPfjTR2WhVjM5pVe9Eqt+dyI/PgJfGn8aZSCJ7xfSM= 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=Vh8Hy4mu; arc=none smtp.client-ip=209.85.210.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="Vh8Hy4mu" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-72097a5ca74so1413551b3a.3; Thu, 31 Oct 2024 23:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730443893; x=1731048693; 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=VUpTv9wExUvhBAoK2KqfAK7bifpKgEoP/EE1D/quHOg=; b=Vh8Hy4muNlikvzTXLpFdVd/s36l9a9K0r0DA8+jT3qF+Uv3udU0kp3vcTASMQl2C2z MHKZOe++dG3jbC/2guuh5PuGponwwB3s9xNth5GmAiPEIFa1E/ALfmte6bwF/gn+Yixt 1Yr9zdgQs7Z9q6GfNoSLzWl6SE0K/vUGaXkmiI8FNb/gCy0m0iPFoxRDGLZm0CEeBELa au8q9BlAOuCpONcei/YGI2qm3OmH16AptBzKKGkO6txDC/I6yhcxEFa0yzEy3G/mIaHK SSX2ujbKSGvgDJ9jiBc8qigU8KBTvCJjMMxXOvOy9QFTuFWtAFsyI0Hnd4aWgooaGIyb p8Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730443893; x=1731048693; 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=VUpTv9wExUvhBAoK2KqfAK7bifpKgEoP/EE1D/quHOg=; b=gjg1ZWRXCYsADtdLOppmV1tbInyHbIGT4NLrheQ7GZMeIKLmBH2Y9+g/ZkAKvbv9bW 4sZjT+eDu5TToxAuVaI81D2oE/R+nPSw2fy0sSgmUEltu2W0Y2z+xL529tLVtdMROisF 0wCtrYQn5TY676PrKw8JsABKMivcaGsgjLTfjtoC8XQN5Lgib/vIjnq+mEOZDFoBC1No 7CMiXbyAEbpbsZmzB9xPvf4R2NFg+REUc47gxkhNfUTkCqd87A/Vp3lOpKzeSrGDDtSa SQSFcKT8VWsqByoHX99ZRjbdWSkcGg5YMfp8KwdX0i4m3N3kyBkZ1MvNWVWxy91F9VWp jQiA== X-Forwarded-Encrypted: i=1; AJvYcCUYGT5sFqRJ4jBE817WEYVS70Gfp9bm6jGSMz2lJoRDNzGo41z6rrdR7DPf9CguBrjtM8ncYrWsXWs8Rdkx@vger.kernel.org, AJvYcCVciixpy+/hJgRZVy8/w9pXGWq3Mw4FQJzJI6EL+g1wsKVXgkIrF9PlvAJM1YXThQISlSYnb5l8G0Ay@vger.kernel.org, AJvYcCXkP/EHxvlRFeS95Z+w177pI001p8+mSIwoSf1qXsG2uGj5zWPRdAODcNkIOsXoz1kHE5FmDi37YPAEGjyK@vger.kernel.org X-Gm-Message-State: AOJu0YwA1vgGvls5aVDfjYwP3yPXWFmvcY9P5FsC4FYvXD3dw5Ph/R6Y YzH5gtv5NcOb7NH/n/6TOP2/PZSQBCefOuv/c3JRVUPUbB0ymsCnMgGDbw== X-Google-Smtp-Source: AGHT+IE+097sdf1GgBu/8uA6WnV5QerdwqvqfQxsQzKml4gDXHjiNGW58zC9ifhtYUrq4e/xLiKiZQ== X-Received: by 2002:a05:6a00:1817:b0:71d:f7ea:89f6 with SMTP id d2e1a72fcca58-720c99b5ca0mr3797240b3a.18.1730443892738; Thu, 31 Oct 2024 23:51:32 -0700 (PDT) Received: from dw-tp.ibmuc.com ([203.81.243.23]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1b8971sm2196209b3a.12.2024.10.31.23.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2024 23:51:32 -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 v4 4/4] ext4: Do not fallback to buffered-io for DIO atomic write Date: Fri, 1 Nov 2024 12:20:54 +0530 Message-ID: <78fb5c40dde4847dc32af09e668a6f81fa251137.1730437365.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" 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. Hence, we should never 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]. While at it let's add an inline helper ext4_want_directio_fallback() which simplifies the logic checks and inherently fixes condition on when to return -ENOTBLK which otherwise was always returning true for any write or directi= o in ext4_iomap_end(). It was ok since ext4 only supports direct-io via iomap. [1]: https://lore.kernel.org/linux-xfs/cover.1729825985.git.ritesh.list@gma= il.com/T/#m9dbecc11bed713ed0d7a486432c56b105b555f04 Suggested-by: Darrick J. Wong # inline helper Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Darrick J. Wong Reviewed-by: Jan Kara --- fs/ext4/file.c | 7 +++++++ fs/ext4/inode.c | 27 ++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 96d936f5584b..a7de03e47db0 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 =3D iocb->ki_pos; err =3D ext4_buffered_write_iter(iocb, from); if (err < 0) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 3e827cfa762e..5b9eeb74ce47 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3444,17 +3444,34 @@ static int ext4_iomap_overwrite_begin(struct inode = *inode, loff_t offset, return ret; } +static inline bool ext4_want_directio_fallback(unsigned flags, ssize_t wri= tten) +{ + /* must be a directio to fall back to buffered */ + if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) !=3D + (IOMAP_WRITE | IOMAP_DIRECT)) + return false; + + /* atomic writes are all-or-nothing */ + if (flags & IOMAP_ATOMIC) + return false; + + /* can only try again if we wrote nothing */ + return written =3D=3D 0; +} + static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t lengt= h, ssize_t written, unsigned flags, struct iomap *iomap) { /* * 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 non-atomic writes, any blocks that may have been + * allocated in preparation for the direct I/O will be reused during + * buffered I/O. For atomic write, we never fallback to buffered-io. */ - if (flags & (IOMAP_WRITE | IOMAP_DIRECT) && written =3D=3D 0) + if (ext4_want_directio_fallback(flags, written)) return -ENOTBLK; return 0; -- 2.46.0