1 #!/usr/bin/perl 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License (the "License"). 7 # You may not use this file except in compliance with the License. 8 # 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 # or http://www.opensolaris.org/os/licensing. 11 # See the License for the specific language governing permissions 12 # and limitations under the License. 13 # 14 # When distributing Covered Code, include this CDDL HEADER in each 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 # If applicable, add the following below this CDDL HEADER, with the 17 # fields enclosed by brackets "[]" replaced with your own identifying 18 # information: Portions Copyright [yyyy] [name of copyright owner] 19 # 20 # CDDL HEADER END 21 # 22 # 23 # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # ident "%Z%%M% %I% %E% SMI" 27 28 # 29 # Put commands in here to flush the file system cache after 30 # file set creation but prior to steady state 31 # 32 # For most file systems, filebench already handles fs cache flushing 33 # For ZFS, it needs some help, so this script does 34 # "zpool export <poolname>" then "zpool import <poolname>" 35 # 36 37 $fs = $ARGV[0]; 38 $dir = $ARGV[1]; 39 40 # 41 # if not zfs, inform user and exit. 42 # 43 if (($fs =~ m/^zfs$/) != 1) { 44 print "filesystem type is: $fs, no action required, so exiting\n"; 45 exit(0); 46 } 47 48 # 49 # It is zfs. Find name of pool to export/import from supplied 50 # directory path name $dir 51 # 52 # Example: 53 # # zfs list -H 54 # tank 164K 24.0G 19K /tank 55 # tank/a 18K 24.0G 18K /tank/a 56 # tank/b 18K 24.0G 18K /wombat 57 # # 58 # # ./fs_flush zfs /wombat 59 # 'zpool export tank' 60 # 'zpool import tank' 61 # # 62 # 63 64 # Get a list of zfs file systems mounted locally 65 @zlist = `/usr/sbin/zfs list -H`; 66 67 # 68 # Compare the list with the supplied directory path name 69 # 70 chomp @zlist; 71 foreach ( @zlist ) { 72 # 73 # For listed zfs file systems, extract the root and 74 # mount point information 75 # 76 my $zline = $_; 77 ($root, $b, $c, $d, $mntpnt) = split /\t/, $zline, 5; 78 79 # See if the supplied directory path includes this mount point 80 if ($dir =~/^$mntpnt/) { 81 82 # 83 # We have a winner! The root name up to the 84 # first forward slash is the pool name 85 # 86 ($pool) = split /\//, $root; 87 88 # Do the cache flushing 89 print "'zpool export $pool'\n"; 90 system("zpool export $pool"); 91 print "'zpool import $pool'\n"; 92 system("zpool import $pool"); 93 exit(0); 94 } 95 } 96