Skip to content

Commit

Permalink
pmlogmv: rework and new pmlogcp command
Browse files Browse the repository at this point in the history
There are lots of cosmetic changes in pmlogmv.c associated with
renaming the command line arguments: oldname, newname ->
srcname, dstname.

But the essential changes are:

1. Allow dstname to be an existing directory and use the basename of
   srcname as the basename of the destination archive

2. Use argv[0] to switch between pmlogmv (move, rename) and pmlogcp
   (copy).

So pmlogmv and pmlogcp now look like and behave much like mv(1)
and cp(1).

A whole bunch of changes in QA to use pmlogcp (in particular) instead
of cp(1), and thereby no longer relying on the shell's glob expansion
to enumerate the files of an archive.

[note to self] one less itch to scratch!
  • Loading branch information
kmcdonell committed Nov 28, 2024
1 parent 1505193 commit 5e2a4f8
Show file tree
Hide file tree
Showing 32 changed files with 293 additions and 207 deletions.
59 changes: 41 additions & 18 deletions man/man1/pmlogmv.1
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,54 @@
.\"
.TH PMLOGMV 1 "PCP" "Performance Co-Pilot"
.SH NAME
\f3pmlogmv\f1 \- move (rename) Performance Co-Pilot archive files
\f3pmlogmv\f1, \f3pmlogcp\f1 \- move (rename) or copy Performance Co-Pilot archive files
.SH SYNOPSIS
\f3pmlogmv\f1
[\f3\-cfNV?\f1]
\f2oldname\f1
\f2newname\f1
\f2srcname\f1
\f2dstname\f1
.br
\f3pmlogcp\f1
[\f3\-cfNV?\f1]
\f2srcname\f1
\f2dstname\f1
.SH DESCRIPTION
A Performance Co-Pilot (PCP) archive consists of multiple files as
created by
.BR pmlogger (1).
.B pmlogmv
allows all the files of a single PCP archive
to be moved or renamed as a group in a single operation.
Similarly
.B pmlogcp
copies all the files of single PCP archive in a single operation.
.PP
The
.I oldname
.I srcname
argument identifies the target archive, and may be either the basename
that is common to all files in that archive or one of the archive's
files.
.PP
The new archive's basename is
.IR newname .
.IR dstname ,
except when
.I dstname
is an existing directory, in which case the files are moved or copied
into
.I dstname
using the same archive basename as
.IR srcname .
.PP
Because PCP archives are important records of system activity, special
care is taken to ensure the integrity of an archive's files.
For recoverable problems encountered during the execution of
.BR pmlogmv ,
.B pmlogmv
or
.BR pmlogcp ,
all the files associated with
.I oldname
.I srcname
will be preserved, and no new files with the
.I newname
.I dstname
prefix will be created.
``Recoverable problems'' include signals that can be caught (such as SIGHUP,
SIGINT, SIGQUIT and SIGTERM), permissions issues, new files already existing,
Expand All @@ -58,9 +76,9 @@ restrictions of
.IR ln (2)
which for most systems means the directories containing both
the
.I oldname
.I srcname
and the
.I newname
.I dstname
PCP archive files need to be within the
.B same
file system.
Expand All @@ -69,9 +87,13 @@ When this is not possible,
falls back to using
.BR cp (1)
to copy
.I oldname
.I srcname
to
.IR newname .
.IR dstname .
.PP
.B pmlogcp
always uses
.BR cp (1).
.SH OPTIONS
The available command line options are:
.TP 5
Expand All @@ -94,10 +116,12 @@ checksum check is skipped.
\fB\-f\fR, \fB\-\-force\fR
Normally
.B pmlogmv
takes a conservative view in respect of
.I newname
and
.B pmlogcp
take a conservative view in respect of
.I dstname
and will not proceed if
.I newname
.I dstname
contains any characters that are likely to cause a problem for
.BR sh (1).
This includes ``glob'' characters like ``?'', ``*'' and ``['', shell
Expand All @@ -109,9 +133,8 @@ a space, etc.
The
.B \-f
flag forces
.B pmlogmv
to proceed, even if
.I newname
the rename or copy to proceed, even if
.I dstname
contains any of these ``unsafe'' characters.
.RE
.TP
Expand Down
6 changes: 3 additions & 3 deletions qa/1272
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
# real QA test starts here
mkdir $tmp

cp tmparch/foo.* $tmp
pmlogmv $tmp/foo $tmp/fool
cp tmparch/foo.* $tmp
pmlogcp tmparch/foo $tmp
pmlogcp tmparch/foo $tmp/fool

cd $tmp

_do_it()
Expand Down
18 changes: 9 additions & 9 deletions qa/1272.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
QA output created by 1272

=== foo -> foo? ===
pmlogmv: newname (foo?) unsafe [shell metacharacter '?']
pmlogmv: dstname (foo?) unsafe [shell metacharacter '?']

=== foo -> foo? ===
link ./foo.0 -> foo?.0
Expand Down Expand Up @@ -31,7 +31,7 @@ fool.index
fool.meta

=== foo -> foo* ===
pmlogmv: newname (foo*) unsafe [shell metacharacter '*']
pmlogmv: dstname (foo*) unsafe [shell metacharacter '*']

=== foo -> foo* ===
link ./foo.0 -> foo*.0
Expand Down Expand Up @@ -61,7 +61,7 @@ fool.index
fool.meta

=== foo -> foo$ ===
pmlogmv: newname (foo$) unsafe [shell metacharacter '$']
pmlogmv: dstname (foo$) unsafe [shell metacharacter '$']

=== foo -> foo$ ===
link ./foo.0 -> foo$.0
Expand Down Expand Up @@ -91,7 +91,7 @@ fool.index
fool.meta

=== foo -> foo[bar] ===
pmlogmv: newname (foo[bar]) unsafe [shell metacharacter '[']
pmlogmv: dstname (foo[bar]) unsafe [shell metacharacter '[']

=== foo -> foo[bar] ===
link ./foo.0 -> foo[bar].0
Expand Down Expand Up @@ -229,7 +229,7 @@ fool.index
fool.meta

=== foo -> foo<x> ===
pmlogmv: newname (foo<x>) unsafe [shell metacharacter '<']
pmlogmv: dstname (foo<x>) unsafe [shell metacharacter '<']

=== foo -> foo<x> ===
link ./foo.0 -> foo<x>.0
Expand Down Expand Up @@ -259,7 +259,7 @@ fool.index
fool.meta

=== foo -> foo| ===
pmlogmv: newname (foo|) unsafe [shell metacharacter '|']
pmlogmv: dstname (foo|) unsafe [shell metacharacter '|']

=== foo -> foo| ===
link ./foo.0 -> foo|.0
Expand Down Expand Up @@ -289,7 +289,7 @@ fool.index
fool.meta

=== foo -> foo; ===
pmlogmv: newname (foo;) unsafe [shell metacharacter ';']
pmlogmv: dstname (foo;) unsafe [shell metacharacter ';']

=== foo -> foo; ===
link ./foo.0 -> foo;.0
Expand Down Expand Up @@ -319,7 +319,7 @@ fool.index
fool.meta

=== foo -> foo& ===
pmlogmv: newname (foo&) unsafe [shell metacharacter '&']
pmlogmv: dstname (foo&) unsafe [shell metacharacter '&']

=== foo -> foo& ===
link ./foo.0 -> foo&.0
Expand Down Expand Up @@ -349,7 +349,7 @@ fool.index
fool.meta

=== foo -> foofoo bar ===
pmlogmv: newname (foofoo bar) unsafe [shell metacharacter ' ']
pmlogmv: dstname (foofoo bar) unsafe [shell metacharacter ' ']

=== foo -> foofoo bar ===
link ./foo.0 -> foofoo bar.0
Expand Down
2 changes: 1 addition & 1 deletion qa/1280
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ _doit()

# real QA test starts here
mkdir $tmp
cp archives/20180416.10.00* $tmp
pmlogcp archives/20180416.10.00 $tmp
cd $tmp
for f in *.xz
do
Expand Down
12 changes: 8 additions & 4 deletions qa/1427
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ cd $seq.tmp
# real QA test starts here

echo "=== no errors case ==="
cp ../archives/foo+.* .
rm -f foo+.*
pmlogcp ../archives/foo+ .
rm -f $tmpdir/foo+.*
pmlogmv -c foo+ $tmpdir/foo+
echo "src ..."; (ls foo+.* 2>&1 | _filter_ls)
echo "dest ..."; (cd $tmpdir; ls foo+.* 2>&1 | _filter_ls)

echo
echo "=== no errors with -v case ==="
cp ../archives/foo+.* .
rm -f foo+.*
pmlogcp ../archives/foo+ .
rm -f $tmpdir/foo+.*
pmlogmv -cV foo+ $tmpdir/foo+ 2>&1 | _filter
echo "src ..."; (ls foo+.* 2>&1 | _filter_ls)
Expand All @@ -95,7 +97,8 @@ chmod 755 md5sum
# containers
#
export PATH=.:$PATH
cp ../archives/foo+.* .
rm -f foo+.*
pmlogcp ../archives/foo+ .
rm -f $tmpdir/foo+.*
pmlogmv -c foo+ $tmpdir/foo+ 2>&1 | _filter
echo "src ..."; (ls foo+.* 2>&1 | _filter_ls)
Expand All @@ -109,7 +112,8 @@ cat <<'End-of-File' >cp
PATH=/bin:/usr/bin cp $*
End-of-File
chmod 755 cp
cp ../archives/foo+.* .
rm -f foo+.*
pmlogcp ../archives/foo+ .
rm -f $tmpdir/foo+.*
pmlogmv=`which pmlogmv`
( PATH=. $pmlogmv -cV foo+ $tmpdir/foo+ ) 2>&1 | _filter
Expand Down
2 changes: 1 addition & 1 deletion qa/1428
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ unset PCP_DERIVED_CONFIG

# real QA test starts here
mkdir -p $tmp
cp archives/daily_report.* $tmp
pmlogcp archives/daily_report $tmp
_doit

echo
Expand Down
2 changes: 1 addition & 1 deletion qa/1474
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $1 != "cputime:" { print }'
base=pcp-pidstat-process-args
mkdir $tmp
cd $tmp
cp $here/archives/$base.* .
pmlogcp $here/archives/$base .
$time -f 'cputime: %U %S' xzcat $base.0.xz >/dev/null 2>$tmp.time
_summary <$tmp.time "data uncompress" | tee -a $here/$seq.full >$tmp.tmp
data=`sed -n <$tmp.tmp -e '/[0-9]cpu (/{
Expand Down
4 changes: 2 additions & 2 deletions qa/1477
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ _doit()
echo "=== cmd=$cmd $* ===" | tee -a $here/$seq.full
[ -d $tmp ] || mkdir $tmp
cd $tmp
rm -f out.*
cp $here/archives/ok-mv-bar.* .
rm -f out.* ok-mv-bar.*
pmlogcp $here/archives/ok-mv-bar .
for cull
do
rm ok-mv-bar.$cull
Expand Down
6 changes: 3 additions & 3 deletions qa/1569
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ _doit pmlogdecompress -f gzip foobar
_doit pmlogdecompress -l 0 foobar
_doit pmlogdecompress -o space foobar
_doit pmlogcompress -o foo foobar
cp $here/archives/foo+.* $tmp
pmlogcp $here/archives/foo+ $tmp
_doit pmlogcompress -l 0 -c no-such-prog $tmp/foo+
_doit pmlogcompress -l 0 -f no-such-prog $tmp/foo+
_doit pmlogcompress -l 0 -c no-such-prog:even-less-likely-prog $tmp/foo+
Expand All @@ -110,7 +110,7 @@ echo
echo "=== some decompress success cases ==="
cd $tmp
rm -f *
cp $here/archives/pcp-meminfo* .
pmlogcp $here/archives/pcp-meminfo .
pmlogdump -z pcp-meminfo >$tmp.pcp-meminfo.dump
stat --format='%n %s' pcp-meminfo* | _filter
_doit pmlogdecompress -N pcp-meminfo
Expand Down Expand Up @@ -172,7 +172,7 @@ _check pcp-meminfo

echo
echo "=== some compress (and decompress) success cases ==="
cp $here/archives/foo+.* .
pmlogcp $here/archives/foo+ .
stat --format='%n %s' foo+* | _filter
pmlogdump -z foo+ >$tmp.foo+.dump
_doit pmlogcompress -NV -l10240 foo+
Expand Down
2 changes: 1 addition & 1 deletion qa/1575
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _setup_control()
_setup()
{
rm -f $tmp/* $tmp.log
cp archives/ok-mv-bigbin.* $tmp
pmlogcp archives/ok-mv-bigbin $tmp
for arch in $tmp/ok-mv-bigbin.*
do
touch -t ${DATE}0102 $arch
Expand Down
2 changes: 1 addition & 1 deletion qa/1576
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ _setup_control()
_setup()
{
rm -f $tmp/* $tmp.log
cp archives/ok-mv-bigbin.* $tmp
pmlogcp archives/ok-mv-bigbin $tmp
for arch in $tmp/ok-mv-bigbin.*
do
touch -t ${DATE}0102 $arch
Expand Down
4 changes: 3 additions & 1 deletion qa/479
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ _filter2()
| _filter
}

cp archives/bozo.client_v2.* $tmp
pmlogcp archives/bozo.client_v2 $tmp
# pmlogcp does not like bad archives
#
cp badarchives/bozo.client_v2.* $tmp
mv $tmp/bozo.client_v2.meta $tmp/bozo.client_v2.save

Expand Down
6 changes: 3 additions & 3 deletions qa/502
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mkdir $tmp.arch
echo "=== metric not in archive ===" | tee -a $seq.full
arch=rewrite
rm -f $tmp.arch/*
cp archives/$arch.* $tmp.arch
pmlogcp archives/$arch $tmp.arch
ls -l $tmp.arch | tee -a $seq.full >$tmp.before
cat <<'End-of-File' >$tmp.conf
metric kernel.all.load { pmid -> 1.2.3 }
Expand Down Expand Up @@ -114,7 +114,7 @@ End-of-File
cat $tmp.conf >>$seq.full
arch=mirage
rm -f $tmp.arch/*
cp archives/$arch.* $tmp.arch
pmlogcp archives/$arch $tmp.arch/$arch
ls $tmp.arch
ls -l $tmp.arch >>$seq.full
pmlogrewrite -s -c $tmp.conf $tmp.arch/$arch $tmp.arch/$arch.expect 2>&1 \
Expand All @@ -136,7 +136,7 @@ End-of-File
cat $tmp.conf >>$seq.full
arch=ok-truncbin
rm -f $tmp.arch/*
cp badarchives/$arch.* $tmp.arch
pmlogcp badarchives/$arch $tmp.arch/$arch
ls -l $tmp.arch >>$seq.full
# Note: 204XXX filtering is because stdio does not always return the same
# value on different platforms ... it is 204800 (EOF) on OpenBSD 6.3
Expand Down
7 changes: 2 additions & 5 deletions qa/503
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ _filter()
_setup()
{
$sudo rm -f $tmp.arch/*
for x in 0 meta index
do
$sudo cp archives/rewrite.$x $tmp.arch/20111001.21.10.$x
$sudo cp archives/rewrite.$x $tmp.arch/20111001.22.10.$x
done
sudo pmlogcp archives/rewrite $tmp.arch/20111001.21.10
sudo pmlogcp archives/rewrite $tmp.arch/20111001.22.10
echo "global { time -> +1:00:00 }" >$tmp.conf.time
$sudo $PMLOGREWRITE -c $tmp.conf.time -i $tmp.arch/20111001.22.10

Expand Down
5 changes: 1 addition & 4 deletions qa/505
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ echo | tee -a $seq.full
echo "metric sample.seconds { type -> U64 }" >$tmp.config
echo "=== -i `cat $tmp.config` ===" | tee -a $seq.full
rm -f $tmp.new.*
for i in index meta 0 1 2
do
cp archives/ok-mv-foo.$i $tmp.new.$i
done
pmlogcp archives/ok-mv-foo $tmp.new
pmlogrewrite -iws -c $tmp.config $tmp.new 2>&1 | _filter
echo "Output archive contains: `ls $tmp.new.* | tee -a $seq.full | wc -l | sed -e 's/ //g'` files"
_cmp $tmp.new
Expand Down
Loading

0 comments on commit 5e2a4f8

Please sign in to comment.