Whamcloud - gitweb
LU-5155 scripts: added lustre/scripts/zfsobj2fid 21/13721/5
authorChristopher J. Morrone <morrone2@llnl.gov>
Wed, 11 Feb 2015 04:13:45 +0000 (21:13 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 11 Mar 2015 23:39:26 +0000 (23:39 +0000)
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 <he.huang@intel.com>
Reviewed-on: http://review.whamcloud.com/13721
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Christopher J. Morrone <morrone2@llnl.gov>
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre.spec.in
lustre/scripts/Makefile.am
lustre/scripts/zfsobj2fid [new file with mode: 0755]

index d435639..6b84c0b 100644 (file)
@@ -442,6 +442,9 @@ find $RPM_BUILD_ROOT%{?rootdir}/lib/modules/%{kversion}/%{kmoddir} \
 %files -f lustre.files
 %defattr(-,root,root)
 %{_sbindir}/*
 %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
 %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
 %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
 %if %{defined rpm_post_base}
 %attr(0555, root, root) %{rpm_post_base}-osd-zfs.sh
 %endif
index 196ba20..11d8be7 100644 (file)
@@ -64,13 +64,18 @@ scriptlibdir = @libexecdir@/@PACKAGE@
 scriptlib_SCRIPTS = haconfig
 scriptlib_DATA = lc_common
 endif # SERVER
 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 \
 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)
 
 
 CLEANFILES = $(genscripts)
 
diff --git a/lustre/scripts/zfsobj2fid b/lustre/scripts/zfsobj2fid
new file mode 100755 (executable)
index 0000000..e229e29
--- /dev/null
@@ -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 <morrone2@llnl.gov>
+# 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], "<dataset> <object>"
+        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())