From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 F03213DD53E for ; Fri, 12 Jun 2026 12:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781269132; cv=none; b=ORXkpGMn+gXMXTIXba69OEOjc7Wk1YwF8IoUIvCHPKuj+rE6lov7ciIkVi+XHZP2DmPYVmTwCMN6vHd7wyTK34upZ6r4Tpt1LjGLnRACT0ie/S4L6eOmbH8hKiqiMRPWbNh2kl9VFu0CvRgV/L77Bs3i+8QaPJpASExSfvrH4HI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781269132; c=relaxed/simple; bh=Pqfx17+79DuqSVcb+AsRH4WiOpNiLOxJmuWGiTA4Zlg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=blnpDDqRo1+K+j7JxRSsLq5uyaJ5ChgKJKWIbR5rlgASdH0IeCPE6TPkqgswqLGmCdpYukKyWOvgWjBkFuWjHiABJh5e3ZGx8iYGdNtX0e4+KCbXoN6FVnwhL0i6JdoN9kkI+Ea89hHSO/4JBSGP48J+gAw07Nic8hIE0zSLw6E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dElEYw9o; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dElEYw9o" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-4602e2a0372so723167f8f.3 for ; Fri, 12 Jun 2026 05:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781269129; x=1781873929; darn=vger.kernel.org; h=user-agent: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=59wd4/+QBimDuJWgIi3+urwJ4PUefXw1ZXMMO24I54E=; b=dElEYw9oQbc4CEPvgyN42T/FF80TeIhug9SEnRmCC6xPrk1wKDUx5qSqAqzFmG3JP2 GV4lM8ILkkBNvUtcojc6zVH+hp4uyaEjjw6iqoknwAKmdc9qdeanbudOLOW/glnXA0pM NsEpX6Sp3US8Ofm+pjInh9ACTdaUtJ6/W33rcfIz8EdcbmJmkYdnblonw/yZxiE/VDWL zWsUY/Voz5p2mEUdJIR4UZ3qpKwV96s5pckvMSVKbrstxyZWGSWIFFsZB7IWtlsLoiHI H91jQziTDCvxtB5mx4lEGfjcCPThBXUeYeI0FeuXIWlHwzkk/bG4rFLyEUjWnhfB5SL4 koiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781269129; x=1781873929; h=user-agent: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=59wd4/+QBimDuJWgIi3+urwJ4PUefXw1ZXMMO24I54E=; b=TISYApg8G2Hm2yGVW9F37Jlf8btSbS1DB+ek4Fp6kt+QxZSPSeCqYYWMnvsLtUqVUn 2+1MVWZiyOo3T17ZXcwGzvSeiXSvA1L3NrcGLATfaFaGKVvAsY0mfVCraxde+LOyMK2h mne73qk/5cx5QdIPl0ps1jRwA4L2o7yXuw1FBv531jGaOf2TfXjNzHHtBJaAPMb6hraP OhkaCZs6LJLD0Cjcot7QYbS4LrJ8mniXR0+fd5JdXjYaldRI6HlqUTkGB5v4Cu+1ouJE kjGZYBeWRYFWUHwIDTuXagRxgh0DyQtxaHKkhCuuuGic9RQn1fEanbZRMF0fepbTf1OK VukQ== X-Forwarded-Encrypted: i=1; AFNElJ+pyjf79WvjbtOaSyiekjqSTkIywlXoSeTiNBpQ/DZ/2qHgTNTStgQOXkGIvDH4uI1xkkEnDYti6XNUtDE=@vger.kernel.org X-Gm-Message-State: AOJu0YznsvNwOaJUWmSUmXK0NpR+je0IhuVrZiZuC1YvDPhrX/iNGmt9 uyfURkjMEFsnwGwhyb5rHuLg0C4XavjXCD5XgRZZKa4NBpZYnNSk0TTn+3KpGP2aXw== X-Gm-Gg: Acq92OGImZd4KsSZ+sEsE7s53IbZuqqUJZSCsM9r4SkcflES9nG/xotF1eTNgyXPZFb OKLbU1kCi4784q9FF82iX7BROQeOVjBL6iM84gJj0F9Do27OVdCeN5kA86tusdBCsoOqtawqvuc grmRhcY89rHwKR3mQj8ObcyjYlBZeOJlW7pSxI9WbdN7RKX7ZrAZBr02aJ/Ee5ETtECc3MWEKJC 9V43RUbeq/asCRjlALUaS+Mw6aQXdxdOupAHh6i5YifFf8IgeWsAJQNLeIK50nYltyMCiBuch0w yZBVfAFZo02YFsCM6PVhQNIlxAURQA7KzMRA8MQ6xg42Btb2eDeFvNlvx7y1j1cvZ+9cg0n8cfO LLJpg8YGYP9ZUfwR/WUz80nkkAk1AN3aGaK8C3IaDFxXR7nDzsE34vCPt8C1Foh5sEYRb57SmSJ Tjt/NUbnec0pP2sD2KwnULH05lzHg9/4PXM4gjLI01hSb/9i4XG5EeLbUKw4w= X-Received: by 2002:a05:6000:40cf:b0:446:db72:e8ec with SMTP id ffacd0b85a97d-4606dbdf6b3mr4287095f8f.23.1781269127976; Fri, 12 Jun 2026 05:58:47 -0700 (PDT) Received: from elver.google.com ([2a00:79e0:2834:9:46c:4c2e:b5ff:53ca]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4606f2d933esm5821770f8f.33.2026.06.12.05.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2026 05:58:47 -0700 (PDT) Date: Fri, 12 Jun 2026 14:58:41 +0200 From: Marco Elver To: Heming Zhao 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: User-Agent: Mutt/2.2.13 (2024-03-09) 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?