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 2009 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 26 # 27 # Put commands in here to flush the file system cache after 28 # file set creation but prior to steady state 29 # 30 # For most file systems, filebench already handles fs cache flushing 31 # For ZFS, it needs some help, so this script does 32 # "zpool export <poolname>" then "zpool import <poolname>" 33 # 34 35 $fs = $ARGV[0]; 36 $dir = $ARGV[1]; 37 38 # 39 # if not zfs, inform user and exit. 40 # 41 if (($fs =~ m/^zfs$/) != 1) { 42 print "filesystem type is: $fs, no action required, so exiting\n"; 43 exit(0); 44 } 45 46 # 47 # It is zfs. Find name of pool to export/import from supplied 48 # directory path name $dir 49 # 50 # Example: 51 # # zfs list -H 52 # tank 164K 24.0G 19K /tank 53 # tank/a 18K 24.0G 18K /tank/a 54 # tank/b 18K 24.0G 18K /wombat 55 # # 56 # # ./fs_flush zfs /wombat 57 # 'zpool export tank' 58 # 'zpool import tank' 59 # # 60 # 61 62 # Get a list of zfs file systems mounted locally 63 @zlist = `/usr/sbin/zfs list -H`; 64 65 # 66 # Compare the list with the supplied directory path name 67 # 68 chomp @zlist; 69 foreach ( @zlist ) { 70 # 71 # For listed zfs file systems, extract the root and 72 # mount point information 73 # 74 my $zline = $_; 75 ($root, $b, $c, $d, $mntpnt) = split /\t/, $zline, 5; 76 77 # See if the supplied directory path includes this mount point 78 if(($mntpnt ne "\/") && ($dir =~/^$mntpnt/)) { 79 80 # 81 # We have a winner! The root name up to the 82 # first forward slash is the pool name 83 # 84 ($pool) = split /\//, $root; 85 86 # save zpool.cache 87 my $tempfile = "/tmp/zpool.cache$$"; 88 my $cachefile = ""; 89 90 if (run_prog("cp /etc/zfs/zpool.cache $tempfile") == 0) { 91 $cachefile = "-c $tempfile " 92 } 93 94 # Do the cache flushing 95 96 print "'zpool export \/ import $pool'\n"; 97 if (run_prog("zpool export $pool") == 0) { 98 system("zpool import $cachefile$pool"); 99 } 100 system("rm -f $tempfile") if ($cachefile ne ""); 101 exit(0); 102 } 103 } 104 exit(-1); 105 106 sub run_prog 107 { 108 my $progname = shift; 109 110 my $res = system($progname); 111 112 #return error if failed for any reason 113 return -1 if (($res == -1) || ($res & 127)); 114 115 return ($res >> 8); 116 }