@@ -306,6 +306,9 @@ func (ctrl *MountController) handleMountOperation(
306306 case block .VolumeTypeTmpfs :
307307 return fmt .Errorf ("not implemented yet" )
308308
309+ case block .VolumeTypeMemory :
310+ return ctrl .handleMemoryMountOperation (logger , filepath .Join (rootPath , mountTarget ), mountRequest , volumeStatus )
311+
309312 case block .VolumeTypeExternal :
310313 return ctrl .handleDiskMountOperation (logger , mountSource , filepath .Join (rootPath , mountTarget ), mountFilesystem , mountRequest , volumeStatus )
311314
@@ -432,6 +435,81 @@ func (ctrl *MountController) handleBindMountOperation(
432435 return nil
433436}
434437
438+ func (ctrl * MountController ) handleMemoryMountOperation (
439+ logger * zap.Logger ,
440+ mountTarget string ,
441+ mountRequest * block.MountRequest ,
442+ volumeStatus * block.VolumeStatus ,
443+ ) error {
444+ _ , ok := ctrl .activeMounts [mountRequest .Metadata ().ID ()]
445+
446+ logger = logger .With (zap .String ("mount_request.id" , mountRequest .Metadata ().ID ()))
447+
448+ if ! ok {
449+ var sizeOpt string
450+
451+ for _ , param := range volumeStatus .TypedSpec ().MountSpec .Parameters {
452+ if param .Name == "size" && param .String != nil {
453+ sizeOpt = fmt .Sprintf ("size=%s" , * param .String )
454+
455+ break
456+ }
457+ }
458+
459+ if sizeOpt == "" {
460+ return fmt .Errorf ("memory volume requires size parameter" )
461+ }
462+
463+ logger .Info ("mounting memory volume" ,
464+ zap .String ("target" , mountTarget ),
465+ zap .String ("size" , sizeOpt ),
466+ )
467+
468+ // Create the mount point directory if it doesn't exist
469+ if err := os .MkdirAll (mountTarget , volumeStatus .TypedSpec ().MountSpec .FileMode ); err != nil {
470+ return fmt .Errorf ("failed to create target path: %w" , err )
471+ }
472+
473+ // Mount tmpfs
474+ if err := unix .Mount ("tmpfs" , mountTarget , "tmpfs" , 0 , sizeOpt ); err != nil {
475+ return fmt .Errorf ("failed to mount tmpfs at %s: %w" , mountTarget , err )
476+ }
477+
478+ if volumeStatus .TypedSpec ().MountSpec .SelinuxLabel != "" {
479+ if err := selinux .SetLabel (mountTarget , volumeStatus .TypedSpec ().MountSpec .SelinuxLabel ); err != nil {
480+ unix .Unmount (mountTarget , 0 ) //nolint:errcheck
481+
482+ return fmt .Errorf ("failed to set selinux label: %w" , err )
483+ }
484+ }
485+
486+ if ! mountRequest .TypedSpec ().ReadOnly && ! mountRequest .TypedSpec ().Detached {
487+ if err := ctrl .updateTargetSettings (mountTarget , volumeStatus .TypedSpec ().MountSpec ); err != nil {
488+ unix .Unmount (mountTarget , 0 ) //nolint:errcheck
489+
490+ return fmt .Errorf ("failed to update target settings: %w" , err )
491+ }
492+ }
493+
494+ logger .Info ("memory volume mounted successfully" ,
495+ zap .String ("volume" , volumeStatus .Metadata ().ID ()),
496+ zap .String ("target" , mountTarget ),
497+ )
498+
499+ ctrl .activeMounts [mountRequest .Metadata ().ID ()] = & mountContext {
500+ point : nil , // No mount.Point for direct unix.Mount
501+ readOnly : mountRequest .TypedSpec ().ReadOnly ,
502+ unmounter : func () error {
503+ return unix .Unmount (mountTarget , 0 )
504+ },
505+ }
506+
507+ return nil
508+ }
509+
510+ return nil
511+ }
512+
435513//nolint:gocyclo
436514func (ctrl * MountController ) handleSymlinkMountOperation (
437515 logger * zap.Logger ,
@@ -778,6 +856,9 @@ func (ctrl *MountController) handleUnmountOperation(
778856 case block .VolumeTypeTmpfs :
779857 return fmt .Errorf ("not implemented yet" )
780858
859+ case block .VolumeTypeMemory :
860+ return ctrl .handleMemoryUnmountOperation (logger , mountRequest , volumeStatus )
861+
781862 case block .VolumeTypeExternal :
782863 return ctrl .handleDiskUnmountOperation (logger , mountRequest , volumeStatus )
783864
@@ -847,6 +928,34 @@ func (ctrl *MountController) handleDirectoryUnmountOperation(
847928 return nil
848929}
849930
931+ func (ctrl * MountController ) handleMemoryUnmountOperation (
932+ logger * zap.Logger ,
933+ mountRequest * block.MountRequest ,
934+ volumeStatus * block.VolumeStatus ,
935+ ) error {
936+ mountCtx , ok := ctrl .activeMounts [mountRequest .Metadata ().ID ()]
937+ if ! ok {
938+ return nil
939+ }
940+
941+ logger .Info ("unmounting memory volume" ,
942+ zap .String ("volume" , volumeStatus .Metadata ().ID ()),
943+ zap .String ("target" , volumeStatus .TypedSpec ().MountLocation ),
944+ )
945+
946+ if err := mountCtx .unmounter (); err != nil {
947+ return fmt .Errorf ("failed to unmount memory volume %q: %w" , mountRequest .Metadata ().ID (), err )
948+ }
949+
950+ delete (ctrl .activeMounts , mountRequest .Metadata ().ID ())
951+
952+ logger .Info ("memory volume unmounted" ,
953+ zap .String ("volume" , volumeStatus .Metadata ().ID ()),
954+ )
955+
956+ return nil
957+ }
958+
850959func (ctrl * MountController ) handleSymlinkUmountOperation (
851960 mountRequest * block.MountRequest ,
852961) error {
0 commit comments