@@ -1801,13 +1801,13 @@ parse_os_release (const char *contents, const char *split)
1801
1801
return ret ;
1802
1802
}
1803
1803
1804
- /* Generate the filename we will use in /boot/loader/entries for this deployment.
1804
+ /* Generate the entry name we will use in /boot/loader/entries for this deployment.
1805
1805
* The provided n_deployments should be the total number of target deployments (which
1806
1806
* might be different from the cached value in the sysroot).
1807
1807
*/
1808
1808
static char *
1809
- bootloader_entry_filename (OstreeSysroot * sysroot , guint n_deployments ,
1810
- OstreeDeployment * deployment )
1809
+ bootloader_entry_name (OstreeSysroot * sysroot , guint n_deployments ,
1810
+ OstreeDeployment * deployment )
1811
1811
{
1812
1812
guint index = n_deployments - ostree_deployment_get_index (deployment );
1813
1813
// Allow opt-out to dropping the stateroot in case of compatibility issues.
@@ -1817,14 +1817,34 @@ bootloader_entry_filename (OstreeSysroot *sysroot, guint n_deployments,
1817
1817
if (use_old_naming )
1818
1818
{
1819
1819
const char * stateroot = ostree_deployment_get_osname (deployment );
1820
- return g_strdup_printf ("ostree-%d-%s.conf " , index , stateroot );
1820
+ return g_strdup_printf ("ostree-%d-%s" , index , stateroot );
1821
1821
}
1822
1822
else
1823
1823
{
1824
- return g_strdup_printf ("ostree-%d.conf " , index );
1824
+ return g_strdup_printf ("ostree-%d" , index );
1825
1825
}
1826
1826
}
1827
1827
1828
+ static guint
1829
+ bootloader_get_max_boot_tries (OstreeSysroot * self , GCancellable * cancellable , GError * * error )
1830
+ {
1831
+ g_autoptr (OstreeRepo ) repo = NULL ;
1832
+ if (!ostree_sysroot_get_repo (self , & repo , cancellable , error ))
1833
+ return 0 ;
1834
+
1835
+ return repo -> boot_counting ;
1836
+ }
1837
+
1838
+ static gboolean
1839
+ bootloader_is_boot_count_enabled (OstreeSysroot * self , GCancellable * cancellable , GError * * error )
1840
+ {
1841
+ g_autoptr (OstreeRepo ) repo = NULL ;
1842
+ if (!ostree_sysroot_get_repo (self , & repo , cancellable , error ))
1843
+ return FALSE;
1844
+
1845
+ return (repo -> boot_counting != 0 ? TRUE : FALSE);
1846
+ }
1847
+
1828
1848
/* Given @deployment, prepare it to be booted; basically copying its
1829
1849
* kernel/initramfs into /boot/ostree (if needed) and writing out an entry in
1830
1850
* /boot/loader/entries.
@@ -1859,7 +1879,7 @@ install_deployment_kernel (OstreeSysroot *sysroot, int new_bootversion,
1859
1879
const char * bootcsum = ostree_deployment_get_bootcsum (deployment );
1860
1880
g_autofree char * bootcsumdir = g_strdup_printf ("ostree/%s-%s" , osname , bootcsum );
1861
1881
g_autofree char * bootconfdir = g_strdup_printf ("loader.%d/entries" , new_bootversion );
1862
- g_autofree char * bootconf_name = bootloader_entry_filename (sysroot , n_deployments , deployment );
1882
+ g_autofree char * bootconf_name = bootloader_entry_name (sysroot , n_deployments , deployment );
1863
1883
1864
1884
if (!glnx_shutil_mkdir_p_at (sysroot -> boot_fd , bootcsumdir , 0775 , cancellable , error ))
1865
1885
return FALSE;
@@ -2173,8 +2193,28 @@ install_deployment_kernel (OstreeSysroot *sysroot, int new_bootversion,
2173
2193
if (!glnx_opendirat (sysroot -> boot_fd , bootconfdir , TRUE, & bootconf_dfd , error ))
2174
2194
return FALSE;
2175
2195
2196
+ g_autofree char * bootconf_filename ;
2197
+ if (bootloader_is_boot_count_enabled (sysroot , cancellable , error ))
2198
+ {
2199
+ guint max_tries = bootloader_get_max_boot_tries (sysroot , cancellable , error );
2200
+
2201
+ if (!ostree_bootconfig_parser_is_parsed (bootconfig ))
2202
+ bootconf_filename = g_strdup_printf ("%s+%u.conf" , bootconf_name , max_tries );
2203
+ else if (!ostree_bootconfig_parser_get_tries_left (bootconfig ) &&
2204
+ !ostree_bootconfig_parser_get_tries_done (bootconfig ) )
2205
+ bootconf_filename = g_strdup_printf ("%s.conf" , bootconf_name );
2206
+ else
2207
+ bootconf_filename = g_strdup_printf ("%s+%" PRIu64 "-%" PRIu64 ".conf" , bootconf_name ,
2208
+ ostree_bootconfig_parser_get_tries_left (bootconfig ),
2209
+ ostree_bootconfig_parser_get_tries_done (bootconfig ));
2210
+ }
2211
+ else
2212
+ {
2213
+ bootconf_filename = g_strdup_printf ("%s.conf" , bootconf_name );
2214
+ }
2215
+
2176
2216
if (!ostree_bootconfig_parser_write_at (ostree_deployment_get_bootconfig (deployment ),
2177
- bootconf_dfd , bootconf_name , cancellable , error ))
2217
+ bootconf_dfd , bootconf_filename , cancellable , error ))
2178
2218
return FALSE;
2179
2219
2180
2220
return TRUE;
@@ -4213,14 +4253,35 @@ ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, OstreeDeploym
4213
4253
ostree_bootconfig_parser_set (new_bootconfig , "options" , kargs_str );
4214
4254
4215
4255
g_autofree char * bootconf_name
4216
- = bootloader_entry_filename (self , self -> deployments -> len , deployment );
4256
+ = bootloader_entry_name (self , self -> deployments -> len , deployment );
4217
4257
4218
4258
g_autofree char * bootconfdir = g_strdup_printf ("loader.%d/entries" , self -> bootversion );
4219
4259
glnx_autofd int bootconf_dfd = -1 ;
4220
4260
if (!glnx_opendirat (self -> boot_fd , bootconfdir , TRUE, & bootconf_dfd , error ))
4221
4261
return FALSE;
4222
4262
4223
- if (!ostree_bootconfig_parser_write_at (new_bootconfig , bootconf_dfd , bootconf_name ,
4263
+ g_autofree char * bootconf_filename ;
4264
+ if (bootloader_is_boot_count_enabled (self , cancellable , error ))
4265
+ {
4266
+ guint max_tries = bootloader_get_max_boot_tries (self , cancellable , error );
4267
+
4268
+ if (!ostree_bootconfig_parser_is_parsed (new_bootconfig ))
4269
+ bootconf_filename = g_strdup_printf ("%s+%u.conf" , bootconf_name , max_tries );
4270
+ else if (!ostree_bootconfig_parser_get_tries_left (new_bootconfig )
4271
+ && !ostree_bootconfig_parser_get_tries_done (new_bootconfig ))
4272
+ bootconf_filename = g_strdup_printf ("%s.conf" , bootconf_name );
4273
+ else
4274
+ bootconf_filename
4275
+ = g_strdup_printf ("%s+%lu-%lu.conf" , bootconf_name ,
4276
+ ostree_bootconfig_parser_get_tries_left (new_bootconfig ),
4277
+ ostree_bootconfig_parser_get_tries_done (new_bootconfig ));
4278
+ }
4279
+ else
4280
+ {
4281
+ bootconf_filename = g_strdup_printf ("%s.conf" , bootconf_name );
4282
+ }
4283
+
4284
+ if (!ostree_bootconfig_parser_write_at (new_bootconfig , bootconf_dfd , bootconf_filename ,
4224
4285
cancellable , error ))
4225
4286
return FALSE;
4226
4287
}
0 commit comments