#!/usr/bin/python

import sys

import isi.misc as misc

# The layout of these masks and releases is documented here:
# https://wiki.west.isilon.com/index.php/OneFS_Version_Integer
MAJOR_MASK =            0xFFFFFF0000000000
DOT_MASK =              0x000000000FF00000
RELEASES_WITH_L3_FIX = (0x0701010000400000,
                        0x0702000000200000)

# To mitigate an L3 corruption bug exposed by NDFU, the DSP was branched to
# implement restrictions on OneFS and SSD firmware.  This branch of the DSP
# includes SSD firmware updates and uses this script to ensure that it can only
# be installed on versions of OneFS that are not affected by the L3 issue.
def main():
    osrev = misc.osrevision()
    for release in RELEASES_WITH_L3_FIX:
        # If the osrevision has matching major, minor, and sub version numbers,
        # and the dot release number is less than when the fix went in, then it
        # is affected by the L3 issue so return one to prevent installation.
        if (((osrev & MAJOR_MASK) == (release & MAJOR_MASK)) and
            ((osrev & DOT_MASK) < (release & DOT_MASK))):
            sys.exit(1)
    # All DSPv2 capable branches other than Jaws and Moby included the fix for
    # the L3 issue in the initial major release so return zero to allow
    # installation.
    sys.exit(0)

if __name__ == '__main__':
    main()
