]> xenbits.xensource.com Git - xen-guest-agent.git/commitdiff
Removing all vif entries from xenstore at startup
authorGuillaume <guillaume.thouvenin@vates.tech>
Fri, 5 Jan 2024 16:45:07 +0000 (17:45 +0100)
committerGuillaume <guillaume.thouvenin@vates.tech>
Tue, 9 Jan 2024 15:56:34 +0000 (16:56 +0100)
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
src/main.rs
src/publisher.rs
src/publisher_xenstore.rs
src/xenstore_schema_rfc.rs
src/xenstore_schema_std.rs

index d582afa2b436d4f378dfc56882b357f621096b64..775231badca729054f86d0fb2997adee2b066e26 100644 (file)
@@ -46,6 +46,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
 
     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),
index 8258e36e9cbbfec2bc96f16052eb13e559fbd1ca..247e9fc764aeb1d47a5d866ae25f35adb8e9fa28 100644 (file)
@@ -40,4 +40,8 @@ impl Publisher {
         }
         Ok(())
     }
+
+    pub fn cleanup_ifaces(&mut self) -> io::Result<()> {
+        Ok(())
+    }
 }
index f970ace6e0511b4c180bfa8b079efc407f7017a1..d4e2ffadd99f5f7c84858bf5b7aefc2a3432e796 100644 (file)
@@ -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<dyn XenstoreSchema>> {
index 74f32a936d303ac4df77a40476475c84cb26b34f..8c80245814641627082bae48353102f33e8847b4 100644 (file)
@@ -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(())
index 98177959c320344f90421d00534517012e0ba55e..585d4a9dbfb5dd7a5042f62a2833b118cf22e64e 100644 (file)
@@ -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 {