Re: [libvirt] [rust PATCH] Add list_all_volumes method for storage_pool::StoragePool
This was copied and barely modified from the implementation of connect::Connect::list_all_storage_pools -- Sage Imel Maseeh College of Engineering and Computer Science Computer Action Team On Thu, Aug 29, 2019 at 2:05 AM Sage Imel wrote: > From: Sage Imel > > Always returns the full list of volumes, > can't just ask it how many volumes are in the pool > > Signed-off-by: Sage Imel > --- > src/storage_pool.rs | 29 - > 1 file changed, 28 insertions(+), 1 deletion(-) > > diff --git a/src/storage_pool.rs b/src/storage_pool.rs > index 38676c2..e8ed21c 100644 > --- a/src/storage_pool.rs > +++ b/src/storage_pool.rs > @@ -18,7 +18,7 @@ > > extern crate libc; > > -use std::str; > +use std::{str, ptr}; > > use connect::sys::virConnectPtr; > use storage_vol::sys::virStorageVolPtr; > @@ -57,6 +57,10 @@ extern "C" { > xml: *const libc::c_char, > flags: libc::c_uint) > -> sys::virStoragePoolPtr; > +fn virStoragePoolListAllVolumes(ptr: sys::virStoragePoolPtr, > +vols: *mut *mut virStorageVolPtr, > +flags:libc::c_uint) > +-> libc::c_int; > fn virStoragePoolLookupByID(c: virConnectPtr, id: libc::c_int) -> > sys::virStoragePoolPtr; > fn virStoragePoolLookupByName(c: virConnectPtr, >id: *const libc::c_char) > @@ -103,6 +107,8 @@ pub const STORAGE_POOL_CREATE_WITH_BUILD: > StoragePoolCreateFlags = 1 << 0; > pub const STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE: > StoragePoolCreateFlags = 1 << 1; > pub const STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE: > StoragePoolCreateFlags = 1 << 2; > > +pub type VirStoragePoolListAllVolumesFlags = self::libc::c_uint; > + > pub type StoragePoolState = self::libc::c_uint; > pub const VIR_STORAGE_POOL_INACTIVE: StoragePoolState = 0; > pub const VIR_STORAGE_POOL_BUILDING: StoragePoolState = 1; > @@ -201,6 +207,27 @@ impl StoragePool { > } > } > > +pub fn list_all_volumes(&self, > + flags: > VirStoragePoolListAllVolumesFlags) > + -> Result, Error> { > +unsafe { > +let mut volumes: *mut virStorageVolPtr = ptr::null_mut(); > +let size = > +virStoragePoolListAllVolumes(self.as_ptr(), &mut volumes, > flags as libc::c_uint); > +if size == -1 { > +return Err(Error::new()); > +} > + > +let mut array: Vec = Vec::new(); > +for x in 0..size as isize { > +array.push(StorageVol::new(*volumes.offset(x))); > +} > +libc::free(volumes as *mut libc::c_void); > + > +return Ok(array); > +} > +} > + > pub fn lookup_by_id(conn: &Connect, id: u32) -> Result Error> { > unsafe { > let ptr = virStoragePoolLookupByID(conn.as_ptr(), id as > libc::c_int); > -- > 2.17.1 > > -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [rust PATCH] Add list_all_volumes method for storage_pool::StoragePool
From: Sage Imel Always returns the full list of volumes, can't just ask it how many volumes are in the pool Signed-off-by: Sage Imel --- src/storage_pool.rs | 29 - 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/storage_pool.rs b/src/storage_pool.rs index 38676c2..e8ed21c 100644 --- a/src/storage_pool.rs +++ b/src/storage_pool.rs @@ -18,7 +18,7 @@ extern crate libc; -use std::str; +use std::{str, ptr}; use connect::sys::virConnectPtr; use storage_vol::sys::virStorageVolPtr; @@ -57,6 +57,10 @@ extern "C" { xml: *const libc::c_char, flags: libc::c_uint) -> sys::virStoragePoolPtr; +fn virStoragePoolListAllVolumes(ptr: sys::virStoragePoolPtr, +vols: *mut *mut virStorageVolPtr, +flags:libc::c_uint) +-> libc::c_int; fn virStoragePoolLookupByID(c: virConnectPtr, id: libc::c_int) -> sys::virStoragePoolPtr; fn virStoragePoolLookupByName(c: virConnectPtr, id: *const libc::c_char) @@ -103,6 +107,8 @@ pub const STORAGE_POOL_CREATE_WITH_BUILD: StoragePoolCreateFlags = 1 << 0; pub const STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE: StoragePoolCreateFlags = 1 << 1; pub const STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE: StoragePoolCreateFlags = 1 << 2; +pub type VirStoragePoolListAllVolumesFlags = self::libc::c_uint; + pub type StoragePoolState = self::libc::c_uint; pub const VIR_STORAGE_POOL_INACTIVE: StoragePoolState = 0; pub const VIR_STORAGE_POOL_BUILDING: StoragePoolState = 1; @@ -201,6 +207,27 @@ impl StoragePool { } } +pub fn list_all_volumes(&self, + flags: VirStoragePoolListAllVolumesFlags) + -> Result, Error> { +unsafe { +let mut volumes: *mut virStorageVolPtr = ptr::null_mut(); +let size = +virStoragePoolListAllVolumes(self.as_ptr(), &mut volumes, flags as libc::c_uint); +if size == -1 { +return Err(Error::new()); +} + +let mut array: Vec = Vec::new(); +for x in 0..size as isize { +array.push(StorageVol::new(*volumes.offset(x))); +} +libc::free(volumes as *mut libc::c_void); + +return Ok(array); +} +} + pub fn lookup_by_id(conn: &Connect, id: u32) -> Result { unsafe { let ptr = virStoragePoolLookupByID(conn.as_ptr(), id as libc::c_int); -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] virDomainGetAutostart takes a pointer that it writes the output value to
No objection, thanks for catching that. -- Sage Imel Lead Linux/Unix System Administrator Maseeh College of Engineering and Computer Science Computer Action Team supp...@cat.pdx.edu - (503) 725-5420 On Wed, Aug 21, 2019 at 3:27 AM Daniel P. Berrangé wrote: > On Thu, Aug 15, 2019 at 02:41:40PM -0700, Sage Imel wrote: > > The current version of get_autostart seg faults. This patch > > correctly passes a pointer to an int to virDomainGetAutostart > > and returns a result based on the value of that int > > > > Signed-off-by: sage Imel > > Jan points out the inconsistent capitalization on your first name. Any > objection to me fixing that when pushing ? > > 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 :| > -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virDomainGetAutostart takes a pointer that it writes the output value to
--- src/domain.rs | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/domain.rs b/src/domain.rs index 11ecb3c..acb9e6e 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -136,7 +136,7 @@ extern "C" { fn virDomainGetHostname(ptr: sys::virDomainPtr, flags: libc::c_uint) -> *mut libc::c_char; fn virDomainGetUUIDString(ptr: sys::virDomainPtr, uuid: *mut libc::c_char) -> libc::c_int; fn virDomainGetXMLDesc(ptr: sys::virDomainPtr, flags: libc::c_uint) -> *mut libc::c_char; -fn virDomainGetAutostart(ptr: sys::virDomainPtr) -> libc::c_int; +fn virDomainGetAutostart(ptr: sys::virDomainPtr, autostart: *mut libc::c_int) -> libc::c_int; fn virDomainSetAutostart(ptr: sys::virDomainPtr, autostart: libc::c_uint) -> libc::c_int; fn virDomainGetID(ptr: sys::virDomainPtr) -> libc::c_uint; fn virDomainSetMaxMemory(ptr: sys::virDomainPtr, memory: libc::c_ulong) -> libc::c_int; @@ -1036,11 +1036,12 @@ impl Domain { pub fn get_autostart(&self) -> Result { unsafe { -let ret = virDomainGetAutostart(self.as_ptr()); +let mut autostart: libc::c_int = 0; +let ret = virDomainGetAutostart(self.as_ptr(), &mut autostart); if ret == -1 { return Err(Error::new()); } -return Ok(ret == 1); +return Ok(autostart == 1); } } -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virDomainGetAutostart takes a pointer that it writes the output value to
The current version of get_autostart seg faults. This patch correctly passes a pointer to an int to virDomainGetAutostart and returns a result based on the value of that int Signed-off-by: sage Imel --- src/domain.rs | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/domain.rs b/src/domain.rs index 11ecb3c..acb9e6e 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -136,7 +136,7 @@ extern "C" { fn virDomainGetHostname(ptr: sys::virDomainPtr, flags: libc::c_uint) -> *mut libc::c_char; fn virDomainGetUUIDString(ptr: sys::virDomainPtr, uuid: *mut libc::c_char) -> libc::c_int; fn virDomainGetXMLDesc(ptr: sys::virDomainPtr, flags: libc::c_uint) -> *mut libc::c_char; -fn virDomainGetAutostart(ptr: sys::virDomainPtr) -> libc::c_int; +fn virDomainGetAutostart(ptr: sys::virDomainPtr, autostart: *mut libc::c_int) -> libc::c_int; fn virDomainSetAutostart(ptr: sys::virDomainPtr, autostart: libc::c_uint) -> libc::c_int; fn virDomainGetID(ptr: sys::virDomainPtr) -> libc::c_uint; fn virDomainSetMaxMemory(ptr: sys::virDomainPtr, memory: libc::c_ulong) -> libc::c_int; @@ -1036,11 +1036,12 @@ impl Domain { pub fn get_autostart(&self) -> Result { unsafe { -let ret = virDomainGetAutostart(self.as_ptr()); +let mut autostart: libc::c_int = 0; +let ret = virDomainGetAutostart(self.as_ptr(), &mut autostart); if ret == -1 { return Err(Error::new()); } -return Ok(ret == 1); +return Ok(autostart == 1); } } -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list