3 # Copyright (c) 2014, Lawrence Livermore National Security, LLC.
4 # Produced at the Lawrence Livermore National Laboratory.
5 # Written by Christopher J. Morrone <morrone2@llnl.gov>
8 # This file is part of lustre-tools-llnl.
10 # This program is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License (as published by the
12 # Free Software Foundation) version 2, dated June 1991.
14 # This program is distributed in the hope that it will be useful, but WITHOUT
15 # ANY WARRANTY; without even the IMPLIED WARRANTY OF
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # terms and conditions of the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software Foundation,
21 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # Given a zfs dataset for a Lustre OST and the object number of a file
24 # in that dataset, this script will call zdb to retreive the Lustre FID
25 # and print it out in standard Lustre FID format.
31 return hex(sum(data[i] << i * 8 for i in range(len(data))))
34 if len(sys.argv) != 3:
35 print('Usage:', sys.argv[0], '<dataset>', '<object>')
38 cmd = ['zdb', '-e', '-vvv', sys.argv[1], sys.argv[2]]
39 process = subprocess.Popen(cmd,
40 stdout=subprocess.PIPE,
41 stderr=subprocess.PIPE,
42 universal_newlines=True)
43 stdout, stderr = process.communicate()
44 result = process.returncode
47 msg = 'Error %d on %s: %s %s' % (result, cmd, stdout, stderr)
48 raise RuntimeError(msg)
50 lines = stdout.splitlines()
56 if not part or part[0] != 'trusted.fid':
66 data.append(int(val, 8))
72 print('FID not found on', sys.argv[1], sys.argv[2])
75 print('[%s:%s:%s]' % (from_bytes(data[0:8]),
76 from_bytes(data[8:12]),
77 from_bytes(data[12:16])))
80 if __name__ == '__main__':