[rust PATCH] add list_volumes function

rodolpheche posted 1 patch 3 years, 6 months ago
Failed in applying to current master (apply log)
src/storage_pool.rs | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
[rust PATCH] add list_volumes function
Posted by rodolpheche 3 years, 6 months ago
---
 src/storage_pool.rs | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/storage_pool.rs b/src/storage_pool.rs
index 96258f0..ad0a51a 100644
--- a/src/storage_pool.rs
+++ b/src/storage_pool.rs
@@ -18,7 +18,7 @@
 
 extern crate libc;
 
-use std::str;
+use std::{ptr, str};
 
 use connect::sys::virConnectPtr;
 use storage_vol::sys::virStorageVolPtr;
@@ -101,6 +101,11 @@ extern "C" {
         info: sys::virStoragePoolInfoPtr,
     ) -> libc::c_int;
     fn virStoragePoolNumOfVolumes(ptr: sys::virStoragePoolPtr) -> libc::c_int;
+    fn virStoragePoolListVolumes(
+        ptr: sys::virStoragePoolPtr,
+        names: *mut *mut libc::c_char,
+        maxnames: libc::c_int,
+    ) -> libc::c_int;
 }
 
 pub type StoragePoolXMLFlags = self::libc::c_uint;
@@ -276,6 +281,22 @@ impl StoragePool {
         }
     }
 
+    pub fn list_volumes(&self) -> Result<Vec<String>, Error> {
+        unsafe {
+            let mut names: [*mut libc::c_char; 1024] = [ptr::null_mut(); 1024];
+            let size = virStoragePoolListVolumes(self.as_ptr(), names.as_mut_ptr(), 1024);
+            if size == -1 {
+                return Err(Error::new());
+            }
+
+            let mut array: Vec<String> = Vec::new();
+            for x in 0..size as usize {
+                array.push(c_chars_to_string!(names[x]));
+            }
+            return Ok(array);
+        }
+    }
+
     pub fn get_uuid_string(&self) -> Result<String, Error> {
         unsafe {
             let mut uuid: [libc::c_char; 37] = [0; 37];
-- 
2.28.0

Re: [rust PATCH] add list_volumes function
Posted by Daniel P. Berrangé 3 years, 6 months ago
Thank you for your contribution, however, we have switched to using
merge requests for all except the primary libvirt.git.

Could you open a merge request at

https://gitlab.com/libvirt/libvirt-rust/

this will ensure the change gets put through the CI system too.

On Thu, Oct 01, 2020 at 02:11:41PM +0200, rodolpheche wrote:
> ---
>  src/storage_pool.rs | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)

We also require commits to have  "Signed-off-by" line to assert
that you're contributing in compliance with the DCO described at

   https://developercertificate.org/

> 
> diff --git a/src/storage_pool.rs b/src/storage_pool.rs
> index 96258f0..ad0a51a 100644
> --- a/src/storage_pool.rs
> +++ b/src/storage_pool.rs
> @@ -18,7 +18,7 @@
>  
>  extern crate libc;
>  
> -use std::str;
> +use std::{ptr, str};
>  
>  use connect::sys::virConnectPtr;
>  use storage_vol::sys::virStorageVolPtr;
> @@ -101,6 +101,11 @@ extern "C" {
>          info: sys::virStoragePoolInfoPtr,
>      ) -> libc::c_int;
>      fn virStoragePoolNumOfVolumes(ptr: sys::virStoragePoolPtr) -> libc::c_int;
> +    fn virStoragePoolListVolumes(
> +        ptr: sys::virStoragePoolPtr,
> +        names: *mut *mut libc::c_char,
> +        maxnames: libc::c_int,
> +    ) -> libc::c_int;
>  }
>  
>  pub type StoragePoolXMLFlags = self::libc::c_uint;
> @@ -276,6 +281,22 @@ impl StoragePool {
>          }
>      }
>  
> +    pub fn list_volumes(&self) -> Result<Vec<String>, Error> {
> +        unsafe {
> +            let mut names: [*mut libc::c_char; 1024] = [ptr::null_mut(); 1024];
> +            let size = virStoragePoolListVolumes(self.as_ptr(), names.as_mut_ptr(), 1024);
> +            if size == -1 {
> +                return Err(Error::new());
> +            }
> +
> +            let mut array: Vec<String> = Vec::new();
> +            for x in 0..size as usize {
> +                array.push(c_chars_to_string!(names[x]));
> +            }
> +            return Ok(array);
> +        }
> +    }
> +
>      pub fn get_uuid_string(&self) -> Result<String, Error> {
>          unsafe {
>              let mut uuid: [libc::c_char; 37] = [0; 37];
> -- 
> 2.28.0
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|