forked from Ivasoft/objectivefs-docker-volume
Reduce snaphots memory usage. Pass mount options to snapshots.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
30
main.go
30
main.go
@@ -383,7 +383,13 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error)
|
||||
dest := filepath.Join(snapshotsPath, i)
|
||||
if err := os.Mkdir(dest, os.ModePerm); err == nil || os.IsExist(err) {
|
||||
// Note: There is a missing "mount" argument so the mount continues running in a background process
|
||||
if err := applyEnv(exec.Command("/sbin/mount.objectivefs", name, dest), v.Env).Run(); err != nil {
|
||||
var ssCmd *exec.Cmd
|
||||
if len(v.Opts) == 0 {
|
||||
ssCmd = exec.Command("/sbin/mount.objectivefs", name, dest)
|
||||
} else {
|
||||
ssCmd = exec.Command("/sbin/mount.objectivefs", "-o"+v.Opts, name, dest)
|
||||
}
|
||||
if err := applyEnv(ssCmd, makeSnapshotEnv(v.Env)).Run(); err != nil {
|
||||
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Warn("Failed to mount a new snapshot.")
|
||||
} else {
|
||||
log.WithFields(log.Fields{"name": r.Name, "snapshot": i}).Debug("Snapshot mounted.")
|
||||
@@ -598,6 +604,28 @@ func applyEnv(cmd *exec.Cmd, env []string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func makeSnapshotEnv(env []string) []string {
|
||||
// We must conserve memory as there are hundreds of snaphots
|
||||
// Note: This is a minimum based on documentation
|
||||
const cacheSizeValue = "CACHESIZE=64MiB"
|
||||
|
||||
result := make([]string, len(env))
|
||||
copy(result, env)
|
||||
|
||||
hasCacheSize := false
|
||||
for i, j := range result {
|
||||
if strings.HasPrefix(j, "CACHESIZE=") {
|
||||
result[i] = cacheSizeValue
|
||||
hasCacheSize = true
|
||||
}
|
||||
}
|
||||
if !hasCacheSize {
|
||||
result = append(result, cacheSizeValue)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func generateSnapshotsFromRulesForNow(rules string) (map[string]bool, error) {
|
||||
if timesB, err := exec.Command("/sbin/mount.objectivefs", "snapshot", "-vs", rules).Output(); err == nil {
|
||||
var result = make(map[string]bool)
|
||||
|
||||
Reference in New Issue
Block a user