summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Zhang <cheng.zhang@citrix.com>2017-02-21 18:13:36 +0800
committerGitHub <noreply@github.com>2017-02-21 18:13:36 +0800
commit02ac798c29d17983d295b3db5c1e9e941d1d3d39 (patch)
treec254cdaabe81843d4f76951167ea71567a7c7d05
parent4eb91d4e30ea6f02fba1f12250c7d77804a1080f (diff)
parenta4716286b6a85c00769d5acad821eec4c7c65cb5 (diff)
downloadvyos-xe-guest-utilities-02ac798c29d17983d295b3db5c1e9e941d1d3d39.tar.gz
vyos-xe-guest-utilities-02ac798c29d17983d295b3db5c1e9e941d1d3d39.zip
Merge pull request #24 from fillzero/CA-240982
CA-240982: Xencenter shows IP address of interface of VM even if I remove IP from the interface
-rw-r--r--xe-daemon/xe-daemon.go23
-rw-r--r--xenstoreclient/xenstore.go34
2 files changed, 46 insertions, 11 deletions
diff --git a/xe-daemon/xe-daemon.go b/xe-daemon/xe-daemon.go
index e30e1dc..eaee8c7 100644
--- a/xe-daemon/xe-daemon.go
+++ b/xe-daemon/xe-daemon.go
@@ -18,7 +18,10 @@ import (
)
const (
- LoggerName string = "xe-daemon"
+ LoggerName string = "xe-daemon"
+ DivisorOne int = 1
+ DivisorTwo int = 2
+ DivisorLeastMultiple int = 2 // The least common multiple, ensure every collector done before executing InvalidCacheFlush.
)
func main() {
@@ -75,11 +78,11 @@ func main() {
name string
Collect func() (guestmetric.GuestMetric, error)
}{
- {1, "CollectOS", collector.CollectOS},
- {1, "CollectMisc", collector.CollectMisc},
- {1, "CollectNetworkAddr", collector.CollectNetworkAddr},
- {1, "CollectDisk", collector.CollectDisk},
- {2, "CollectMemory", collector.CollectMemory},
+ {DivisorOne, "CollectOS", collector.CollectOS},
+ {DivisorOne, "CollectMisc", collector.CollectMisc},
+ {DivisorOne, "CollectNetworkAddr", collector.CollectNetworkAddr},
+ {DivisorOne, "CollectDisk", collector.CollectDisk},
+ {DivisorTwo, "CollectMemory", collector.CollectMemory},
}
lastUniqueID, err := xs.Read("unique-domain-id")
@@ -125,6 +128,14 @@ func main() {
}
}
}
+ if count%DivisorLeastMultiple == 0 {
+ if cx, ok := xs.(*xenstoreclient.CachedXenStore); ok {
+ err := cx.InvalidCacheFlush()
+ if err != nil {
+ logger.Printf("InvalidCacheFlush error: %#v\n", err)
+ }
+ }
+ }
}
if updated {
diff --git a/xenstoreclient/xenstore.go b/xenstoreclient/xenstore.go
index 77126f0..5112c40 100644
--- a/xenstoreclient/xenstore.go
+++ b/xenstoreclient/xenstore.go
@@ -461,9 +461,14 @@ func (xs *XenStore) StopWatch() error {
return nil
}
+type Content struct {
+ value string
+ keepalive bool
+}
+
type CachedXenStore struct {
xs XenStoreClient
- writeCache map[string]string
+ writeCache map[string]Content
}
func NewCachedXenstore(tx uint32) (XenStoreClient, error) {
@@ -473,17 +478,19 @@ func NewCachedXenstore(tx uint32) (XenStoreClient, error) {
}
return &CachedXenStore{
xs: xs,
- writeCache: make(map[string]string, 0),
+ writeCache: make(map[string]Content, 0),
}, nil
}
func (xs *CachedXenStore) Write(path string, value string) error {
- if v, ok := xs.writeCache[path]; ok && v == value {
+ if v, ok := xs.writeCache[path]; ok && v.value == value {
+ v.keepalive = true
+ xs.writeCache[path] = v
return nil
}
err := xs.xs.Write(path, value)
if err == nil {
- xs.writeCache[path] = value
+ xs.writeCache[path] = Content{value: value, keepalive: true}
}
return err
}
@@ -529,7 +536,24 @@ func (xs *CachedXenStore) StopWatch() error {
}
func (xs *CachedXenStore) Clear() {
- xs.writeCache = make(map[string]string, 0)
+ xs.writeCache = make(map[string]Content, 0)
+}
+
+func (xs *CachedXenStore) InvalidCacheFlush() error {
+ for key, value := range xs.writeCache {
+ if value.keepalive {
+ value.keepalive = false
+ xs.writeCache[key] = value
+ } else {
+ err := xs.Rm(key)
+ if err != nil {
+ return err
+ } else {
+ delete(xs.writeCache, key)
+ }
+ }
+ }
+ return nil
}
func getDevPath() (devPath string, err error) {