Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/puffs/rump_nqmfs Not Quite MFS



details:   https://anonhg.NetBSD.org/src/rev/32bed2d91e6a
branches:  trunk
changeset: 752862:32bed2d91e6a
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Mar 08 12:46:33 2010 +0000

description:
Not Quite MFS

Instead of copulating with newfs to produce a new FFS image into
memory, mmap() a given existing image and pass that as the backing
store.  If -s is given, mmap is done with MAP_SHARED and changes
are kept across mounts, else MAP_COPY (i.e. MAP_PRIVATE for us) is
done and changes are lost when the server exits.

Note: -s does not guarantee any kind of file system safety whatsoever
and in case of kill, crash, exit or other form of elusion,
everything will be, according to our theme, quite screwed.

diffstat:

 usr.sbin/puffs/rump_nqmfs/Makefile     |   12 +++
 usr.sbin/puffs/rump_nqmfs/rump_nqmfs.c |  131 +++++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+), 0 deletions(-)

diffs (151 lines):

diff -r 5bf4ae676bc8 -r 32bed2d91e6a usr.sbin/puffs/rump_nqmfs/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/puffs/rump_nqmfs/Makefile        Mon Mar 08 12:46:33 2010 +0000
@@ -0,0 +1,12 @@
+#      $NetBSD: Makefile,v 1.1 2010/03/08 12:46:33 pooka Exp $
+#
+
+PROG=  rump_nqmfs
+
+LDADD+=        -lrumpfs_mfs -lrumpfs_ffs
+
+ISRUMP=                # affirmative
+NOMAN=         # si, signor
+RUMP_DISKFS=   # well, uh, yea, but there's ffs
+
+.include <bsd.prog.mk>
diff -r 5bf4ae676bc8 -r 32bed2d91e6a usr.sbin/puffs/rump_nqmfs/rump_nqmfs.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/puffs/rump_nqmfs/rump_nqmfs.c    Mon Mar 08 12:46:33 2010 +0000
@@ -0,0 +1,131 @@
+/*     $NetBSD: rump_nqmfs.c,v 1.1 2010/03/08 12:46:34 pooka Exp $     */
+
+/*
+ * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Not Quite MFS.  Instead of allocating memory and creating a FFS file system
+ * there, mmap a file (which should contain ffs) and use that as the backend.
+ * You can also give a newly created image as the file ...
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <err.h>
+#include <mntopts.h>
+#include <puffs.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <rump/p2k.h>
+#include <rump/ukfs.h>
+
+const struct mntopt mopts[] = {
+       MOPT_STDOPTS,
+       MOPT_NULL,
+};
+
+static void
+usage(void)
+{
+
+       fprintf(stderr, "%s: [-o args] fspec mountpoint\n", getprogname());
+       exit(1);
+}
+
+static struct mfs_args args;
+static char *mntpath, *mntfile;
+static int mntflags, altflags;
+
+int
+main(int argc, char *argv[])
+{
+       struct stat sb;
+       mntoptparse_t mp;
+       void *membase;
+       int ch, fd, rdonly, shared;
+
+       setprogname(argv[0]);
+       puffs_unmountonsignal(SIGINT, true);
+       puffs_unmountonsignal(SIGTERM, true);
+
+       shared = mntflags = altflags = 0;
+
+       memset(&args, 0, sizeof(args));
+       while ((ch = getopt(argc, argv, "o:s")) != -1) {
+               switch (ch) {
+               case 'o':
+                       mp = getmntopts(optarg, mopts, &mntflags, &altflags);
+                       if (mp == NULL)
+                               err(1, "getmntopts");
+                       freemntopts(mp);
+                       break;
+               case 's':
+                       shared = 1;
+                       break;
+               default:
+                       usage();
+                       break;
+               }
+       }
+       argc -= optind;
+       argv += optind;
+       
+       if (argc != 2)
+               usage();
+       mntfile = argv[0];
+       mntpath = argv[1];
+       rdonly = mntflags & MNT_RDONLY;
+
+       if (stat(mntfile, &sb) == -1)
+               err(1, "stat fspec");
+       if (!S_ISREG(sb.st_mode))
+               errx(1, "fspec must be a regular file");
+
+       fd = open(mntfile, rdonly ? O_RDONLY: O_RDWR);
+       if (fd == -1)
+               err(1, "open fspec");
+
+       membase = mmap(NULL, sb.st_size, PROT_READ | (rdonly ? 0 : PROT_WRITE),
+           MAP_FILE | (shared ? MAP_SHARED : MAP_COPY), fd, 0);
+       if (membase == MAP_FAILED)
+               err(1, "cannot mmap fpsec");
+
+       args.fspec = mntfile;
+       args.base = membase;
+       args.size = sb.st_size;
+
+       if (p2k_run_fs(MOUNT_MFS, "/swabbie", mntpath,
+           0, &args, sizeof(args), 0) == -1)
+               err(1, "p2k");
+
+       return 0;
+}



Home | Main Index | Thread Index | Old Index