[libvirt] [PATCH v2] storage: List directory volumes for dir/fs/netfs pools

Eric Blake eblake at redhat.com
Thu May 26 19:41:43 UTC 2011


On 05/26/2011 01:34 PM, Cole Robinson wrote:
> Since directories can be used for <filesystem> passthrough, they are
> basically storage volumes.
> 
> v2:
>     Skip ., .., lost+found dirs
> 
> Signed-off-by: Cole Robinson <crobinso at redhat.com>
> ---
>  src/storage/storage_backend.c    |   44 +++++++++++++++++++++++++++++++------
>  src/storage/storage_backend.h    |    7 +++++-
>  src/storage/storage_backend_fs.c |   14 ++++++++---
>  src/util/storage_file.c          |   30 +++++++++++++++++++++++++-
>  4 files changed, 82 insertions(+), 13 deletions(-)

Almost there.

> 
> diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
> index 02e455f..77095f2 100644
> --- a/src/storage/storage_backend.c
> +++ b/src/storage/storage_backend.c
> @@ -994,6 +994,7 @@ virStorageBackendVolOpenCheckMode(const char *path, unsigned int flags)
>  {
>      int fd, mode = 0;
>      struct stat sb;
> +    char *base = basename(path);

basename() is not portable (some, but not all, implementations modify
the string in place, and it is not required to be threadsafe).  Instead,
use "dirname.h" from gnulib (we already have it imported) and the
function base_name() (which malloc's the result) or last_component()
(which returns a pointer into the middle of path).

> +    else if (S_ISDIR(sb.st_mode)) {
> +        mode = VIR_STORAGE_VOL_OPEN_DIR;
> +
> +        if (STREQ(base, ".") ||
> +            STREQ(base, "..") ||
> +            STREQ(base, "lost+found")) {

Given your usage, I think last_component() is the better fit.

ACK with that fixed.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

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


More information about the libvir-list mailing list