@@ -238,33 +238,37 @@ func (u *Unikontainer) SetupNet() (types.NetDevParams, error) {
238238// 3. Container rootfs as block device (if MountRootfs=true and supported)
239239// 4. Container rootfs as shared-fs: virtiofs > 9pfs (if MountRootfs=true and supported)
240240// 5. No rootfs
241- func ( u * Unikontainer ) chooseRootfs ( ) (types.RootfsParams , error ) {
242- bundleDir := filepath .Clean (u . State . Bundle )
243- rootfsDir := filepath .Clean (u . Spec . Root . Path )
241+ func ChooseRootfs ( bundle , specRoot string , annot map [ string ] string , cfg * UruncConfig ) (types.RootfsParams , error ) {
242+ bundleDir := filepath .Clean (bundle )
243+ rootfsDir := filepath .Clean (specRoot )
244244 rootfsDir , err := resolveAgainstBase (bundleDir , rootfsDir )
245245 if err != nil {
246246 uniklog .Errorf ("could not resolve rootfs directory %s: %v" , rootfsDir , err )
247247 return types.RootfsParams {}, err
248248 }
249249
250- unikernelType := u .State .Annotations [annotType ]
250+ if cfg == nil {
251+ return types.RootfsParams {}, fmt .Errorf ("urunc config is required for guest rootfs selection" )
252+ }
253+
254+ unikernelType := annot [annotType ]
251255 unikernel , err := unikernels .New (unikernelType )
252256 if err != nil {
253257 return types.RootfsParams {}, err
254258 }
255259
256- vmmType := u . State . Annotations [annotHypervisor ]
257- vmm , err := hypervisors .NewVMM (hypervisors .VmmType (vmmType ), u . UruncCfg .Monitors )
260+ vmmType := annot [annotHypervisor ]
261+ vmm , err := hypervisors .NewVMM (hypervisors .VmmType (vmmType ), cfg .Monitors )
258262 if err != nil {
259263 return types.RootfsParams {}, err
260264 }
261265
262- virtiofsdConfig := u . UruncCfg .ExtraBins ["virtiofsd" ]
266+ virtiofsdConfig := cfg .ExtraBins ["virtiofsd" ]
263267
264268 selector := & rootfsSelector {
265269 bundle : bundleDir ,
266270 cntrRootfs : rootfsDir ,
267- annot : u . State . Annotations ,
271+ annot : annot ,
268272 unikernel : unikernel ,
269273 vmm : vmm ,
270274 vfsdPath : virtiofsdConfig .Path ,
@@ -426,11 +430,28 @@ func (u *Unikontainer) Exec(metrics m.Writer) error {
426430 // if the respective annotation is set then, depending on the guest
427431 // (supports block or 9pfs), it will use the supported option. In case
428432 // both ae supported, then the block option will be used by default.
429- rootfsParams , err := u .chooseRootfs ()
430- if err != nil {
431- uniklog .Errorf ("could not choose guest rootfs: %v" , err )
432- return err
433+ var rootfsParams types.RootfsParams
434+
435+ // Read the rootfs choice written by the shim.
436+ if rootfsParamsJSON := u .Spec .Annotations [annotRootfsParams ]; rootfsParamsJSON != "" {
437+ if err := json .Unmarshal ([]byte (rootfsParamsJSON ), & rootfsParams ); err != nil {
438+ return fmt .Errorf ("could not decode guest rootfs params: %w" , err )
439+ }
440+ }
441+
442+ // If there is no shim choice, the runtime chooses rootfs here.
443+ if rootfsParams .MonRootfs == "" {
444+ rootfsParams , err = ChooseRootfs (u .State .Bundle , u .Spec .Root .Path , u .State .Annotations , u .UruncCfg )
445+ if err != nil {
446+ uniklog .Errorf ("could not choose guest rootfs: %v" , err )
447+ return err
448+ }
433449 }
450+ uniklog .WithFields (logrus.Fields {
451+ "rootfs_type" : rootfsParams .Type ,
452+ "rootfs_path" : rootfsParams .Path ,
453+ "mon_rootfs" : rootfsParams .MonRootfs ,
454+ }).Debug ("guest rootfs params" )
434455
435456 // TODO: Add support for using both an existing
436457 // block based snapshot of the container's rootfs
@@ -479,6 +500,10 @@ func (u *Unikontainer) Exec(metrics m.Writer) error {
479500 }
480501 }
481502
503+ if err = os .MkdirAll (rootfsParams .MonRootfs , 0o755 ); err != nil {
504+ return fmt .Errorf ("failed to create monitor rootfs directory %s: %w" , rootfsParams .MonRootfs , err )
505+ }
506+
482507 err = rfsBuilder .preSetup ()
483508 if err != nil {
484509 return fmt .Errorf ("pre setup step for rootfs failed: %w" , err )
0 commit comments