Whamcloud - gitweb
LU-2353 tests: Introduce back end mount/unmount helpers 85/5785/6
authorLi Wei <wei.g.li@intel.com>
Wed, 20 Mar 2013 12:06:20 +0000 (20:06 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 14 Nov 2013 08:14:57 +0000 (08:14 +0000)
Some tests need to access back end file systems directly.  Currently,
for ldiskfs targets, they either mount the devices as ldiskfs or
invoke the ldiskfs-specific debugfs tool; for ZFS targets, they simply
skip forward.  Many of them could actually work on both back end
types.  Since the mount/unmount procedures diff for ldiskfs and ZFS
back ends, this patch introduces a pair of generic helpers,
mount_fstype()/unmount_fstype(), to hide the differences from tests.
Then, sanity 27z is adapted to work with ZFS targets using the new
helpers, as an example.

Test-Parameters: mdsfilesystemtype=zfs ostfilesystemtype=zfs mdtfilesystemtype=zfs
Change-Id: I0b6b358b147240519f28852ba2c8fea85c09aab3
Signed-off-by: Li Wei <wei.g.li@intel.com>
Reviewed-on: http://review.whamcloud.com/5785
Tested-by: Jenkins
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/tests/sanity.sh
lustre/tests/test-framework.sh

index 65ffad9..9471531 100644 (file)
@@ -1718,26 +1718,7 @@ check_seq_oid()
                local dev=$(ostdevname $ost)
                local oid_hex
 
                local dev=$(ostdevname $ost)
                local oid_hex
 
-               if [ $(facet_fstype ost$ost) != ldiskfs ]; then
-                       echo "Currently only works with ldiskfs-based OSTs"
-                       continue
-               fi
-
-                log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
-
-                #don't unmount/remount the OSTs if we don't need to do that
-               # LU-2577 changes filter_fid to be smaller, so debugfs needs
-               # update too, until that use mount/ll_decode_filter_fid/mount
-               local dir=$(facet_mntpt ost$ost)
-               local opts=${OST_MOUNT_OPTS}
-
-               if !  do_facet ost$ost test -b ${dev}; then
-                       opts=$(csa_add "$opts" -o loop)
-               fi
-
-               stop ost$ost
-               do_facet ost$ost mount -t $(facet_fstype ost$ost) $opts $dev $dir ||
-                       { error "mounting $dev as $FSTYPE failed"; return 3; }
+               log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
 
                seq=$(echo $seq | sed -e "s/^0x//g")
                if [ $seq == 0 ]; then
 
                seq=$(echo $seq | sed -e "s/^0x//g")
                if [ $seq == 0 ]; then
@@ -1745,25 +1726,48 @@ check_seq_oid()
                else
                        oid_hex=$(echo $hex | sed -e "s/^0x//g")
                fi
                else
                        oid_hex=$(echo $hex | sed -e "s/^0x//g")
                fi
-               local obj_file=$(do_facet ost$ost find $dir/O/$seq -name $oid_hex)
-               local ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID $obj_file)
-               do_facet ost$ost umount -d $dir
-               start ost$ost $dev $OST_MOUNT_OPTS
+               local obj_file="O/$seq/d$((oid %32))/$oid_hex"
 
 
-               # re-enable when debugfs will understand new filter_fid
-               #local ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
-                #           $dev 2>/dev/null" | grep "parent=")
+               local ff
+               #
+               # Don't unmount/remount the OSTs if we don't need to do that.
+               # LU-2577 changes filter_fid to be smaller, so debugfs needs
+               # update too, until that use mount/ll_decode_filter_fid/mount.
+               # Re-enable when debugfs will understand new filter_fid.
+               #
+               if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
+                       ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
+                               $dev 2>/dev/null" | grep "parent=")
+               else
+                       stop ost$ost
+                       mount_fstype ost$ost
+                       ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
+                               $(facet_mntpt ost$ost)/$obj_file)
+                       unmount_fstype ost$ost
+                       start ost$ost $dev $OST_MOUNT_OPTS
+               fi
 
 
-                [ -z "$ff" ] && error "$obj_file: no filter_fid info"
+               [ -z "$ff" ] && error "$obj_file: no filter_fid info"
 
 
-                echo "$ff" | sed -e 's#.*objid=#got: objid=#'
+               echo "$ff" | sed -e 's#.*objid=#got: objid=#'
 
 
-                # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
-                # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
-                local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
-                local ff_pseq=$(echo $ff_parent | cut -d: -f1)
-                local ff_poid=$(echo $ff_parent | cut -d: -f2)
-                local ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
+               # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
+               # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
+               local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
+               local ff_pseq=$(echo $ff_parent | cut -d: -f1)
+               local ff_poid=$(echo $ff_parent | cut -d: -f2)
+               local ff_pstripe
+               if echo $ff_parent | grep -q 'stripe='; then
+                       ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
+               else
+                       #
+                       # $LL_DECODE_FILTER_FID does not print "stripe="; look
+                       # into f_ver in this case.  See the comment on
+                       # ff_parent.
+                       #
+                       ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
+                               sed -e 's/\]//')
+               fi
 
                 # compare lmm_seq and filter_fid->ff_parent.f_seq
                 [ $ff_pseq = $lmm_seq ] ||
 
                 # compare lmm_seq and filter_fid->ff_parent.f_seq
                 [ $ff_pseq = $lmm_seq ] ||
@@ -1771,7 +1775,7 @@ check_seq_oid()
                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
                 [ $ff_poid = $lmm_oid ] ||
                         error "FF parent OID $ff_poid != $lmm_oid"
                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
                 [ $ff_poid = $lmm_oid ] ||
                         error "FF parent OID $ff_poid != $lmm_oid"
-                [ $ff_pstripe = $stripe_nr ] ||
+               (($ff_pstripe == $stripe_nr)) ||
                         error "FF stripe $ff_pstripe != $stripe_nr"
 
                 stripe_nr=$((stripe_nr + 1))
                         error "FF stripe $ff_pstripe != $stripe_nr"
 
                 stripe_nr=$((stripe_nr + 1))
index e5c8c62..58a88a4 100644 (file)
@@ -2994,6 +2994,84 @@ facet_mntpt () {
     echo -n $mntpt
 }
 
     echo -n $mntpt
 }
 
+mount_ldiskfs() {
+       local facet=$1
+       local dev=$(facet_device $facet)
+       local mnt=$(facet_mntpt $facet)
+       local opts
+
+       if ! do_facet $facet test -b $dev; then
+               opts="-o loop"
+       fi
+       do_facet $facet mount -t ldiskfs $opts $dev $mnt
+}
+
+unmount_ldiskfs() {
+       local facet=$1
+       local dev=$(facet_device $facet)
+       local mnt=$(facet_mntpt $facet)
+
+       do_facet $facet umount -d $mnt
+}
+
+var_name() {
+       echo -n "$1" | tr -c '[:alnum:]\n' '_'
+}
+
+mount_zfs() {
+       local facet=$1
+       local ds=$(facet_device $facet)
+       local mnt=$(facet_mntpt $facet)
+       local canmnt
+       local mntpt
+
+       import_zpool $facet
+       canmnt=$(do_facet $facet $ZFS get -H -o value canmount $ds)
+       mntpt=$(do_facet $facet $ZFS get -H -o value mountpoint $ds)
+       do_facet $facet $ZFS set canmount=noauto $ds
+       #
+       # The "legacy" mount method is used here because "zfs unmount $mnt"
+       # calls stat(2) on $mnt/../*, which may include $MOUNT.  If certain
+       # targets are not available at the time, the stat(2) on $MOUNT will
+       # hang.
+       #
+       do_facet $facet $ZFS set mountpoint=legacy $ds
+       do_facet $facet mount -t zfs $ds $mnt
+       eval export mz_$(var_name ${facet}_$ds)_canmount=$canmnt
+       eval export mz_$(var_name ${facet}_$ds)_mountpoint=$mntpt
+}
+
+unmount_zfs() {
+       local facet=$1
+       local ds=$(facet_device $facet)
+       local mnt=$(facet_mntpt $facet)
+       local var_mntpt=mz_$(var_name ${facet}_$ds)_mountpoint
+       local var_canmnt=mz_$(var_name ${facet}_$ds)_canmount
+       local mntpt=${!var_mntpt}
+       local canmnt=${!var_canmnt}
+
+       unset $var_mntpt
+       unset $var_canmnt
+       do_facet $facet umount $mnt
+       do_facet $facet $ZFS set mountpoint=$mntpt $ds
+       do_facet $facet $ZFS set canmount=$canmnt $ds
+       export_zpool $facet
+}
+
+mount_fstype() {
+       local facet=$1
+       local fstype=$(facet_fstype $facet)
+
+       mount_$fstype $facet
+}
+
+unmount_fstype() {
+       local facet=$1
+       local fstype=$(facet_fstype $facet)
+
+       unmount_$fstype $facet
+}
+
 ########
 ## MountConf setup
 
 ########
 ## MountConf setup