[libvirt] Fix handling of QED file format

From: "Daniel P. Berrange" <berrange@redhat.com> To help us detect when new storage file versions come into existance log a warning if the storage file magic matches, but the version does not Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/storage_file.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 17a47cf..4281d90 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -756,16 +756,26 @@ virStorageFileProbeFormatFromBuf(const char *path, { int format = VIR_STORAGE_FILE_RAW; int i; + int possibleFormat = VIR_STORAGE_FILE_RAW; + VIR_DEBUG("path=%s", path); /* First check file magic */ for (i = 0 ; i < VIR_STORAGE_FILE_LAST ; i++) { - if (virStorageFileMatchesMagic(i, buf, buflen) && - virStorageFileMatchesVersion(i, buf, buflen)) { + if (virStorageFileMatchesMagic(i, buf, buflen)) { + if (!virStorageFileMatchesVersion(i, buf, buflen)) { + possibleFormat = i; + continue; + } format = i; goto cleanup; } } + if (possibleFormat != VIR_STORAGE_FILE_RAW) + VIR_WARN("File %s matches %s magic, but version is wrong. " + "Please report new version to libvir-list@redhat.com", + path, virStorageFileFormatTypeToString(possibleFormat)); + /* No magic, so check file extension */ for (i = 0 ; i < VIR_STORAGE_FILE_LAST ; i++) { if (virStorageFileMatchesExtension(i, path)) { -- 1.7.11.7

On 12/13/12 15:26, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
To help us detect when new storage file versions come into existance log a warning if the storage file magic matches, but the version does not
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/storage_file.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
ACK

From: "Daniel P. Berrange" <berrange@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/storage_file.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 4281d90..69a66ff 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -628,6 +628,9 @@ virStorageFileMatchesVersion(int format, (buf[fileTypeInfo[format].versionOffset+2] << 8) | (buf[fileTypeInfo[format].versionOffset+3]); } + + VIR_DEBUG("Compare version %d vs %d", + version, fileTypeInfo[format].versionNumber); if (version != fileTypeInfo[format].versionNumber) return false; @@ -650,6 +653,8 @@ virStorageFileGetMetadataFromBuf(int format, size_t buflen, virStorageFileMetadata *meta) { + VIR_DEBUG("path=%s format=%d", path, format); + /* XXX we should consider moving virStorageBackendUpdateVolInfo * code into this method, for non-magic files */ @@ -785,6 +790,7 @@ virStorageFileProbeFormatFromBuf(const char *path, } cleanup: + VIR_DEBUG("format=%d", format); return format; } @@ -963,6 +969,9 @@ virStorageFileGetMetadataRecurse(const char *path, int format, bool allow_probe, virHashTablePtr cycle) { int fd; + VIR_DEBUG("path=%s format=%d uid=%d gid=%d probe=%d", + path, format, (int)uid, (int)gid, allow_probe); + virStorageFileMetadataPtr ret = NULL; if (virHashLookup(cycle, path)) { @@ -1027,6 +1036,9 @@ virStorageFileGetMetadata(const char *path, int format, uid_t uid, gid_t gid, bool allow_probe) { + VIR_DEBUG("path=%s format=%d uid=%d gid=%d probe=%d", + path, format, (int)uid, (int)gid, allow_probe); + virHashTablePtr cycle = virHashCreate(5, NULL); virStorageFileMetadataPtr ret; -- 1.7.11.7

On 12/13/12 15:26, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/storage_file.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 4281d90..69a66ff 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -628,6 +628,9 @@ virStorageFileMatchesVersion(int format, (buf[fileTypeInfo[format].versionOffset+2] << 8) | (buf[fileTypeInfo[format].versionOffset+3]); } + + VIR_DEBUG("Compare version %d vs %d",
I'd write this as "Detected version %d, expected version %d" or something to clarify which was detected without looking into the code.
+ version, fileTypeInfo[format].versionNumber); if (version != fileTypeInfo[format].versionNumber) return false;
ACK with the message tweaked. Peter

From: "Daniel P. Berrange" <berrange@redhat.com> The QED file format is non-versioned, so although the magic value matched, libvirt rejected it due to lack of a version number to compare against. We need to distinguish this case by allowing a value of '-2' to indicate a non-versioned file where only the magic is required to match Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/storage_file.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 69a66ff..c0bb977 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -174,8 +174,8 @@ static struct FileTypeInfo const fileTypeInfo[] = { }, [VIR_STORAGE_FILE_QED] = { /* http://wiki.qemu.org/Features/QED */ - "QED\0", NULL, - LV_LITTLE_ENDIAN, -1, -1, + "QED", NULL, + LV_LITTLE_ENDIAN, -2, -1, QED_HDR_IMAGE_SIZE, 8, 1, -1, qedGetBackingStore, }, [VIR_STORAGE_FILE_VMDK] = { @@ -612,6 +612,12 @@ virStorageFileMatchesVersion(int format, if (fileTypeInfo[format].versionOffset == -1) return false; + /* -2 == non-versioned file format, so trivially match */ + if (fileTypeInfo[format].versionOffset == -2) { + VIR_WARN("Non-versioned file matches"); + return true; + } + if ((fileTypeInfo[format].versionOffset + 4) > buflen) return false; -- 1.7.11.7

On 12/13/12 15:26, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
The QED file format is non-versioned, so although the magic value matched, libvirt rejected it due to lack of a version number to compare against. We need to distinguish this case by allowing a value of '-2' to indicate a non-versioned file where only the magic is required to match
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/storage_file.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 69a66ff..c0bb977 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -174,8 +174,8 @@ static struct FileTypeInfo const fileTypeInfo[] = { }, [VIR_STORAGE_FILE_QED] = { /* http://wiki.qemu.org/Features/QED */ - "QED\0", NULL, - LV_LITTLE_ENDIAN, -1, -1, + "QED", NULL, + LV_LITTLE_ENDIAN, -2, -1, QED_HDR_IMAGE_SIZE, 8, 1, -1, qedGetBackingStore, }, [VIR_STORAGE_FILE_VMDK] = { @@ -612,6 +612,12 @@ virStorageFileMatchesVersion(int format, if (fileTypeInfo[format].versionOffset == -1) return false;
+ /* -2 == non-versioned file format, so trivially match */ + if (fileTypeInfo[format].versionOffset == -2) { + VIR_WARN("Non-versioned file matches");
Are you sure you want to log this as a warning? Since we know that this file is unversioned do we need to spam the user's log with that?
+ return true; + } + if ((fileTypeInfo[format].versionOffset + 4) > buflen) return false;

On Thu, Dec 13, 2012 at 03:49:00PM +0100, Peter Krempa wrote:
On 12/13/12 15:26, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
The QED file format is non-versioned, so although the magic value matched, libvirt rejected it due to lack of a version number to compare against. We need to distinguish this case by allowing a value of '-2' to indicate a non-versioned file where only the magic is required to match
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/storage_file.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 69a66ff..c0bb977 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -174,8 +174,8 @@ static struct FileTypeInfo const fileTypeInfo[] = { }, [VIR_STORAGE_FILE_QED] = { /* http://wiki.qemu.org/Features/QED */ - "QED\0", NULL, - LV_LITTLE_ENDIAN, -1, -1, + "QED", NULL, + LV_LITTLE_ENDIAN, -2, -1, QED_HDR_IMAGE_SIZE, 8, 1, -1, qedGetBackingStore, }, [VIR_STORAGE_FILE_VMDK] = { @@ -612,6 +612,12 @@ virStorageFileMatchesVersion(int format, if (fileTypeInfo[format].versionOffset == -1) return false;
+ /* -2 == non-versioned file format, so trivially match */ + if (fileTypeInfo[format].versionOffset == -2) { + VIR_WARN("Non-versioned file matches");
Are you sure you want to log this as a warning? Since we know that this file is unversioned do we need to spam the user's log with that?
Doh, I meant to remove that debug line 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 :|

On 12/13/12 15:51, Daniel P. Berrange wrote:
On Thu, Dec 13, 2012 at 03:49:00PM +0100, Peter Krempa wrote:
On 12/13/12 15:26, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
The QED file format is non-versioned, so although the magic value matched, libvirt rejected it due to lack of a version number to compare against. We need to distinguish this case by allowing a value of '-2' to indicate a non-versioned file where only the magic is required to match
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/util/storage_file.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 69a66ff..c0bb977 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -174,8 +174,8 @@ static struct FileTypeInfo const fileTypeInfo[] = { }, [VIR_STORAGE_FILE_QED] = { /* http://wiki.qemu.org/Features/QED */ - "QED\0", NULL, - LV_LITTLE_ENDIAN, -1, -1, + "QED", NULL, + LV_LITTLE_ENDIAN, -2, -1, QED_HDR_IMAGE_SIZE, 8, 1, -1, qedGetBackingStore, }, [VIR_STORAGE_FILE_VMDK] = { @@ -612,6 +612,12 @@ virStorageFileMatchesVersion(int format, if (fileTypeInfo[format].versionOffset == -1) return false;
+ /* -2 == non-versioned file format, so trivially match */ + if (fileTypeInfo[format].versionOffset == -2) { + VIR_WARN("Non-versioned file matches");
Are you sure you want to log this as a warning? Since we know that this file is unversioned do we need to spam the user's log with that?
Doh, I meant to remove that debug line
Daniel
Ah, great. ACK when you do that. Peter
participants (2)
-
Daniel P. Berrange
-
Peter Krempa