Unnecessary WARNING when a snapshot of a gjournaled filesystem is mounted

From: Andreas Longwitz <longwitz_at_incore.de>
Date: Tue, 28 Dec 2021 11:43:23 UTC
When I mount on a FreeBSD V12 server a snapshot living on /dev/md0 of a
gjournaled filesystem with

    mount -r /dev/md0 /mnt/var

the kernel gives the following WARNING:

<kern.crit> dsssrvt3 kernel: WARNING: /mnt/var: GJOURNAL flag on fs but
no gjournal provider below

Of course the kernel is right, /dev/md0 is never a gjournal provider. I
think this warning is unnecassary and a little bit confusing when
mounting a snapshot. With the patch

--- ffs_vfsops.c.1st    2020-11-17 06:48:00.000000000 +0100
+++ ffs_vfsops.c        2021-12-21 11:38:15.000000000 +0100
@@ -875,9 +875,10 @@
                        mp->mnt_flag |= MNT_GJOURNAL;
                        MNT_IUNLOCK(mp);
                } else {
-                       printf("WARNING: %s: GJOURNAL flag on fs "
-                           "but no gjournal provider below\n",
-                           mp->mnt_stat.f_mntonname);
+                       if ((mp->mnt_flag & MNT_RDONLY) == 0)
+                           printf("WARNING: %s: GJOURNAL flag on fs "
+                               "but no gjournal provider below\n",
+                               mp->mnt_stat.f_mntonname);
                        free(mp->mnt_gjprovider, M_UFSMNT);
                        mp->mnt_gjprovider = NULL;
                }

the WARNING is gone. Because I was not able to write a simple request
for the condition "mount a snapshot" I have used the condition "mount
read only". I would like to know if this can be done better.

Andreas