From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 B7909400E07 for ; Mon, 15 Jun 2026 15:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781536178; cv=none; b=kwB2U6R5rJ6VdUkXk4SXM/S1nZhjSJDAv2KpcjgIvj/py9L0f0HnzpAnP45ksIKmbXhRQZX2OQJIpnC3B2Dl6GBlXKfoH2/Pp+PfVQZ3p2CXIPPwGKOw5pGEpicq2aUZX42iWXXhg4ejyMOFMWxna7uYSKioXcCrs23kEnG6Pkw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781536178; c=relaxed/simple; bh=ni84w/01+N3dJ3ED+7jfXvZ9Q1gy2jaETrYrPpi4hcs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hVK1W4BZVgIOlu0fJWrv9hf+R3xkwG5GQBs5DxLM+sEv9NLohFRfpGIC2aOKAnoU8HEfJaC+MgOa6FuHaMGFtYPzLNFEpwuIDGGylwnCdyn8wXldFrbYmXiYUjXBeV0ptHb4VL7QG8YOfF2nZ/IQJFUAOYEBzLJnqIL7I14Jp8c= 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=Qh/rqv4y; arc=none smtp.client-ip=209.85.128.45 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="Qh/rqv4y" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490d6730461so3657065e9.3 for ; Mon, 15 Jun 2026 08:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1781536175; x=1782140975; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=eUEkUrsanBqZijxmCAC0JPoHe2szL/h32mFkqnSHjAk=; b=Qh/rqv4y08X3uY2XmAYNfBjZCDXhN7hdwjl/WH7TPLxX9YJOFBA5MCZfM/UejRPtvK G4yXJYtRyZISco2ezYcjow1RG8e2hl/j9/BhKLJKk75jRZCIWrsJ3xqg21OuheX2dXNs vzGl9qxUDFC2hCEHYdl8dHbQRRggcR1K3ERgH90Fwq0U+eFtvGU+GkASUdi25+EPfacv 7hDuT29Fb9fbflr9L+rxBelQrrt/Tldq5G4Z8SGZE/dwS8gBS/UQqrcBrrWQZe1t0fUi 9UtwGWm86LVrKDLPpSTBpn3zejBUAXIx0sQ1tabYjw/gkJeKnFRQcVqVTofQLLST6BNh BuvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781536175; x=1782140975; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eUEkUrsanBqZijxmCAC0JPoHe2szL/h32mFkqnSHjAk=; b=p78ZzY/bT/ESFahziOOLp737Nb+K7Ag2GR2n1gqTd+Fgua+uFSCo5HLtAqiONaAQTj 36uyVsqaYa9uSlLh3aZYgPMqq0juWWbSxzuKJD9FSictPzh5OSS6hAEaRzxNYsw4cxwk 2U/LzpUz4ERHuTRPtp1UuwGpaVy+GbnAQ8LoxUJfRMdcBWyAdIsXLNCrLk5/61KM3CAF K2iiT8UgpuGXGCSj+c5OXD1wS/Xf2b9VNcC+KQd7TuL3Fkeb9uPy6D90qlqShRdCnBbg yOeRwp9h47gNn7lWfjiuY83iRyN5sOp2fRmOdXu0dl51HSbxjmUIUccDCQTkXaj9dlpf 23MA== X-Forwarded-Encrypted: i=1; AFNElJ8nqBzHPVVeHxnQysKu2/YGskvzS0hWnuced4f6AQ8+2v/B8vSgmaE6B+zGRVEQZIO8Hp3/6enE2MTaXAI=@vger.kernel.org X-Gm-Message-State: AOJu0YxtWMFZpNnND3mqYrcG9ZeI7C7o25/CwIGgVpOVIvLtHx4cdDGd sKzcauzjUZib3LQhBgR2pOdBGtPOcbDVcy5CpeAQE3tlCeImqvuU3KlXDwAR55Yk+Z0= X-Gm-Gg: Acq92OEsqsUUottrD3/oQKMmcXYEHXyQxeye5UchtaLnOVI7emhXDjHDz/gPQyEOB8C DVVoR93YX0C8qKd1REpdf1gyK3OipKLwBiy9CyXmABzvinHdkGfKFo0Dw0bRwBVXbCWI+nFsBqT 2T/qXvQGRFwpCkP2LdhzbigpzZeEa0fGCxxsMSsiYIgxB+3C0Addw+rslTTPKrjyfEOnwzWctzw Lzw5Ot+kA7mMH/HkycsVu12w/AKND/cPzljSHhncZOdLuHZYCG0rhUxICmcwXnuR1LhN5795Pwd bEKcCxIEHxd72SQs1OHEdf9vAgi+5XN535pCTGNZ3+TqAqJYZuz7df8F94h4gHMDRpgVKdBg11O E3+mzYRPYG8YUjle4O2jh9ecDIClqMsbz9jb79QmssX9OE0a5VXkTByiZGNgR6bn+8JF/Dd4Che l1/qqnMiTi6R8tCDNpG1Qk5XtfZVgb2AgA X-Received: by 2002:a05:600c:4745:b0:488:7e7b:dbc2 with SMTP id 5b1f17b1804b1-490ec4fd3e4mr93700105e9.3.1781536175225; Mon, 15 Jun 2026 08:09:35 -0700 (PDT) Received: from localhost ([202.127.77.110]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3081e5d810fsm15466767eec.12.2026.06.15.08.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 08:09:34 -0700 (PDT) Date: Mon, 15 Jun 2026 23:09:31 +0800 From: Heming Zhao To: Marco Elver Cc: Mark Fasheh , Joel Becker , Joseph Qi , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: Re: [PATCH] ocfs2: fix orphan inode disk leak in ocfs2_dio_end_io() on I/O error Message-ID: References: <20260611150341.3964327-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Jun 12, 2026 at 02:58:41PM +0200, Marco Elver wrote: > On Fri, Jun 12, 2026 at 09:27AM +0800, Heming Zhao wrote: > > On Thu, Jun 11, 2026 at 05:01:50PM +0200, Marco Elver wrote: > > > When an extending direct I/O write or a direct I/O write racing with an > > > unlink is initiated, ocfs2_direct_IO() places the user inode into the > > > system orphan directory and sets the OCFS2_DIO_ORPHANED_FL flag to > > > ensure defined behavior and crash consistency. > > > > > > However, if the direct I/O request encounters an error or gets > > > asynchronous cancellation (bytes <= 0), the VFS completion hook > > > ocfs2_dio_end_io() bypasses ocfs2_dio_end_io_write() entirely and > > > executes ocfs2_dio_free_write_ctx(). This completely omits the teardown > > > of the orphan entry, leaking the user inode in the orphan directory and > > > leaving the OCFS2_DIO_ORPHANED_FL disk flag set. > > > > > > Because the OCFS2_DIO_ORPHANED_FL flag remains active, subsequent VFS > > > final inode eviction (ocfs2_delete_inode) observes the flag, assumes a > > > direct I/O write is actively in progress, and refuses to wipe the inode. > > > This results in an irrecoverable disk storage and resource leak that can > > > only be reclaimed if the cluster unmounts or crashes. > > > > > > Fix this by ensuring that ocfs2_dio_end_io() inspects dw_orphaned even > > > when an I/O error occurs, and executes ocfs2_del_inode_from_orphan() to > > > liberate the inode before destroying the in-memory write context. > > > > > > Fixes: 5040f8df56fb ("ocfs2: free up write context when direct IO failed") > > > Assisted-by: Antigravity:Gemini > > > Signed-off-by: Marco Elver > > > --- > > > fs/ocfs2/aops.c | 17 +++++++++++++++-- > > > 1 file changed, 15 insertions(+), 2 deletions(-) > > > > > > diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c > > > index 4acdbb70882c..ad3f2057e26e 100644 > > > --- a/fs/ocfs2/aops.c > > > +++ b/fs/ocfs2/aops.c > > > @@ -2419,11 +2419,24 @@ static int ocfs2_dio_end_io(struct kiocb *iocb, > > > mlog_ratelimited(ML_ERROR, "Direct IO failed, bytes = %lld", > > > (long long)bytes); > > > if (private) { > > > - if (bytes > 0) > > > + if (bytes > 0) { > > > ret = ocfs2_dio_end_io_write(inode, private, offset, > > > bytes); > > > - else > > > + } else { > > > + struct ocfs2_dio_write_ctxt *dwc = private; > > > + > > > + if (dwc->dw_orphaned) { > > > + struct buffer_head *di_bh = NULL; > > > + > > > + if (ocfs2_inode_lock(inode, &di_bh, 1) == 0) { > > > + ocfs2_del_inode_from_orphan(OCFS2_SB(inode->i_sb), > > > + inode, di_bh, 0, 0); > > > + ocfs2_inode_unlock(inode, 1); > > > + brelse(di_bh); > > > + } > > > > Calling only ocfs2_del_inode_from_orphan() without ocfs2_truncate_file() will > > leave stale blocks beyond the EOF. > > Right. > > > I think the existing OCFS2 code already handles error/crash cases for orphaned > > inodes, and this "leaking" behavior is by design. > > please refer to ocfs2_recover_orphans() and ocfs2_add_inode_to_orphan(). > > Periodic scans skip direct I/O entries to avoid racing with active > direct I/O on live nodes: > > In fs/ocfs2/journal.c:ocfs2_orphan_filldir(): > > /* do not include dio entry in case of orphan scan */ > if ((p->orphan_reco_type == ORPHAN_NO_NEED_TRUNCATE) && > (!strncmp(name, OCFS2_DIO_ORPHAN_PREFIX, > OCFS2_DIO_ORPHAN_PREFIX_LEN))) > return true; > > Is something else recovering them? Searching for ORPHAN_NEED_TRUNCATE, i.e.: - ocfs2_recover_node() calls ocfs2_queue_recovery_completion() with the ORPHAN_NEED_TRUNCATE flag. - ocfs2_complete_mount_recovery() calls subroutines with the ORPHAN_NEED_TRUNCATE flag. ocfs2 is a cluster fs. When one node crashes, another node handles the recovery. - Heming