Skip to contentSkip to conversation

xfsprogs/io: add readdir command

PATCH Superseded Brian Foster 3 participants 5 messages Jul 24, 2013 – Aug 8, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfsprogs/io: add readdir command

readdir reads the directory entries from an open directory from the provided offset (or 0 if not specified). On completion, readdir prints summary information regarding the number of operations and bytes transferred. Options are available to specify the starting offset, length and verbose mode to dump directory entry information.

---

v2:
- Convert from getdents to readdir.
- Use configure mechanism for libc readdir() availability (zab).
- Add extra dirent fields to verbose output (zab).

 configure.ac          |   1 +
 include/builddefs.in  |   1 +
 io/Makefile           |   5 ++
 io/init.c             |   1 +
 io/io.h               |   6 ++
 io/readdir.c          | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++
 m4/package_libcdev.m4 |  15 ++++
 7 files changed, 219 insertions(+)
 create mode 100644 io/readdir.c
configure.ac +1 -0
index e5fd94e..da099d8 100644
@@ -112,6 +112,7 @@ AC_HAVE_FIEMAP
 AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
 AC_HAVE_BLKID_TOPO($enable_blkid)
+AC_HAVE_READDIR
 
 AC_CHECK_SIZEOF([long])
 AC_CHECK_SIZEOF([char *])
include/builddefs.in +1 -0
index 744e8d3..944bcf6 100644
@@ -103,6 +103,7 @@ HAVE_FALLOCATE = @have_fallocate@
 HAVE_FIEMAP = @have_fiemap@
 HAVE_PREADV = @have_preadv@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
+HAVE_READDIR = @have_readdir@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #	   -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
io/Makefile +5 -0
index 50edf91..d73f9b9 100644
@@ -80,6 +80,11 @@ ifeq ($(HAVE_PREADV),yes)
 LCFLAGS += -DHAVE_PREADV -DHAVE_PWRITEV
 endif
 
+ifeq ($(HAVE_READDIR),yes)
+CFILES += readdir.c
+LCFLAGS += -DHAVE_READDIR
+endif
+
 default: depend $(LTCOMMAND)
 
 include $(BUILDRULES)
io/init.c +1 -0
index ca3055a..ee99761 100644
@@ -74,6 +74,7 @@ init_commands(void)
 	fiemap_init();
 	pwrite_init();
 	quit_init();
+	readdir_init();
 	resblks_init();
 	sendfile_init();
 	shutdown_init();
io/io.h +6 -0
index 91f0e3e..e1f5328 100644
@@ -149,3 +149,9 @@ extern void		sync_range_init(void);
 #else
 #define sync_range_init()	do { } while (0)
 #endif
+
+#ifdef HAVE_READDIR
+extern void		readdir_init(void);
+#else
+#define readdir_init()		do { } while (0)
+#endif
io/readdir.c new file +190 -0

190 lines not on this page · raw message

m4/package_libcdev.m4 +15 -0
index f489f52..8267ba0 100644
@@ -170,3 +170,18 @@ AC_DEFUN([AC_HAVE_SYNC_FILE_RANGE],
     AC_SUBST(have_sync_file_range)
   ])
 
+#
+# Check if we have a readdir libc call
+#
+AC_DEFUN([AC_HAVE_READDIR],
+  [ AC_MSG_CHECKING([for readdir])
+    AC_TRY_LINK([
+#include <dirent.h>
+    ], [
+         readdir(0);
+    ], have_readdir=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_readdir)
+  ])
+
Signature · 6 lines
1.8.1.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 7 lines · Brian Foster

readdir reads the directory entries from an open directory from the provided offset (or 0 if not specified). On completion, readdir prints summary information regarding the number of operations and bytes transferred. Options are available to specify the starting offset, length and verbose mode to dump directory entry information.

Quoted 8 lines

---

v2:
- Convert from getdents to readdir.
- Use configure mechanism for libc readdir() availability (zab).
- Add extra dirent fields to verbose output (zab).

Just started to look at this.

Shouldn't there be a "closedir(dir);" to close the directory stream and release the directory structure?

Could we get a little info for the xfs_io man page?

Looks like a nice feature.

Thanks.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 11 lines · Mark Tinguely
Quoted 10 lines · Brian Foster

readdir reads the directory entries from an open directory from the provided offset (or 0 if not specified). On completion, readdir prints summary information regarding the number of operations and bytes transferred. Options are available to specify the starting offset, length and verbose mode to dump directory entry information.

---

Quoted 8 lines
Quoted 5 lines

v2:
- Convert from getdents to readdir.
- Use configure mechanism for libc readdir() availability (zab).
- Add extra dirent fields to verbose output (zab).

Just started to look at this.

Hi Mark,

Thanks for looking at this...

Quoted 3 lines

Shouldn't there be a "closedir(dir);" to close the directory stream and release the directory structure?

According to the man page, closedir() would also close the fd. I gave it a quick test to be sure and I end up with behavior like this:

xfs_io> open /export/test
xfs_io> readdir
[00000000 [00000004 [00000006 [00000009 [00000200 read 104 bytes from offset 0
104.000000 bytes, 4 ops, 0.0000 sec (5.220 MiB/sec and 210526.3158 ops/sec) xfs_io> close
close: Bad file descriptor

That said, I'm not sure what the ramifications of repeated readdir commands might be (i.e., repeated fdopendir() calls on the same fd). Perhaps the right thing to do here is dup() file->fd prior to fdopendir() and then add the closedir().

Quoted 2 lines

Could we get a little info for the xfs_io man page?

Ok.

Brian

Quoted 5 lines

Looks like a nice feature.

Thanks.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 45 lines · Brian Foster
Quoted 11 lines · Mark Tinguely
Quoted 10 lines · Brian Foster

readdir reads the directory entries from an open directory from the provided offset (or 0 if not specified). On completion, readdir prints summary information regarding the number of operations and bytes transferred. Options are available to specify the starting offset, length and verbose mode to dump directory entry information.

---

Quoted 8 lines
Quoted 5 lines

v2:
- Convert from getdents to readdir.
- Use configure mechanism for libc readdir() availability (zab).
- Add extra dirent fields to verbose output (zab).

Just started to look at this.

Hi Mark,

Thanks for looking at this...

Quoted 3 lines

Shouldn't there be a "closedir(dir);" to close the directory stream and release the directory structure?

According to the man page, closedir() would also close the fd. I gave it a quick test to be sure and I end up with behavior like this:

xfs_io> open /export/test
xfs_io> readdir
[00000000 [00000004 [00000006 [00000009 [00000200 read 104 bytes from offset 0
104.000000 bytes, 4 ops, 0.0000 sec (5.220 MiB/sec and 210526.3158 ops/sec) xfs_io> close
close: Bad file descriptor

That said, I'm not sure what the ramifications of repeated readdir commands might be (i.e., repeated fdopendir() calls on the same fd). Perhaps the right thing to do here is dup() file->fd prior to fdopendir() and then add the closedir().

Quoted 13 lines
Quoted 2 lines

Could we get a little info for the xfs_io man page?

Ok.

Brian

Quoted 5 lines

Looks like a nice feature.

Thanks.

--Mark.

I was thinking multiple commands in a xfs_io session.

Thanks for the offset clarification.

--Mark.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw
In reply to Mark Tinguely
Quoted 2 lines · Mark Tinguely

Could we get a little info for the xfs_io man page?

Yup, otherwise xfs/293 fails :)

# ./check xfs/293
FSTYP         -- xfs (non-debug)
PLATFORM      -- Linux/x86_64 bp-05 3.11.0-rc1+
MKFS_OPTIONS  -- -f -bsize=4096 /dev/sdb2
MOUNT_OPTIONS -- -o context=system_u:object_r:nfs_t:s0 /dev/sdb2 /mnt/scratch

xfs/293 10s ... - output mismatch (see /mnt/test2/git/xfstests/results/xfs/293.out.bad)
--- tests/xfs/293.out 2013-03-27 12:57:49.318520102 -0500
+++ /mnt/test2/git/xfstests/results/xfs/293.out.bad 2013-08-08 15:38:30.881221070 -0500
@@ -1,2 +1,3 @@
QA output created by 293
Silence is golden
+readdir not documented in the xfs_io manpage
...
(Run 'diff -u tests/xfs/293.out /mnt/test2/git/xfstests/results/xfs/293.out.bad' to see the entire diff)
Ran: xfs/293
Failures: xfs/293
Failed 1 of 1 tests

/me pats self on back ;)

-Eric

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs