From nobody Thu May 2 06:54:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567069563; cv=none; d=zoho.com; s=zohoarc; b=IKpOMjeiE4ZmX3dYMJkRLdCsueVoK65lOlJiqGbzqBb5VYsqQD82FBnpK/w60y3hifSu2zFQlwKEcRaLhCK/rNx6XtbkdHvB1ia9SfAsYyM9YYph9giITn9ngJL8v+3VrGC+5xasieUyZHI/VfiThVPasAeQuqwH+WBJKJM1rJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567069563; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=TzMqZU/nZ6ggpMwNXCt4YDWfw10F5Q78yaJ5tQBqJ1c=; b=UakjI10kluplRTqVk4jr4xWAlSQXvFMQrcSAcvB706IuZq5CaTkEz9BLvMI4yYwDtPlCw6px6/5ufPaZtmrH7ZXvyzxa1Pe64CRTPPHvzmhhe/soS6mKgskIeLquZPIz0IXYcBPYuAJi1DkCXn7Avunh7X8vMWghjQAqavHZmlU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567069563125235.80285615360515; Thu, 29 Aug 2019 02:06:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 34E4E3D96B; Thu, 29 Aug 2019 09:06:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D43FA19C4F; Thu, 29 Aug 2019 09:05:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6A4AA180B536; Thu, 29 Aug 2019 09:05:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7T95tGo000750 for ; Thu, 29 Aug 2019 05:05:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id F1F2B5D9D3; Thu, 29 Aug 2019 09:05:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED1535D9C9 for ; Thu, 29 Aug 2019 09:05:53 +0000 (UTC) Received: from expn.cat.pdx.edu (expn.cat.pdx.edu [131.252.208.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 363A630842A8 for ; Thu, 29 Aug 2019 09:05:52 +0000 (UTC) Received: from noko.cat.pdx.edu (postfix@noko.cat.pdx.edu [10.218.212.15]) by expn.cat.pdx.edu (8.15.2/8.15.2/Debian-3) with ESMTP id x7T95n1v002747; Thu, 29 Aug 2019 02:05:49 -0700 Received: by noko.cat.pdx.edu (Postfix, from userid 3404) id 314E91A007B; Thu, 29 Aug 2019 02:05:49 -0700 (PDT) From: Sage Imel To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 02:05:12 -0700 Message-Id: <20190829090512.7407-1-sage@cat.pdx.edu> X-Spam-Status: No, score=2.3 required=5.0 tests=AWL,L_RCVDUSER,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on expn.cat.pdx.edu X-Virus-Scanned: clamav-milter 0.100.3 at expn.cat.pdx.edu X-Virus-Status: Clean X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 238 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 29 Aug 2019 09:05:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 29 Aug 2019 09:05:52 +0000 (UTC) for IP:'131.252.208.110' DOMAIN:'expn.cat.pdx.edu' HELO:'expn.cat.pdx.edu' FROM:'sage@cat.pdx.edu' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 131.252.208.110 expn.cat.pdx.edu 131.252.208.110 expn.cat.pdx.edu X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Sage Imel , Sage Imel Subject: [libvirt] [rust PATCH] Add list_all_volumes method for storage_pool::StoragePool X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Aug 2019 09:06:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 @@ =20 extern crate libc; =20 -use std::str; +use std::{str, ptr}; =20 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: StoragePoolCr= eateFlags =3D 1 << 0; pub const STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE: StoragePoolCreateFlags= =3D 1 << 1; pub const STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE: StoragePoolCreateFl= ags =3D 1 << 2; =20 +pub type VirStoragePoolListAllVolumesFlags =3D self::libc::c_uint; + pub type StoragePoolState =3D self::libc::c_uint; pub const VIR_STORAGE_POOL_INACTIVE: StoragePoolState =3D 0; pub const VIR_STORAGE_POOL_BUILDING: StoragePoolState =3D 1; @@ -201,6 +207,27 @@ impl StoragePool { } } =20 + pub fn list_all_volumes(&self, + flags: VirStoragePoolListAllVolumesFlags) + -> Result, Error> { + unsafe { + let mut volumes: *mut virStorageVolPtr =3D ptr::null_mut(); + let size =3D + virStoragePoolListAllVolumes(self.as_ptr(), &mut volumes, = flags as libc::c_uint); + if size =3D=3D -1 { + return Err(Error::new()); + } + + let mut array: Vec =3D 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 =3D virStoragePoolLookupByID(conn.as_ptr(), id as libc= ::c_int); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list