[libvirt] [PATCH] storage: Small file probing fixup

Fallback to possible storage format after nothing else than magic has matched, since this is likely theformat user wants even though we don't know any better. Also fix a comment which wasn't very clear about what "skip" meant. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=836676 Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/util/virstoragefile.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b985df4..b083530 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -79,7 +79,8 @@ struct FileTypeInfo { enum lv_endian endian; /* Endianness of file format */ int versionOffset; /* Byte offset from start of file * where we find version number, - * -1 to skip version test */ + * -1 to fail version test, + * -2 to pass version test */ int versionNumber; /* Version number to validate */ int sizeOffset; /* Byte offset from start of file * where we find capacity info, @@ -662,6 +663,10 @@ virStorageFileProbeFormatFromBuf(const char *path, } } + if (format == VIR_STORAGE_FILE_RAW && + possibleFormat != VIR_STORAGE_FILE_RAW) + format = possibleFormat; + cleanup: VIR_DEBUG("format=%d", format); return format; -- 1.8.2.1

On 06/10/13 09:58, Martin Kletzander wrote:
Fallback to possible storage format after nothing else than magic has matched, since this is likely theformat user wants even though we don't know any better.
Also fix a comment which wasn't very clear about what "skip" meant.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=836676
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/util/virstoragefile.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b985df4..b083530 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -79,7 +79,8 @@ struct FileTypeInfo { enum lv_endian endian; /* Endianness of file format */ int versionOffset; /* Byte offset from start of file * where we find version number, - * -1 to skip version test */ + * -1 to fail version test,
"always fail the version test" perhaps?
+ * -2 to pass version test */ int versionNumber; /* Version number to validate */ int sizeOffset; /* Byte offset from start of file * where we find capacity info,
ACK to this hunk.
@@ -662,6 +663,10 @@ virStorageFileProbeFormatFromBuf(const char *path, } }
+ if (format == VIR_STORAGE_FILE_RAW && + possibleFormat != VIR_STORAGE_FILE_RAW) + format = possibleFormat; +
I don't think we should do this. If a version check is required for a format we should honor this and return this as a raw image instead of masking it with a possible match.
cleanup: VIR_DEBUG("format=%d", format); return format;
Peter

On 06/10/2013 11:25 AM, Peter Krempa wrote:
On 06/10/13 09:58, Martin Kletzander wrote:
Fallback to possible storage format after nothing else than magic has matched, since this is likely theformat user wants even though we don't know any better.
Also fix a comment which wasn't very clear about what "skip" meant.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=836676
Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/util/virstoragefile.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b985df4..b083530 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -79,7 +79,8 @@ struct FileTypeInfo { enum lv_endian endian; /* Endianness of file format */ int versionOffset; /* Byte offset from start of file * where we find version number, - * -1 to skip version test */ + * -1 to fail version test,
"always fail the version test" perhaps?
Pushed as following, feel free to change it further as comments are trivial. commit 78cbff0ff23cc86d44005878f10023568604bd09 Author: Martin Kletzander <mkletzan@redhat.com> Date: Mon Jun 10 11:44:31 2013 +0200 storage: fix description of versionOffset diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b985df4..a391738 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -79,7 +79,8 @@ struct FileTypeInfo { enum lv_endian endian; /* Endianness of file format */ int versionOffset; /* Byte offset from start of file * where we find version number, - * -1 to skip version test */ + * -1 to always fail the version test, + * -2 to always pass the version test */ int versionNumber; /* Version number to validate */ int sizeOffset; /* Byte offset from start of file * where we find capacity info, -- Martin
participants (2)
-
Martin Kletzander
-
Peter Krempa