All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: Andrey Albershteyn <aalbersh@redhat.com>, Karel Zak <kzak@redhat.com>
Cc: esandeen@redhat.com, util-linux@vger.kernel.org
Subject: Re: [PATCH 0/2] libblkid: add FSSIZE with XFS implementation
Date: Tue, 26 Apr 2022 23:10:12 -0500	[thread overview]
Message-ID: <facb3c36-0088-d645-6162-4d52fc94557f@redhat.com> (raw)
In-Reply-To: <YmfPPbgZtZi1iSXv@aalbersh.remote.csb>

On 4/26/22 5:53 AM, Andrey Albershteyn wrote:
> On Tue, Apr 26, 2022 at 10:21:04AM +0200, Karel Zak wrote:
>> On Mon, Apr 25, 2022 at 10:38:02AM -0500, Eric Sandeen wrote:
>>> On 4/25/22 8:43 AM, Karel Zak wrote:
>>>>
>>>>  Thanks Andrey,
>>>>
>>>> the code looks good.
>>>>
>>>> On Thu, Apr 21, 2022 at 03:09:44PM +0200, Andrey Albershteyn wrote:
>>>>> I had a look into other fs, like ext4 and btrfs, to implement FSSIZE
>>>>> for them, but I think I don't have enough expertize to do that as
>>>>> they have not so trivial metadata overhead calculation :)
>>>>
>>>> But it would be nice to have ext4 and btrfs too. Maybe Eric can help
>>>> you :-)
>>>>
>>>>     Karel
>>>
>>> For ext4 something like e2fsprogs does is probably ok:
>>>
>>> static __u64 e2p_free_blocks_count(struct ext2_super_block *super)
>>> {
>>>         return super->s_free_blocks_count |
>>>                 (ext2fs_has_feature_64bit(super) ?
>>>                 (__u64) super->s_free_blocks_hi << 32 : 0);
>>> }

Whoops, I mis-pasted, that should have been:

static __u64 e2p_blocks_count(struct ext2_super_block *super)
{
        return super->s_blocks_count |
                (ext2fs_has_feature_64bit(super) ?
                (__u64) super->s_blocks_count_hi << 32 : 0);
}

(blocks count, not free blocks count)

> If we want to mimic statfs(2) + lsblk, then, I think this one won't
> be exactly it. I suppose s_free_blocks_count contains number of not
> used blocks which will vary with utilization... The statfs()
> calculates total number of blocks as total_blocks - (journalsize +
> each group free space). As far as I got it, both journalsize and
> group free space is not so trivial to calculate.

(Sorry for mixing this up by pasting e2p_free_blocks_count)

Ok, so I'm remembering what FSSIZE does in lsblk now :) it simply returns:

	dev->fsstat.f_frsize * dev->fsstat.f_blocks

i.e. calculating the value based on statfs values.

This does get a little tricky for ext4, because statfs "f_blocks" is
affected by the minixdf/bsddf mount options.

ext4's f_blocks statfs calculation looks like this:

        buf->f_blocks = ext4_blocks_count(es) - EXT4_C2B(sbi, overhead);

the default behavior, bsddf, subtracts out the overhead.

The overhead is a little tricky to calculate, but I /think/ it's precomputed and
stored in the superblock as well for (newer?) ext4, in the s_overhead_clusters
field.

So I *think* you can just do:

(block size) * (blocks count - overhead)

and get the same answer as statfs and lsblk. Does that work?

(Getting block count is a little tricky, because it may be split across
2 fields; s_blocks_count_lo for the lower 32 bits on smaller filesystems,
and s_blocks_count_hi only if EXT4_FEATURE_INCOMPAT_64BIT is set.)

(ext2 is messier, as a precomputed overhead value is not stored on disk.
Perhaps returning FSSIZE only if the type is ext4 might make sense.)

If I'm wrong about s_overhead_clusters being pre-calculated and stored, perhaps
just ignoring "overhead' altogether and treating FSSIZE in the "minixdf"
sense, and simply return s_blocks_count_lo & s_blocks_count_hi for an
answer.

Thanks,
-Eric


  parent reply	other threads:[~2022-04-27  4:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-21 13:09 [PATCH 0/2] libblkid: add FSSIZE with XFS implementation Andrey Albershteyn
2022-04-21 13:09 ` [PATCH 1/2] libblkid: add interface for FSSIZE field Andrey Albershteyn
2022-04-25 13:40   ` Karel Zak
2022-04-21 13:09 ` [PATCH 2/2] libblkid: implement FSSIZE calculation for XFS Andrey Albershteyn
2022-04-25 13:43 ` [PATCH 0/2] libblkid: add FSSIZE with XFS implementation Karel Zak
2022-04-25 15:38   ` Eric Sandeen
2022-04-26  8:21     ` Karel Zak
     [not found]       ` <YmfPPbgZtZi1iSXv@aalbersh.remote.csb>
2022-04-27  4:10         ` Eric Sandeen [this message]
2022-04-29  8:43           ` Karel Zak

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=facb3c36-0088-d645-6162-4d52fc94557f@redhat.com \
    --to=sandeen@redhat.com \
    --cc=aalbersh@redhat.com \
    --cc=esandeen@redhat.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.