qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] block: handle filenames with colons better


From: Iustin Pop
Subject: [Qemu-devel] [PATCH] block: handle filenames with colons better
Date: Thu, 16 Aug 2012 16:58:36 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Commit 947995c (block: protect path_has_protocol from filenames with
colons) introduced a way to handle filenames with colons based on
whether the path contains a slash or not. IMHO this is not optimal,
since we shouldn't rely on the contents of the path but rather on
whether the given path exists as a file or not.

As such, this patch tries to handle both files with and without
slashes by falling back to opening them as files if no drivers
supporting the protocol has been identified.

Signed-off-by: Iustin Pop <address@hidden>
---
 I've tested this with both slash-containing and slash-free names and it works
 as expected. I believe falling back to file is safe, as the "file"
 block driver will just fail and return NULL if the path doesn't exist.

 Side note: this is the third way that a file can be opened, and as such
 the code flow is quite unclear; first, paths pointing to block or char
 devices are opened in any case, even if they have colons, since the
 call to find_hdev_driver will probe for the and the raw drivers will
 identify them; second, slash-containing paths will be opened via the
 first call to bdrv_find_format("file") since path_has_protocol will
 return false; and finally, slash-free paths will be opened in this
 second call to said function. I don't know if all this could be cleaned
 and organised better.

 block.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 470bdcc..367879f 100644
--- a/block.c
+++ b/block.c
@@ -499,7 +499,12 @@ BlockDriver *bdrv_find_protocol(const char *filename)
             return drv1;
         }
     }
-    return NULL;
+    /*
+     * No bdrv_driver identified the protocol we extracted from the
+     * path; maybe this is not actually a protocol, but just a file
+     * containing a colon? Fallback to bdrv_find_format.
+     */
+    return bdrv_find_format("file");
 }
 
 static int find_image_format(const char *filename, BlockDriver **pdrv)
-- 
1.7.10




reply via email to

[Prev in Thread] Current Thread [Next in Thread]