MCPcopy
hub / github.com/cubefs/cubefs / startServer

Method startServer

client/blockcache/bcache/service.go:131–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

129}
130
131func (s *bcacheStore) startServer() (err error) {
132 // create socket dir
133 os.MkdirAll(filepath.Dir(UnixSocketPath), FilePerm)
134
135 unixSocketLockFile, err = os.OpenFile(UnixSocketLock, os.O_CREATE|os.O_RDWR, 0o666)
136 if err != nil {
137 return errors.New(fmt.Sprintf("Error: creating lock file %s", UnixSocketLock))
138 }
139
140 err = syscall.Flock(int(unixSocketLockFile.Fd()), syscall.LOCK_EX|syscall.LOCK_NB)
141 if err != nil {
142 return errors.New(fmt.Sprintf("Error: acquire flock of %s failed, maybe server exists", UnixSocketLock))
143 }
144
145 if _, err := os.Stat(UnixSocketPath); err == nil {
146 os.Remove(UnixSocketPath)
147 }
148
149 s.stopC = make(chan struct{})
150 ln, err := net.Listen("unix", UnixSocketPath)
151 if err != nil {
152 panic(err)
153 }
154 go func(stopC chan struct{}) {
155 defer ln.Close()
156 for {
157 conn, err := ln.Accept()
158 select {
159 case <-stopC:
160 return
161 default:
162 }
163 if err != nil {
164 continue
165 }
166 go s.serveConn(conn, stopC)
167 }
168 }(s.stopC)
169
170 log.LogInfof("start blockcache server.")
171 return
172}
173
174func (s *bcacheStore) stopServer() {
175 if s.stopC != nil {

Callers 1

doStartFunction · 0.45

Calls 10

serveConnMethod · 0.95
NewFunction · 0.92
LogInfofFunction · 0.92
DirMethod · 0.80
AcceptMethod · 0.80
OpenFileMethod · 0.65
FdMethod · 0.65
StatMethod · 0.65
RemoveMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected