#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell
#
# a test program that opens the intermezzo device to talk to presto,
# and cleans up the fileset information for the cache.  This can be done
# instead of running a whole ongoing Lento process to shut down the
# cache within presto so that subsequent simple test codes can work.
#

use strict;

use lib qw(/usr/lib/intermezzo /usr/lib/intermezzo/i386-linux);
use Lento::Psdev;

=pod

=head1  NAME

closejournal - forcefully close journal file

=head1  SYNOPSIS

closejournal fset-mount-point [intermezzo-device]

=head1  DESCRIPTION

In order to unmount InterMezzo file systems, the kernel must close the
journal files for all filesets it is using in a cache.  This command
closes a single fileset's journal file.  It is called by B<umountizo.2>. 

=head1 Arguments

Command line arguments:

=over 4

=item B<fset-mount-point> Directory in the InterMezzo file system
where the fileset is mounted.

=item B<intermezzo-device> Optional: make the close journal ioctls to the given device (default t</dev/intermezzo0>.)

=back

=cut

my $mountpoint = shift @ARGV;
my $devname = shift @ARGV;

if (!$mountpoint) {
  die "You must supply the following arguments:\n  <mountpoint> [<device>]\n";
}

if (!$devname) {
  $devname = "/dev/intermezzo0";
}

print "closejournal: Opening psdev channel to presto:\n";
print "   mount = $mountpoint\n";
print "  device = $devname\n";

$::prestodev = $devname;
$::psdev = Lento::Psdev->new($::prestodev);
$::psdev->open();
$::psdev->clearallfsetroots($mountpoint);

