From: Guillaume Date: Fri, 5 Jan 2024 16:45:07 +0000 (+0100) Subject: Removing all vif entries from xenstore at startup X-Git-Tag: 0.4.0~11^2 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=80803a6469a5763629d2a3095ebba80f0dab6bc8;p=xen-guest-agent.git Removing all vif entries from xenstore at startup When interfaces reported by Xenstore are suppressed while the service is not running, these data remain. To avoid this we start by removing all entries from previous agent. Entries that are still valid will be repopulated immediatly. Fixes: #12 --- diff --git a/src/main.rs b/src/main.rs index d582afa..775231b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,10 @@ async fn main() -> Result<(), Box> { let mut collector_memory = MemorySource::new()?; + // Remove old entries from previous agent to avoid having unknown + // interfaces. We will repopulate existing ones immediatly. + publisher.cleanup_ifaces()?; + let kernel_info = collect_kernel()?; let mem_total_kb = match collector_memory.get_total_kb() { Ok(mem_total_kb) => Some(mem_total_kb), diff --git a/src/publisher.rs b/src/publisher.rs index 8258e36..247e9fc 100644 --- a/src/publisher.rs +++ b/src/publisher.rs @@ -40,4 +40,8 @@ impl Publisher { } Ok(()) } + + pub fn cleanup_ifaces(&mut self) -> io::Result<()> { + Ok(()) + } } diff --git a/src/publisher_xenstore.rs b/src/publisher_xenstore.rs index f970ace..d4e2ffa 100644 --- a/src/publisher_xenstore.rs +++ b/src/publisher_xenstore.rs @@ -10,6 +10,7 @@ pub trait XenstoreSchema { ) -> io::Result<()>; fn publish_memfree(&self, mem_free_kb: usize) -> io::Result<()>; fn publish_netevent(&mut self, event: &NetEvent) -> io::Result<()>; + fn cleanup_ifaces(&mut self) -> io::Result<()>; } pub struct Publisher { @@ -36,6 +37,10 @@ impl Publisher { pub fn publish_netevent(&mut self, event: &NetEvent) -> io::Result<()> { self.schema.publish_netevent(event) } + + pub fn cleanup_ifaces(&mut self) -> io::Result<()> { + self.schema.cleanup_ifaces() + } } fn schema_from_name(name: &str) -> io::Result<&'static dyn Fn(Xs) -> Box> { diff --git a/src/xenstore_schema_rfc.rs b/src/xenstore_schema_rfc.rs index 74f32a9..8c80245 100644 --- a/src/xenstore_schema_rfc.rs +++ b/src/xenstore_schema_rfc.rs @@ -34,6 +34,11 @@ impl XenstoreSchema for Schema { Ok(()) } + fn cleanup_ifaces(&mut self) -> io::Result<()> { + // Currently only vif interfaces are cleaned + xs_unpublish(&self.xs, "data/net") + } + fn publish_memfree(&self, _mem_free_kb: usize) -> io::Result<()> { //xs_publish(&self.xs, "data/meminfo_free", &mem_free_kb.to_string())?; Ok(()) diff --git a/src/xenstore_schema_std.rs b/src/xenstore_schema_std.rs index 9817795..585d4a9 100644 --- a/src/xenstore_schema_std.rs +++ b/src/xenstore_schema_std.rs @@ -137,6 +137,11 @@ impl XenstoreSchema for Schema { } Ok(()) } + + fn cleanup_ifaces(&mut self) -> io::Result<()> { + // Currently only vif interfaces are cleaned + xs_unpublish(&self.xs, "attr/vif") + } } impl Schema {