Skip to content

Commit

Permalink
fsync, improved output test
Browse files Browse the repository at this point in the history
  • Loading branch information
mgree committed Jun 16, 2021
1 parent fef3148 commit 9d0ae6d
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/fs.rs
Expand Up @@ -879,6 +879,18 @@ impl Filesystem for FS {
reply.ok()
}

fn fsync(
&mut self,
_req: &Request<'_>,
_ino: u64,
_fh: u64,
_datasync: bool,
reply: ReplyEmpty,
) {
self.sync();
reply.ok();
}

// TODO
fn copy_file_range(
&mut self,
Expand All @@ -896,18 +908,6 @@ impl Filesystem for FS {
reply.error(libc::ENOSYS);
}

// TODO
fn fsync(
&mut self,
_req: &Request<'_>,
_ino: u64,
_fh: u64,
_datasync: bool,
reply: ReplyEmpty,
) {
reply.error(libc::ENOSYS);
}

// TODO
fn ioctl(
&mut self,
Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
@@ -0,0 +1 @@
fsync
27 changes: 27 additions & 0 deletions tests/fsync.c
@@ -0,0 +1,27 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
char *path;

if (argc == 1) {
path = ".";
} else if (argc == 2) {
path = argv[1];
} else if (argc > 2) {
fprintf(stderr, "Usage: %s [path]\n", argv[0]);
return 1;
}

int fd = open(path, O_RDONLY);
if (fd == -1) {
perror(argv[0]);
return 2;
}

fsync(fd);
close(fd);

return 0;
}
69 changes: 69 additions & 0 deletions tests/fsync.sh
@@ -0,0 +1,69 @@
#!/bin/sh

fail() {
echo FAILED: $1
if [ "$MNT" ]
then
cd
umount "$MNT"
rmdir "$MNT"
rm "$TGT"
rm "$TGT2"
fi
exit 1
}

gcc -o fsync fsync.c || fail gcc

MNT=$(mktemp -d)
TGT=$(mktemp)

ffs -o "$TGT" "$MNT" ../json/object.json &
PID=$!
sleep 2
mkdir "$MNT"/pockets
echo keys >"$MNT"/pockets/pants
echo pen >"$MNT"/pockets/shirt
./fsync "$MNT"
cat "$TGT"
stat "$TGT"
[ -f "$TGT" ] || fail output1
[ -s "$TGT" ] || fail output2

umount "$MNT" || fail unmount1
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process1

# easiest to just test using ffs, but would be cool to get outside validation
#if [ "$RUNNER_OS" = "Linux" ]
#then
# echo "ABORTING TEST, currently broken on Linux (see https://github.com/cberner/fuser/issues/153)"
# exit 0
#fi
ffs --no-output "$MNT" "$TGT" >"$TGT2" &
PID=$!
sleep 2

case $(ls "$MNT") in
(eyes*fingernails*human*name*pockets) ;;
(*) fail ls1;;
esac
case $(ls "$MNT"/pockets) in
(pants*shirt) ;;
(*) fail ls2;;
esac

[ "$(cat $MNT/name)" = "Michael Greenberg" ] || fail name
[ "$(cat $MNT/eyes)" -eq 2 ] || fail eyes
[ "$(cat $MNT/fingernails)" -eq 10 ] || fail fingernails
[ "$(cat $MNT/human)" = "true" ] || fail human
[ "$(cat $MNT/pockets/pants)" = "keys" ] || fail pants
[ "$(cat $MNT/pockets/shirt)" = "pen" ] || fail shirt

umount "$MNT" || fail unmount2
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process2

rmdir "$MNT" || fail mount
rm "$TGT"
rm "$TGT2"
3 changes: 3 additions & 0 deletions tests/output.sh
Expand Up @@ -62,6 +62,9 @@ umount "$MNT" || fail unmount2
sleep 1
kill -0 $PID >/dev/null 2>&1 && fail process2

stat "$TGT2"
[ -f "$TGT2" ] || fail tgt2
[ -s "$TGT2" ] && fail tgt2_nonemptty

rmdir "$MNT" || fail mount
rm "$TGT"
Expand Down

0 comments on commit 9d0ae6d

Please sign in to comment.