This file is indexed.

/usr/lib/xcp/bin/xe-scsi-dev-map is in xcp-xapi 1.3.2-5.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/python
#
# Copyright (c) Citrix Systems 2008. All rights reserved.
#
# map serial numbers from scsi devices to device names
#

import os
import re
import subprocess

def doexec(args, inputtext=None):
    """Execute a subprocess, then return its return code, stdout and stderr"""
    proc = subprocess.Popen(args, stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 close_fds=True)
    (stdout, stderr) = proc.communicate(inputtext)
    retcode = proc.returncode
    return (retcode, stdout, stderr)

def pread(cmdlist):
    """ process read wrapper """
    cmdlist_for_exec = []
    cmdlist_for_log = []
    for item in cmdlist:
        if type(item) == type(""):
            cmdlist_for_exec.append(item)
            cmdlist_for_log.append(item)
        else:
            cmdlist_for_exec.append(item[0])
            cmdlist_for_log.append(item[1])

    (retcode, stdout, stderr) = doexec(cmdlist_for_exec)
    if retcode:
        raise
    return stdout

def match_sd(string):
    """ return sd* """
    regex = re.compile("^sd")
    return regex.search(string, 0)

def main():
    """ main entry for scsi checker """

    # get devices in /dev/sd*

    findser = "Unit serial number:"
    prefix = "/dev/"
    idlist = {}
    try:
        devlist = os.listdir(prefix)
        for name in filter(match_sd, devlist):
            filepath = prefix + name
            command = ["/usr/bin/sg_inq", filepath]
            try:
                retinfo = pread(command)
                index = retinfo.find(findser)
                if index != -1:
                    if idlist.has_key(retinfo[index+len(findser):len(retinfo)].strip()):
                        idlist[retinfo[index+len(findser):len(retinfo)].strip()].append(filepath)
                    else:
                        idlist[retinfo[index+len(findser):len(retinfo)].strip()]=[filepath]
            except:
                pass
    except:
        pass


    # get devices in /dev/disk/by-id/*
    
    prefix = "/dev/disk/by-id/"
    try:
        disklist = os.listdir(prefix)
        for name in disklist:
            filepath = prefix + name
            command = ["/usr/bin/sg_inq", filepath]
            try:
                retinfo = pread(command)
                index = retinfo.find(findser)
                if index != -1:
                    if idlist.has_key(retinfo[index+len(findser):len(retinfo)].strip()):
                        idlist[retinfo[index+len(findser):len(retinfo)].strip()].append(filepath)
                    else:
                        idlist[retinfo[index+len(findser):len(retinfo)].strip()]=[filepath]
            except:
                pass
    except:
        pass

    # get devices in /dev/mapper/*
    prefix = "/dev/mapper/"
    try:
        disklist = os.listdir(prefix)
        for name in disklist:
            filepath = prefix + name
            command = ["/usr/bin/sg_inq", filepath]
            try:
                retinfo = pread(command)
                index = retinfo.find(findser)
                if index != -1:
                    if idlist.has_key(retinfo[index+len(findser):len(retinfo)].strip()):
                        idlist[retinfo[index+len(findser):len(retinfo)].strip()].append(filepath)
                    else:
                        idlist[retinfo[index+len(findser):len(retinfo)].strip()]=[filepath]
            except:
                pass
    except:
        pass

    for id in idlist:
        print
        print "serial number '%s' maps the following devices " % id
        for mapping in idlist[id]:
            print "            %s" % mapping
    print 

if __name__ == "__main__":
    main()