@@ -124,7 +124,9 @@ type MountPoint struct {
124124
125125// Setup sets up a mount point by either mounting the volume if it is
126126// configured, or creating the source directory if supplied.
127- func (m * MountPoint ) Setup (mountLabel string , rootUID , rootGID int ) (path string , err error ) {
127+ // The, optional, checkFun parameter allows doing additional checking
128+ // before creating the source directory on the host.
129+ func (m * MountPoint ) Setup (mountLabel string , rootUID , rootGID int , checkFun func (m * MountPoint ) error ) (path string , err error ) {
128130 defer func () {
129131 if err == nil {
130132 if label .RelabelNeeded (m .Mode ) {
@@ -164,6 +166,14 @@ func (m *MountPoint) Setup(mountLabel string, rootUID, rootGID int) (path string
164166 }
165167 // system.MkdirAll() produces an error if m.Source exists and is a file (not a directory),
166168 if m .Type == mounttypes .TypeBind {
169+ // Before creating the source directory on the host, invoke checkFun if it's not nil. One of
170+ // the use case is to forbid creating the daemon socket as a directory if the daemon is in
171+ // the process of shutting down.
172+ if checkFun != nil {
173+ if err := checkFun (m ); err != nil {
174+ return "" , err
175+ }
176+ }
167177 // idtools.MkdirAllNewAs() produces an error if m.Source exists and is a file (not a directory)
168178 // also, makes sure that if the directory is created, the correct remapped rootUID/rootGID will own it
169179 if err := idtools .MkdirAllNewAs (m .Source , 0755 , rootUID , rootGID ); err != nil {
0 commit comments