From patchwork Mon Apr 8 08:20:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 13620750 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7FEB2C69C for ; Mon, 8 Apr 2024 08:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564463; cv=none; b=pa0A8DvQa28LfimC+wWj4WRt1NXpMTi0AdStZffnosNGW2kDqUgQW2zpesII5dGD9/QALDJrSnO6jUpPc0oUOT1+6YbiLlzAo4Ex4AQfOcgcp09SpfA+RRItmw3ePmRls28k0m+2EG/IsSzvAMMTEe/w6g0zXO1h0G1bgjQ2YPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564463; c=relaxed/simple; bh=9pdjTt/gh0IhCKPLnY5Sq7vErp/pf4in6ThDa1bno0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iWEcpod46z4Nj/CGWUS0xICw7OBYaO0FdsRb5/vnlABmFxZqUPq2j72//bjJxAqTkkC3nbq2EcAFL5KybmI1Xt7qnhmLi31WBaudFdSk84pLzWRDIhA63ke9hzF9Vw3gWDRfplARFI/bWSyahAK7CLpg141glEkmkn20ybAi28Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=LLz2ffsr; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="LLz2ffsr" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2d6c9678cbdso53847781fa.2 for ; Mon, 08 Apr 2024 01:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1712564458; x=1713169258; darn=lists.linux.dev; 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=bUkZlQs220fLoYzRdwgTqLyT2iPPHzAzB+hnAyoHG0Q=; b=LLz2ffsrCHbRpDwjQe/4yisY/2N0EluEFD3S5DyIkuynwbnvtu5SPfxjQA3YgseX0i bsYJFA38ZkPTcdEISt27IXwnGGu7nJtgME5Up7Cd/dgaevYBxg3DABzDXpIMStT0WjcJ i5jvPUnTj4B489WPwfq/bHZFdUWNfkhefb6QQzTmgU2O/cn7txEkz4tGcm7BhdIGhe+h 9en5/NuIp3HqYvxswTZo4EutGMZkr+sVp/E7KdQwth5eVloQD2+5SyNC13eLZthvix4i Iuz6+18aILigkExxOv+33YwI18bODjjaroYV+45q+SHmpWIKl3xuTH0Un+Ng4kauhVFh D3Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712564458; x=1713169258; 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=bUkZlQs220fLoYzRdwgTqLyT2iPPHzAzB+hnAyoHG0Q=; b=cYDKy1v8L4jRIECTTQ/LFhzX9+fEfyOblcPWdkD2nMVoMeApoTv+oSfFSS0kEAxFZi 7mXbVPf+yG+UMGFhM5H8U/YZekkgbhU8yVlfZnAOkUYtnkygbTJ4W8DO1UQrCZWv65u7 lE3GTcMI4EPkzsiElhcoN1Dxlu8H5zyl8cqLENHLDPfuMRHuHU+b5AcGkIvetfeAt3Wx JzvuFBr31exfuZ/oMnjMTOx+RppL04fjF/29VsAFk6IGphkP2YLYA1lTBtB4kh36+FBL xg0xYCaiQoNZ/7n9u6smpaxRkIepnwRRqe1l3UC72quOJK/PvMWIkokQ/KPYVlIZx3Rx Wjaw== X-Gm-Message-State: AOJu0YxQPrl1Pt3GvNSl4DIfWFZqP8s4Veg+0uZyu5+Bn2aG8hDKi/3G /b4fw2l/SJ3YgaopurcA2RLNpuV4R6cj0UJAH7yxWDtBYCQVzueR5aPbulGezki+anXzP54RuFZ D X-Google-Smtp-Source: AGHT+IE07kMDKS4YSoKAIJ9In4NQkJSEgsfbItrlBx05S2XyreseWGEWSg8Y6cBtDOINo07IujO0oA== X-Received: by 2002:a2e:8e86:0:b0:2d8:6104:f95a with SMTP id z6-20020a2e8e86000000b002d86104f95amr5088732ljk.23.1712564458133; Mon, 08 Apr 2024 01:20:58 -0700 (PDT) Received: from localhost.localdomain ([23.247.139.60]) by smtp.gmail.com with ESMTPSA id ft4-20020a17090b0f8400b002a54c4dd0f2sm213894pjb.43.2024.04.08.01.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:20:57 -0700 (PDT) From: Su Yue To: ocfs2-devel@lists.linux.dev Cc: joseph.qi@linux.alibaba.com, akpm@linux-foundation.org, Su Yue Subject: [PATCH v3 1/4] ocfs2: return real error code in ocfs2_dio_wr_get_block Date: Mon, 8 Apr 2024 16:20:38 +0800 Message-ID: <20240408082041.20925-2-glass.su@suse.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408082041.20925-1-glass.su@suse.com> References: <20240408082041.20925-1-glass.su@suse.com> Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ocfs2_dio_wr_get_block always returns -EIO in case of errors. However, some programs expect right exit codes while doing dio. For example, tools like fio treat -ENOSPC as expected code while doing stress jobs. And quota tools expect -EDQUOT when disk quota exceeds. -EIO is too strong return code in the dio path. The caller of ocfs2_dio_wr_get_block is __blockdev_direct_IO which is widely used and it handles error codes well. I have checked functions called by ocfs2_dio_wr_get_block and their return codes look good and clear. So I think it's safe to let ocfs2_dio_wr_get_block return real error code. Reviewed-by: Joseph Qi Signed-off-by: Su Yue --- fs/ocfs2/aops.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index b82185075de7..f0467d3b3c88 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -2283,8 +2283,6 @@ static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock, ocfs2_inode_unlock(inode, 1); brelse(di_bh); out: - if (ret < 0) - ret = -EIO; return ret; } From patchwork Mon Apr 8 08:20:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 13620751 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (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 0AF682C859 for ; Mon, 8 Apr 2024 08:21:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564466; cv=none; b=TRz+xz3s0vZWl2xm5q/fbUs6oMljstGsp2LLRKDVM1m5n5l0vdfM2bWSCSuK9Sv5snvNcRFZSWg5YogiI8FW8R3L10W0cuS7DpLGOI3gIfcohCXybuadlDs7pKPHs1oBYlSeM/hkQZxZKFqtWfPXprzytHulpA1pbjA4hpVka3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564466; c=relaxed/simple; bh=E8uSWe7pC+CVsWMJcUUu1kL8RPlbZxsgmhC0boH9X+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HXAg2U6Grll+vX09B+ic3bfgiR/u+334h7Cos1E4JUeLj/OJsZiY4d4C256rZ2wxdOg9J5cMliiygyINxIrNFNeQwrxd3W7Dpj5Qx5O6NJqkgIuYgEe7wAaIOTzJC+omm8mVOkKW2cDU/Xmxwg6V22LEKLCf8uC0Ph+IRKsjuuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=DnKkB6V0; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="DnKkB6V0" Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2d6fc3adaacso52738061fa.2 for ; Mon, 08 Apr 2024 01:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1712564460; x=1713169260; darn=lists.linux.dev; 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=uFmqypw/aseL1xkegBMxmm6qJqyDfXccXXSHs6zN11E=; b=DnKkB6V02/BUTIdiGsgFlBf3ZxthbqmeFy6pkX62qN6i0I3bTSbsGZvCKJN55IL0L5 KiS98EQlbHU496OlulVhHpcDnpABM/Ae+h0Avbl93QI0kzBPYwWkLydw9g5vAYri4V1i XD0B+eBDfnVSquvOiMBxN2NmhE/A5eUF3kCO7m1p8qZqQ2aIWzU1xtlRWfRkQ1ob2CfS oo08jTBZZT2y6QzEvfmYp0zhIlfUbKX/t7WUvkcj7hCWGAolBZKi7dYMI4CvMP/OwpwM 47q0ICG5KJr8h0M+D6MupaRIPsxgqy+sW8NEE6qBMEsmMpxowORZlsO8CKVpAAlprhxu 3UNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712564460; x=1713169260; 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=uFmqypw/aseL1xkegBMxmm6qJqyDfXccXXSHs6zN11E=; b=cZEjd0UCpYnBSHpL3dsfA0TEUOnEUMu0AXLtj2rkqmiiVz/U5go82V5UYqtGtVfLiK whvKpVSctqQbX/rDjJ9bcJIhtfeIZkxIBqDvSDmaqSiq2NjmJhCRg2sJ8y27yL0eSSCs Ofunvtuj6XMgc+ztWPHwKylrO2xFq3rRJsiJWz5B0tdWPAPBAVXghL+MBVPHspR//fdv kxtGzCeA9L9cfRKyJ5JgkxnI0SV9TLP7kLNSm+3DJyj1UX8szbcU46BLSlbwGv9YhgHc n2id5d4k+XflM5nT7WNC2eV/e4hvpmzvinXbcUlgSdc6E+k0N0DQiPTiKCncC+0MuM1D z4Vw== X-Gm-Message-State: AOJu0YxaZ+DMUJl7Q3YvmARoFzsxpsy45Ag3T1tnRQRjBMSrPuTUPduJ mGrvUQm4mmyCutxgJq4kt/sewoCGHUlri9jqR9bybWFrfzqw91bb/wG/q4s6lUEemnbJltjQr08 E X-Google-Smtp-Source: AGHT+IEqq1vha+qKaVfI1kyySiExDvzAayata71PCI5zFqSP6Oueu4/iT+nyoyyycsFGyfuAHTXxZQ== X-Received: by 2002:a2e:8755:0:b0:2d8:687e:4fef with SMTP id q21-20020a2e8755000000b002d8687e4fefmr5189466ljj.12.1712564460545; Mon, 08 Apr 2024 01:21:00 -0700 (PDT) Received: from localhost.localdomain ([23.247.139.60]) by smtp.gmail.com with ESMTPSA id ft4-20020a17090b0f8400b002a54c4dd0f2sm213894pjb.43.2024.04.08.01.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:20:59 -0700 (PDT) From: Su Yue To: ocfs2-devel@lists.linux.dev Cc: joseph.qi@linux.alibaba.com, akpm@linux-foundation.org, Su Yue Subject: [PATCH v3 2/4] ocfs2: fix races between hole punching and AIO+DIO Date: Mon, 8 Apr 2024 16:20:39 +0800 Message-ID: <20240408082041.20925-3-glass.su@suse.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408082041.20925-1-glass.su@suse.com> References: <20240408082041.20925-1-glass.su@suse.com> Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 After commit "ocfs2: return real error code in ocfs2_dio_wr_get_block", fstests/generic/300 become from always failed to sometimes failed: ======================================================================== [ 473.293420 ] run fstests generic/300 [ 475.296983 ] JBD2: Ignoring recovery information on journal [ 475.302473 ] ocfs2: Mounting device (253,1) on (node local, slot 0) with ordered data mode. [ 494.290998 ] OCFS2: ERROR (device dm-1): ocfs2_change_extent_flag: Owner 5668 has an extent at cpos 78723 which can no longer be found [ 494.291609 ] On-disk corruption discovered. Please run fsck.ocfs2 once the filesystem is unmounted. [ 494.292018 ] OCFS2: File system is now read-only. [ 494.292224 ] (kworker/19:11,2628,19):ocfs2_mark_extent_written:5272 ERROR: status = -30 [ 494.292602 ] (kworker/19:11,2628,19):ocfs2_dio_end_io_write:2374 ERROR: status = -3 fio: io_u error on file /mnt/scratch/racer: Read-only file system: write offset=460849152, buflen=131072 ========================================================================= In __blockdev_direct_IO, ocfs2_dio_wr_get_block is called to add unwritten extents to a list. extents are also inserted into extent tree in ocfs2_write_begin_nolock. Then another thread call fallocate to puch a hole at one of the unwritten extent. The extent at cpos was removed by ocfs2_remove_extent(). At end io worker thread, ocfs2_search_extent_list found there is no such extent at the cpos. T1 T2 T3 inode lock ... insert extents ... inode unlock ocfs2_fallocate __ocfs2_change_file_space inode lock lock ip_alloc_sem ocfs2_remove_inode_range inode ocfs2_remove_btree_range ocfs2_remove_extent ^---remove the extent at cpos 78723 ... unlock ip_alloc_sem inode unlock ocfs2_dio_end_io ocfs2_dio_end_io_write lock ip_alloc_sem ocfs2_mark_extent_written ocfs2_change_extent_flag ocfs2_search_extent_list ^---failed to find extent ... unlock ip_alloc_sem In most filesystems, fallocate is not compatible with racing with AIO+DIO, so fix it by adding to wait for all dio before fallocate/punch_hole like ext4. Fixes: b25801038da5 ("ocfs2: Support xfs style space reservation ioctls") Reviewed-by: Joseph Qi Signed-off-by: Su Yue --- fs/ocfs2/file.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 0da8e7bd3261..ccc57038a977 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c @@ -1936,6 +1936,8 @@ static int __ocfs2_change_file_space(struct file *file, struct inode *inode, inode_lock(inode); + /* Wait all existing dio workers, newcomers will block on i_rwsem */ + inode_dio_wait(inode); /* * This prevents concurrent writes on other nodes */ From patchwork Mon Apr 8 08:20:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 13620752 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 22CE7171A5 for ; Mon, 8 Apr 2024 08:21:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564467; cv=none; b=jIYdEYK52bwb35AGhpCywwO5fSMLfTHVi4wuiYXa5nLTGrSW/DS/97z/f+/oNyIvYk0mktBpBL0ytj0l5Cm7yRa3UF+jpvDafr1lttttqCUTV7/hZTm3Tstyn7kSfJhB+p1cpDQ2Z9cJ2Vuixcr8B2DyQTa5IyoG+QSVRa4BNio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564467; c=relaxed/simple; bh=/AeG3DYk/eW8cLN2CW8Rk7adOidcJzjowoR1eCXFPbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GfuxyQOTm6GemAfKiIcrUl3ggCxy3qG5mSpcoUiDtt+A7AS4YSdrlYITfTe768ekC1cK4i47JYp5uNtLxRVo6ZJF0w2mVxfzeBX3R0uv7rxBBZQqEdBfttOvlExZCad7CgOxcdhLTqBFqT9+USIFWt47bK+Sq31O7JG28Xl/sp8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Q5CI7OIo; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Q5CI7OIo" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d715638540so50448571fa.3 for ; Mon, 08 Apr 2024 01:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1712564463; x=1713169263; darn=lists.linux.dev; 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=6BbkJ+XSY9Df+z1Sk0IjqHeYerqOmLYxKLPipkVMz3A=; b=Q5CI7OIojCDy35jXzi+BFizVbCqtWnipj8v+hbt36i96zlfmVlgEytJX9B9CAadU8v j8C41rH5/FUh52dKraNFz2QAVvoH+PXZAHJ39L1JsENmcJ12JwfyyyvzSJnwkUnJ5j+m gqpV1aD1KEqgFj7z6775f3RA/K8macw0jZTYodiLUn0YyPWjBffRpAKoJBJpX5CGVBO+ ZVhA080Nvj2+P/G4QvAf5Fg8JYsvKxNbnbM7GuQiXQ7DC0Jd/lJok/wDzZ8Gu9gWqW/g W8ccmiQJWWT9BVxLSn+jnKxul7dP4SZgrrRb07LEngauCL7v77nDum/aAP5Grk9j7cDz MECg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712564463; x=1713169263; 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=6BbkJ+XSY9Df+z1Sk0IjqHeYerqOmLYxKLPipkVMz3A=; b=jNtmz7amdnd1MwaHGTG0J3XUK7+60N1jbRWy48jx7D9G8GJlLBiO8IdXFsTj+CHVUm AX+ufPrYhqFxJ/llDsiu6+BUDciqc9stT1nin1sUnNr52U/j+AD5TRIBavvEiN4hdXOC tNvzF8tN987KeQV7DOc2eT2OcIAiMcIAbDzPpQOBdX8dztbTB4EFcwZ9DANmsWjDd7YS u+cqjthSJPF/maQzPSO6NaZl5YLy91U/PFSKPPlf1MKt7qbQl8qEjrH7GBbO2GDIEBJ7 RbGEFaZWX2pc2QHK3xETANiBXpUkR9GweCVkr0haqLJazu9Mmv8U58Q0o0Gl5Y+vqyTS dB4g== X-Gm-Message-State: AOJu0Yw2gd2VBwGXiL+yD9+EJ5HpnN47yULFQ3Lo+RNJurc3C1FwNHAd 9n1z0zXHfBIAhhOggI5vi4QYbqjM73XNzBJow+2fHHYpd+Psj19oamvvV/REw23/Txw34B4Hudz I X-Google-Smtp-Source: AGHT+IEe4n5Goe2Qrz8BVTkFpurqZ5DQIv6sG3hd7tS/0HzuvhZZk+wMuzTRZvj8N4a0q6lntdBcjQ== X-Received: by 2002:a2e:914d:0:b0:2d8:8368:e22d with SMTP id q13-20020a2e914d000000b002d88368e22dmr1870881ljg.42.1712564463223; Mon, 08 Apr 2024 01:21:03 -0700 (PDT) Received: from localhost.localdomain ([23.247.139.60]) by smtp.gmail.com with ESMTPSA id ft4-20020a17090b0f8400b002a54c4dd0f2sm213894pjb.43.2024.04.08.01.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:21:02 -0700 (PDT) From: Su Yue To: ocfs2-devel@lists.linux.dev Cc: joseph.qi@linux.alibaba.com, akpm@linux-foundation.org, Su Yue Subject: [PATCH v3 3/4] ocfs2: update inode fsync transaction id in ocfs2_unlink and ocfs2_link Date: Mon, 8 Apr 2024 16:20:40 +0800 Message-ID: <20240408082041.20925-4-glass.su@suse.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408082041.20925-1-glass.su@suse.com> References: <20240408082041.20925-1-glass.su@suse.com> Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 transaction id should be updated in ocfs2_unlink and ocfs2_link. Otherwise, inode link will be wrong after journal replay even fsync was called before power failure: ======================================================================= $ touch testdir/bar $ ln testdir/bar testdir/bar_link $ fsync testdir/bar $ stat -c %h $SCRATCH_MNT/testdir/bar 1 $ stat -c %h $SCRATCH_MNT/testdir/bar 1 ======================================================================= Fixes: ccd979bdbce9 ("[PATCH] OCFS2: The Second Oracle Cluster Filesystem") Reviewed-by: Joseph Qi Signed-off-by: Su Yue --- fs/ocfs2/namei.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index 9221a33f917b..55c9d90caaaf 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c @@ -797,6 +797,7 @@ static int ocfs2_link(struct dentry *old_dentry, ocfs2_set_links_count(fe, inode->i_nlink); fe->i_ctime = cpu_to_le64(inode_get_ctime_sec(inode)); fe->i_ctime_nsec = cpu_to_le32(inode_get_ctime_nsec(inode)); + ocfs2_update_inode_fsync_trans(handle, inode, 0); ocfs2_journal_dirty(handle, fe_bh); err = ocfs2_add_entry(handle, dentry, inode, @@ -993,6 +994,7 @@ static int ocfs2_unlink(struct inode *dir, drop_nlink(inode); drop_nlink(inode); ocfs2_set_links_count(fe, inode->i_nlink); + ocfs2_update_inode_fsync_trans(handle, inode, 0); ocfs2_journal_dirty(handle, fe_bh); inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); From patchwork Mon Apr 8 08:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 13620753 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A45B6171A5 for ; Mon, 8 Apr 2024 08:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564470; cv=none; b=MvX0McHqo5qDUn+c7EjCNGoj4a7hebaorWQdOLD7ioTNBh5RlNKzhjt246h2lKl4/8urMcY6hmREP46nIwFxkgjzj/EsWKWbaImrnjmCQAwa55KUPdcbIiYCfM/37USJwanccg+dtbQ8zB5c+DvIyURI6VcWi5OqxXIKjjd6Czs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712564470; c=relaxed/simple; bh=mK7rcVaB2D0toNvRyCcgZ1X3G+t/7C+8rbRG8O1FM04=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SfN5mAW9HKy/LW7zdMLs/a9NWDv+6j/jfuKm0/m3fNXT6oCxg/mCyDiqbs5/axWlIB9IF5uOl+PU3ZgpEFaw7TftCd1Rv8NyAFqaE9pmKu2L64KVcxd8irfBfSJBlDoc0pyfykxHlUrXlVoQ36v8+b09TWiTo2BJsamqv3oOm4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=c5KRKQ4k; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="c5KRKQ4k" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d8743ecebdso20673851fa.1 for ; Mon, 08 Apr 2024 01:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1712564466; x=1713169266; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i/UfPcAmlpDEI2X3qdBAd3zI4r9LsmLNdFyUr1d0two=; b=c5KRKQ4k3e8UYt+vJ+OtttFfsvtKVskq6qlKVCqkpmEVF3CD34V/WoNmxn/payoU3C N1lV5kXakB8SWvxzlIGhKa0kOI796BOONUUhdXNL/4EeYQ3/xeA9fC2sr6PWhulN1bj4 78xEQ9USwKgpbTeNAoABxAIupFn6Ar08yZas7Qo3xOMkklllm1HyBFMm1jOjRsbLveNo Ct1azBE9uU2x8JBWlN0HWpFq540pbxzbDjMCF1FMqs3cBIa/erzGD6XCjpCJMjfb0Wcz 38/kL28jfJGJzq2YnaGHxlIoBjizn30Gt9LnTh3t5YdGn0WBzObkgXgOBrNrJ6l/zBZP sVNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712564466; x=1713169266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i/UfPcAmlpDEI2X3qdBAd3zI4r9LsmLNdFyUr1d0two=; b=thZGHJTJmetAKa+TQ0DaGvs307Bhv/9d79++g0fkkjle47D4DlCDlGKfvHdumI2tk8 TsapQ0OKbcQeEB6ayqbUct6WBlW+l8dr/dyOI4bbGBk8m0tqpaGhCBuLR57nd7tyyvGX FCswiup+Ek4KIWtm2DFWHYBgeq9kNo+KKI9H+Fc9KhGaz6rKetxdmEUw+ApylepHlBm2 MDQOlnlkIHenMxQOzqQ1CVRwKHcvbpOV3fKMsUe/B7EYLahukuC9IDqbr3WHlXfw45AS xgl/CjcN378zf7NY/e6+Q6RdyLhpAfpwUfqYS/kbDW2RtI16EXKITrGrf5aJMfW2NxoI N44A== X-Gm-Message-State: AOJu0Yw6oFvubon3n3yIqh0hnMfLxwpx9pjXA0TqobUvb5IF3Efgk/30 wHdB+VB8mdEREC+8o/i6JyR6zOTIogup0zPYUVZr4NmczxhbQSzhdEeI5KPSpbwIVa+mxW9TBJb g X-Google-Smtp-Source: AGHT+IHzVSOiezSBXFvSq3/0put944IgNKdojUNy3Mick3/iwkhlz1nMjmrUTxqhXCFWs6ozpGuKOg== X-Received: by 2002:a2e:b049:0:b0:2d8:1c09:cdc4 with SMTP id d9-20020a2eb049000000b002d81c09cdc4mr5919805ljl.21.1712564466129; Mon, 08 Apr 2024 01:21:06 -0700 (PDT) Received: from localhost.localdomain ([23.247.139.60]) by smtp.gmail.com with ESMTPSA id ft4-20020a17090b0f8400b002a54c4dd0f2sm213894pjb.43.2024.04.08.01.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 01:21:04 -0700 (PDT) From: Su Yue To: ocfs2-devel@lists.linux.dev Cc: joseph.qi@linux.alibaba.com, akpm@linux-foundation.org, Su Yue Subject: [PATCH v3 4/4] ocfs2: use coarse time for new created files Date: Mon, 8 Apr 2024 16:20:41 +0800 Message-ID: <20240408082041.20925-5-glass.su@suse.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408082041.20925-1-glass.su@suse.com> References: <20240408082041.20925-1-glass.su@suse.com> Precedence: bulk X-Mailing-List: ocfs2-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The default atime related mount option is '-o realtime' which means file atime should be updated if atime <= ctime or atime <= mtime. atime should be updated in the following scenario, but it is not: ========================================================== $ rm /mnt/testfile; $ echo test > /mnt/testfile $ stat -c "%X %Y %Z" /mnt/testfile 1711881646 1711881646 1711881646 $ sleep 5 $ cat /mnt/testfile > /dev/null $ stat -c "%X %Y %Z" /mnt/testfile 1711881646 1711881646 1711881646 ========================================================== And the reason the atime in the test is not updated is that ocfs2 calls ktime_get_real_ts64() in __ocfs2_mknod_locked during file creation. Then inode_set_ctime_current() is called in inode_set_ctime_current() calls ktime_get_coarse_real_ts64() to get current time. ktime_get_real_ts64() is accurater than ktime_get_coarse_real_ts64(). In my test box, I saw ctime set by ktime_get_coarse_real_ts64() is less than ktime_get_real_ts64() even ctime is set later. The ctime of the new inode is smaller than atime. The call trace is like: ocfs2_create ocfs2_mknod __ocfs2_mknod_locked .... ktime_get_real_ts64 <------- set atime,ctime,mtime, more accurate ocfs2_populate_inode ... ocfs2_init_acl ocfs2_acl_set_mode inode_set_ctime_current current_time ktime_get_coarse_real_ts64 <-------less accurate ocfs2_file_read_iter ocfs2_inode_lock_atime ocfs2_should_update_atime atime <= ctime ? <-------- false, ctime < atime due to accuracy So here call ktime_get_coarse_real_ts64 to set inode time coarser while creating new files. It may lower the accuracy of file times. But it's not a big deal since we already use coarse time in other places like ocfs2_update_inode_atime and inode_set_ctime_current. Fixes: c62c38f6b91b ("ocfs2: replace CURRENT_TIME macro") Reviewed-by: Joseph Qi Signed-off-by: Su Yue --- fs/ocfs2/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index 55c9d90caaaf..4d1ea8703fcd 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c @@ -566,7 +566,7 @@ static int __ocfs2_mknod_locked(struct inode *dir, fe->i_last_eb_blk = 0; strcpy(fe->i_signature, OCFS2_INODE_SIGNATURE); fe->i_flags |= cpu_to_le32(OCFS2_VALID_FL); - ktime_get_real_ts64(&ts); + ktime_get_coarse_real_ts64(&ts); fe->i_atime = fe->i_ctime = fe->i_mtime = cpu_to_le64(ts.tv_sec); fe->i_mtime_nsec = fe->i_ctime_nsec = fe->i_atime_nsec =