Re: [PATCHv2 2/4] Enhance virStorageFileIsSharedFS

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

 



On Fri, Jun 25, 2010 at 01:22:15PM -0400, Laine Stump wrote:
> virStorageFileIsSharedFS would previously only work if the entire path
> in question was stat'able by the uid of the libvirtd process. This
> patch changes it to crawl backwards up the path retrying the statfs
> call until it gets to a partial path that *can* be stat'ed.
> 
> This is necessary to use the function to learn the fstype for files
> stored as a different user (and readable only by that user) on a
> root-squashed remote filesystem.
> ---
>  src/util/storage_file.c |   37 ++++++++++++++++++++++++++++++++++++-
>  1 files changed, 36 insertions(+), 1 deletions(-)
> 
> diff --git a/src/util/storage_file.c b/src/util/storage_file.c
> index 6cc8d5f..0adea40 100644
> --- a/src/util/storage_file.c
> +++ b/src/util/storage_file.c
> @@ -434,9 +434,44 @@ virStorageFileGetMetadata(const char *path,
>  
>  int virStorageFileIsSharedFS(const char *path)
>  {
> +    char *dirpath, *p;
>      struct statfs sb;
> +    int statfs_ret;
>  
> -    if (statfs(path, &sb) < 0) {
> +    if ((dirpath = strdup(path)) == NULL) {
> +        virReportOOMError();
> +        return -1;
> +    }
> +
> +    do {
> +
> +        /* Try less and less of the path until we get to a
> +         * directory we can stat. Even if we don't have 'x'
> +         * permission on any directory in the path on the NFS
> +         * server (assuming it's NFS), we will be able to stat the
> +         * mount point, and that will properly tell us if the
> +         * fstype is NFS.
> +         */
> +
> +        if ((p = strrchr(dirpath, '/')) == NULL) {
> +            virReportSystemError(EINVAL,
> +                         _("Invalid relative path '%s'"), path);
> +            VIR_FREE(dirpath);
> +            return -1;
> +        }
> +
> +        if (p == dirpath)
> +            *(p+1) = '\0';
> +        else
> +            *p = '\0';
> +
> +        statfs_ret = statfs(dirpath, &sb);
> +
> +    } while ((statfs_ret < 0) && (p != dirpath));
> +
> +    VIR_FREE(dirpath);
> +
> +    if (statfs_ret < 0) {
>          virReportSystemError(errno,
>                               _("cannot determine filesystem for '%s'"),
>                               path);

ACK

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
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]