From patchwork Sat Apr 15 07:44:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=AVvSWhnr; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz51y0qnfz23rw for ; Sat, 15 Apr 2023 17:44:54 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz51x2NyYz4xD5 for ; Sat, 15 Apr 2023 17:44:53 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz51x2LHwz4xFL; Sat, 15 Apr 2023 17:44:53 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=AVvSWhnr; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz51x2FM2z4xD5 for ; Sat, 15 Apr 2023 17:44:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbjDOHou (ORCPT ); Sat, 15 Apr 2023 03:44:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbjDOHon (ORCPT ); Sat, 15 Apr 2023 03:44:43 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66BC57EF4; Sat, 15 Apr 2023 00:44:42 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-63b5c4c76aaso488380b3a.2; Sat, 15 Apr 2023 00:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544681; x=1684136681; 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=7vOY0HWRCluzQ1SEYQtrOup46nyHU1j9BhalfWc1/Wc=; b=AVvSWhnrwAMRCIdKokU7uzmWCuYDUfPc34wSJo/z5Zo7GVRd6m1pYqlJQnsqUSzuNH 999XGdnlXt7lqrZcivo7PFXlrIIDJVXJDOIya9ktN7b8n/dTEmNE379MEJmQEASeBRhh oXxISc6V+IOikMb2Rw/2Hi7QpEmfxKpjUEDR+BniA47RNmZBW1YNoHSv28DJfEjDpODL qMnHD4oKlUI9UfAxH55DU+jRs/yOWVCHxPsfQvcgQS3EUUNN1bMRmnpwzyW+OirEMDt9 6lhei7vBvojNw/5eId78jHKunCMtlJXdcQ0jFHszXdlmGAInxhUQ4Vx5c3RclTy9LY5F vkWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544681; x=1684136681; 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=7vOY0HWRCluzQ1SEYQtrOup46nyHU1j9BhalfWc1/Wc=; b=dLidJ4lWDB4T5dYpikQS5jb/wWMfI5jiV1YVZUIouQvC8Ox1Z68Atqm0YeMcdirwDE q/GEywQswfrcjPMoBYeP22T2Y7RVCfVj+3yZTrwn8XAP7vUKB6kF3HXkiy7Q803xD/Lw B9A9l2RgjSWmbDs3Fzce5vnCVCYKUQsFVtlA1yMzlo87ai1GpoLDb7HO8j/7UEcTv2Jc qJhpZGChBPF/+CFCbRaQmR8Mp1szOjjQ4JLY6FT8CAZ7t+Q5tMNS+zqYN2XMZy3U+h7U 8L/ZgMDgmGZXU+H5jTvQ4xqa8r7n/OHN3JlcBjFax+xuFACm1oDs1qef/QSdECTuaI1h oHjg== X-Gm-Message-State: AAQBX9eF7wlMdniJclckZhFM/v6eZlCl52oMY7bxtxUX/nq0WS3MC3Xp litalXcmC61XSevWvHdHPBLnIfoMqEc= X-Google-Smtp-Source: AKy350YIEcGHEax4uzNq4buxjf4mwsz1Fw7BeaZlYji1LG+NEq8La8T60pKIznx4AoL0ilKpgTmGRw== X-Received: by 2002:a05:6a00:2eaa:b0:638:edbc:74ca with SMTP id fd42-20020a056a002eaa00b00638edbc74camr12805761pfb.0.1681544681369; Sat, 15 Apr 2023 00:44:41 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:44:41 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" Subject: [RFCv4 1/9] ext2/dax: Fix ext2_setsize when len is page aligned Date: Sat, 15 Apr 2023 13:14:22 +0530 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org PAGE_ALIGN(x) macro gives the next highest value which is multiple of pagesize. But if x is already page aligned then it simply returns x. So, if x passed is 0 in dax_zero_range() function, that means the length gets passed as 0 to ->iomap_begin(). In ext2 it then calls ext2_get_blocks -> max_blocks as 0 and hits bug_on here in ext2_get_blocks(). BUG_ON(maxblocks == 0); Instead we should be calling dax_truncate_page() here which takes care of it. i.e. it only calls dax_zero_range if the offset is not page/block aligned. This can be easily triggered with following on fsdax mounted pmem device. dd if=/dev/zero of=file count=1 bs=512 truncate -s 0 file [79.525838] EXT2-fs (pmem0): DAX enabled. Warning: EXPERIMENTAL, use at your own risk [79.529376] ext2 filesystem being mounted at /mnt1/test supports timestamps until 2038 (0x7fffffff) [93.793207] ------------[ cut here ]------------ [93.795102] kernel BUG at fs/ext2/inode.c:637! [93.796904] invalid opcode: 0000 [#1] PREEMPT SMP PTI [93.798659] CPU: 0 PID: 1192 Comm: truncate Not tainted 6.3.0-rc2-xfstests-00056-g131086faa369 #139 [93.806459] RIP: 0010:ext2_get_blocks.constprop.0+0x524/0x610 <...> [93.835298] Call Trace: [93.836253] [93.837103] ? lock_acquire+0xf8/0x110 [93.838479] ? d_lookup+0x69/0xd0 [93.839779] ext2_iomap_begin+0xa7/0x1c0 [93.841154] iomap_iter+0xc7/0x150 [93.842425] dax_zero_range+0x6e/0xa0 [93.843813] ext2_setsize+0x176/0x1b0 [93.845164] ext2_setattr+0x151/0x200 [93.846467] notify_change+0x341/0x4e0 [93.847805] ? lock_acquire+0xf8/0x110 [93.849143] ? do_truncate+0x74/0xe0 [93.850452] ? do_truncate+0x84/0xe0 [93.851739] do_truncate+0x84/0xe0 [93.852974] do_sys_ftruncate+0x2b4/0x2f0 [93.854404] do_syscall_64+0x3f/0x90 [93.855789] entry_SYSCALL_64_after_hwframe+0x72/0xdc Reviewed-by: Darrick J. Wong Signed-off-by: Ritesh Harjani (IBM) --- fs/ext2/inode.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 26f135e7ffce..dc76147e7b07 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -1259,9 +1259,8 @@ static int ext2_setsize(struct inode *inode, loff_t newsize) inode_dio_wait(inode); if (IS_DAX(inode)) - error = dax_zero_range(inode, newsize, - PAGE_ALIGN(newsize) - newsize, NULL, - &ext2_iomap_ops); + error = dax_truncate_page(inode, newsize, NULL, + &ext2_iomap_ops); else error = block_truncate_page(inode->i_mapping, newsize, ext2_get_block); From patchwork Sat Apr 15 07:44:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=TuqKnR0o; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz51y0CsYz1yZr for ; Sat, 15 Apr 2023 17:44:53 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz51x6Kmzz4xFL for ; Sat, 15 Apr 2023 17:44:53 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz51x6Hcqz4xFd; Sat, 15 Apr 2023 17:44:53 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=TuqKnR0o; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz51x6DFPz4xFL for ; Sat, 15 Apr 2023 17:44:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229543AbjDOHox (ORCPT ); Sat, 15 Apr 2023 03:44:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjDOHot (ORCPT ); Sat, 15 Apr 2023 03:44:49 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 140CF868B; Sat, 15 Apr 2023 00:44:45 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-246eebbde1cso1108634a91.3; Sat, 15 Apr 2023 00:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544684; x=1684136684; 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=JODBs8P43hIsjCqqKREf8+XQIM2HCnjU8ac1MO4CF9k=; b=TuqKnR0o5I31KY6e/wi+o6tNH9OI89axfVGQkYcEZnSmZQEv7Jw9B8oFIO2jl+qhRU HMpfSvYdg6JVnD+zL4Mzy9fk3OYa6vkifgouGHc9uuAzdEBLfmv88+yRzpC/Wye9DqM1 Jsm0MHWy8acyyZ7Sk8daYEyoxYTNiT8EAwsw4htv57sBXDW0NPToSj7amozmSUzjL11q MlpCANPD+dhLi3p7D/mBzuDhWy5rhbd69ielYZav9IWK8uwhRBoV5pHAf9QZTuIxUcpx zUG7xbnqknUbWwh/qA8T6cog8Er051vfvJ1J7CCsHfKBfSKHXuAVUtFcorms24h/weAN BCww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544684; x=1684136684; 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=JODBs8P43hIsjCqqKREf8+XQIM2HCnjU8ac1MO4CF9k=; b=QJdT4JL8p18BDMSNS+Kd9tXtKi3enCo9eEU2c05Z2emhI6rHHrq/sU5pm/Nr+ZlNiG ddwSR4FIkvGiQNldCr3NOvkXTvoZLo3WKOsY0rN89mLQvsQ1zxLtq/7MsWXc0wbcTCYr pyMJY786JWYkjQlOs1oe3HexDjnp9TOFfyeldBLBdNrPhvqrj7y0lMzIFDfUeDBzrj6+ uGIa+6yj9v237ENNT/XuebcyD0JG/E5JeRk9SNTdC3rn5wAmb1WBXQMZs5jhUw+gVDAe icOecZeFwIC41uBO7f7eQ5lU4YfAqKpen7flzFyxwne8CiALSDZaorQqjEjr3LkR9wpT 9hlA== X-Gm-Message-State: AAQBX9eiI/6AfWc30sT/6DHN+NE5+7rAOBpM2jqegtC3KLCoAa9U7QXP IGTnWdgi/siITr5AdfNdeDQbBZtZgoA= X-Google-Smtp-Source: AKy350bzHhQ5NkkCLeAdY3bmXMZ1yRt4VLg/Ib/J5UuMSngm0T53CeysT2Mobk25WBpXUyjm6kfJjA== X-Received: by 2002:a05:6a00:168e:b0:626:2984:8a76 with SMTP id k14-20020a056a00168e00b0062629848a76mr11872495pfc.34.1681544684189; Sat, 15 Apr 2023 00:44:44 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:44:43 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" Subject: [RFCv4 2/9] fs/buffer.c: Add generic_buffer_fsync implementation Date: Sat, 15 Apr 2023 13:14:23 +0530 Message-Id: <5969eb067ad38272a1bb0df516965301ff08a919.1681544352.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Some of the higher layers like iomap takes inode_lock() when calling generic_write_sync(). Also writeback already happens from other paths without inode lock, so it's difficult to say that we really need sync_mapping_buffers() to take any inode locking here. Having said that, let's add generic_buffer_fsync() implementation in buffer.c with no inode_lock/unlock() for now so that filesystems like ext2 and ext4's nojournal mode can use it. Ext4 when got converted to iomap for direct-io already copied it's own variant of __generic_file_fsync() without lock. Hence let's add a helper API and use it both in ext2 and ext4. Later we can review other filesystems as well to see if we can make generic_buffer_fsync() which does not take any inode_lock() as the default path. Tested-by: Disha Goel Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Christoph Hellwig --- fs/buffer.c | 43 +++++++++++++++++++++++++++++++++++++ include/linux/buffer_head.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/fs/buffer.c b/fs/buffer.c index 9e1e2add541e..df98f1966a71 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -593,6 +593,49 @@ int sync_mapping_buffers(struct address_space *mapping) } EXPORT_SYMBOL(sync_mapping_buffers); +/** + * generic_buffer_fsync - generic buffer fsync implementation + * for simple filesystems with no inode lock + * + * @file: file to synchronize + * @start: start offset in bytes + * @end: end offset in bytes (inclusive) + * @datasync: only synchronize essential metadata if true + * + * This is a generic implementation of the fsync method for simple + * filesystems which track all non-inode metadata in the buffers list + * hanging off the address_space structure. + */ +int generic_buffer_fsync(struct file *file, loff_t start, loff_t end, + bool datasync) +{ + struct inode *inode = file->f_mapping->host; + int err; + int ret; + + err = file_write_and_wait_range(file, start, end); + if (err) + return err; + + ret = sync_mapping_buffers(inode->i_mapping); + if (!(inode->i_state & I_DIRTY_ALL)) + goto out; + if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) + goto out; + + err = sync_inode_metadata(inode, 1); + if (ret == 0) + ret = err; + +out: + /* check and advance again to catch errors after syncing out buffers */ + err = file_check_and_advance_wb_err(file); + if (ret == 0) + ret = err; + return ret; +} +EXPORT_SYMBOL(generic_buffer_fsync); + /* * Called when we've recently written block `bblock', and it is known that * `bblock' was for a buffer_boundary() buffer. This means that the block at diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 8f14dca5fed7..3170d0792d52 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -211,6 +211,8 @@ int inode_has_buffers(struct inode *); void invalidate_inode_buffers(struct inode *); int remove_inode_buffers(struct inode *inode); int sync_mapping_buffers(struct address_space *mapping); +int generic_buffer_fsync(struct file *file, loff_t start, loff_t end, + bool datasync); void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len); static inline void clean_bdev_bh_alias(struct buffer_head *bh) From patchwork Sat Apr 15 07:44:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=HHDTBjl5; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz5235bSFz1yZr for ; Sat, 15 Apr 2023 17:44:59 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52357fsz4xFL for ; Sat, 15 Apr 2023 17:44:59 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz52355G7z4xFd; Sat, 15 Apr 2023 17:44:59 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=HHDTBjl5; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52351ZBz4xFL for ; Sat, 15 Apr 2023 17:44:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229760AbjDOHo5 (ORCPT ); Sat, 15 Apr 2023 03:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjDOHow (ORCPT ); Sat, 15 Apr 2023 03:44:52 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD3738A5E; Sat, 15 Apr 2023 00:44:47 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-51b514a8424so442013a12.1; Sat, 15 Apr 2023 00:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544687; x=1684136687; 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=Cy+/pZaqvES6mObQuwzhCbnK8v685tx7A3EGdbbD7vE=; b=HHDTBjl51tdnyl/bgJ4jslA6NFKk+j7wrfQh4wmRk61cWn/vb+JZKL4R0rJ4vpGe0d H+8KAWPfy6JNBfQqBpUO/hPR4Lmjr7+KCZkxzYOZ3MqzGAqP5KbPILBnxwOS1cNGFZV1 hx1SvoQC/fnZbx/1s0l60DAsiEKocoYuZDTieFKOwjQOhukwLlOpIslFcbvrMbkbRV/f fQaVisaPQevsW0L7Bjczxe77D+ZZ3e9aL6fhmsr75ZxPfmZZ0qWyI/lOOikvSII0Nzng m4bDjnsKJUJ/vqLVgHDiCRk4bkGNqsyEDPGNZrnu+GmPD9wMVgyZsJ0vjfQJg4pYahwV 5cuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544687; x=1684136687; 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=Cy+/pZaqvES6mObQuwzhCbnK8v685tx7A3EGdbbD7vE=; b=N8IshrsVt7pVw1AaNQaN1i/krm4i94VVQWv5DmW59WcOQS9yIILziinpYN1FLwe5Vn KWUrnKRFj5eP1Nb7no92hsmRQAfK35Zl7Vbw4YwBn55yFnjxQvZsNSuXcB9z7jwxU19L aRPwCdGohLEgJMTlrQ8eOaurdBDfiW945rXvd7jUl/bYjWjVtsl7s/A/JQZogbTWa0r6 kfNl09Lit3Q3wDRAIYal+emAiJ6E7nzOvOsBqKZk5dpuzokAJSoFX0QeWDruqwEC8/3u C1i0JGZj7ySkrFOXwMfBG4EBhw2Gs58/wC9+xgkeOobft62QvBnUVtvC+toXa1ldOc6O QM6g== X-Gm-Message-State: AAQBX9cy8jJxXaEgz5IN+f+r4n9n8VYeHARYXiUrbhXvr1kqM3MR+xJa jy4DCnF5b5T3QgCCM/YTumhGcnJwvj8= X-Google-Smtp-Source: AKy350bkRSa5QvV4TPqBzo8ysEia+irgvscjVC6wFL+vx5+TcBFsGRWpHM5eTvuptGRUD9YsTtPyzA== X-Received: by 2002:a05:6a00:22d4:b0:63b:7ab1:6c48 with SMTP id f20-20020a056a0022d400b0063b7ab16c48mr1967987pfj.6.1681544686893; Sat, 15 Apr 2023 00:44:46 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:44:46 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" Subject: [RFCv4 3/9] ext4: Use generic_buffer_fsync() implementation Date: Sat, 15 Apr 2023 13:14:24 +0530 Message-Id: <9622b68c186c364b54269ad67ff0efb72227a29e.1681544352.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org ext4 when got converted to iomap for dio, it copied __generic_file_fsync implementation to avoid taking inode_lock in order to avoid any deadlock (since iomap takes an inode_lock while calling generic_write_sync()). The previous patch already added generic_buffer_fsync() which does not take any inode_lock(). Hence kill the redundant code and use generic_buffer_fsync() function instead. Tested-by: Disha Goel Signed-off-by: Ritesh Harjani (IBM) --- fs/ext4/fsync.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index 027a7d7037a0..4f2af43f8b0f 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "ext4.h" #include "ext4_jbd2.h" @@ -78,21 +79,13 @@ static int ext4_sync_parent(struct inode *inode) return ret; } -static int ext4_fsync_nojournal(struct inode *inode, bool datasync, - bool *needs_barrier) +static int ext4_fsync_nojournal(struct file *file, loff_t start, loff_t end, + int datasync, bool *needs_barrier) { - int ret, err; - - ret = sync_mapping_buffers(inode->i_mapping); - if (!(inode->i_state & I_DIRTY_ALL)) - return ret; - if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) - return ret; - - err = sync_inode_metadata(inode, 1); - if (!ret) - ret = err; + struct inode *inode = file->f_inode; + int ret; + ret = generic_buffer_fsync(file, start, end, datasync); if (!ret) ret = ext4_sync_parent(inode); if (test_opt(inode->i_sb, BARRIER)) @@ -148,6 +141,14 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) goto out; } + if (!sbi->s_journal) { + ret = ext4_fsync_nojournal(file, start, end, datasync, + &needs_barrier); + if (needs_barrier) + goto issue_flush; + goto out; + } + ret = file_write_and_wait_range(file, start, end); if (ret) goto out; @@ -166,13 +167,12 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) * (they were dirtied by commit). But that's OK - the blocks are * safe in-journal, which is all fsync() needs to ensure. */ - if (!sbi->s_journal) - ret = ext4_fsync_nojournal(inode, datasync, &needs_barrier); - else if (ext4_should_journal_data(inode)) + if (ext4_should_journal_data(inode)) ret = ext4_force_commit(inode->i_sb); else ret = ext4_fsync_journal(inode, datasync, &needs_barrier); +issue_flush: if (needs_barrier) { err = blkdev_issue_flush(inode->i_sb->s_bdev); if (!ret) From patchwork Sat Apr 15 07:44:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769245 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=R12mBpVI; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz5265CrJz1yZr for ; Sat, 15 Apr 2023 17:45:02 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz5264n7zz4xDH for ; Sat, 15 Apr 2023 17:45:02 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz5264l8wz4xFL; Sat, 15 Apr 2023 17:45:02 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=R12mBpVI; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz5264dLBz4xDH for ; Sat, 15 Apr 2023 17:45:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjDOHo7 (ORCPT ); Sat, 15 Apr 2023 03:44:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbjDOHow (ORCPT ); Sat, 15 Apr 2023 03:44:52 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BDDD83DF; Sat, 15 Apr 2023 00:44:50 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-51b6d0b9430so230219a12.2; Sat, 15 Apr 2023 00:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544690; x=1684136690; 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=LMu2Z6KXv/0ceszG2jht7fa1feJSyyCUFNwC5P7U1ig=; b=R12mBpVIScO/ybPKCDH+JA3H7SvOdnUIhGwGxVav53/bIcvfxai/+q0DQ6dvi2oLN2 qniiJBvJekfKVTBmhhnS5kN9OP1FaYQDDMoA2bTINwznRT+F0K0ZBYCBq+R2uvhR6EgD OE+HHJcyKcph9LQNn3r8FDCxzueT0+VYZbzgCrsicJIShA0iDF1nP755vYNN9MYYaW4W DUMV7QMMb7PDWuupfrlnoXOogHWKuOPLeXSktKyojtR2fIzTrIawSTM6CnjF/+eCnid4 zg8ak6lkMtuGnRmjUov95qXmy77hd9XIJg7F9y5HcGNFfvDm4l2y0qpP0eb5PBX11I1q 2gqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544690; x=1684136690; 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=LMu2Z6KXv/0ceszG2jht7fa1feJSyyCUFNwC5P7U1ig=; b=BbXFtOra9yOdv035l3+8yLyeQI6OHSFTtI1d8Vu0yM+hVxvwNzmYIj9HmbfUEgVILh F0iIKHYuWNpwG4Yl3gkVqZ4LBv3sDGN8Ls+Vxw1SLVbkhhGfVtw/1JBbH5Elr5PUPgHX G4uZTmUQ9G9u2M/JCi73lJEIkASIFeaZas3bHylvE+FB72g4q5+LVTq8HHTdsGyQD4CV HAxv+VwE7ij/KsW0lPl7gZx4u0bOoOLYM9YPHZE/6+q5qZCETouNEC0HX9xEaCyO/bpC JralMijfQnStbbC/Z2bmyEu7PLRyXzPMX/kE8UALvirmbrIAp8C0c0pHRtE2CwZPm2rc QcYg== X-Gm-Message-State: AAQBX9fWZ2KoPs2Gwxlh7oD/woFnjTvqJjO10orkauNmAwNqKqw4F8a7 OEv5HSpIeDf6Lycg+38JBtTVdeS+X/A= X-Google-Smtp-Source: AKy350a1py+A7j06L0ZyRrBPuohZ8Nn4i1Q0VPjHPJjZK93ITUNmMxKkUXY3eG+T9irqebwTWiy+CA== X-Received: by 2002:a05:6a00:16c1:b0:636:4523:da93 with SMTP id l1-20020a056a0016c100b006364523da93mr12289799pfc.12.1681544689698; Sat, 15 Apr 2023 00:44:49 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:44:49 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" Subject: [RFCv4 4/9] ext2: Use generic_buffer_fsync() implementation Date: Sat, 15 Apr 2023 13:14:25 +0530 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Next patch converts ext2 to use iomap interface for DIO. iomap layer can call generic_write_sync() -> ext2_fsync() from iomap_dio_complete while still holding the inode_lock(). Now writeback from other paths doesn't need inode_lock(). It seems there is also no need of an inode_lock() for sync_mapping_buffers(). It uses it's own mapping->private_lock for it's buffer list handling. Hence this patch is in preparation to move ext2 to iomap. This uses generic_buffer_fsync() which does not take any inode_lock() in ext2_fsync(). Tested-by: Disha Goel Signed-off-by: Ritesh Harjani (IBM) --- fs/ext2/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 6b4bebe982ca..7603427fb38f 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ext2.h" #include "xattr.h" #include "acl.h" @@ -153,7 +154,9 @@ int ext2_fsync(struct file *file, loff_t start, loff_t end, int datasync) int ret; struct super_block *sb = file->f_mapping->host->i_sb; - ret = generic_file_fsync(file, start, end, datasync); + ret = generic_buffer_fsync(file, start, end, datasync); + if (!ret) + ret = blkdev_issue_flush(sb->s_bdev); if (ret == -EIO) /* We don't really know where the IO error happened... */ ext2_error(sb, __func__, From patchwork Sat Apr 15 07:44:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=WVFn5pYv; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz52D6X1fz1yZk for ; Sat, 15 Apr 2023 17:45:08 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52D6CWKz4xDH for ; Sat, 15 Apr 2023 17:45:08 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz52D68p7z4xFL; Sat, 15 Apr 2023 17:45:08 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=WVFn5pYv; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52D62ndz4xDH for ; Sat, 15 Apr 2023 17:45:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229623AbjDOHpF (ORCPT ); Sat, 15 Apr 2023 03:45:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjDOHoz (ORCPT ); Sat, 15 Apr 2023 03:44:55 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7922486A8; Sat, 15 Apr 2023 00:44:53 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-5180af0e886so1137529a12.2; Sat, 15 Apr 2023 00:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544692; x=1684136692; 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=/aUzNSib1xZc4N397XkhllM7kWsYiTGLSPxW8fTLrLg=; b=WVFn5pYvfKGrsqMwyiypVB7vkhJ5P2GUPONFvv48C4qek8FMe5fTf6mFH0EsKrhvCQ KIHV5ex11xDPOhHH5XBWcSlIX3BBni+JvM7xQecyGMR9BXgSUEe6W/1nJhreYPJeoEtR 6SedOs4bg2OwGPNWaiySdSoAZqllK9ZD94eHBTTQQB570R1Wcb3TI//Qeziu9y+OVXd5 YimEkStskKrdcNrOijumamMiR+nRxPxCSVFgTSvOV/i/nJfuDYqDVSFsmeIFr9WIN4zw XcMVxxK4Up6+1S3KO4dnltsErCtufLvYyWSEij5cJmb4S3Wnam099nGelO6/2fen0+pD X6Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544692; x=1684136692; 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=/aUzNSib1xZc4N397XkhllM7kWsYiTGLSPxW8fTLrLg=; b=eioknrazavQVai581Ttg6huTs9kXahufK31rnYOejBurcuF44twM7rQa6C7Ya96m9R zx0d+A3eGQn/yvRGRLvQqkGmIyfIZRTFA1iuRr2cQ5EME+SsBPEE4acP0jh7DyOWjIKl IqqyVzLrPCgp9elecX94zZMY7DrsmepmiWP/tkcvq+rQLDZVbdQ8oJ/hlGjY0K4nvCQb akOZj0Y1PbKEDzJ5ymPg15xAdxoum6/3A16VVMHlJ3raezVYkT2W+/CIotHu598xspx1 ++sTxUxypCF77pKE5qNoQzUKm+dpwreftZ4b7ngJFvvo1hKAjjmhHOB2g2+LWYYXuo9G 14zQ== X-Gm-Message-State: AAQBX9fy3GXzh+eDn2EQ5kLVBDOYcL7NVTsy3ILRZ3UMvwfhzKoeoVk4 RQirDEBHARTF4LsSq2Q00EYTNEe0tPQ= X-Google-Smtp-Source: AKy350YUv4pndk80/2asqlsQ5hSjyKR6oaJ1rz1MKbgBJCERTnTrz2RF5erXdlwkMYkF8lML4AYOFw== X-Received: by 2002:a05:6a00:1a43:b0:634:657e:546e with SMTP id h3-20020a056a001a4300b00634657e546emr11785404pfv.5.1681544692428; Sat, 15 Apr 2023 00:44:52 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:44:52 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" Subject: [RFCv4 5/9] ext2: Move direct-io to use iomap Date: Sat, 15 Apr 2023 13:14:26 +0530 Message-Id: <78fed3db1cd6889b2c26866b9ce3c2538c7a77f7.1681544352.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This patch converts ext2 direct-io path to iomap interface. - This also takes care of DIO_SKIP_HOLES part in which we return -ENOTBLK from ext2_iomap_begin(), in case if the write is done on a hole. - This fallbacks to buffered-io in case of DIO_SKIP_HOLES or in case of a partial write or if any error is detected in ext2_iomap_end(). We try to return -ENOTBLK in such cases. - For any unaligned or extending DIO writes, we pass IOMAP_DIO_FORCE_WAIT flag to ensure synchronous writes. - For extending writes we set IOMAP_F_DIRTY in ext2_iomap_begin because otherwise with dsync writes on devices that support FUA, generic_write_sync won't be called and we might miss inode metadata updates. - Since ext2 already now uses _nolock vartiant of sync write. Hence there is no inode lock problem with iomap in this patch. - ext2_iomap_ops are now being shared by DIO, DAX & fiemap path Tested-by: Disha Goel Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Christoph Hellwig --- fs/ext2/ext2.h | 1 + fs/ext2/file.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext2/inode.c | 53 ++++++++++++++-------- 3 files changed, 150 insertions(+), 19 deletions(-) diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index cb78d7dcfb95..00168447d48c 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -753,6 +753,7 @@ extern unsigned long ext2_count_free (struct buffer_head *, unsigned); extern struct inode *ext2_iget (struct super_block *, unsigned long); extern int ext2_write_inode (struct inode *, struct writeback_control *); extern void ext2_evict_inode(struct inode *); +void ext2_write_failed(struct address_space *mapping, loff_t to); extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int); extern int ext2_setattr (struct mnt_idmap *, struct dentry *, struct iattr *); extern int ext2_getattr (struct mnt_idmap *, const struct path *, diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 7603427fb38f..704abe0a79cb 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -164,12 +164,124 @@ int ext2_fsync(struct file *file, loff_t start, loff_t end, int datasync) return ret; } +static ssize_t ext2_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) +{ + struct file *file = iocb->ki_filp; + struct inode *inode = file->f_mapping->host; + ssize_t ret; + + inode_lock_shared(inode); + ret = iomap_dio_rw(iocb, to, &ext2_iomap_ops, NULL, 0, NULL, 0); + inode_unlock_shared(inode); + + return ret; +} + +static int ext2_dio_write_end_io(struct kiocb *iocb, ssize_t size, + int error, unsigned int flags) +{ + loff_t pos = iocb->ki_pos; + struct inode *inode = file_inode(iocb->ki_filp); + + if (error) + goto out; + + /* + * If we are extending the file, we have to update i_size here before + * page cache gets invalidated in iomap_dio_rw(). This prevents racing + * buffered reads from zeroing out too much from page cache pages. + * Note that all extending writes always happens synchronously with + * inode lock held by ext2_dio_write_iter(). So it is safe to update + * inode size here for extending file writes. + */ + pos += size; + if (pos > i_size_read(inode)) { + i_size_write(inode, pos); + mark_inode_dirty(inode); + } +out: + return error; +} + +static const struct iomap_dio_ops ext2_dio_write_ops = { + .end_io = ext2_dio_write_end_io, +}; + +static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) +{ + struct file *file = iocb->ki_filp; + struct inode *inode = file->f_mapping->host; + ssize_t ret; + unsigned int flags = 0; + unsigned long blocksize = inode->i_sb->s_blocksize; + loff_t offset = iocb->ki_pos; + loff_t count = iov_iter_count(from); + + inode_lock(inode); + ret = generic_write_checks(iocb, from); + if (ret <= 0) + goto out_unlock; + + ret = kiocb_modified(iocb); + if (ret) + goto out_unlock; + + /* use IOMAP_DIO_FORCE_WAIT for unaligned or extending writes */ + if (iocb->ki_pos + iov_iter_count(from) > i_size_read(inode) || + (!IS_ALIGNED(iocb->ki_pos | iov_iter_alignment(from), blocksize))) + flags |= IOMAP_DIO_FORCE_WAIT; + + ret = iomap_dio_rw(iocb, from, &ext2_iomap_ops, &ext2_dio_write_ops, + flags, NULL, 0); + + /* ENOTBLK is magic return value for fallback to buffered-io */ + if (ret == -ENOTBLK) + ret = 0; + + if (ret < 0 && ret != -EIOCBQUEUED) + ext2_write_failed(inode->i_mapping, offset + count); + + /* handle case for partial write and for fallback to buffered write */ + if (ret >= 0 && iov_iter_count(from)) { + loff_t pos, endbyte; + ssize_t status; + int ret2; + + iocb->ki_flags &= ~IOCB_DIRECT; + pos = iocb->ki_pos; + status = generic_perform_write(iocb, from); + if (unlikely(status < 0)) { + ret = status; + goto out_unlock; + } + + iocb->ki_pos += status; + ret += status; + endbyte = pos + status - 1; + ret2 = filemap_write_and_wait_range(inode->i_mapping, pos, + endbyte); + if (!ret2) + invalidate_mapping_pages(inode->i_mapping, + pos >> PAGE_SHIFT, + endbyte >> PAGE_SHIFT); + if (ret > 0) + generic_write_sync(iocb, ret); + } + +out_unlock: + inode_unlock(inode); + return ret; +} + static ssize_t ext2_file_read_iter(struct kiocb *iocb, struct iov_iter *to) { #ifdef CONFIG_FS_DAX if (IS_DAX(iocb->ki_filp->f_mapping->host)) return ext2_dax_read_iter(iocb, to); #endif + if (iocb->ki_flags & IOCB_DIRECT) + return ext2_dio_read_iter(iocb, to); + return generic_file_read_iter(iocb, to); } @@ -179,6 +291,9 @@ static ssize_t ext2_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (IS_DAX(iocb->ki_filp->f_mapping->host)) return ext2_dax_write_iter(iocb, from); #endif + if (iocb->ki_flags & IOCB_DIRECT) + return ext2_dio_write_iter(iocb, from); + return generic_file_write_iter(iocb, from); } diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index dc76147e7b07..75983215c7a1 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -56,7 +56,7 @@ static inline int ext2_inode_is_fast_symlink(struct inode *inode) static void ext2_truncate_blocks(struct inode *inode, loff_t offset); -static void ext2_write_failed(struct address_space *mapping, loff_t to) +void ext2_write_failed(struct address_space *mapping, loff_t to) { struct inode *inode = mapping->host; @@ -809,9 +809,27 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, bool new = false, boundary = false; u32 bno; int ret; + bool create = flags & IOMAP_WRITE; + + /* + * For writes that could fill holes inside i_size on a + * DIO_SKIP_HOLES filesystem we forbid block creations: only + * overwrites are permitted. + */ + if ((flags & IOMAP_DIRECT) && + (first_block << blkbits) < i_size_read(inode)) + create = 0; + + /* + * Writes that span EOF might trigger an IO size update on completion, + * so consider them to be dirty for the purposes of O_DSYNC even if + * there is no other metadata changes pending or have been made here. + */ + if ((flags & IOMAP_WRITE) && offset + length > i_size_read(inode)) + iomap->flags |= IOMAP_F_DIRTY; ret = ext2_get_blocks(inode, first_block, max_blocks, - &bno, &new, &boundary, flags & IOMAP_WRITE); + &bno, &new, &boundary, create); if (ret < 0) return ret; @@ -823,6 +841,12 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->bdev = inode->i_sb->s_bdev; if (ret == 0) { + /* + * Switch to buffered-io for writing to holes in a non-extent + * based filesystem to avoid stale data exposure problem. + */ + if (!create && (flags & IOMAP_WRITE) && (flags & IOMAP_DIRECT)) + return -ENOTBLK; iomap->type = IOMAP_HOLE; iomap->addr = IOMAP_NULL_ADDR; iomap->length = 1 << blkbits; @@ -844,6 +868,13 @@ static int ext2_iomap_end(struct inode *inode, loff_t offset, loff_t length, ssize_t written, unsigned flags, struct iomap *iomap) { + /* + * Switch to buffered-io in case of any error. + * Blocks allocated can be used by the buffered-io path. + */ + if ((flags & IOMAP_DIRECT) && (flags & IOMAP_WRITE) && written == 0) + return -ENOTBLK; + if (iomap->type == IOMAP_MAPPED && written < length && (flags & IOMAP_WRITE)) @@ -908,22 +939,6 @@ static sector_t ext2_bmap(struct address_space *mapping, sector_t block) return generic_block_bmap(mapping,block,ext2_get_block); } -static ssize_t -ext2_direct_IO(struct kiocb *iocb, struct iov_iter *iter) -{ - struct file *file = iocb->ki_filp; - struct address_space *mapping = file->f_mapping; - struct inode *inode = mapping->host; - size_t count = iov_iter_count(iter); - loff_t offset = iocb->ki_pos; - ssize_t ret; - - ret = blockdev_direct_IO(iocb, inode, iter, ext2_get_block); - if (ret < 0 && iov_iter_rw(iter) == WRITE) - ext2_write_failed(mapping, offset + count); - return ret; -} - static int ext2_writepages(struct address_space *mapping, struct writeback_control *wbc) { @@ -946,7 +961,7 @@ const struct address_space_operations ext2_aops = { .write_begin = ext2_write_begin, .write_end = ext2_write_end, .bmap = ext2_bmap, - .direct_IO = ext2_direct_IO, + .direct_IO = noop_direct_IO, .writepages = ext2_writepages, .migrate_folio = buffer_migrate_folio, .is_partially_uptodate = block_is_partially_uptodate, From patchwork Sat Apr 15 07:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=jFOFwyy3; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz52g4NSQz1yZk for ; Sat, 15 Apr 2023 17:45:31 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52g3vk4z4x5c for ; Sat, 15 Apr 2023 17:45:31 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz52g3rwMz4xFL; Sat, 15 Apr 2023 17:45:31 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=jFOFwyy3; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52g3mvtz4x5c for ; Sat, 15 Apr 2023 17:45:31 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229766AbjDOHpJ (ORCPT ); Sat, 15 Apr 2023 03:45:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjDOHo5 (ORCPT ); Sat, 15 Apr 2023 03:44:57 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 328E49019; Sat, 15 Apr 2023 00:44:56 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-5191796a483so1160065a12.0; Sat, 15 Apr 2023 00:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544695; x=1684136695; 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=OTMdTuJ1OD5jmTv0pV5ODd1Pf3L2FjXJKk2J+PBTNqI=; b=jFOFwyy3sNBSjRqyH8M3Jqs/3hXDZqy8ajlKuvzqmJkgjkToo1Gjc0MAkYwRDoQyie yyc8BRv/p7of6b9bZHML22pTs/1QlJpZdgiQaJW9CwqgR+SEAWCYXe0G+xbq0d7+D44p Klpn4kESSoD9DmhBGURLb4INlfBzOX9+0U46Efp7U9OIiM7ye7ELHSJJ0zTD2/3fbNOh 0e7lhEnDVIBXE1fEyOOkGTIZz6/Xe1zMoTu1ePMEfK+kIhKS8ndLrawjqHRT9/f/WfFh 6olmKY2bxsyBx+lUKrinF/VsEYsacf1ywLKilq7hl7lnCZsKX95naIKOPq77RyR1qCop dgsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544695; x=1684136695; 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=OTMdTuJ1OD5jmTv0pV5ODd1Pf3L2FjXJKk2J+PBTNqI=; b=fCmNyukooK3e0MlAnxbHXKIbq0MTtBKjKI61uYz2aG+DCyelTDNGA2S96HXw7ymL5v v/yNs48tnAxYSCrHBqvGcPzg+EqvpOLa7HDQXl8WnzNqdrPAIMtUmMMksesevYzu2PlZ lXXyR6O2Pnd4QfmMwbVSZ3/MAmm5Mkrsy83dXpjA24qNpOEeKZno4/2xoNEOgM1w++V/ C2LTL0ZQ5cenS24sJbhQWirtQoQVrAyE9CU0U38xdTgX4HSZMdD8TImgQyt+2AYX1vXo /9h187RRIHFDmQk91ZDTADd9dmX1Qs1uoVG7oJuRl8RY70rqE6VbU5cZT/toB+NzdY0M K3wg== X-Gm-Message-State: AAQBX9exXaRjvgtmqg37Zy5mRU0Qr8W+GGAQAULFuncam+EiAPJxBg6m 668IkZhSqXk9Fty0hVFB7ryfemOXUeY= X-Google-Smtp-Source: AKy350b897C3EJIGHiO70O0YVw9HfkI1MNCBDSVe/WugbWQtSc7Wh3w0VdIHcQa5LE+rLzVEXYgQ3g== X-Received: by 2002:a05:6a00:b50:b0:633:490f:a18b with SMTP id p16-20020a056a000b5000b00633490fa18bmr11676202pfo.23.1681544695389; Sat, 15 Apr 2023 00:44:55 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:44:55 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" , Christoph Hellwig Subject: [RFCv4 6/9] fs.h: Add TRACE_IOCB_STRINGS for use in trace points Date: Sat, 15 Apr 2023 13:14:27 +0530 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add TRACE_IOCB_STRINGS macro which can be used in the trace point patch to print different flag values with meaningful string output. Tested-by: Disha Goel Reviewed-by: Christoph Hellwig Signed-off-by: Ritesh Harjani (IBM) --- include/linux/fs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index c85916e9f7db..bdc1f7ed2aba 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -340,6 +340,20 @@ enum rw_hint { /* can use bio alloc cache */ #define IOCB_ALLOC_CACHE (1 << 21) +/* for use in trace events */ +#define TRACE_IOCB_STRINGS \ + { IOCB_HIPRI, "HIPRI" }, \ + { IOCB_DSYNC, "DSYNC" }, \ + { IOCB_SYNC, "SYNC" }, \ + { IOCB_NOWAIT, "NOWAIT" }, \ + { IOCB_APPEND, "APPEND" }, \ + { IOCB_EVENTFD, "EVENTFD"}, \ + { IOCB_DIRECT, "DIRECT" }, \ + { IOCB_WRITE, "WRITE" }, \ + { IOCB_WAITQ, "WAITQ" }, \ + { IOCB_NOIO, "NOIO" }, \ + { IOCB_ALLOC_CACHE, "ALLOC_CACHE" } + struct kiocb { struct file *ki_filp; loff_t ki_pos; From patchwork Sat Apr 15 07:44:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=mIXPpLLf; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz52F2Xbvz23rw for ; Sat, 15 Apr 2023 17:45:09 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52F25Trz4xDH for ; Sat, 15 Apr 2023 17:45:09 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz52F22Tfz4xFL; Sat, 15 Apr 2023 17:45:09 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=mIXPpLLf; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52F1x6xz4xDH for ; Sat, 15 Apr 2023 17:45:09 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbjDOHpH (ORCPT ); Sat, 15 Apr 2023 03:45:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbjDOHpA (ORCPT ); Sat, 15 Apr 2023 03:45:00 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05766868B; Sat, 15 Apr 2023 00:44:59 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id lh8so7638933plb.1; Sat, 15 Apr 2023 00:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544698; x=1684136698; 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=dq3WSJRx+3juJv5mvF0LWC9xqRUZPcnpXvObkoDs6EI=; b=mIXPpLLfqW0plhN4QYG/ap6gBD3EY8FzALweFpVqSeEZeOpsWFnV++4I/ALh1xWNDU Ggil12rwHtirg9XJKiZzauJdwLWXIPKYz4kGkfGyjqh1tM7qa9YgFCsj2SizyqC5S9Tm g+JA2v1vbcP7pPvx9xYyv0eoiusA9OcuKQMfcxgiT5Zt1CbvC4RFbs36dypdcsKWsoEL yFuTSqYq3H1hyNpmO3TJwUlLXVmfCzlLJNXd1Gr94Ddw1le0LmRY+rw0Y4dEds8PSFxd 4OStfMflbgVnS33B3ZgAyXTgDe55wEamFea6SiMhDXUW24FZn+OC5wjY6aKVHj8jmhao O15w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544698; x=1684136698; 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=dq3WSJRx+3juJv5mvF0LWC9xqRUZPcnpXvObkoDs6EI=; b=SoaETanySaeYMyZoH7IifoMX8mQRAVvIf4vfNghb2+HfANDdAEfy7I1gssNwEgEBx5 CgA/ViU29kCXU2HObmVHsEjjKa1fPxC9KNIByo35U8zUz5nFt7gns4wLIEfzg6delbwM 7yilr5gkTB8tsk6xocJ6+f/wCKUWKpbqDaKbkntALG+tOGAbCyGiZzkuvAC26Jhxt0Kz GEXXqEWSoQA7LQMav7aboBvw8e8xSb1wS9SOYMHutCpXBk2Gohjc2hnEjuThMZZE3baJ XxcyTpNYtQSf8J/o9pSxjcETCyyLNZuFzoKhzKHnDKCNLCvqBhZzEGLjjgOgpknSXlP3 m62Q== X-Gm-Message-State: AAQBX9eM1ntE6GPaAzdBEoWIl8FRMlEbXjDT3HyX1DFbQc/HogYyPfFH Gcc4Timx9DL4TthxWoYwJg34/PX4WVs= X-Google-Smtp-Source: AKy350Z1ZbbVZBs8Tgi+MyQJG9cccXlO+XWJZnxuwSK9NziOsQ+aa3U4p2KyOqXPwhifSL1q+1s+dQ== X-Received: by 2002:a05:6a20:8401:b0:ee:658c:ad4e with SMTP id c1-20020a056a20840100b000ee658cad4emr4945001pzd.25.1681544698121; Sat, 15 Apr 2023 00:44:58 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:44:57 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" Subject: [RFCv4 7/9] ext2: Add direct-io trace points Date: Sat, 15 Apr 2023 13:14:28 +0530 Message-Id: <31978052d40e4e6b148e0c8cf6ca07bdfc7990e5.1681544352.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This patch adds the trace point to ext2 direct-io apis in fs/ext2/file.c Here is how the output looks like xfs_io-4099 [004] 81.431800: ext2_dio_write_iter_start: dev 7:7 ino 0xc isize 0x4000 pos 0x4000 count 4096 flags DIRECT aio 0 ret=0 xfs_io-4099 [004] 81.432002: ext2_dio_write_end_io: dev 7:7 ino 0xc isize 0x5000 pos 0x4000 count 4096 flags DIRECT aio 0 ret=0 xfs_io-4099 [004] 81.432014: ext2_dio_write_iter_dio_end: dev 7:7 ino 0xc isize 0x5000 pos 0x5000 count 0 flags DIRECT aio 0 ret=4096 aio-dio-fcntl-r-4103 [005] 81.461123: ext2_dio_write_iter_start: dev 7:7 ino 0xc isize 0x400 pos 0x200 count 512 flags DIRECT|WRITE aio 1 ret=0 aio-dio-fcntl-r-4103 [005] 81.462099: ext2_dio_write_end_io: dev 7:7 ino 0xc isize 0x400 pos 0x200 count 512 flags DIRECT|WRITE aio 1 ret=0 aio-dio-fcntl-r-4103 [005] 81.462133: ext2_dio_write_iter_dio_end: dev 7:7 ino 0xc isize 0x400 pos 0x400 count 0 flags DIRECT|WRITE aio 1 ret=512 Reported-and-tested-by: Disha Goel [Need to add CFLAGS_trace for fixing unable to find trace file problem] Signed-off-by: Ritesh Harjani (IBM) --- fs/ext2/Makefile | 5 ++- fs/ext2/file.c | 10 +++++- fs/ext2/trace.c | 6 ++++ fs/ext2/trace.h | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 fs/ext2/trace.c create mode 100644 fs/ext2/trace.h diff --git a/fs/ext2/Makefile b/fs/ext2/Makefile index 311479d864a7..8860948ef9ca 100644 --- a/fs/ext2/Makefile +++ b/fs/ext2/Makefile @@ -6,7 +6,10 @@ obj-$(CONFIG_EXT2_FS) += ext2.o ext2-y := balloc.o dir.o file.o ialloc.o inode.o \ - ioctl.o namei.o super.o symlink.o + ioctl.o namei.o super.o symlink.o trace.o + +# For tracepoints to include our trace.h from tracepoint infrastructure +CFLAGS_trace.o := -I$(src) ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext2-$(CONFIG_EXT2_FS_POSIX_ACL) += acl.o diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 704abe0a79cb..c3e8d8cc6792 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -29,6 +29,7 @@ #include "ext2.h" #include "xattr.h" #include "acl.h" +#include "trace.h" #ifdef CONFIG_FS_DAX static ssize_t ext2_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) @@ -170,9 +171,11 @@ static ssize_t ext2_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) struct inode *inode = file->f_mapping->host; ssize_t ret; + trace_ext2_dio_read_begin(iocb, to, 0); inode_lock_shared(inode); ret = iomap_dio_rw(iocb, to, &ext2_iomap_ops, NULL, 0, NULL, 0); inode_unlock_shared(inode); + trace_ext2_dio_read_end(iocb, to, ret); return ret; } @@ -200,6 +203,7 @@ static int ext2_dio_write_end_io(struct kiocb *iocb, ssize_t size, mark_inode_dirty(inode); } out: + trace_ext2_dio_write_endio(iocb, size, error); return error; } @@ -216,7 +220,9 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) unsigned long blocksize = inode->i_sb->s_blocksize; loff_t offset = iocb->ki_pos; loff_t count = iov_iter_count(from); + ssize_t status = 0; + trace_ext2_dio_write_begin(iocb, from, 0); inode_lock(inode); ret = generic_write_checks(iocb, from); if (ret <= 0) @@ -244,7 +250,6 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) /* handle case for partial write and for fallback to buffered write */ if (ret >= 0 && iov_iter_count(from)) { loff_t pos, endbyte; - ssize_t status; int ret2; iocb->ki_flags &= ~IOCB_DIRECT; @@ -270,6 +275,9 @@ static ssize_t ext2_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) out_unlock: inode_unlock(inode); + if (status) + trace_ext2_dio_write_buff_end(iocb, from, status); + trace_ext2_dio_write_end(iocb, from, ret); return ret; } diff --git a/fs/ext2/trace.c b/fs/ext2/trace.c new file mode 100644 index 000000000000..b01cdf6526fd --- /dev/null +++ b/fs/ext2/trace.c @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "ext2.h" +#include + +#define CREATE_TRACE_POINTS +#include "trace.h" diff --git a/fs/ext2/trace.h b/fs/ext2/trace.h new file mode 100644 index 000000000000..37228a2c2fa6 --- /dev/null +++ b/fs/ext2/trace.h @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM ext2 + +#if !defined(_EXT2_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define _EXT2_TRACE_H + +#include + +DECLARE_EVENT_CLASS(ext2_dio_class, + TP_PROTO(struct kiocb *iocb, struct iov_iter *iter, ssize_t ret), + TP_ARGS(iocb, iter, ret), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(loff_t, isize) + __field(loff_t, pos) + __field(size_t, count) + __field(int, ki_flags) + __field(bool, aio) + __field(ssize_t, ret) + ), + TP_fast_assign( + __entry->dev = file_inode(iocb->ki_filp)->i_sb->s_dev; + __entry->ino = file_inode(iocb->ki_filp)->i_ino; + __entry->isize = file_inode(iocb->ki_filp)->i_size; + __entry->pos = iocb->ki_pos; + __entry->count = iov_iter_count(iter); + __entry->ki_flags = iocb->ki_flags; + __entry->aio = !is_sync_kiocb(iocb); + __entry->ret = ret; + ), + TP_printk("dev %d:%d ino 0x%lx isize 0x%llx pos 0x%llx count %zu flags %s aio %d ret %zd", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->ino, + __entry->isize, + __entry->pos, + __entry->count, + __print_flags(__entry->ki_flags, "|", TRACE_IOCB_STRINGS), + __entry->aio, + __entry->ret) +); + +#define DEFINE_DIO_RW_EVENT(name) \ +DEFINE_EVENT(ext2_dio_class, name, \ + TP_PROTO(struct kiocb *iocb, struct iov_iter *iter, ssize_t ret), \ + TP_ARGS(iocb, iter, ret)) +DEFINE_DIO_RW_EVENT(ext2_dio_write_begin); +DEFINE_DIO_RW_EVENT(ext2_dio_write_end); +DEFINE_DIO_RW_EVENT(ext2_dio_write_buff_end); +DEFINE_DIO_RW_EVENT(ext2_dio_read_begin); +DEFINE_DIO_RW_EVENT(ext2_dio_read_end); + +TRACE_EVENT(ext2_dio_write_endio, + TP_PROTO(struct kiocb *iocb, ssize_t size, int ret), + TP_ARGS(iocb, size, ret), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(loff_t, isize) + __field(loff_t, pos) + __field(ssize_t, size) + __field(int, ki_flags) + __field(bool, aio) + __field(int, ret) + ), + TP_fast_assign( + __entry->dev = file_inode(iocb->ki_filp)->i_sb->s_dev; + __entry->ino = file_inode(iocb->ki_filp)->i_ino; + __entry->isize = file_inode(iocb->ki_filp)->i_size; + __entry->pos = iocb->ki_pos; + __entry->size = size; + __entry->ki_flags = iocb->ki_flags; + __entry->aio = !is_sync_kiocb(iocb); + __entry->ret = ret; + ), + TP_printk("dev %d:%d ino 0x%lx isize 0x%llx pos 0x%llx size %zd flags %s aio %d ret %d", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->ino, + __entry->isize, + __entry->pos, + __entry->size, + __print_flags(__entry->ki_flags, "|", TRACE_IOCB_STRINGS), + __entry->aio, + __entry->ret) +); + +#endif /* _EXT2_TRACE_H */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . +#define TRACE_INCLUDE_FILE trace +#include From patchwork Sat Apr 15 07:44:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=rqMdHgKt; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz52l35q0z1yZk for ; Sat, 15 Apr 2023 17:45:35 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52l2gbfz4x5c for ; Sat, 15 Apr 2023 17:45:35 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz52l2Y0yz4xFL; Sat, 15 Apr 2023 17:45:35 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=rqMdHgKt; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52l2SFTz4x5c for ; Sat, 15 Apr 2023 17:45:35 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbjDOHpc (ORCPT ); Sat, 15 Apr 2023 03:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229847AbjDOHpC (ORCPT ); Sat, 15 Apr 2023 03:45:02 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B322C9742; Sat, 15 Apr 2023 00:45:01 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-63b5c4c76aaso488437b3a.2; Sat, 15 Apr 2023 00:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544701; x=1684136701; 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=h3bFGTlu3ywJiImKEXsaqXr4UVp+VKQfACyqLEyVcDA=; b=rqMdHgKtL8a63yiIEjpiwlXwkF9YbeGj46sA7GCKNX+IbxgCF3hCl4MmAOzSkueg4/ 0nvmop8ZOHQZJY1tzjJHBoshlEnotOM+2CAXUuWbHgEGQ/l0CuZskFxwKqMTaIImxuXB kf/tphfugu2IxUS0e5p64tkgV8J8aIJ88Op2BWvB9pTFfUi31uhlYe9UvjcfTFeHey/K qEy5Glht6VSM9YIWWwFs5KUeZRK1PZkHcwrYj36feYWRTI4dTj9kXH/W55NBR+Atyy8U h+B+Yr98a+zhj0v30u3ToxGnzIqQMsiN6B/TeW7WR8K0C2LQwruaYzMuxrE0cZN1ddPn mHmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544701; x=1684136701; 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=h3bFGTlu3ywJiImKEXsaqXr4UVp+VKQfACyqLEyVcDA=; b=ASI9oVkoSPgk+m7oqVG/3UKauss/gMBeFlLdFSnakFXwuEjznIX57/ins3k7y8Hz3+ /78ELA3KlGGXB95nD5EUSLN7n24t1RLxnMfRdq+HO4xWYj8achCL5J4TqKyzL0G6VO7E +O/rf+eI2Nsa+F/1Wk885njJO74jOKOCpsvUrT3plb7RX+SXIINvPEgGPO7Zh4rDYQH5 VcaPgqSpD4dxEBj9q1ysSH9iOGnRhFJhtgO64amUpE1kVycBRgu+FYVyMt0SmP13KH0J dPpF0wLd28EDycTAHiYIdGVgYoMBzWj8FCEab4fYU3lj325OXcYKWoYVAtqd/oDxr0qA Lo2Q== X-Gm-Message-State: AAQBX9cwJphaDNjC//htORu5Ln432D4er9GhcT2POiS+XQbsMWRK6+Dr YambhOgyDEkLrpcOO9C8UIe3OdCfuQE= X-Google-Smtp-Source: AKy350Z7K9hQWK0ODGog7Gg4kBjX4TEWrmZ5vgneHSaNZp7ABstvZLv52a7mB56nquLZaSDtDFVPJQ== X-Received: by 2002:a05:6a00:10c7:b0:5a8:a0df:a624 with SMTP id d7-20020a056a0010c700b005a8a0dfa624mr11744429pfu.22.1681544701013; Sat, 15 Apr 2023 00:45:01 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:45:00 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" , Christoph Hellwig Subject: [RFCv4 8/9] iomap: Remove IOMAP_DIO_NOSYNC unused dio flag Date: Sat, 15 Apr 2023 13:14:29 +0530 Message-Id: <98ac88dea1a83a8083f5a741e4af400f27821a48.1681544352.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org IOMAP_DIO_NOSYNC earlier was added for use in btrfs. But it seems for aio dsync writes this is not useful anyway. For aio dsync case, we we queue the request and return -EIOCBQUEUED. Now, since IOMAP_DIO_NOSYNC doesn't let iomap_dio_complete() to call generic_write_sync(), hence we may lose the sync write. Hence kill this flag as it is not in use by any FS now. Tested-by: Disha Goel Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Ritesh Harjani (IBM) --- fs/iomap/direct-io.c | 2 +- include/linux/iomap.h | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f771001574d0..36ab1152dbea 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -541,7 +541,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, } /* for data sync or sync, we need sync completion processing */ - if (iocb_is_dsync(iocb) && !(dio_flags & IOMAP_DIO_NOSYNC)) { + if (iocb_is_dsync(iocb)) { dio->flags |= IOMAP_DIO_NEED_SYNC; /* diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 0f8123504e5e..e2b836c2e119 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -377,12 +377,6 @@ struct iomap_dio_ops { */ #define IOMAP_DIO_PARTIAL (1 << 2) -/* - * The caller will sync the write if needed; do not sync it within - * iomap_dio_rw. Overrides IOMAP_DIO_FORCE_WAIT. - */ -#define IOMAP_DIO_NOSYNC (1 << 3) - ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, const struct iomap_ops *ops, const struct iomap_dio_ops *dops, unsigned int dio_flags, void *private, size_t done_before); From patchwork Sat Apr 15 07:44:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ritesh Harjani (IBM)" X-Patchwork-Id: 1769250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=2leh=ag=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=lUixrBJ6; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz52p3hwdz1yZk for ; Sat, 15 Apr 2023 17:45:38 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52p3F9sz4x5c for ; Sat, 15 Apr 2023 17:45:38 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Pz52p3Bg1z4xFL; Sat, 15 Apr 2023 17:45:38 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=lUixrBJ6; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pz52p33wSz4x5c for ; Sat, 15 Apr 2023 17:45:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbjDOHpf (ORCPT ); Sat, 15 Apr 2023 03:45:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjDOHpH (ORCPT ); Sat, 15 Apr 2023 03:45:07 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1FB483DF; Sat, 15 Apr 2023 00:45:04 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2467729fbc4so1604308a91.1; Sat, 15 Apr 2023 00:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681544704; x=1684136704; 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=UC4njAHIv2ukYsLLd4EVfdpnd2WOl/cSebcSSE8kz+4=; b=lUixrBJ6NdQUMytPXZ1OazICdL3ZRQqtjpnREVHTxuvO+3cwaNTOQi8JlPH7ziJXjw gAixEj58woVhDJHLY79ZPgViDM7l01zPpreIu6KwkybqjD24w9ERRB3lNOdQyddxBAcR P1sd6ptO2vGx4RBdI5VzIQc3Q5gf1knAHSehK6vW548clSgiNLCdVl3ahQSsxtYKp/F0 zEFR/OI1kkBdDnDhE/b32LaZshT1rWcMHvI4c7hyZOX8PiEoWVwWiwoAqlTf5rNA7IK1 pwsx8IsCkH4RXCaJwsQ8xFMJP9CNzrZ2lNGISc+r5XJPzLDcDxPvB/nqntF2QjzurXdx rGFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681544704; x=1684136704; 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=UC4njAHIv2ukYsLLd4EVfdpnd2WOl/cSebcSSE8kz+4=; b=Ea4QQWCCvJD5wDnkExBPDmiJJhpudWT+eQg2+A54lQ/cpqdXgk00EPawpMAdTeK3dD 1s2AEra/1Ea/OUUVWlLaezZvYRHqr/eeTszf8OYbDIws0ntvPYELU6vSjmOspKxfp27z 63YzxXoumoDl822oWGmh/pZzdmIZGOmpxfjDLZBB3OEbjwH4ntFPdaD0/Raw2uCi+3kP LfgoSl7jAuAaOA7tR2Mua//+H38xEA3V2OWlkrMdOJjIbWBxeayc2OwZr1k7f6X/7vp9 gE6S4SCIaWeVGw1GR+HRVFb8P7vPipNvjoj3L/CNrBMDXbY+C+A6YZe7+2HwIeU6en/T HgwQ== X-Gm-Message-State: AAQBX9d7/P+2DguGggExKV1JPmSKhMn3bLVr3jwh9B3eqKb+yBy3h7Qz SKTxbGHjiaBbExMHQzpkEiPs6aWKtFw= X-Google-Smtp-Source: AKy350a3c4CsjCT+f51TqgC33BAfCBQ9QK0BFS6LLRgHszkgORkmXFaHt14gCkqYwE+6cBvppFffmQ== X-Received: by 2002:a05:6a00:1a09:b0:636:e52f:631e with SMTP id g9-20020a056a001a0900b00636e52f631emr11473833pfv.1.1681544703770; Sat, 15 Apr 2023 00:45:03 -0700 (PDT) Received: from rh-tp.. ([2406:7400:63:2dd2:1827:1d70:2273:8ee0]) by smtp.gmail.com with ESMTPSA id e21-20020aa78255000000b0063b675f01a5sm2338789pfn.11.2023.04.15.00.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Apr 2023 00:45:03 -0700 (PDT) From: "Ritesh Harjani (IBM)" To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jan Kara , Christoph Hellwig , "Darrick J . Wong" , Ojaswin Mujoo , Disha Goel , "Ritesh Harjani (IBM)" Subject: [RFCv4 9/9] iomap: Add couple of DIO tracepoints Date: Sat, 15 Apr 2023 13:14:30 +0530 Message-Id: <793d0cc2d49ef472038fca2cbe638e18be40cb0c.1681544352.git.ritesh.list@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add iomap_dio_rw_queued and iomap_dio_complete tracepoint. iomap_dio_rw_queued is mostly only to know that the request was queued and -EIOCBQUEUED was returned. It is mostly iomap_dio_complete which has all the details. a.out-1827 [004] 707.806763: iomap_dio_rw_queued: dev 7:7 ino 0xd size 0x1000 offset 0x1000 length 0x0 ksoftirqd/3-31 [003] 707.806968: iomap_dio_complete: dev 7:7 ino 0xd size 0x1000 offset 0x1000 flags DIRECT aio 1 error 0 ret 4096 Signed-off-by: Ritesh Harjani (IBM) --- fs/iomap/direct-io.c | 5 ++++- fs/iomap/trace.c | 1 + fs/iomap/trace.h | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 36ab1152dbea..cef28cfd77b7 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -130,6 +130,7 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) if (ret > 0) ret += dio->done_before; + trace_iomap_dio_complete(iocb, dio->error, ret); kfree(dio); return ret; @@ -650,8 +651,10 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, */ dio->wait_for_completion = wait_for_completion; if (!atomic_dec_and_test(&dio->ref)) { - if (!wait_for_completion) + if (!wait_for_completion) { + trace_iomap_dio_rw_queued(inode, iomi.pos, iomi.len); return ERR_PTR(-EIOCBQUEUED); + } for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); diff --git a/fs/iomap/trace.c b/fs/iomap/trace.c index da217246b1a9..728d5443daf5 100644 --- a/fs/iomap/trace.c +++ b/fs/iomap/trace.c @@ -3,6 +3,7 @@ * Copyright (c) 2019 Christoph Hellwig */ #include +#include /* * We include this last to have the helpers above available for the trace diff --git a/fs/iomap/trace.h b/fs/iomap/trace.h index f6ea9540d082..9c017af93302 100644 --- a/fs/iomap/trace.h +++ b/fs/iomap/trace.h @@ -83,6 +83,7 @@ DEFINE_RANGE_EVENT(iomap_writepage); DEFINE_RANGE_EVENT(iomap_release_folio); DEFINE_RANGE_EVENT(iomap_invalidate_folio); DEFINE_RANGE_EVENT(iomap_dio_invalidate_fail); +DEFINE_RANGE_EVENT(iomap_dio_rw_queued); #define IOMAP_TYPE_STRINGS \ { IOMAP_HOLE, "HOLE" }, \ @@ -183,6 +184,40 @@ TRACE_EVENT(iomap_iter, (void *)__entry->caller) ); +TRACE_EVENT(iomap_dio_complete, + TP_PROTO(struct kiocb *iocb, int error, ssize_t ret), + TP_ARGS(iocb, error, ret), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(ino_t, ino) + __field(loff_t, isize) + __field(loff_t, pos) + __field(int, ki_flags) + __field(bool, aio) + __field(int, error) + __field(ssize_t, ret) + ), + TP_fast_assign( + __entry->dev = file_inode(iocb->ki_filp)->i_sb->s_dev; + __entry->ino = file_inode(iocb->ki_filp)->i_ino; + __entry->isize = file_inode(iocb->ki_filp)->i_size; + __entry->pos = iocb->ki_pos; + __entry->ki_flags = iocb->ki_flags; + __entry->aio = !is_sync_kiocb(iocb); + __entry->error = error; + __entry->ret = ret; + ), + TP_printk("dev %d:%d ino 0x%lx size 0x%llx offset 0x%llx flags %s aio %d error %d ret %zd", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->ino, + __entry->isize, + __entry->pos, + __print_flags(__entry->ki_flags, "|", TRACE_IOCB_STRINGS), + __entry->aio, + __entry->error, + __entry->ret) +); + #endif /* _IOMAP_TRACE_H */ #undef TRACE_INCLUDE_PATH