public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Tso" <tytso@mit.edu>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: Daniel Tang <danielzgtg.opensource@gmail.com>,
	linux-ext4@vger.kernel.org
Subject: Re: [GIT PULL] e4defrag inline data segfault fix
Date: Fri, 16 Jan 2026 17:47:47 -1000	[thread overview]
Message-ID: <20260117034747.GA19954@macsyma.local> (raw)
In-Reply-To: <20260117023559.GC15522@frogsfrogsfrogs>

On Fri, Jan 16, 2026 at 06:35:59PM -0800, Darrick J. Wong wrote:
> > -	/* Has no blocks */
> > -	if (buf->st_blocks == 0) {
> > +	/* Has 0 or 1 blocks, no point to defragment */
> > +	if (buf->st_blocks <= buf->st_blksize / 512) {
> 
> ...because can't you call FS_IOC_GETFLAGS and look for
> EXT4_INLINE_DATA_FL?

I could have checked for EXT4_INLINE_DATA_FL, but we need to call
stat(2) to check for the st_blocks == 0 case, and while it is harmless
to defrag a file with a single data block, it's also pointless and a
waste of system calls.  So it's best that we skip defragging the file
in these cases:

  A) A zero-length file with st_blocks == 0
  B) A file with a single data block (st_blocks == st_blksize / 512)
  C) A file with inline data (st_blocks == 1)

... and we can do that only by checking the values returned by
stat(2).

Yes, (B) and (C) relies on Linux's behavior, since Posix is silent on
the semantics of st_blocks, but e4defrag works only by using a
Linux-specific ioctl, and using FS_IOC_GETFLAGS would also be
Linux-only.

    	       	       	       		- Ted

  reply	other threads:[~2026-01-17  3:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 10:25 [GIT PULL] e4defrag inline data segfault fix Daniel Tang
2026-01-16 17:21 ` Darrick J. Wong
2026-01-16 23:44   ` Theodore Tso
2026-01-17  2:35     ` Darrick J. Wong
2026-01-17  3:47       ` Theodore Tso [this message]
2026-01-17  4:49         ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260117034747.GA19954@macsyma.local \
    --to=tytso@mit.edu \
    --cc=danielzgtg.opensource@gmail.com \
    --cc=djwong@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox