Secondaries should contain redundant information from the primary
superblock. It does this for the filesystem geometry information,
but not inode values (rootino, rt inos, quota inos).

This patch updates all the secondaries from the primary just before
it marks the filesystem as good to go.

So it's got all the inodes, geometry, etc correct in them?

So what about the fact that the kernel code doesn't keep all
copies up to date? e.g. growfs will only write new values into
a handful of superblocks, changing sunit/swidth via mount options
only change the primary, etc....

If you are going to change mkfs to keep them all up to date, the
kernel code really needs to do the same thing....

Yes it should :) Geometry information was already done across all
the AGs.

/*
- * Dump all inodes and buffers before marking us all done.
- * Need to drop references to inodes we still hold, first.
+ * Flush out all inodes and buffers before marking us all done.
*/
libxfs_rtmount_destroy(mp);
libxfs_icache_purge();
- libxfs_bcache_purge();
+ libxfs_bcache_flush();

Don't you still need a purge there to free all the objects in the
cache?

No, the flush does what is required. There is no libxfs_icache_flush
at the moment, so I left the purge there for that.

libxfs_umount later on does a libxfs_*_purge() anyway.

The main thing is to make sure all objects are written to disk before
the sb_inprogress field in the primary superblock is zeroed.