Skip to content

Commit

Permalink
Updated check fs
Browse files Browse the repository at this point in the history
  • Loading branch information
johscheuer committed Feb 28, 2017
1 parent 9008773 commit 036002c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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))
Expand Down
50 changes: 31 additions & 19 deletions quobyte_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 036002c

Please sign in to comment.