All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation
@ 2022-04-25 15:08 Andrey Albershteyn
  2022-04-25 15:08 ` [PATCH v2 1/3] libblkid: add interface for FSSIZE field Andrey Albershteyn
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-25 15:08 UTC (permalink / raw)
  To: util-linux; +Cc: Andrey Albershteyn

In discussion [1] it was suggested that adding new field FSSIZE
would be useful (size of filesystem, like in lsblk). These patches
add new FSSIZE field together with implementation for XFS.

[1]: https://bugzilla.redhat.com/show_bug.cgi?id=2064810

Changes from v1:
- Minor refactor: Make use of uint64_t, use
  blkid_probe_sprintf_value()
- Add patch #3 - enable FSSIZE in blkid and add new golden output in
  the tests

Andrey Albershteyn (3):
  libblkid: add interface for FSSIZE field
  libblkid: implement FSSIZE calculation for XFS
  blkid: add FSSIZE tag with tests for XFS

 libblkid/samples/superblocks.c         |  2 +-
 libblkid/src/blkid.h.in                |  1 +
 libblkid/src/superblocks/superblocks.c | 11 +++++++++++
 libblkid/src/superblocks/superblocks.h |  1 +
 libblkid/src/superblocks/xfs.c         | 10 ++++++++++
 misc-utils/blkid.c                     |  3 ++-
 tests/expected/blkid/low-probe-xfs     |  1 +
 tests/expected/blkid/low-probe-xfs-v5  |  1 +
 8 files changed, 28 insertions(+), 2 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] libblkid: add interface for FSSIZE field
  2022-04-25 15:08 [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation Andrey Albershteyn
@ 2022-04-25 15:08 ` Andrey Albershteyn
  2022-04-25 15:08 ` [PATCH v2 2/3] libblkid: implement FSSIZE calculation for XFS Andrey Albershteyn
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-25 15:08 UTC (permalink / raw)
  To: util-linux; +Cc: Andrey Albershteyn

Add interface to let filesystem probe calculate and set FSSIZE.
Enable that field in the 'superblocks' sample.

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
 libblkid/samples/superblocks.c         |  2 +-
 libblkid/src/blkid.h.in                |  1 +
 libblkid/src/superblocks/superblocks.c | 11 +++++++++++
 libblkid/src/superblocks/superblocks.h |  1 +
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libblkid/samples/superblocks.c b/libblkid/samples/superblocks.c
index 7d9555771..38903ecee 100644
--- a/libblkid/samples/superblocks.c
+++ b/libblkid/samples/superblocks.c
@@ -44,7 +44,7 @@ int main(int argc, char *argv[])
 			BLKID_SUBLKS_UUID | BLKID_SUBLKS_UUIDRAW |
 			BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
 			BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
-			BLKID_SUBLKS_MAGIC);
+			BLKID_SUBLKS_MAGIC | BLKID_SUBLKS_FSSIZE);
 
 	rc = blkid_do_safeprobe(pr);
 	if (rc == -1)
diff --git a/libblkid/src/blkid.h.in b/libblkid/src/blkid.h.in
index 3cd4116d9..ad4becf0a 100644
--- a/libblkid/src/blkid.h.in
+++ b/libblkid/src/blkid.h.in
@@ -281,6 +281,7 @@ extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable)
 #define BLKID_SUBLKS_VERSION	(1 << 8) /* read FS type from superblock */
 #define BLKID_SUBLKS_MAGIC	(1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
 #define BLKID_SUBLKS_BADCSUM	(1 << 10) /* allow a bad checksum */
+#define BLKID_SUBLKS_FSSIZE	(1 << 11) /* read and define FSSIZE from superblock */
 
 #define BLKID_SUBLKS_DEFAULT	(BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
 				 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c
index f21365538..9adc2cfa3 100644
--- a/libblkid/src/superblocks/superblocks.c
+++ b/libblkid/src/superblocks/superblocks.c
@@ -7,6 +7,7 @@
  * GNU Lesser General Public License.
  */
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -584,6 +585,16 @@ static int blkid_probe_set_usage(blkid_probe pr, int usage)
 	return blkid_probe_set_value(pr, "USAGE", (unsigned char *) u, strlen(u) + 1);
 }
 
+int blkid_probe_set_fssize(blkid_probe pr, uint64_t size)
+{
+	struct blkid_chain *chn = blkid_probe_get_chain(pr);
+
+	if (!(chn->flags & BLKID_SUBLKS_FSSIZE))
+		return 0;
+
+	return blkid_probe_sprintf_value(pr, "FSSIZE", "%" PRIu64, size);
+}
+
 int blkid_probe_set_id_label(blkid_probe pr, const char *name,
 			     const unsigned char *data, size_t len)
 {
diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
index 9c489c438..67803679f 100644
--- a/libblkid/src/superblocks/superblocks.h
+++ b/libblkid/src/superblocks/superblocks.h
@@ -111,6 +111,7 @@ extern int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
 			     const unsigned char *data, size_t len, int enc);
 
 int blkid_probe_set_block_size(blkid_probe pr, unsigned block_size);
+int blkid_probe_set_fssize(blkid_probe pr, uint64_t size);
 
 extern int blkid_probe_is_bitlocker(blkid_probe pr);
 extern int blkid_probe_is_ntfs(blkid_probe pr);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] libblkid: implement FSSIZE calculation for XFS
  2022-04-25 15:08 [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation Andrey Albershteyn
  2022-04-25 15:08 ` [PATCH v2 1/3] libblkid: add interface for FSSIZE field Andrey Albershteyn
@ 2022-04-25 15:08 ` Andrey Albershteyn
  2022-04-25 15:08 ` [PATCH v2 3/3] blkid: add FSSIZE tag with tests " Andrey Albershteyn
  2022-04-26  8:32 ` [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation Karel Zak
  3 siblings, 0 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-25 15:08 UTC (permalink / raw)
  To: util-linux; +Cc: Andrey Albershteyn

The implementation is similar to one provided by statfs(2) + lsblk.

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
 libblkid/src/superblocks/xfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libblkid/src/superblocks/xfs.c b/libblkid/src/superblocks/xfs.c
index d8c6fb6d4..444050f55 100644
--- a/libblkid/src/superblocks/xfs.c
+++ b/libblkid/src/superblocks/xfs.c
@@ -158,6 +158,15 @@ static int xfs_verify_sb(struct xfs_super_block *ondisk)
 	return 1;
 }
 
+static uint64_t xfs_fssize(struct xfs_super_block *xs)
+{
+	uint32_t lsize = xs->sb_logstart ? xs->sb_logblocks : 0;
+	uint64_t avail_blocks = be64_to_cpu(xs->sb_dblocks) - be32_to_cpu(lsize);
+	uint64_t fssize = avail_blocks*be32_to_cpu(xs->sb_blocksize);
+
+	return fssize;
+}
+
 static int probe_xfs(blkid_probe pr, const struct blkid_idmag *mag)
 {
 	struct xfs_super_block *xs;
@@ -173,6 +182,7 @@ static int probe_xfs(blkid_probe pr, const struct blkid_idmag *mag)
 		blkid_probe_set_label(pr, (unsigned char *) xs->sb_fname,
 				sizeof(xs->sb_fname));
 	blkid_probe_set_uuid(pr, xs->sb_uuid);
+	blkid_probe_set_fssize(pr, xfs_fssize(xs));
 	blkid_probe_set_block_size(pr, be16_to_cpu(xs->sb_sectsize));
 	return 0;
 }
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] blkid: add FSSIZE tag with tests for XFS
  2022-04-25 15:08 [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation Andrey Albershteyn
  2022-04-25 15:08 ` [PATCH v2 1/3] libblkid: add interface for FSSIZE field Andrey Albershteyn
  2022-04-25 15:08 ` [PATCH v2 2/3] libblkid: implement FSSIZE calculation for XFS Andrey Albershteyn
@ 2022-04-25 15:08 ` Andrey Albershteyn
  2022-04-26  8:32 ` [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation Karel Zak
  3 siblings, 0 replies; 5+ messages in thread
From: Andrey Albershteyn @ 2022-04-25 15:08 UTC (permalink / raw)
  To: util-linux; +Cc: Andrey Albershteyn

The FSSIZE tag was added to the libblkid. Enable this tag in blkid
and update tests golden output for XFS test cases.

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
 misc-utils/blkid.c                    | 3 ++-
 tests/expected/blkid/low-probe-xfs    | 1 +
 tests/expected/blkid/low-probe-xfs-v5 | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index d79527e3f..2edcd2b41 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -921,7 +921,8 @@ int main(int argc, char **argv)
 			blkid_probe_set_superblocks_flags(pr,
 				BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
 				BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
-				BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION);
+				BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION |
+				BLKID_SUBLKS_FSSIZE);
 
 
 			if (fltr_usage &&
diff --git a/tests/expected/blkid/low-probe-xfs b/tests/expected/blkid/low-probe-xfs
index 6eb1b4600..a91e92bcc 100644
--- a/tests/expected/blkid/low-probe-xfs
+++ b/tests/expected/blkid/low-probe-xfs
@@ -1,4 +1,5 @@
 ID_FS_BLOCK_SIZE=512
+ID_FS_FSSIZE=11862016
 ID_FS_LABEL=test-xfs
 ID_FS_LABEL_ENC=test-xfs
 ID_FS_TYPE=xfs
diff --git a/tests/expected/blkid/low-probe-xfs-v5 b/tests/expected/blkid/low-probe-xfs-v5
index 513a3818f..129b41f26 100644
--- a/tests/expected/blkid/low-probe-xfs-v5
+++ b/tests/expected/blkid/low-probe-xfs-v5
@@ -1,4 +1,5 @@
 ID_FS_BLOCK_SIZE=512
+ID_FS_FSSIZE=17469440
 ID_FS_LABEL=test-xfs-v5
 ID_FS_LABEL_ENC=test-xfs-v5
 ID_FS_TYPE=xfs
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation
  2022-04-25 15:08 [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation Andrey Albershteyn
                   ` (2 preceding siblings ...)
  2022-04-25 15:08 ` [PATCH v2 3/3] blkid: add FSSIZE tag with tests " Andrey Albershteyn
@ 2022-04-26  8:32 ` Karel Zak
  3 siblings, 0 replies; 5+ messages in thread
From: Karel Zak @ 2022-04-26  8:32 UTC (permalink / raw)
  To: Andrey Albershteyn; +Cc: util-linux

On Mon, Apr 25, 2022 at 05:08:36PM +0200, Andrey Albershteyn wrote:
> Andrey Albershteyn (3):
>   libblkid: add interface for FSSIZE field
>   libblkid: implement FSSIZE calculation for XFS
>   blkid: add FSSIZE tag with tests for XFS
> 
>  libblkid/samples/superblocks.c         |  2 +-
>  libblkid/src/blkid.h.in                |  1 +
>  libblkid/src/superblocks/superblocks.c | 11 +++++++++++
>  libblkid/src/superblocks/superblocks.h |  1 +
>  libblkid/src/superblocks/xfs.c         | 10 ++++++++++
>  misc-utils/blkid.c                     |  3 ++-
>  tests/expected/blkid/low-probe-xfs     |  1 +
>  tests/expected/blkid/low-probe-xfs-v5  |  1 +
>  8 files changed, 28 insertions(+), 2 deletions(-)

Applied, thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-26  8:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-25 15:08 [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation Andrey Albershteyn
2022-04-25 15:08 ` [PATCH v2 1/3] libblkid: add interface for FSSIZE field Andrey Albershteyn
2022-04-25 15:08 ` [PATCH v2 2/3] libblkid: implement FSSIZE calculation for XFS Andrey Albershteyn
2022-04-25 15:08 ` [PATCH v2 3/3] blkid: add FSSIZE tag with tests " Andrey Albershteyn
2022-04-26  8:32 ` [PATCH v2 0/3] libblkid: add FSSIZE with XFS implementation Karel Zak

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.