1 /* $NetBSD: h_ffs_server.c,v 1.2 2012/08/24 20:25:50 jmmv Exp $ */ 2 3 /* 4 * rump server for advanced quota tests 5 */ 6 7 #include "../common/h_fsmacros.h" 8 9 #include <err.h> 10 #include <semaphore.h> 11 #include <sys/types.h> 12 #include <sys/mount.h> 13 14 #include <stdlib.h> 15 #include <unistd.h> 16 17 #include <ufs/ufs/ufsmount.h> 18 19 #include <rump/rump.h> 20 #include <rump/rump_syscalls.h> 21 22 int background = 0; 23 24 static void 25 usage(void) 26 { 27 fprintf(stderr, "usage: %s [-b] [-l] diskimage bindurl\n", 28 getprogname()); 29 exit(1); 30 } 31 32 static void 33 die(const char *reason, int error) 34 { 35 36 warnx("%s: %s", reason, strerror(error)); 37 if (background) 38 rump_daemonize_done(error); 39 exit(1); 40 } 41 42 static sem_t sigsem; 43 static void 44 sigreboot(int sig) 45 { 46 47 sem_post(&sigsem); 48 } 49 50 int 51 main(int argc, char **argv) 52 { 53 int error; 54 struct ufs_args uargs; 55 const char *filename; 56 const char *serverurl; 57 int log = 0; 58 int ch; 59 60 while ((ch = getopt(argc, argv, "bl")) != -1) { 61 switch(ch) { 62 case 'b': 63 background = 1; 64 break; 65 case 'l': 66 log = 1; 67 break; 68 default: 69 usage(); 70 } 71 } 72 argc -= optind; 73 argv += optind; 74 75 if (argc != 2) 76 usage(); 77 78 filename = argv[0]; 79 serverurl = argv[1]; 80 81 if (background) { 82 error = rump_daemonize_begin(); 83 if (error) 84 errx(1, "rump daemonize: %s", strerror(error)); 85 } 86 87 error = rump_init(); 88 if (error) 89 die("rump init failed", error); 90 91 if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1) 92 die("mount point create", errno); 93 rump_pub_etfs_register("/diskdev", filename, RUMP_ETFS_BLK); 94 uargs.fspec = __UNCONST("/diskdev"); 95 if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, (log) ? MNT_LOG : 0, 96 &uargs, sizeof(uargs)) == -1) 97 die("mount ffs", errno); 98 99 error = rump_init_server(serverurl); 100 if (error) 101 die("rump server init failed", error); 102 if (background) 103 rump_daemonize_done(RUMP_DAEMONIZE_SUCCESS); 104 105 sem_init(&sigsem, 0, 0); 106 signal(SIGTERM, sigreboot); 107 signal(SIGINT, sigreboot); 108 sem_wait(&sigsem); 109 110 rump_sys_reboot(0, NULL); 111 /*NOTREACHED*/ 112 return 0; 113 } 114