rump_lfs.c revision 1.6
11.6Spooka/* $NetBSD: rump_lfs.c,v 1.6 2009/08/06 01:00:04 pooka Exp $ */ 21.1Spooka 31.1Spooka/* 41.3Spooka * Copyright (c) 2008 Antti Kantee. All Rights Reserved. 51.1Spooka * 61.1Spooka * Redistribution and use in source and binary forms, with or without 71.1Spooka * modification, are permitted provided that the following conditions 81.1Spooka * are met: 91.1Spooka * 1. Redistributions of source code must retain the above copyright 101.1Spooka * notice, this list of conditions and the following disclaimer. 111.1Spooka * 2. Redistributions in binary form must reproduce the above copyright 121.1Spooka * notice, this list of conditions and the following disclaimer in the 131.1Spooka * documentation and/or other materials provided with the distribution. 141.1Spooka * 151.1Spooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 161.1Spooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 171.1Spooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 181.1Spooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 191.1Spooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 201.1Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 211.1Spooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 221.1Spooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 231.1Spooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 241.1Spooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 251.1Spooka * SUCH DAMAGE. 261.1Spooka */ 271.1Spooka 281.1Spooka#include <sys/types.h> 291.1Spooka#include <sys/mount.h> 301.1Spooka 311.1Spooka#include <ufs/ufs/ufsmount.h> 321.1Spooka 331.1Spooka#include <err.h> 341.6Spooka#include <pthread.h> 351.6Spooka#include <stdio.h> 361.1Spooka#include <stdlib.h> 371.1Spooka#include <unistd.h> 381.1Spooka 391.6Spooka#include <rump/rump.h> 401.1Spooka#include <rump/p2k.h> 411.4Spooka#include <rump/ukfs.h> 421.1Spooka 431.2Spooka#include "mount_lfs.h" 441.1Spooka 451.6Spookastatic void * 461.6Spookacleaner(void *arg) 471.6Spooka{ 481.6Spooka const char *the_argv[7]; 491.6Spooka 501.6Spooka the_argv[0] = "megamaid"; 511.6Spooka the_argv[1] = "-D"; /* don't fork() & detach */ 521.6Spooka the_argv[2] = arg; 531.6Spooka 541.6Spooka sleep(1); /* XXXtehsuck: wait until mount is complete is other thread */ 551.6Spooka lfs_cleaner_main(3, __UNCONST(the_argv)); 561.6Spooka 571.6Spooka return NULL; 581.6Spooka} 591.6Spooka 601.1Spookaint 611.1Spookamain(int argc, char *argv[]) 621.1Spooka{ 631.1Spooka struct ufs_args args; 641.6Spooka char canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN], rawdev[MAXPATHLEN]; 651.6Spooka pthread_t cleanerthread; 661.2Spooka int mntflags; 671.2Spooka int rv; 681.1Spooka 691.1Spooka setprogname(argv[0]); 701.1Spooka 711.4Spooka /* 721.4Spooka * Load FFS and LFS already here. we need both and link set 731.4Spooka * lossage does not allow them to be linked on the command line. 741.4Spooka */ 751.4Spooka ukfs_init(); 761.5Spooka if (ukfs_modload("librumpfs_ffs.so") != 1) 771.4Spooka err(1, "modload ffs"); 781.5Spooka if (ukfs_modload("librumpfs_lfs.so") != 1) 791.4Spooka err(1, "modload lfs"); 801.4Spooka 811.2Spooka mount_lfs_parseargs(argc, argv, &args, &mntflags, canon_dev, canon_dir); 821.6Spooka 831.6Spooka /* 841.6Spooka * XXX: this particular piece inspired by the cleaner code. 851.6Spooka * obviously FIXXXME along with the cleaner. 861.6Spooka */ 871.6Spooka sprintf(rawdev, "/dev/r%s", canon_dev+5); 881.6Spooka rump_etfs_register(rawdev, canon_dev, RUMP_ETFS_CHR); 891.6Spooka 901.6Spooka /* 911.6Spooka * We basically have two choices: 921.6Spooka * 1) run the cleaner in another process and do rump ipc syscalls 931.6Spooka * 2) run it off a thread in this process and do rump syscalls 941.6Spooka * as function calls. 951.6Spooka * 961.6Spooka * opt for "2" for now 971.6Spooka */ 981.6Spooka#ifndef CLEANER_TESTING 991.6Spooka if ((mntflags & MNT_RDONLY) == 0) { 1001.6Spooka if (pthread_create(&cleanerthread, NULL, 1011.6Spooka cleaner, canon_dir) == -1) 1021.6Spooka err(1, "cannot start cleaner"); 1031.6Spooka } 1041.6Spooka#else 1051.6Spooka ukfs_mount(MOUNT_LFS, canon_dev, canon_dir, mntflags, 1061.6Spooka &args, sizeof(args)); 1071.6Spooka cleaner(canon_dir); 1081.6Spooka#endif 1091.6Spooka 1101.2Spooka rv = p2k_run_fs(MOUNT_LFS, canon_dev, canon_dir, mntflags, 1111.2Spooka &args, sizeof(args), 0); 1121.1Spooka if (rv) 1131.1Spooka err(1, "mount"); 1141.1Spooka 1151.1Spooka return 0; 1161.1Spooka} 117