diff --git a/main.go b/main.go index 5ae6117..3ef1de2 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,8 @@ func main() { quobyteRegistry := flag.String("registry", "localhost:7861", "URL to the registry server(s) in the form of host[:port][,host:port] or SRV record name") group := flag.String("group", "root", "Group to create the unix socket") + maxWaitTime := flag.Float64("max-wait-time", 30, "Maximimum wait time for filesystem checks to complete when a Volume is created before returning an error") + maxFSChecks := flag.Int("max-fs-checks", 5, "Maximimum number of filesystem checks when a Volume is created before returning an error") showVersion := flag.Bool("version", false, "Shows version string") flag.Parse() @@ -46,7 +48,7 @@ func main() { mountAll(*quobyteMountOptions, *quobyteRegistry, *quobyteMountPath) } - qDriver := newQuobyteDriver(*quobyteAPIURL, *quobyteUser, *quobytePassword, *quobyteMountPath) + qDriver := newQuobyteDriver(*quobyteAPIURL, *quobyteUser, *quobytePassword, *quobyteMountPath, *maxFSChecks, *maxWaitTime) handler := volume.NewHandler(qDriver) log.Println(handler.ServeUnix(*group, quobyteID)) diff --git a/quobyte_driver.go b/quobyte_driver.go index 955c0be..e445a2b 100644 --- a/quobyte_driver.go +++ b/quobyte_driver.go @@ -18,13 +18,17 @@ type quobyteDriver struct { client *quobyte_api.QuobyteClient quobyteMount string m *sync.Mutex + maxFSChecks int + maxWaitTime float64 } -func newQuobyteDriver(apiURL string, username string, password string, quobyteMount string) quobyteDriver { +func newQuobyteDriver(apiURL string, username string, password string, quobyteMount string, maxFSChecks int, maxWaitTime float64) quobyteDriver { driver := quobyteDriver{ client: quobyte_api.NewQuobyteClient(apiURL, username, password), quobyteMount: quobyteMount, m: &sync.Mutex{}, + maxFSChecks: maxFSChecks, + maxWaitTime: maxWaitTime, } return driver @@ -59,45 +63,53 @@ func (driver quobyteDriver) Create(request volume.Request) volume.Response { mPoint := filepath.Join(driver.quobyteMount, request.Name) log.Printf("Validate mounting volume %s on %s\n", request.Name, mPoint) - if err := check_mount_point(mPoint); err != nil { + if err := driver.checkMountPoint(mPoint); err != nil { return volume.Response{Err: err.Error()} } return volume.Response{Err: ""} } -func (driver quobyteDriver) Remove(request volume.Request) volume.Response { - log.Printf("Removing volume %s\n", request.Name) - driver.m.Lock() - defer driver.m.Unlock() - - if err := driver.client.DeleteVolumeByName(request.Name, ""); err != nil { - log.Println(err) - return volume.Response{Err: err.Error()} - } +func (driver quobyteDriver) checkMountPoint(mPoint string) error { + start := time.Now() - return volume.Response{Err: ""} -} - -func check_mount_point(mPoint string) error { - // We try it 5 times ~5 seconds -> move this into config? - max_tries := 5 + backoff := 1 tries := 0 var mount_error error - for tries <= max_tries { + for tries <= driver.maxFSChecks { mount_error = nil if fi, err := os.Lstat(mPoint); err != nil || !fi.IsDir() { + log.Printf("Unsuccessful Filesystem Check for %s after %d tries", mPoint, tries) mount_error = err } else { return nil } - time.Sleep(1 * time.Second) + time.Sleep(time.Duration(backoff) * time.Second) + if time.Since(start).Seconds() > driver.maxWaitTime { + log.Printf("Abort checking mount point do to time out after %f\n", driver.maxWaitTime) + return mount_error + } + + backoff *= 2 } return mount_error } +func (driver quobyteDriver) Remove(request volume.Request) volume.Response { + log.Printf("Removing volume %s\n", request.Name) + driver.m.Lock() + defer driver.m.Unlock() + + if err := driver.client.DeleteVolumeByName(request.Name, ""); err != nil { + log.Println(err) + return volume.Response{Err: err.Error()} + } + + return volume.Response{Err: ""} +} + func (driver quobyteDriver) Mount(request volume.MountRequest) volume.Response { driver.m.Lock() defer driver.m.Unlock()