Re: [PATCHv3 4/4] storage: probe qcow2 volumes in gluster pool

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Nov 11, 2013 at 09:19:31PM -0700, Eric Blake wrote:
> diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
> index bc90de9..69e8e61 100644
> --- a/src/storage/storage_backend_gluster.c
> +++ b/src/storage/storage_backend_gluster.c
> @@ -116,6 +116,12 @@ virStorageBackendGlusterOpen(virStoragePoolObjPtr pool)
>          goto error;
>      }
> 
> +    if (glfs_chdir(ret->vol, ret->dir) < 0) {
> +        virReportSystemError(errno, _("failed to change to directory '%s'"),
> +                             ret->dir);
> +        goto error;
> +    }
> +
>      return ret;
> 
>  error:
> @@ -124,6 +130,37 @@ error:
>  }
> 
> 
> +static int

s/int/ssize_t/ ?

> +virStorageBackendGlusterReadHeader(glfs_fd_t *fd,
> +                                   const char *name,
> +                                   int maxlen,

s/int/size_t/ ?

> +                                   char **buf)
> +{
> +    char *s;
> +    size_t nread = 0;
> +
> +    if (VIR_ALLOC_N(*buf, maxlen) < 0)
> +        return -1;
> +
> +    s = *buf;
> +    while (maxlen) {
> +        ssize_t r = glfs_read(fd, s, maxlen, 0);
> +        if (r < 0 && errno == EINTR)
> +            continue;
> +        if (r < 0) {
> +            VIR_FREE(*buf);
> +            virReportSystemError(errno, _("unable to read '%s'"), name);
> +            return r;
> +        }
> +        if (r == 0)
> +            return nread;
> +        buf += r;
> +        maxlen -= r;
> +        nread += r;
> +    }
> +    return nread;
> +}
> +
>  /* Populate *volptr for the given name and stat information, or leave
>   * it NULL if the entry should be skipped (such as ".").  Return 0 on
>   * success, -1 on failure. */
> @@ -137,6 +174,10 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
>      char *tmp;
>      int ret = -1;
>      virStorageVolDefPtr vol = NULL;
> +    glfs_fd_t *fd = NULL;
> +    virStorageFileMetadata *meta = NULL;
> +    char *header = NULL;
> +    ssize_t len = VIR_STORAGE_MAX_HEADER;
> 
>      /* Silently skip directories, including '.' and '..'.  FIXME:
>       * should non-'.' subdirectories be listed as type dir?  */
> @@ -162,11 +203,57 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
>      }
>      state->uri->path = tmp;
> 
> +    if (!(fd = glfs_open(state->vol, name, O_RDONLY| O_NONBLOCK | O_NOCTTY))) {
> +        if ((errno == ENOENT || errno == ELOOP) &&
> +            S_ISLNK(st->st_mode)) {
> +            VIR_WARN("ignoring dangling symlink '%s'", name);
> +            ret = 0;
> +        } else {
> +            virReportSystemError(errno, _("cannot open volume '%s'"), name);
> +        }
> +        goto cleanup;
> +    }
> +
> +    if ((len = virStorageBackendGlusterReadHeader(fd, name, len, &header)) < 0)
> +        goto cleanup;
> +
> +    if ((vol->target.format = virStorageFileProbeFormatFromBuf(name,
> +                                                               header,
> +                                                               len)) < 0 ||
> +        !(meta = virStorageFileGetMetadataFromBuf(name, header, len,
> +                                                  vol->target.format)))
> +        goto cleanup;


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]