Skip to content

Commit

Permalink
Turn slowfs into a library
Browse files Browse the repository at this point in the history
Rather than build a binary that a test will need to execute, turn the
slowfs filesystem into a library, with mount() and unmount() calls.

This means we don't have to worry about paths at runtime. However,
the test Makefile will need to be aware of the necessary libraries at
build-time.

Signed-off-by: Jeremy Kerr <[email protected]>
  • Loading branch information
jk-ozlabs committed Jun 16, 2008
1 parent 2b2307e commit aa850a4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 45 deletions.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@ all: tests benchmarks

.PHONY: tests benchmarks libs

tests benchmarks: bin/run-tests lib/slowfs/slowfs
tests benchmarks: bin/run-tests libs
$(MAKE) -C $@ all


bin/run-tests: lib/talloc/talloc.o bin/run-tests.o bin/capabilities.o bin/test.o
$(LINK.o) -o $@ $^

libs: lib/talloc/talloc.o
libs: lib/talloc/talloc.o lib/slowfs/slowfs.o

lib/slowfs/slowfs: CFLAGS += $(shell pkg-config fuse --cflags)
lib/slowfs/slowfs: LDFLAGS += $(shell pkg-config fuse --libs)
lib/slowfs/slowfs.o: CFLAGS += $(shell pkg-config fuse --cflags)

clean:
cd tests && make clean
cd benchmarks && make clean
rm -f bin/capabilities bin/run-tests
rm -f bin/*.o lib/talloc/talloc.o
rm -f bin/*.o lib/talloc/talloc.o lib/slowfs/slowfs.o

check: clean all
bin/run-tests
80 changes: 78 additions & 2 deletions lib/slowfs/slowfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

#include <pthread.h>

#include <talloc/talloc.h>

#include <fuse.h>
#include <fuse_lowlevel.h>


#define FILE_SIZE 4096
static const char *file_name = "/slowfs";

struct slowfs {
struct fuse *fuse;
struct fuse_chan *chan;
char *mountpoint;
int fuse_rc;
pthread_t pthread;
};

static int slowfs_getattr(const char *path, struct stat *statbuf)
{
int rc = -ENOENT;
Expand Down Expand Up @@ -74,7 +90,67 @@ static struct fuse_operations ops = {
.read = slowfs_read,
};

int main(int argc, char *argv[])
static void *slowfs_fn(void *arg)
{
struct slowfs *slowfs = arg;

slowfs->fuse_rc = fuse_loop(slowfs->fuse);

return slowfs;
}

struct slowfs *slowfs_mount(const char *mountpoint)
{
struct slowfs *slowfs;

slowfs = talloc(NULL, struct slowfs);
if (!slowfs) {
perror("talloc");
goto out_free;
}

slowfs->mountpoint = talloc_strdup(slowfs, mountpoint);
if (!slowfs->mountpoint) {
perror("talloc");
goto out_free;
}

slowfs->chan = fuse_mount(mountpoint, NULL);
if (!slowfs->chan) {
perror("fuse_mount");
goto out_free;
}

slowfs->fuse = fuse_new(slowfs->chan, NULL, &ops, sizeof(ops), NULL);
if (!slowfs->fuse) {
perror("fuse_new");
goto out_free;
}

if (fuse_daemonize(1)) {
perror("fuse_daemonize");
goto out_free;
}

if (pthread_create(&slowfs->pthread, NULL, slowfs_fn, slowfs)) {
perror("pthread_create");
goto out_free;
}

/* fuse_set_signal_handlers() ? */

return slowfs;

out_free:
talloc_free(slowfs);
return NULL;
}

void slowfs_unmount(struct slowfs *slowfs)
{
return fuse_main(argc, argv, &ops, NULL);
fuse_exit(slowfs->fuse);
fuse_unmount(slowfs->mountpoint, slowfs->chan);
pthread_join(slowfs->pthread, NULL);
talloc_free(slowfs);
}

49 changes: 12 additions & 37 deletions tests/14-dma/05-schedule-during-fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <test/spu_syscalls.h>
#include <test/hw.h>

#include <slowfs/slowfs.h>

#define SLOWFS_BINARY "lib/slowfs/slowfs"
#define SLOWFS_DIR "mnt"
#define SLOWFS_FILE "mnt/slowfs"
Expand Down Expand Up @@ -118,25 +120,11 @@ static uint32_t spe_program[] = {
0x00001337, /* stop */
};


static void unmount_slowfs(void)
{
int pid;

pid = fork();
if (!pid) {
execlp("fusermount", "fusermount", "-u", SLOWFS_DIR, NULL);
exit(EXIT_FAILURE);
}

waitpid(pid, NULL, 0);

rmdir(SLOWFS_DIR);
}
static struct slowfs *slowfs;

static int map_slowfs_file(void **map, int *len)
{
int rc, fd, status;
int rc, fd;
struct stat statbuf;

rc = mkdir(SLOWFS_DIR, 0755);
Expand All @@ -145,23 +133,10 @@ static int map_slowfs_file(void **map, int *len)
return rc;
}

rc = fork();

if (rc < 0) {
perror("fork");
goto err_umount;
}

if (rc == 0) {
execl(SLOWFS_BINARY, SLOWFS_BINARY, SLOWFS_DIR, NULL);
exit(EXIT_FAILURE);
}

waitpid(rc, &status, 0);

if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
fprintf(stderr, "failed mounting slowfs\n");
goto err_umount;
slowfs = slowfs_mount(SLOWFS_DIR);
if (!slowfs) {
fprintf(stderr, "failed to mount slowfs on %s\n", SLOWFS_DIR);
return -1;
}

fd = open(SLOWFS_FILE, O_RDONLY);
Expand Down Expand Up @@ -193,17 +168,18 @@ static int map_slowfs_file(void **map, int *len)
err_close:
close(fd);
err_umount:
unmount_slowfs();
slowfs_unmount(slowfs);
return rc;

}

static void unmap_slow_file(void *map, int len)
{
if (len)
if (map != MAP_FAILED)
munmap(map, len);

unmount_slowfs();
slowfs_unmount(slowfs);
rmdir(SLOWFS_DIR);
}

struct spe_thread_info {
Expand Down Expand Up @@ -280,7 +256,6 @@ int main(void)
rc = 0;
}


out_unmap:
unmap_slow_file(slow_map, slow_map_len);
return rc;
Expand Down
4 changes: 3 additions & 1 deletion tests/14-dma/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
obj += 01-spe-get 02-spe-put 03-hugepage-spe-faulted 04-hugepage-ppe-faulted \
05-schedule-during-fault

05-schedule-during-fault: LDFLAGS += -lpthread
05-schedule-during-fault: LDFLAGS += -lpthread -lfuse
05-schedule-during-fault: 05-schedule-during-fault.o ../../lib/slowfs/slowfs.o \
../../lib/talloc/talloc.o

$(obj): pattern.o

0 comments on commit aa850a4

Please sign in to comment.