From: Christopher J. Morrone Date: Wed, 11 Feb 2015 04:13:45 +0000 (-0700) Subject: LU-5155 scripts: added lustre/scripts/zfsobj2fid X-Git-Tag: 2.7.51~51 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=2ccda307213e93439fb3e182eb2618f8dac21419 LU-5155 scripts: added lustre/scripts/zfsobj2fid The zfsobj2fid script converts ZFS object xattr FID to standard Lustre FID format so it can be used with Lustre tools like "lfs fid2path". Change-Id: Id87ff0533a5431a292bca24a76815642f4318083 Signed-off-by: Isaac Huang Reviewed-on: http://review.whamcloud.com/13721 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Christopher J. Morrone Reviewed-by: Nathaniel Clark Reviewed-by: Oleg Drokin --- diff --git a/lustre.spec.in b/lustre.spec.in index d435639..6b84c0b 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -442,6 +442,9 @@ find $RPM_BUILD_ROOT%{?rootdir}/lib/modules/%{kversion}/%{kmoddir} \ %files -f lustre.files %defattr(-,root,root) %{_sbindir}/* +%if %{with zfs} +%exclude %{_sbindir}/zfsobj2fid +%endif %if %{with lustre_utils} %if %{with servers} %{_libexecdir}/lustre/lc_common @@ -511,6 +514,7 @@ find $RPM_BUILD_ROOT%{?rootdir}/lib/modules/%{kversion}/%{kmoddir} \ %files osd-zfs %defattr(-,root,root) %{?rootdir}/lib/modules/%{kversion}/%{kmoddir}/kernel/fs/@PACKAGE@/osd_zfs.ko +%{_sbindir}/zfsobj2fid %if %{defined rpm_post_base} %attr(0555, root, root) %{rpm_post_base}-osd-zfs.sh %endif diff --git a/lustre/scripts/Makefile.am b/lustre/scripts/Makefile.am index 196ba20..11d8be7 100644 --- a/lustre/scripts/Makefile.am +++ b/lustre/scripts/Makefile.am @@ -64,13 +64,18 @@ scriptlibdir = @libexecdir@/@PACKAGE@ scriptlib_SCRIPTS = haconfig scriptlib_DATA = lc_common endif # SERVER + +if ZFS_ENABLED +sbin_SCRIPTS += zfsobj2fid +endif + endif # UTILS EXTRA_DIST = license-status version_tag.pl version_tag-git.pl \ version_tag-none.pl lustre_rmmod ldev lc_mon lhbadm \ lc_servip lustre_routes_config lustre_routes_conversion \ $(addsuffix .in,$(genscripts)) lfs_migrate lustre_req_history \ - lustre lnet lc_common haconfig Lustre.ha_v2 dkms.mkconf + lustre lnet lc_common haconfig Lustre.ha_v2 dkms.mkconf zfsobj2fid CLEANFILES = $(genscripts) diff --git a/lustre/scripts/zfsobj2fid b/lustre/scripts/zfsobj2fid new file mode 100755 index 0000000..e229e29 --- /dev/null +++ b/lustre/scripts/zfsobj2fid @@ -0,0 +1,76 @@ +#!/usr/bin/env python + +# Copyright (c) 2014, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# Written by Christopher J. Morrone +# LLNL-CODE-468512 +# +# This file is part of lustre-tools-llnl. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License (as published by the +# Free Software Foundation) version 2, dated June 1991. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# terms and conditions of the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# Given a zfs dataset for a Lustre OST and the object number of a file +# in that dataset, this script will call zdb to retreive the Lustre FID +# and print it out in standard Lustre FID format. + +import sys +import subprocess + +def from_bytes(b): + return sum(b[i] << i*8 for i in range(len(b))) + +def main(): + if len(sys.argv) != 3: + print "Usage:", sys.argv[0], " " + return 1 + + p = subprocess.Popen(["zdb", "-e", "-vvv", sys.argv[1], sys.argv[2]], + stdout=subprocess.PIPE) + pout, perr = p.communicate() + + b = bytearray() + found_fid = False + for line in pout.split('\n'): + part = line.split() + if not part or part[0] != 'trusted.fid': + continue + fid = part[2] + found_fid = True + while len(fid) > 0: + val = fid[0] + fid = fid[1:] + if val == '\\': + val = fid[0:3] + fid = fid[3:] + b.append(int(val, 8)) + else: + b.append(ord(val)) + break + + if not found_fid: + print "FID not found on", sys.argv[1], sys.argv[2] + return 1 + + print '[' \ + + hex(from_bytes(b[0:8])) \ + + ':' \ + + hex(from_bytes(b[8:12])) \ + + ':' \ + + hex(from_bytes(b[12:16])) \ + + ']' + + return 0 + +if __name__ == '__main__': + sys.exit(main())