func iterateVolumes(config *config.TopLevelConfig, dispatch func(v *volumeDispatch)) { tenants, err := config.ListTenants() if err != nil { log.Warn("Could not locate any tenant information; sleeping.") return } for _, tenant := range tenants { volumes, err := config.ListVolumes(tenant) if err != nil { log.Warnf("Could not list volumes for tenant %q: sleeping.", tenant) return } dispatch(&volumeDispatch{config, tenant, volumes}) } }
func wrapSnapshotAction(config *config.TopLevelConfig, action func(config *config.TopLevelConfig, pool, volName string, volume *config.VolumeConfig)) { tenants, err := config.ListTenants() if err != nil { if conv, ok := err.(*etcd.EtcdError); ok && conv.ErrorCode == 100 { // should never be hit because we create it at volmaster boot, but yeah. return } log.Errorf("Runtime configuration incorrect: %v", err) return } for _, tenant := range tenants { volumes, err := config.ListVolumes(tenant) conv, ok := err.(*etcd.EtcdError) if err != nil { if ok && conv.ErrorCode == 100 { continue } log.Errorf("Runtime configuration incorrect: %v", err) return } for volName, volume := range volumes { duration, err := time.ParseDuration(volume.Options.Snapshot.Frequency) if err != nil { log.Errorf("Runtime configuration incorrect; cannot use %q as a snapshot frequency", volume.Options.Snapshot.Frequency) return } if volume.Options.UseSnapshots && time.Now().Unix()%int64(duration.Seconds()) == 0 { action(config, volume.Options.Pool, volName, volume) } } } }