Module Name: src Committed By: pooka Date: Thu Jul 29 14:47:45 UTC 2010
Modified Files: src/tests/fs/common: Makefile fstest_lfs.c Log Message: Include & use lfs megamaid. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/fs/common/Makefile cvs rdiff -u -r1.1 -r1.2 src/tests/fs/common/fstest_lfs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/fs/common/Makefile diff -u src/tests/fs/common/Makefile:1.3 src/tests/fs/common/Makefile:1.4 --- src/tests/fs/common/Makefile:1.3 Thu Jul 29 14:15:46 2010 +++ src/tests/fs/common/Makefile Thu Jul 29 14:47:44 2010 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.3 2010/07/29 14:15:46 pooka Exp $ +# $NetBSD: Makefile,v 1.4 2010/07/29 14:47:44 pooka Exp $ # .include <bsd.own.mk> @@ -20,4 +20,7 @@ CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/mount_nfs -I${NETBSDSRCDIR}/sbin/mount CPPFLAGS+= -DMOUNT_NOMAIN -DMOUNTNFS_RETRYRPC=1 +.include "../../../libexec/lfs_cleanerd/Makefile.inc" +CPPFLAGS+= -DUSE_RUMP -DLFS_CLEANER_AS_LIB + .include <bsd.lib.mk> Index: src/tests/fs/common/fstest_lfs.c diff -u src/tests/fs/common/fstest_lfs.c:1.1 src/tests/fs/common/fstest_lfs.c:1.2 --- src/tests/fs/common/fstest_lfs.c:1.1 Thu Jul 29 14:15:46 2010 +++ src/tests/fs/common/fstest_lfs.c Thu Jul 29 14:47:44 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fstest_lfs.c,v 1.1 2010/07/29 14:15:46 pooka Exp $ */ +/* $NetBSD: fstest_lfs.c,v 1.2 2010/07/29 14:47:44 pooka Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -33,6 +33,8 @@ #include <sys/stat.h> #include <atf-c.h> +#include <pthread.h> +#include <semaphore.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -44,11 +46,18 @@ #include <rump/rump_syscalls.h> #include "h_fsmacros.h" +#include "mount_lfs.h" + +sem_t lfs_clearnerloop; struct lfstestargs { struct ufs_args ta_uargs; + pthread_t ta_cleanerthread; + sem_t ta_cleanerloop; char ta_devpath[MAXPATHLEN]; char ta_imgpath[MAXPATHLEN]; + char ta_mntpath[MAXPATHLEN]; + char ta_hostpath[MAXPATHLEN]; }; int @@ -74,9 +83,11 @@ if (args == NULL) return -1; + strcpy(args->ta_hostpath, image); snprintf(args->ta_devpath, MAXPATHLEN, "/dev/device%d.lfs", num); snprintf(args->ta_imgpath, MAXPATHLEN, "%s", image); args->ta_uargs.fspec = args->ta_devpath; + sem_init(&args->ta_cleanerloop, 0, 0); res = rump_pub_etfs_register(args->ta_devpath, image, RUMP_ETFS_BLK); if (res != 0) { @@ -104,18 +115,46 @@ if (res != 0) return res; + pthread_join(args->ta_cleanerthread, NULL); free(args); return 0; } +static void * +cleaner(void *arg) +{ + char thepath[MAXPATHLEN]; + struct lfstestargs *args = arg; + const char *the_argv[7]; + char buf[64]; + + /* this inspired by the cleaner code. fixme */ + sprintf(thepath, "/dev/r%s", args->ta_devpath+5); + rump_pub_etfs_register(thepath, args->ta_hostpath, RUMP_ETFS_CHR); + sprintf(buf, "%p", &args->ta_cleanerloop); + + the_argv[0] = "megamaid"; + the_argv[1] = "-D"; /* don't fork() & detach */ + the_argv[2] = "-S"; + the_argv[3] = buf; + the_argv[4] = args->ta_mntpath; + the_argv[5] = NULL; + + /* xxxatf */ + optind = 1; + opterr = 1; + + lfs_cleaner_main(5, __UNCONST(the_argv)); + + return NULL; +} + int lfs_fstest_mount(const atf_tc_t *tc, void *buf, const char *path, int flags) { - int res; struct lfstestargs *args = buf; - - /* XXX: should start cleanerd */ + int res; res = rump_sys_mkdir(path, 0777); if (res == -1) @@ -123,7 +162,18 @@ res = rump_sys_mount(MOUNT_LFS, path, flags, &args->ta_uargs, sizeof(args->ta_uargs)); - return res; + if (res == -1) + return res; + + strcpy(args->ta_mntpath, path); + res = pthread_create(&args->ta_cleanerthread, NULL, cleaner, args); + if (res) + return res; + + /* wait for cleaner to initialize */ + sem_wait(&args->ta_cleanerloop); + + return 0; } int @@ -132,8 +182,9 @@ int res; res = rump_sys_unmount(path, flags); - if (res == -1) + if (res == -1) { return res; + } res = rump_sys_rmdir(path); return res;