init-fs: Add --epoch
authorColin Walters <walters@verbum.org>
Fri, 12 Apr 2024 12:56:13 +0000 (08:56 -0400)
committerColin Walters <walters@verbum.org>
Fri, 12 Apr 2024 12:56:13 +0000 (08:56 -0400)
I want to add another variant here, and `--modern` is now old.  Let's
acknowledge that we may want to make even more changes in the
future.  So `--modern == --epoch=1` but I will add `--epoch=2` after
this.

man/ostree-admin-init-fs.xml
src/ostree/ot-admin-builtin-init-fs.c
tests/admin-test.sh

index 50e6d44e18926eee7760ad15d8d3df54c956601b..ead3d325d43b48e15848aea0db161f52e7bdc234 100644 (file)
@@ -57,17 +57,48 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
         <title>Description</title>
 
         <para>
-            Initialize an empty physical root filesystem in the designated PATH, with normal toplevels and correct permissions for each directory.  Primarily useful for operating system installers.
+            Initialize an empty physical root filesystem in the designated PATH, with normal toplevels and correct permissions for each directory.
+            Primarily useful for operating system installers.
         </para>
     </refsect1>
 
+
+    <refsect1>
+        <title>Options</title>
+
+        <variablelist>
+            <varlistentry>
+                <term><option>--modern</option></term>
+                <listitem><para>
+                    Equivalent to <literal>--epoch=1</literal>.
+                </para></listitem>
+            </varlistentry>
+
+            <varlistentry>
+                <term><option>--epoch</option></term>
+                <listitem><para>
+                    This accepts an integer value in the range [0-1], inclusive.  The default is zero
+                    for compatibility.
+                </para>
+                <para>
+                    When set to 1, the command will skip adding a number of toplevel "API filesystems"
+                    such as <literal>/proc</literal>
+                    to the toplevel of the physical root.  These should be unnecessary, as they
+                    should only be mounted in the final deployment root.  The main exception
+                    is <literal>/boot</literal>, which may need to be mounted in some setups
+                    before the target root.
+                </para></listitem>
+            </varlistentry>
+        </variablelist>
+    </refsect1>          
+
     <refsect1>
         <title>Example</title>
         <para><command>$ mkdir /example</command></para>
-        <para><command>$ ostree admin init-fs /example</command></para>
+        <para><command>$ ostree admin init-fs --epoch=1 /example</command></para>
         <para><command>$ ls /example </command></para>
         <para>
-            <emphasis>boot</emphasis>&nbsp;&nbsp; <emphasis>dev</emphasis>&nbsp;&nbsp; <emphasis>home</emphasis>&nbsp;&nbsp; <emphasis>ostree</emphasis>&nbsp;&nbsp; <emphasis>proc</emphasis>&nbsp;&nbsp; <emphasis>root</emphasis>&nbsp;&nbsp; <emphasis>run</emphasis>&nbsp;&nbsp; <emphasis>sys</emphasis>&nbsp;&nbsp; <emphasis>tmp</emphasis>
+            <emphasis>boot</emphasis>&nbsp;&nbsp;
         </para>
     </refsect1>
 </refentry>
index 9cda9afcfaaf391724a888af7cf7cadb322a8a56..7662f4795409cfddd06e9515045a8c05b0102fc5 100644 (file)
 #include <glib/gi18n.h>
 
 static gboolean opt_modern;
+static gint opt_epoch;
 
 static GOptionEntry options[]
     = { { "modern", 0, 0, G_OPTION_ARG_NONE, &opt_modern, "Only create /boot and /ostree", NULL },
+        { "epoch", 'E', 0, G_OPTION_ARG_INT, &opt_epoch,
+          "An integer value, defines initial state.  Must be in the range [0-1], inclusive.",
+          NULL },
         { NULL } };
 
 gboolean
@@ -62,12 +66,19 @@ ot_admin_builtin_init_fs (int argc, char **argv, OstreeCommandInvocation *invoca
   if (!glnx_shutil_mkdir_p_at (root_dfd, "boot", 0755, cancellable, error))
     return FALSE;
 
+  if (opt_epoch < 0)
+    return glnx_throw (error, "Invalid epoch: %d", opt_epoch);
+
+  /* --modern is equivalent to --epoch=1 */
+  if (opt_modern && opt_epoch == 0)
+    opt_epoch = 1;
+
   /* See https://github.com/coreos/coreos-assembler/pull/688
    * For Fedora CoreOS at least, we have this now to the point where we don't
    * need this stuff in the physical sysroot.  I'm not sure we ever really did,
    * but to be conservative, make it opt-in to the new model of just boot/ and ostree/.
    */
-  if (!opt_modern)
+  if (opt_epoch == 0)
     {
       const char *traditional_toplevels[] = { "boot", "dev", "home", "proc", "run", "sys" };
       for (guint i = 0; i < G_N_ELEMENTS (traditional_toplevels); i++)
index 3417d01adbeb77f0c8b264f01de79ba85e4db654..2cd8473270777da319e33f53bf83fe2006418783 100644 (file)
@@ -21,13 +21,15 @@ set -euo pipefail
 
 echo "1..$((31 + ${extra_admin_tests:-0}))"
 
-mkdir sysrootmin
-${CMD_PREFIX} ostree admin init-fs --modern sysrootmin
-assert_has_dir sysrootmin/boot
-assert_has_dir sysrootmin/ostree/repo
-assert_not_has_dir sysrootmin/home
-rm sysrootmin -rf
-echo "ok init-fs --modern"
+for flag in --modern --epoch=1; do
+    mkdir sysrootmin
+    ${CMD_PREFIX} ostree admin init-fs --modern sysrootmin
+    assert_has_dir sysrootmin/boot
+    assert_has_dir sysrootmin/ostree/repo
+    assert_not_has_dir sysrootmin/home
+    rm sysrootmin -rf
+done
+echo "ok init-fs"
 
 function validate_bootloader() {
     cd ${test_tmpdir};