[libvirt] [PATCH 3/6] storage: fs: Don't attempt directory creation if it already exists

tzheng tzheng at redhat.com
Thu Jul 16 06:02:39 UTC 2015


Hi,Cole

After this patch is included in libvirt on rhel7.2,virt-manager can not 
create dir pool with existing directory.
There is no default pool created in a fresh rhel7.2 system,so if I try 
to create default pool,the below error shows:
Error creating pool: Could not build storage pool: failed to create 
directory '/var/lib/libvirt/images': File exists

Do you think it's acceptable for this change since the 
directory(/var/lib/libvirt/images) is created by libvirt,if users want 
to create pool with /var/lib/libvirt/images,they need to delete images 
directory firstly,if so I think maybe some notes in doc is 
preferred,thanks very much.

On 04/28/2015 04:48 AM, Cole Robinson wrote:
> The current code attempts to handle this, but it only catches mkdir
> failing with EEXIST. However if say trying to build /tmp for an
> unprivileged qemu:///session, mkdir will fail with EPERM.
>
> Rather than catch any errors, just don't attempt mkdir if the directory
> already exists.
> ---
>   src/util/virfile.c | 13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/src/util/virfile.c b/src/util/virfile.c
> index 87d121d..23a1655 100644
> --- a/src/util/virfile.c
> +++ b/src/util/virfile.c
> @@ -2289,12 +2289,13 @@ virDirCreateNoFork(const char *path,
>       int ret = 0;
>       struct stat st;
>   
> -    if ((mkdir(path, mode) < 0)
> -        && !((errno == EEXIST) && (flags & VIR_DIR_CREATE_ALLOW_EXIST))) {
> -        ret = -errno;
> -        virReportSystemError(errno, _("failed to create directory '%s'"),
> -                             path);
> -        goto error;
> +    if (!(flags & VIR_DIR_CREATE_ALLOW_EXIST) || !virFileExists(path)) {
> +        if (mkdir(path, mode) < 0) {
> +            ret = -errno;
> +            virReportSystemError(errno, _("failed to create directory '%s'"),
> +                                 path);
> +            goto error;
> +        }
>       }
>   
>       if (stat(path, &st) == -1) {




More information about the libvir-list mailing list