Skip to content

Commit

Permalink
Add lflush script
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Garlick <garlick@llnl.gov>
  • Loading branch information
morrone committed May 3, 2010
1 parent a2c9f41 commit ea8bae5
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lustre/doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ MANFILES = lustre.7 lfs.1 mount.lustre.8 mkfs.lustre.8 tunefs.lustre.8 lctl.8 \
llapi_quotactl.3 llobdstat.8 llstat.8 \
plot-llstat.8 l_getgroups.8 lst.8 routerstat.8 lshowmount.8 \
ll_recover_lost_found_objs.8 llog_reader.8 llapi_file_open.3 \
llapi_file_create.3 llapi_file_get_stripe.3 liblustreapi.7 lpurge.8
llapi_file_create.3 llapi_file_get_stripe.3 liblustreapi.7 lpurge.8 lflush.8
if UTILS
man_MANS = $(MANFILES)
endif
Expand Down
43 changes: 43 additions & 0 deletions lustre/doc/lflush.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.TH LFLUSH 8 Lustre LLNL LFLUSH
.SH NAME
lflush \- revoke all client locks
.SH SYNOPSIS
.B "lflush [-v]"
.br
.SH DESCRIPTION
.B lflush
synchronously revokes all Lustre MDC, OSC, and MGC locks on the local client,
returning them to the lock manager for reuse. This causes all Lustre
page cache pages to be flushed (if dirty) or discarded (if clean).
If Lustre servers are unavailable,
.B lflush
will block until recovery is complete.
.LP
.B lflush
can be called from a batch resource manager epilog script to ensure that the
next job has all available memory. In the case of slurm, the node will
remain in COMPLETING state while the epilog script executes.
.LP
A server will be skipped if its lock_count, lock_unused_count, and
resource_count proc files all contain zeros.
.LP
.B lflush
must be run as root.
.SH OPTIONS
.B lflush
accepts the following options:
.TP
.I "-v"
causes
.B lflush
to list each server before it flushes the servers locks.
.SH FILES
/proc/fs/lustre/ldlm/namespaces/<server>/lru_size
.br
/proc/fs/lustre/ldlm/namespaces/<server>/lock_count
.br
/proc/fs/lustre/ldlm/namespaces/<server>/lock_unused_count
.br
/proc/fs/lustre/ldlm/namespaces/<server>/resource_count
.SH AUTHOR
Herb Wartens and Jim Garlick
2 changes: 1 addition & 1 deletion lustre/utils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ AM_LDFLAGS := -L$(top_builddir)/lnet/utils

LIBPTLCTL := $(top_builddir)/lnet/utils/libptlctl.a

sbin_scripts =
sbin_scripts = lflush
noinst_scripts = lrun
bin_scripts = llstat llobdstat plot-llstat

Expand Down
84 changes: 84 additions & 0 deletions lustre/utils/lflush
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
#
# Revoke all client locks, which should write all dirty Lustre
# page cache pages and discard the clean ones.
#
# Based on flush-lustre-client-locks script by Herb Wartens.
#

declare -r nsdir=/proc/fs/lustre/ldlm/namespaces
declare -r prog=lflush

vopt=0
retval=0

die()
{
echo "${prog}: $1" >&2
exit 1
}

warn()
{
echo "${prog}: $1" >&2
}

lock_count()
{
local server=$1
local nlock nulock nres

pushd ${nsdir} >/dev/null || die "could not chdir to ${nsdir}"
[ "${server}" = "*" ] && die "could not find any servers"
nlock=$(cat ${server}/lock_count 2>/dev/null)
nulock=$(cat ${server}/lock_unused_count 2>/dev/null)
nres=$(cat ${server}/resource_count 2>/dev/null)
popd >/dev/null

return $((${nlock:-0}+${nulock:-0}+${nres:-0}))
}

# Flush all locks for all servers
flush_locks()
{
local server count

pushd ${nsdir} >/dev/null || die "could not chdir to ${nsdir}"
for server in *; do
[ "${server}" = "*" ] && die "could not find any servers"
if ! lock_count ${server}; then
[ ${vopt} = 1 ] && warn "flushing ${server}"
if ! echo clear >${server}/lru_size; then
warn "problem flushing ${server}"
retval=1
fi
fi
done
popd >/dev/null
}

##
## MAIN
##

[ $(id -u) = 0 ] || die "must run as root"

if [ ! -d /proc/fs/lustre/ldlm/namespaces ]; then
warn "lustre client is not active - nothing to do"
exit 0
fi

while getopts "v" opt; do
case ${opt} in
v) vopt=1 ;;
*) die "Usage: ${prog} [-v]" ;;
esac
done

if [ -x /bin/sync ]; then
/bin/sync
fi

flush_locks

exit ${retval}

0 comments on commit ea8bae5

Please sign in to comment.