[libvirt] [PATCHv2 13/33] test: storage: Initialize storage source to correct type

Eric Blake eblake at redhat.com
Fri May 23 17:29:09 UTC 2014


On 05/22/2014 07:47 AM, Peter Krempa wrote:
> Stat the path of the storage file being tested to set the correct type
> into the virStorageSource. This will avoid breaking the test suite when
> inquiring metadata of directory paths in the next patches.
> ---
>  tests/virstoragetest.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
> index fb96c71..746bf63 100644
> --- a/tests/virstoragetest.c
> +++ b/tests/virstoragetest.c
> @@ -98,6 +98,7 @@ testStorageFileGetMetadata(const char *path,
>                             uid_t uid, gid_t gid,
>                             bool allow_probe)
>  {
> +    struct stat st;
>      virStorageSourcePtr ret = NULL;
> 
>      if (VIR_ALLOC(ret) < 0)
> @@ -106,6 +107,15 @@ testStorageFileGetMetadata(const char *path,
>      ret->type = VIR_STORAGE_TYPE_FILE;
>      ret->format = format;
> 
> +    if (stat(path, &st) == 0) {

Same question as in 12/33 on whether we should cache a struct stat to
minimize the calls to stat() (or at most have one stat() prior to open,
and one fstat() after open or after any resize operation).  Another good
reason to minimize stats, as well as to trust open/fstat more than
stat/open, is to minimize TOCTTOU races.  But this patch makes sense
whether or not we do that as a followup.

ACK.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140523/86b5ba3b/attachment-0001.sig>


More information about the libvir-list mailing list