11.19Sbrad/* $NetBSD: rump_lfs.c,v 1.19 2019/08/30 23:41:48 brad 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.15Spooka#include <puffs.h> 361.6Spooka#include <stdio.h> 371.1Spooka#include <stdlib.h> 381.1Spooka#include <unistd.h> 391.1Spooka 401.6Spooka#include <rump/rump.h> 411.1Spooka#include <rump/p2k.h> 421.4Spooka#include <rump/ukfs.h> 431.1Spooka 441.2Spooka#include "mount_lfs.h" 451.1Spooka 461.19Sbrad#define RUMPRAWDEVICE "/dev/rrumpy0" 471.19Sbrad 481.6Spookastatic void * 491.6Spookacleaner(void *arg) 501.6Spooka{ 511.19Sbrad const char *the_argv[9]; 521.6Spooka 531.6Spooka the_argv[0] = "megamaid"; 541.6Spooka the_argv[1] = "-D"; /* don't fork() & detach */ 551.19Sbrad the_argv[2] = "-J"; /* treat arg as a device */ 561.19Sbrad the_argv[3] = RUMPRAWDEVICE; 571.19Sbrad the_argv[4] = arg; 581.6Spooka 591.19Sbrad lfs_cleaner_main(5, __UNCONST(the_argv)); 601.6Spooka 611.6Spooka return NULL; 621.6Spooka} 631.6Spooka 641.1Spookaint 651.1Spookamain(int argc, char *argv[]) 661.1Spooka{ 671.18Sdholland struct ulfs_args args; 681.13Spooka char canon_dev[UKFS_DEVICE_MAXPATHLEN], canon_dir[MAXPATHLEN]; 691.7Spooka char rawdev[MAXPATHLEN]; 701.8Spooka struct p2k_mount *p2m; 711.6Spooka pthread_t cleanerthread; 721.13Spooka struct ukfs_part *part; 731.13Spooka int mntflags; 741.2Spooka int rv; 751.1Spooka 761.1Spooka setprogname(argv[0]); 771.15Spooka puffs_unmountonsignal(SIGINT, true); 781.15Spooka puffs_unmountonsignal(SIGTERM, true); 791.4Spooka 801.16Spooka if (argc >= 3) { 811.16Spooka UKFS_DEVICE_ARGVPROBE(&part); 821.16Spooka if (part != ukfs_part_none) { 831.16Spooka errx(1, "lfs does not currently support " 841.16Spooka "embedded partitions"); 851.16Spooka } 861.7Spooka } 871.2Spooka mount_lfs_parseargs(argc, argv, &args, &mntflags, canon_dev, canon_dir); 881.6Spooka 891.17Sriastrad /* Reset getopt for lfs_cleaner_main. */ 901.17Sriastrad optreset = 1; 911.17Sriastrad optind = 1; 921.17Sriastrad 931.12Spooka p2m = p2k_init(0); 941.12Spooka if (!p2m) 951.12Spooka err(1, "init p2k"); 961.6Spooka /* 971.6Spooka * XXX: this particular piece inspired by the cleaner code. 981.6Spooka * obviously FIXXXME along with the cleaner. 991.6Spooka */ 1001.19Sbrad strlcpy(rawdev, RUMPRAWDEVICE, MAXPATHLEN); 1011.9Spooka rump_pub_etfs_register(rawdev, canon_dev, RUMP_ETFS_CHR); 1021.6Spooka 1031.6Spooka /* 1041.6Spooka * We basically have two choices: 1051.6Spooka * 1) run the cleaner in another process and do rump ipc syscalls 1061.6Spooka * 2) run it off a thread in this process and do rump syscalls 1071.6Spooka * as function calls. 1081.6Spooka * 1091.6Spooka * opt for "2" for now 1101.6Spooka */ 1111.8Spooka#ifdef CLEANER_TESTING 1121.8Spooka ukfs_mount(MOUNT_LFS, canon_dev, canon_dir, mntflags, 1131.8Spooka &args, sizeof(args)); 1141.8Spooka cleaner(canon_dir); 1151.8Spooka#endif 1161.10Spooka if (p2k_setup_diskfs(p2m, MOUNT_LFS, canon_dev, part, canon_dir, 1171.10Spooka mntflags, &args, sizeof(args)) == -1) 1181.8Spooka err(1, "mount"); 1191.14Spooka ukfs_part_release(part); 1201.8Spooka 1211.6Spooka#ifndef CLEANER_TESTING 1221.6Spooka if ((mntflags & MNT_RDONLY) == 0) { 1231.6Spooka if (pthread_create(&cleanerthread, NULL, 1241.6Spooka cleaner, canon_dir) == -1) 1251.6Spooka err(1, "cannot start cleaner"); 1261.6Spooka } 1271.6Spooka#endif 1281.6Spooka 1291.8Spooka rv = p2k_mainloop(p2m); 1301.8Spooka if (rv == -1) 1311.8Spooka err(1, "fs service"); 1321.1Spooka 1331.1Spooka return 0; 1341.1Spooka} 135