Fix: Fail fast on unsupported volume versions (#8047)
* Fix: Fail fast when initializing volume with Version 0 * Fix: Fail fast when loading unsupported volume version (e.g. 0 or 4) * Refactor: Use IsSupportedVersion helper function for version validation
This commit is contained in:
@@ -11,3 +11,7 @@ const (
|
|||||||
func GetCurrentVersion() Version {
|
func GetCurrentVersion() Version {
|
||||||
return Version3
|
return Version3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsSupportedVersion(v Version) bool {
|
||||||
|
return v >= Version1 && v <= Version3
|
||||||
|
}
|
||||||
|
|||||||
@@ -106,6 +106,9 @@ func (v *Volume) load(alsoLoadIndex bool, createDatIfMissing bool, needleMapKind
|
|||||||
if alreadyHasSuperBlock {
|
if alreadyHasSuperBlock {
|
||||||
err = v.readSuperBlock()
|
err = v.readSuperBlock()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
if !needle.IsSupportedVersion(v.SuperBlock.Version) {
|
||||||
|
glog.Fatalf("Unsupported volume %d version %v", v.Id, v.SuperBlock.Version)
|
||||||
|
}
|
||||||
v.volumeInfo.Version = uint32(v.SuperBlock.Version)
|
v.volumeInfo.Version = uint32(v.SuperBlock.Version)
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("readSuperBlock volume %d version %v", v.Id, v.SuperBlock.Version)
|
glog.V(2).Infof("readSuperBlock volume %d version %v", v.Id, v.SuperBlock.Version)
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ func (v *Volume) maybeWriteSuperBlock(ver needle.Version) error {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if datSize == 0 {
|
if datSize == 0 {
|
||||||
|
if !needle.IsSupportedVersion(ver) {
|
||||||
|
return fmt.Errorf("volume super block version %d is not supported", ver)
|
||||||
|
}
|
||||||
v.SuperBlock.Version = ver
|
v.SuperBlock.Version = ver
|
||||||
_, e = v.DataBackend.WriteAt(v.SuperBlock.Bytes(), 0)
|
_, e = v.DataBackend.WriteAt(v.SuperBlock.Bytes(), 0)
|
||||||
if e != nil && os.IsPermission(e) {
|
if e != nil && os.IsPermission(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user