Source-Changes-HG archive

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

[src/trunk]: src/share/examples/puffs/pgfs puffs file system server backed by...



details:   https://anonhg.NetBSD.org/src/rev/fb415f98a569
branches:  trunk
changeset: 770317:fb415f98a569
user:      yamt <yamt%NetBSD.org@localhost>
date:      Wed Oct 12 01:05:00 2011 +0000

description:
puffs file system server backed by postgresql

diffstat:

 share/examples/puffs/pgfs/Makefile     |    22 +
 share/examples/puffs/pgfs/README       |    15 +
 share/examples/puffs/pgfs/check.sql    |   110 ++
 share/examples/puffs/pgfs/fix.sql      |    42 +
 share/examples/puffs/pgfs/mount.c      |   186 ++++
 share/examples/puffs/pgfs/newfs.sql    |   105 ++
 share/examples/puffs/pgfs/pgfs.h       |    77 +
 share/examples/puffs/pgfs/pgfs_db.c    |   967 ++++++++++++++++++++++++
 share/examples/puffs/pgfs/pgfs_db.h    |    86 ++
 share/examples/puffs/pgfs/pgfs_debug.c |    60 +
 share/examples/puffs/pgfs/pgfs_debug.h |    33 +
 share/examples/puffs/pgfs/pgfs_puffs.c |  1261 ++++++++++++++++++++++++++++++++
 share/examples/puffs/pgfs/pgfs_subs.c  |   927 +++++++++++++++++++++++
 share/examples/puffs/pgfs/pgfs_subs.h  |    73 +
 share/examples/puffs/pgfs/pgfs_waitq.c |    99 ++
 share/examples/puffs/pgfs/pgfs_waitq.h |    34 +
 16 files changed, 4097 insertions(+), 0 deletions(-)

diffs (truncated from 4161 to 300 lines):

diff -r 52dda1fa3fea -r fb415f98a569 share/examples/puffs/pgfs/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/puffs/pgfs/Makefile        Wed Oct 12 01:05:00 2011 +0000
@@ -0,0 +1,22 @@
+
+PROG=  mount_pgfs
+SRCS=  mount.c pgfs_subs.c pgfs_db.c pgfs_puffs.c pgfs_waitq.c pgfs_debug.c
+
+DPADD+=        ${LIBPUFFS} ${LIBUTIL}
+LDADD+=        -lpuffs -lutil
+
+NOMAN=
+
+PGINC!=                pg_config --includedir
+PGLIBDIR!=     pg_config --libdir
+CPPFLAGS+=     -I${PGINC}
+LDFLAGS+=      -L${PGLIBDIR}
+LDFLAGS+=      -Wl,-R${PGLIBDIR}
+LDFLAGS+=      -lpq
+
+DBG+=          -g
+#DBG?=         -g
+
+WARNS?=                4
+
+.include <bsd.prog.mk>
diff -r 52dda1fa3fea -r fb415f98a569 share/examples/puffs/pgfs/README
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/puffs/pgfs/README  Wed Oct 12 01:05:00 2011 +0000
@@ -0,0 +1,15 @@
+$NetBSD: README,v 1.1 2011/10/12 01:05:00 yamt Exp $
+
+pgfs - a puffs file system server backed by a PostgreSQL database
+
+install:
+       install postgresql (tested with 9.2devel)
+       # make
+       # make install
+
+newfs:
+       # createdb hoge
+       # psql -f newfs.sql hoge
+
+mount:
+       # mount_pgfs -o dbname=hoge,dbuser=takashi,nconn=16 a /mnt
diff -r 52dda1fa3fea -r fb415f98a569 share/examples/puffs/pgfs/check.sql
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/puffs/pgfs/check.sql       Wed Oct 12 01:05:00 2011 +0000
@@ -0,0 +1,110 @@
+-- $NetBSD: check.sql,v 1.1 2011/10/12 01:05:00 yamt Exp $
+
+-- Copyright (c)2010,2011 YAMAMOTO Takashi,
+-- 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 AND CONTRIBUTORS ``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.
+
+-- filesystem consistency checks.  ie. something like "fsck -n"
+
+BEGIN;
+SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+SET TRANSACTION READ ONLY;
+SET search_path TO pgfs;
+SELECT count(*) AS "unreferenced files (dirent)"
+       FROM file f LEFT JOIN dirent d
+       ON f.fileid = d.child_fileid
+       WHERE f.fileid <> 1 AND d.child_fileid IS NULL;
+SELECT count(*) AS "unreferenced files (nlink)"
+       FROM file f
+       WHERE f.nlink = 0;
+SELECT count(*) AS "regular files without datafork"
+       FROM file f LEFT JOIN datafork df
+       ON f.fileid = df.fileid
+       WHERE df.fileid IS NULL AND f.type IN ('regular', 'link');
+SELECT count(*) AS "broken datafork reference"
+       FROM file f INNER JOIN datafork df
+       ON f.fileid = df.fileid
+       WHERE f.type NOT IN ('regular', 'link');
+SELECT count(*) AS "unreferenced dataforks"
+       FROM file f RIGHT JOIN datafork df
+       ON f.fileid = df.fileid
+       WHERE f.fileid IS NULL;
+SELECT count(*) AS "dataforks without large object"
+       FROM datafork df LEFT JOIN pg_largeobject_metadata lm
+       ON df.loid = lm.oid
+       WHERE lm.oid IS NULL;
+SELECT count(*) AS "unreferenced large objects"
+       FROM datafork df RIGHT JOIN pg_largeobject_metadata lm
+       ON df.loid = lm.oid
+       WHERE df.loid IS NULL;
+SELECT count(*) AS "dirent broken parent_fileid references"
+       FROM dirent d LEFT JOIN file f
+       ON d.parent_fileid = f.fileid
+       WHERE f.fileid IS NULL OR f.type <> 'directory';
+SELECT count(*) AS "dirent broken child_fileid references"
+       FROM dirent d LEFT JOIN file f
+       ON d.child_fileid = f.fileid
+       WHERE f.fileid IS NULL;
+SELECT count(*) AS "dirent loops" FROM file f WHERE EXISTS (
+       WITH RECURSIVE r AS
+       (
+                       SELECT d.* FROM dirent d
+                               WHERE d.child_fileid = f.fileid
+               UNION ALL
+                       SELECT d.* FROM dirent d INNER JOIN r
+                               ON d.child_fileid = r.parent_fileid
+       )
+       SELECT * FROM r WHERE r.parent_fileid = f.fileid);
+SELECT count(*) AS "broken nlink"
+       FROM
+       (
+       SELECT coalesce(fp.fileid, fc.fileid) AS fileid,
+               coalesce(fp.nlink, 0) + coalesce(fc.nlink, 0) +
+               CASE
+                       WHEN coalesce(fp.fileid, fc.fileid) = 1 THEN 1
+                       ELSE 0
+               END
+               AS nlink
+               FROM
+               (
+               SELECT child_fileid AS fileid, count(*) AS nlink
+                       FROM dirent
+                       GROUP BY child_fileid
+               ) fp
+               FULL JOIN
+               (
+               SELECT count(*) AS nlink, d.parent_fileid AS fileid
+                       FROM dirent d
+                       JOIN file f
+                       ON d.child_fileid = f.fileid
+                       WHERE f.type = 'directory'
+                       GROUP BY parent_fileid
+               ) fc
+               ON fp.fileid = fc.fileid
+       ) d
+       FULL JOIN file f
+       ON d.fileid = f.fileid
+       WHERE (d.nlink IS NULL AND (f.fileid <> 1 AND f.nlink <> 0))
+           OR f.nlink IS NULL
+           OR d.nlink <> f.nlink;
+COMMIT;
diff -r 52dda1fa3fea -r fb415f98a569 share/examples/puffs/pgfs/fix.sql
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/puffs/pgfs/fix.sql Wed Oct 12 01:05:00 2011 +0000
@@ -0,0 +1,42 @@
+-- $NetBSD: fix.sql,v 1.1 2011/10/12 01:05:00 yamt Exp $
+
+-- Copyright (c)2011 YAMAMOTO Takashi,
+-- 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 AND CONTRIBUTORS ``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.
+
+-- remove orphaned files unless there's mount_pgfs connectd this db
+
+BEGIN;
+SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
+SET search_path TO pgfs;
+WITH
+pgfs_clients AS (SELECT -count(*) FROM pg_stat_activity WHERE
+       application_name = 'pgfs' AND datid IN (SELECT oid FROM pg_database
+       WHERE datname = current_database())),
+files_to_remove AS (DELETE FROM file WHERE nlink IN (SELECT * FROM pgfs_clients)
+       RETURNING fileid),
+removed_files AS (DELETE FROM datafork WHERE CASE WHEN fileid IN (SELECT * FROM
+       files_to_remove) THEN lo_unlink(loid) = 1 ELSE false END
+       RETURNING fileid)
+SELECT fileid AS "orphaned files" from removed_files;
+COMMIT;
diff -r 52dda1fa3fea -r fb415f98a569 share/examples/puffs/pgfs/mount.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/examples/puffs/pgfs/mount.c Wed Oct 12 01:05:00 2011 +0000
@@ -0,0 +1,186 @@
+/*     $NetBSD: mount.c,v 1.1 2011/10/12 01:05:00 yamt Exp $   */
+
+/*-
+ * Copyright (c)2010,2011 YAMAMOTO Takashi,
+ * 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 AND CONTRIBUTORS ``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.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: mount.c,v 1.1 2011/10/12 01:05:00 yamt Exp $");
+#endif /* not lint */
+
+#include <err.h>
+#include <errno.h>
+#include <mntopts.h>
+#include <paths.h>
+#include <puffs.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "pgfs.h"
+#include "pgfs_db.h"
+
+#define        PGFS_MNT_ALT_DUMMY      1
+#define        PGFS_MNT_ALT_DEBUG      2
+
+int
+main(int argc, char *argv[])
+{
+       extern char *optarg;
+       extern int optind;
+       mntoptparse_t mp;
+       struct puffs_usermount *pu;
+       struct puffs_ops *pops;
+       int mntflags;
+       int altmntflags;
+       int ch;
+       int error;
+       const char *dbname = NULL;
+       const char *dbuser = NULL;
+       static const struct mntopt mopts[] = {
+               MOPT_STDOPTS,
+               MOPT_SYNC,
+               { .m_option = "dbname", .m_inverse = 0,
+                 .m_flag = PGFS_MNT_ALT_DUMMY, .m_altloc = 1, },
+               { .m_option = "dbuser", .m_inverse = 0,
+                 .m_flag = PGFS_MNT_ALT_DUMMY, .m_altloc = 1, },
+               { .m_option = "debug", .m_inverse = 0,
+                 .m_flag = PGFS_MNT_ALT_DEBUG, .m_altloc = 1, },
+               { .m_option = "nconn", .m_inverse = 0,
+                 .m_flag = PGFS_MNT_ALT_DUMMY, .m_altloc = 1, },
+               MOPT_NULL,
+       };
+       uint32_t pflags = PUFFS_KFLAG_NOCACHE_NAME|PUFFS_KFLAG_WTCACHE;
+       unsigned int nconn = 8;
+       bool debug = false;
+       bool dosync;
+
+       mntflags = 0;
+       altmntflags = 0;
+       while ((ch = getopt(argc, argv, "o:")) != -1) {
+               long v;
+
+               switch (ch) {
+               case 'o':
+                       mp = getmntopts(optarg, mopts, &mntflags,
+                           &altmntflags);
+                       if (mp == NULL) {
+                               err(EXIT_FAILURE, "getmntopts");



Home | Main Index | Thread Index | Old Index