| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: rump_lfs.c,v 1.5 2009/07/21 00:40:44 pooka Exp $ */ | | 1 | /* $NetBSD: rump_lfs.c,v 1.6 2009/08/06 01:00:04 pooka Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2008 Antti Kantee. All Rights Reserved. | | 4 | * Copyright (c) 2008 Antti Kantee. All Rights Reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
| @@ -21,50 +21,96 @@ | | | @@ -21,50 +21,96 @@ |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 | * SUCH DAMAGE. | | 25 | * SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/types.h> | | 28 | #include <sys/types.h> |
29 | #include <sys/mount.h> | | 29 | #include <sys/mount.h> |
30 | | | 30 | |
31 | #include <ufs/ufs/ufsmount.h> | | 31 | #include <ufs/ufs/ufsmount.h> |
32 | | | 32 | |
33 | #include <err.h> | | 33 | #include <err.h> |
34 | #include <puffs.h> | | 34 | #include <pthread.h> |
| | | 35 | #include <stdio.h> |
35 | #include <stdlib.h> | | 36 | #include <stdlib.h> |
36 | #include <unistd.h> | | 37 | #include <unistd.h> |
37 | | | 38 | |
| | | 39 | #include <rump/rump.h> |
38 | #include <rump/p2k.h> | | 40 | #include <rump/p2k.h> |
39 | #include <rump/ukfs.h> | | 41 | #include <rump/ukfs.h> |
40 | | | 42 | |
41 | #include "mount_lfs.h" | | 43 | #include "mount_lfs.h" |
42 | | | 44 | |
| | | 45 | static void * |
| | | 46 | cleaner(void *arg) |
| | | 47 | { |
| | | 48 | const char *the_argv[7]; |
| | | 49 | |
| | | 50 | the_argv[0] = "megamaid"; |
| | | 51 | the_argv[1] = "-D"; /* don't fork() & detach */ |
| | | 52 | the_argv[2] = arg; |
| | | 53 | |
| | | 54 | sleep(1); /* XXXtehsuck: wait until mount is complete is other thread */ |
| | | 55 | lfs_cleaner_main(3, __UNCONST(the_argv)); |
| | | 56 | |
| | | 57 | return NULL; |
| | | 58 | } |
| | | 59 | |
43 | int | | 60 | int |
44 | main(int argc, char *argv[]) | | 61 | main(int argc, char *argv[]) |
45 | { | | 62 | { |
46 | struct ufs_args args; | | 63 | struct ufs_args args; |
47 | char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN]; | | 64 | char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN], rawdev[MAXPATHLEN]; |
| | | 65 | pthread_t cleanerthread; |
48 | int mntflags; | | 66 | int mntflags; |
49 | int rv; | | 67 | int rv; |
50 | | | 68 | |
51 | setprogname(argv[0]); | | 69 | setprogname(argv[0]); |
52 | | | 70 | |
53 | /* | | 71 | /* |
54 | * Load FFS and LFS already here. we need both and link set | | 72 | * Load FFS and LFS already here. we need both and link set |
55 | * lossage does not allow them to be linked on the command line. | | 73 | * lossage does not allow them to be linked on the command line. |
56 | */ | | 74 | */ |
57 | ukfs_init(); | | 75 | ukfs_init(); |
58 | if (ukfs_modload("librumpfs_ffs.so") != 1) | | 76 | if (ukfs_modload("librumpfs_ffs.so") != 1) |
59 | err(1, "modload ffs"); | | 77 | err(1, "modload ffs"); |
60 | if (ukfs_modload("librumpfs_lfs.so") != 1) | | 78 | if (ukfs_modload("librumpfs_lfs.so") != 1) |
61 | err(1, "modload lfs"); | | 79 | err(1, "modload lfs"); |
62 | | | 80 | |
63 | mount_lfs_parseargs(argc, argv, &args, &mntflags, canon_dev, canon_dir); | | 81 | mount_lfs_parseargs(argc, argv, &args, &mntflags, canon_dev, canon_dir); |
| | | 82 | |
| | | 83 | /* |
| | | 84 | * XXX: this particular piece inspired by the cleaner code. |
| | | 85 | * obviously FIXXXME along with the cleaner. |
| | | 86 | */ |
| | | 87 | sprintf(rawdev, "/dev/r%s", canon_dev+5); |
| | | 88 | rump_etfs_register(rawdev, canon_dev, RUMP_ETFS_CHR); |
| | | 89 | |
| | | 90 | /* |
| | | 91 | * We basically have two choices: |
| | | 92 | * 1) run the cleaner in another process and do rump ipc syscalls |
| | | 93 | * 2) run it off a thread in this process and do rump syscalls |
| | | 94 | * as function calls. |
| | | 95 | * |
| | | 96 | * opt for "2" for now |
| | | 97 | */ |
| | | 98 | #ifndef CLEANER_TESTING |
| | | 99 | if ((mntflags & MNT_RDONLY) == 0) { |
| | | 100 | if (pthread_create(&cleanerthread, NULL, |
| | | 101 | cleaner, canon_dir) == -1) |
| | | 102 | err(1, "cannot start cleaner"); |
| | | 103 | } |
| | | 104 | #else |
| | | 105 | ukfs_mount(MOUNT_LFS, canon_dev, canon_dir, mntflags, |
| | | 106 | &args, sizeof(args)); |
| | | 107 | cleaner(canon_dir); |
| | | 108 | #endif |
| | | 109 | |
64 | rv = p2k_run_fs(MOUNT_LFS, canon_dev, canon_dir, mntflags, | | 110 | rv = p2k_run_fs(MOUNT_LFS, canon_dev, canon_dir, mntflags, |
65 | &args, sizeof(args), 0); | | 111 | &args, sizeof(args), 0); |
66 | if (rv) | | 112 | if (rv) |
67 | err(1, "mount"); | | 113 | err(1, "mount"); |
68 | | | 114 | |
69 | return 0; | | 115 | return 0; |
70 | } | | 116 | } |