CVS commit: src/share/examples/puffs/pgfs

2014-10-18 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Oct 18 07:11:07 UTC 2014

Modified Files:
src/share/examples/puffs/pgfs: pgfs_puffs.c

Log Message:
de-foodify comment


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/share/examples/puffs/pgfs/pgfs_puffs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/pgfs_puffs.c
diff -u src/share/examples/puffs/pgfs/pgfs_puffs.c:1.4 src/share/examples/puffs/pgfs/pgfs_puffs.c:1.5
--- src/share/examples/puffs/pgfs/pgfs_puffs.c:1.4	Wed Apr 11 14:26:44 2012
+++ src/share/examples/puffs/pgfs/pgfs_puffs.c	Sat Oct 18 07:11:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_puffs.c,v 1.4 2012/04/11 14:26:44 yamt Exp $	*/
+/*	$NetBSD: pgfs_puffs.c,v 1.5 2014/10/18 07:11:07 snj Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -32,7 +32,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_puffs.c,v 1.4 2012/04/11 14:26:44 yamt Exp $);
+__RCSID($NetBSD: pgfs_puffs.c,v 1.5 2014/10/18 07:11:07 snj Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -548,7 +548,7 @@ pgfs_node_read(struct puffs_usermount *p
 retry:
 	xc = begin(pu, read);
 	/*
-	 * try to update atime first as it's prune to conflict with other
+	 * try to update atime first as it's prone to conflict with other
 	 * transactions.  eg. read-ahead requests can conflict each other.
 	 * we don't want to retry my_lo_read as it's expensive.
 	 *



CVS commit: src/share/examples/puffs/pgfs

2013-04-22 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Mon Apr 22 13:27:08 UTC 2013

Modified Files:
src/share/examples/puffs/pgfs: Makefile

Log Message:
make pg_config overridable


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/examples/puffs/pgfs/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/Makefile
diff -u src/share/examples/puffs/pgfs/Makefile:1.1 src/share/examples/puffs/pgfs/Makefile:1.2
--- src/share/examples/puffs/pgfs/Makefile:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/Makefile	Mon Apr 22 13:27:08 2013
@@ -7,8 +7,10 @@ LDADD+=	-lpuffs -lutil
 
 NOMAN=
 
-PGINC!=		pg_config --includedir
-PGLIBDIR!=	pg_config --libdir
+PG_CONFIG=	pg_config
+
+PGINC!=		${PG_CONFIG} --includedir
+PGLIBDIR!=	${PG_CONFIG} --libdir
 CPPFLAGS+=	-I${PGINC}
 LDFLAGS+=	-L${PGLIBDIR}
 LDFLAGS+=	-Wl,-R${PGLIBDIR}



CVS commit: src/share/examples/puffs/pgfs

2012-04-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Apr 11 14:25:54 UTC 2012

Modified Files:
src/share/examples/puffs/pgfs: mount.c pgfs_puffs.c

Log Message:
- enable writeback cache and namecache.
- use setback hack to reduce number of puffs OPs.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/examples/puffs/pgfs/mount.c \
src/share/examples/puffs/pgfs/pgfs_puffs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/mount.c
diff -u src/share/examples/puffs/pgfs/mount.c:1.1 src/share/examples/puffs/pgfs/mount.c:1.2
--- src/share/examples/puffs/pgfs/mount.c:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/mount.c	Wed Apr 11 14:25:54 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mount.c,v 1.1 2011/10/12 01:05:00 yamt Exp $	*/
+/*	$NetBSD: mount.c,v 1.2 2012/04/11 14:25:54 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: mount.c,v 1.1 2011/10/12 01:05:00 yamt Exp $);
+__RCSID($NetBSD: mount.c,v 1.2 2012/04/11 14:25:54 yamt Exp $);
 #endif /* not lint */
 
 #include err.h
@@ -73,7 +73,7 @@ main(int argc, char *argv[])
 		  .m_flag = PGFS_MNT_ALT_DUMMY, .m_altloc = 1, },
 		MOPT_NULL,
 	};
-	uint32_t pflags = PUFFS_KFLAG_NOCACHE_NAME|PUFFS_KFLAG_WTCACHE;
+	uint32_t pflags = PUFFS_KFLAG_IAONDEMAND;
 	unsigned int nconn = 8;
 	bool debug = false;
 	bool dosync;
Index: src/share/examples/puffs/pgfs/pgfs_puffs.c
diff -u src/share/examples/puffs/pgfs/pgfs_puffs.c:1.1 src/share/examples/puffs/pgfs/pgfs_puffs.c:1.2
--- src/share/examples/puffs/pgfs/pgfs_puffs.c:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/pgfs_puffs.c	Wed Apr 11 14:25:54 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_puffs.c,v 1.1 2011/10/12 01:05:00 yamt Exp $	*/
+/*	$NetBSD: pgfs_puffs.c,v 1.2 2012/04/11 14:25:54 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -32,7 +32,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_puffs.c,v 1.1 2011/10/12 01:05:00 yamt Exp $);
+__RCSID($NetBSD: pgfs_puffs.c,v 1.2 2012/04/11 14:25:54 yamt Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -655,6 +655,7 @@ retry:
 	if (error != 0) {
 		goto got_error;
 	}
+	puffs_setback(puffs_cc_getcc(pu), PUFFS_SETBACK_INACT_N2);
 	return 0;
 got_error:
 	rollback(xc);
@@ -704,6 +705,7 @@ retry:
 	if (error != 0) {
 		goto got_error;
 	}
+	puffs_setback(puffs_cc_getcc(pu), PUFFS_SETBACK_INACT_N2);
 	return 0;
 got_error:
 	rollback(xc);



CVS commit: src/share/examples/puffs/pgfs

2012-04-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Apr 11 14:26:20 UTC 2012

Modified Files:
src/share/examples/puffs/pgfs: newfs.sql pgfs_puffs.c pgfs_subs.c
pgfs_subs.h

Log Message:
reduce number of SQL statements for inactivate


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/examples/puffs/pgfs/newfs.sql \
src/share/examples/puffs/pgfs/pgfs_subs.h
cvs rdiff -u -r1.2 -r1.3 src/share/examples/puffs/pgfs/pgfs_puffs.c
cvs rdiff -u -r1.3 -r1.4 src/share/examples/puffs/pgfs/pgfs_subs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/newfs.sql
diff -u src/share/examples/puffs/pgfs/newfs.sql:1.1 src/share/examples/puffs/pgfs/newfs.sql:1.2
--- src/share/examples/puffs/pgfs/newfs.sql:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/newfs.sql	Wed Apr 11 14:26:19 2012
@@ -1,4 +1,4 @@
--- $NetBSD: newfs.sql,v 1.1 2011/10/12 01:05:00 yamt Exp $
+-- $NetBSD: newfs.sql,v 1.2 2012/04/11 14:26:19 yamt Exp $
 
 -- Copyright (c)2010,2011 YAMAMOTO Takashi,
 -- All rights reserved.
@@ -71,7 +71,7 @@ CREATE TABLE file (
 -- datafork table maintains the association between our files and its backing
 -- large objects.
 CREATE TABLE datafork (
-	fileid fileid PRIMARY KEY REFERENCES file,
+	fileid fileid PRIMARY KEY, -- REFERENCES file
 	loid Oid NOT NULL UNIQUE);
 -- we want the following but lo lives in system catalogs.
 --	loid REFERENCES pg_largeobject_metadata(oid);
Index: src/share/examples/puffs/pgfs/pgfs_subs.h
diff -u src/share/examples/puffs/pgfs/pgfs_subs.h:1.1 src/share/examples/puffs/pgfs/pgfs_subs.h:1.2
--- src/share/examples/puffs/pgfs/pgfs_subs.h:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/pgfs_subs.h	Wed Apr 11 14:26:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_subs.h,v 1.1 2011/10/12 01:05:00 yamt Exp $	*/
+/*	$NetBSD: pgfs_subs.h,v 1.2 2012/04/11 14:26:19 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -68,6 +68,6 @@ int mklinkfile(struct Xconn *, fileid_t,
 uid_t, gid_t, fileid_t *);
 int mklinkfile_lo(struct Xconn *, fileid_t, const char *, enum vtype, mode_t,
 uid_t, gid_t, fileid_t *, int *);
-int cleanupfile(struct Xconn *, fileid_t, struct vattr *);
+int cleanupfile(struct Xconn *, fileid_t);
 int check_path(struct Xconn *, fileid_t, fileid_t);
 int isempty(struct Xconn *, fileid_t, bool *);

Index: src/share/examples/puffs/pgfs/pgfs_puffs.c
diff -u src/share/examples/puffs/pgfs/pgfs_puffs.c:1.2 src/share/examples/puffs/pgfs/pgfs_puffs.c:1.3
--- src/share/examples/puffs/pgfs/pgfs_puffs.c:1.2	Wed Apr 11 14:25:54 2012
+++ src/share/examples/puffs/pgfs/pgfs_puffs.c	Wed Apr 11 14:26:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_puffs.c,v 1.2 2012/04/11 14:25:54 yamt Exp $	*/
+/*	$NetBSD: pgfs_puffs.c,v 1.3 2012/04/11 14:26:19 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -32,7 +32,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_puffs.c,v 1.2 2012/04/11 14:25:54 yamt Exp $);
+__RCSID($NetBSD: pgfs_puffs.c,v 1.3 2012/04/11 14:26:19 yamt Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -720,7 +720,6 @@ pgfs_node_inactive(struct puffs_usermoun
 {
 	struct Xconn *xc;
 	fileid_t fileid = cookie_to_fileid(opc);
-	struct vattr va;
 	int error;
 
 	/*
@@ -734,18 +733,10 @@ pgfs_node_inactive(struct puffs_usermoun
 	DPRINTF(%llu\n, fileid);
 retry:
 	xc = begin(pu);
-	error = getattr(xc, fileid, va, GETATTR_NLINK|GETATTR_TYPE);
+	error = cleanupfile(xc, fileid);
 	if (error != 0) {
-		DPRINTF(%llu GETATTR fail\n, fileid);
 		goto got_error;
 	}
-	if (va.va_nlink == 0) {
-		DPRINTF(%llu nlink=0\n, fileid);
-		error = cleanupfile(xc, fileid, va);
-		if (error != 0) {
-			goto got_error;
-		}
-	}
 	error = commit(xc);
 	if (error != 0) {
 		goto got_error;

Index: src/share/examples/puffs/pgfs/pgfs_subs.c
diff -u src/share/examples/puffs/pgfs/pgfs_subs.c:1.3 src/share/examples/puffs/pgfs/pgfs_subs.c:1.4
--- src/share/examples/puffs/pgfs/pgfs_subs.c:1.3	Thu Oct 13 14:40:06 2011
+++ src/share/examples/puffs/pgfs/pgfs_subs.c	Wed Apr 11 14:26:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_subs.c,v 1.3 2011/10/13 14:40:06 yamt Exp $	*/
+/*	$NetBSD: pgfs_subs.c,v 1.4 2012/04/11 14:26:19 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -46,7 +46,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_subs.c,v 1.3 2011/10/13 14:40:06 yamt Exp $);
+__RCSID($NetBSD: pgfs_subs.c,v 1.4 2012/04/11 14:26:19 yamt Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -785,18 +785,31 @@ mklinkfile_lo(struct Xconn *xc, fileid_t
 }
 
 int
-cleanupfile(struct Xconn *xc, fileid_t fileid, struct vattr *va)
+cleanupfile(struct Xconn *xc, fileid_t fileid)
 {
 	static struct cmd *c;
+	char *type;
+	unsigned int vtype;
+	int error;
 
-	/*
-	 * XXX what to do when the filesystem is shared?
-	 */
-
-	if (va-va_type == VREG || va-va_type == VLNK) {

CVS commit: src/share/examples/puffs/pgfs

2012-04-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Apr 11 14:26:45 UTC 2012

Modified Files:
src/share/examples/puffs/pgfs: pgfs_db.c pgfs_db.h pgfs_puffs.c

Log Message:
abuse application_name to show the last puffs activity for the connection.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/examples/puffs/pgfs/pgfs_db.c \
src/share/examples/puffs/pgfs/pgfs_db.h
cvs rdiff -u -r1.3 -r1.4 src/share/examples/puffs/pgfs/pgfs_puffs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/pgfs_db.c
diff -u src/share/examples/puffs/pgfs/pgfs_db.c:1.1 src/share/examples/puffs/pgfs/pgfs_db.c:1.2
--- src/share/examples/puffs/pgfs/pgfs_db.c:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/pgfs_db.c	Wed Apr 11 14:26:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_db.c,v 1.1 2011/10/12 01:05:00 yamt Exp $	*/
+/*	$NetBSD: pgfs_db.c,v 1.2 2012/04/11 14:26:44 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -32,7 +32,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_db.c,v 1.1 2011/10/12 01:05:00 yamt Exp $);
+__RCSID($NetBSD: pgfs_db.c,v 1.2 2012/04/11 14:26:44 yamt Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -652,13 +652,50 @@ simplefetch(struct Xconn *xc, Oid type, 
 	return error;
 }
 
+static void
+setlabel(struct Xconn *xc, const char *label)
+{
+	int error;
+
+	/*
+	 * put the label into application_name so that it's shown in
+	 * pg_stat_activity.  we are sure that our labels don't need
+	 * PQescapeStringConn.
+	 *
+	 * example:
+	 *	SELECT pid,application_name,query FROM pg_stat_activity
+	 *	WHERE state  'idle'
+	 */
+
+	if (label != NULL) {
+		struct cmd *c;
+		char cmd_str[1024];
+
+		snprintf(cmd_str, sizeof(cmd_str),
+		SET application_name TO 'pgfs: %s', label);
+		c = createcmd(cmd_str, CMD_NOPREPARE);
+		error = simplecmd(xc, c);
+		freecmd(c);
+		assert(error == 0);
+	} else {
+#if 0 /* don't bother to clear label */
+		static struct cmd *c;
+
+		CREATECMD_NOPARAM(c, SET application_name TO 'pgfs');
+		error = simplecmd(xc, c);
+		assert(error == 0);
+#endif
+	}
+}
+
 struct Xconn *
-begin(struct puffs_usermount *pu)
+begin(struct puffs_usermount *pu, const char *label)
 {
 	struct Xconn *xc = getxc(puffs_cc_getcc(pu));
 	static struct cmd *c;
 	int error;
 
+	setlabel(xc, label);
 	CREATECMD_NOPARAM(c, BEGIN);
 	assert(!xc-in_trans);
 	error = simplecmd(xc, c);
@@ -669,12 +706,13 @@ begin(struct puffs_usermount *pu)
 }
 
 struct Xconn *
-begin_readonly(struct puffs_usermount *pu)
+begin_readonly(struct puffs_usermount *pu, const char *label)
 {
 	struct Xconn *xc = getxc(puffs_cc_getcc(pu));
 	static struct cmd *c;
 	int error;
 
+	setlabel(xc, label);
 	CREATECMD_NOPARAM(c, BEGIN READ ONLY);
 	assert(!xc-in_trans);
 	error = simplecmd(xc, c);
@@ -706,6 +744,7 @@ rollback(struct Xconn *xc)
 		assert(error == 0);
 	}
 	DPRINTF(xc %p rollback %p\n, xc, xc-owner);
+	setlabel(xc, NULL);
 	relxc(xc);
 }
 
@@ -717,6 +756,7 @@ commit(struct Xconn *xc)
 
 	CREATECMD_NOPARAM(c, COMMIT);
 	error = simplecmd(xc, c);
+	setlabel(xc, NULL);
 	if (error == 0) {
 		DPRINTF(xc %p commit %p\n, xc, xc-owner);
 		relxc(xc);
@@ -841,7 +881,7 @@ pgfs_connectdb(struct puffs_usermount *p
 		assert(xc-id  32);
 		PQsetNoticeReceiver(conn, pgfs_notice_receiver, xc);
 		TAILQ_INSERT_HEAD(xclist, xc, list);
-		xc2 = begin(pu);
+		xc2 = begin(pu, NULL);
 		assert(xc2 == xc);
 		c = createcmd(SET search_path TO pgfs, CMD_NOPREPARE);
 		error = simplecmd(xc, c);
@@ -929,7 +969,7 @@ flush_xacts(struct puffs_usermount *pu)
 	DPRINTF(%p start flushing\n, cc);
 	flusher = cc;
 retry:
-	xc = begin(pu);
+	xc = begin(pu, flush);
 	CREATECMD_NOPARAM(c, SELECT setval('dummyseq', 1) WHERE 
 	pg_current_xlog_insert_location()  pg_current_xlog_location());
 	error = sendcmd(xc, c);
Index: src/share/examples/puffs/pgfs/pgfs_db.h
diff -u src/share/examples/puffs/pgfs/pgfs_db.h:1.1 src/share/examples/puffs/pgfs/pgfs_db.h:1.2
--- src/share/examples/puffs/pgfs/pgfs_db.h:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/pgfs_db.h	Wed Apr 11 14:26:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_db.h,v 1.1 2011/10/12 01:05:00 yamt Exp $	*/
+/*	$NetBSD: pgfs_db.h,v 1.2 2012/04/11 14:26:44 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -60,8 +60,8 @@ void fetchinit(struct fetchstatus *, str
 int fetchnext(struct fetchstatus *, unsigned int, const Oid *, ...);
 void fetchdone(struct fetchstatus *);
 
-struct Xconn *begin(struct puffs_usermount *);
-struct Xconn *begin_readonly(struct puffs_usermount *);
+struct Xconn *begin(struct puffs_usermount *, const char *);
+struct Xconn *begin_readonly(struct puffs_usermount *, const char *);
 void rollback(struct Xconn *);
 int commit(struct Xconn *);
 int commit_sync(struct Xconn *);

Index: src/share/examples/puffs/pgfs/pgfs_puffs.c
diff -u 

CVS commit: src/share/examples/puffs/pgfs

2012-04-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Apr 11 14:27:15 UTC 2012

Modified Files:
src/share/examples/puffs/pgfs: newfs.sql

Log Message:
remove FK references as it creates more problems than it solves.
particularly, it involves shared lock on the referenced table
and causes frequent deadlock.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/share/examples/puffs/pgfs/newfs.sql

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/newfs.sql
diff -u src/share/examples/puffs/pgfs/newfs.sql:1.2 src/share/examples/puffs/pgfs/newfs.sql:1.3
--- src/share/examples/puffs/pgfs/newfs.sql:1.2	Wed Apr 11 14:26:19 2012
+++ src/share/examples/puffs/pgfs/newfs.sql	Wed Apr 11 14:27:15 2012
@@ -1,4 +1,4 @@
--- $NetBSD: newfs.sql,v 1.2 2012/04/11 14:26:19 yamt Exp $
+-- $NetBSD: newfs.sql,v 1.3 2012/04/11 14:27:15 yamt Exp $
 
 -- Copyright (c)2010,2011 YAMAMOTO Takashi,
 -- All rights reserved.
@@ -79,10 +79,10 @@ CREATE TABLE datafork (
 -- a row in the dirent table describes a directory entry.
 -- the .. and . entries are handled differently and never appear here.
 CREATE TABLE dirent (
-	parent_fileid fileid NOT NULL REFERENCES file,
+	parent_fileid fileid NOT NULL, -- REFERENCES file,
 	name text NOT NULL,
 	cookie int8 NOT NULL UNIQUE DEFAULT nextval('dircookie_seq'),
-	child_fileid fileid NOT NULL REFERENCES file,
+	child_fileid fileid NOT NULL, -- REFERENCES file,
 	CONSTRAINT dirent_pkey PRIMARY KEY(parent_fileid, name),
 	CONSTRAINT dirent_notdot CHECK(name  '.'),
 	CONSTRAINT dirent_notdotdot CHECK(name  '..'),



CVS commit: src/share/examples/puffs/pgfs

2012-04-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Apr 11 14:27:43 UTC 2012

Modified Files:
src/share/examples/puffs/pgfs: pgfs_db.c

Log Message:
setlabel: save SQL statements by caching the last label


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/share/examples/puffs/pgfs/pgfs_db.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/pgfs_db.c
diff -u src/share/examples/puffs/pgfs/pgfs_db.c:1.2 src/share/examples/puffs/pgfs/pgfs_db.c:1.3
--- src/share/examples/puffs/pgfs/pgfs_db.c:1.2	Wed Apr 11 14:26:44 2012
+++ src/share/examples/puffs/pgfs/pgfs_db.c	Wed Apr 11 14:27:43 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_db.c,v 1.2 2012/04/11 14:26:44 yamt Exp $	*/
+/*	$NetBSD: pgfs_db.c,v 1.3 2012/04/11 14:27:43 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -32,7 +32,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_db.c,v 1.2 2012/04/11 14:26:44 yamt Exp $);
+__RCSID($NetBSD: pgfs_db.c,v 1.3 2012/04/11 14:27:43 yamt Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -61,6 +61,7 @@ struct Xconn {
 	struct puffs_cc *owner;
 	bool in_trans;
 	int id;
+	const char *label;
 };
 
 static void
@@ -652,6 +653,11 @@ simplefetch(struct Xconn *xc, Oid type, 
 	return error;
 }
 
+/*
+ * setlabel: set the descriptive label for the connection.
+ *
+ * we use simple pointer comparison for label equality check.
+ */
 static void
 setlabel(struct Xconn *xc, const char *label)
 {
@@ -667,7 +673,7 @@ setlabel(struct Xconn *xc, const char *l
 	 *	WHERE state  'idle'
 	 */
 
-	if (label != NULL) {
+	if (label != NULL  label != xc-label) {
 		struct cmd *c;
 		char cmd_str[1024];
 
@@ -677,6 +683,7 @@ setlabel(struct Xconn *xc, const char *l
 		error = simplecmd(xc, c);
 		freecmd(c);
 		assert(error == 0);
+		xc-label = label;
 	} else {
 #if 0 /* don't bother to clear label */
 		static struct cmd *c;
@@ -878,6 +885,7 @@ pgfs_connectdb(struct puffs_usermount *p
 		xc-owner = NULL;
 		xc-in_trans = false;
 		xc-id = xcid++;
+		xc-label = NULL;
 		assert(xc-id  32);
 		PQsetNoticeReceiver(conn, pgfs_notice_receiver, xc);
 		TAILQ_INSERT_HEAD(xclist, xc, list);



CVS commit: src/share/examples/puffs/pgfs

2012-04-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Apr 11 14:28:18 UTC 2012

Modified Files:
src/share/examples/puffs/pgfs: pgfs_subs.c

Log Message:
don't bother to call lo_close.
as we ever open a few LOs at most in a transaction, just let them be closed
automatically at the end of the transaction.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/share/examples/puffs/pgfs/pgfs_subs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/pgfs_subs.c
diff -u src/share/examples/puffs/pgfs/pgfs_subs.c:1.4 src/share/examples/puffs/pgfs/pgfs_subs.c:1.5
--- src/share/examples/puffs/pgfs/pgfs_subs.c:1.4	Wed Apr 11 14:26:19 2012
+++ src/share/examples/puffs/pgfs/pgfs_subs.c	Wed Apr 11 14:28:18 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_subs.c,v 1.4 2012/04/11 14:26:19 yamt Exp $	*/
+/*	$NetBSD: pgfs_subs.c,v 1.5 2012/04/11 14:28:18 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -46,7 +46,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_subs.c,v 1.4 2012/04/11 14:26:19 yamt Exp $);
+__RCSID($NetBSD: pgfs_subs.c,v 1.5 2012/04/11 14:28:18 yamt Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -335,6 +335,14 @@ my_lo_open(struct Xconn *xc, Oid loid, i
 int
 my_lo_close(struct Xconn *xc, int32_t fd)
 {
+#if 1
+	/*
+	 * do nothing.
+	 *
+	 * LO handles are automatically closed at the end of transactions.
+	 * our transactions are small enough.
+	 */
+#else
 	static struct cmd *c;
 	int32_t ret;
 	int error;
@@ -349,6 +357,7 @@ my_lo_close(struct Xconn *xc, int32_t fd
 		return error;
 	}
 	assert(ret == 0);
+#endif
 	return 0;
 }
 



CVS commit: src/share/examples/puffs/pgfs

2012-04-11 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Apr 11 14:28:46 UTC 2012

Modified Files:
src/share/examples/puffs/pgfs: newfs.sql

Log Message:
comment


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/share/examples/puffs/pgfs/newfs.sql

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/newfs.sql
diff -u src/share/examples/puffs/pgfs/newfs.sql:1.3 src/share/examples/puffs/pgfs/newfs.sql:1.4
--- src/share/examples/puffs/pgfs/newfs.sql:1.3	Wed Apr 11 14:27:15 2012
+++ src/share/examples/puffs/pgfs/newfs.sql	Wed Apr 11 14:28:46 2012
@@ -1,4 +1,4 @@
--- $NetBSD: newfs.sql,v 1.3 2012/04/11 14:27:15 yamt Exp $
+-- $NetBSD: newfs.sql,v 1.4 2012/04/11 14:28:46 yamt Exp $
 
 -- Copyright (c)2010,2011 YAMAMOTO Takashi,
 -- All rights reserved.
@@ -44,8 +44,8 @@ CREATE DOMAIN uid AS int8 NOT NULL CHECK
 CREATE DOMAIN gid AS int8 NOT NULL CHECK(VALUE = 0);
 CREATE DOMAIN mode AS int8 NOT NULL CHECK(VALUE = 0 AND VALUE = 7*8*8+7*8+7);
 CREATE DOMAIN nlink AS int8 NOT NULL CHECK(VALUE = 0);
-CREATE SEQUENCE fileid_seq START WITH 1;
-CREATE SEQUENCE dircookie_seq START WITH 3;
+CREATE SEQUENCE fileid_seq START WITH 1; -- 1 will be used for root directory
+CREATE SEQUENCE dircookie_seq START WITH 3; -- see PGFS_DIRCOOKIE_*
 CREATE TYPE filetype AS ENUM (
 	'regular',
 	'directory',



CVS commit: src/share/examples/puffs/pgfs

2011-10-13 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Thu Oct 13 14:40:06 UTC 2011

Modified Files:
src/share/examples/puffs/pgfs: pgfs_subs.c

Log Message:
isempty: fix a query result type.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/share/examples/puffs/pgfs/pgfs_subs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/pgfs_subs.c
diff -u src/share/examples/puffs/pgfs/pgfs_subs.c:1.2 src/share/examples/puffs/pgfs/pgfs_subs.c:1.3
--- src/share/examples/puffs/pgfs/pgfs_subs.c:1.2	Wed Oct 12 16:24:39 2011
+++ src/share/examples/puffs/pgfs/pgfs_subs.c	Thu Oct 13 14:40:06 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_subs.c,v 1.2 2011/10/12 16:24:39 yamt Exp $	*/
+/*	$NetBSD: pgfs_subs.c,v 1.3 2011/10/13 14:40:06 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -46,7 +46,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_subs.c,v 1.2 2011/10/12 16:24:39 yamt Exp $);
+__RCSID($NetBSD: pgfs_subs.c,v 1.3 2011/10/13 14:40:06 yamt Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -906,10 +906,8 @@ check_path(struct Xconn *xc, fileid_t ga
 int
 isempty(struct Xconn *xc, fileid_t fileid, bool *emptyp)
 {
-	fileid_t dummy;
+	int32_t dummy;
 	static struct cmd *c;
-	static const Oid types[] = { INT8OID, };
-	struct fetchstatus s;
 	int error;
 
 	CREATECMD(c,
@@ -919,9 +917,7 @@ isempty(struct Xconn *xc, fileid_t filei
 	if (error != 0) {
 		return error;
 	}
-	fetchinit(s, xc);
-	error = FETCHNEXT(s, types, dummy);
-	fetchdone(s);
+	error = simplefetch(xc, INT4OID, dummy);
 	assert(error != 0 || dummy == 1);
 	if (error == ENOENT) {
 		*emptyp = true;



CVS commit: src/share/examples/puffs/pgfs

2011-10-12 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Wed Oct 12 16:24:39 UTC 2011

Modified Files:
src/share/examples/puffs/pgfs: fix.sql pgfs_subs.c

Log Message:
tweak some sql statements to improve chances to use the index.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/examples/puffs/pgfs/fix.sql \
src/share/examples/puffs/pgfs/pgfs_subs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/examples/puffs/pgfs/fix.sql
diff -u src/share/examples/puffs/pgfs/fix.sql:1.1 src/share/examples/puffs/pgfs/fix.sql:1.2
--- src/share/examples/puffs/pgfs/fix.sql:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/fix.sql	Wed Oct 12 16:24:39 2011
@@ -1,4 +1,4 @@
--- $NetBSD: fix.sql,v 1.1 2011/10/12 01:05:00 yamt Exp $
+-- $NetBSD: fix.sql,v 1.2 2011/10/12 16:24:39 yamt Exp $
 
 -- Copyright (c)2011 YAMAMOTO Takashi,
 -- All rights reserved.
@@ -35,8 +35,7 @@ pgfs_clients AS (SELECT -count(*) FROM p
 	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;
+removed_files AS (DELETE FROM datafork WHERE fileid IN (SELECT * FROM
+	files_to_remove) RETURNING fileid, loid)
+SELECT fileid AS orphaned files FROM removed_files WHERE lo_unlink(loid) = 1;
 COMMIT;
Index: src/share/examples/puffs/pgfs/pgfs_subs.c
diff -u src/share/examples/puffs/pgfs/pgfs_subs.c:1.1 src/share/examples/puffs/pgfs/pgfs_subs.c:1.2
--- src/share/examples/puffs/pgfs/pgfs_subs.c:1.1	Wed Oct 12 01:05:00 2011
+++ src/share/examples/puffs/pgfs/pgfs_subs.c	Wed Oct 12 16:24:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pgfs_subs.c,v 1.1 2011/10/12 01:05:00 yamt Exp $	*/
+/*	$NetBSD: pgfs_subs.c,v 1.2 2011/10/12 16:24:39 yamt Exp $	*/
 
 /*-
  * Copyright (c)2010,2011 YAMAMOTO Takashi,
@@ -46,7 +46,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: pgfs_subs.c,v 1.1 2011/10/12 01:05:00 yamt Exp $);
+__RCSID($NetBSD: pgfs_subs.c,v 1.2 2011/10/12 16:24:39 yamt Exp $);
 #endif /* not lint */
 
 #include assert.h
@@ -795,18 +795,24 @@ cleanupfile(struct Xconn *xc, fileid_t f
 
 	if (va-va_type == VREG || va-va_type == VLNK) {
 		static struct cmd *c_datafork;
+		int32_t ret;
 		int error;
 
-		/*
-		 * use CASE instead of AND to preserve the evaluation ordering.
-		 */
 		CREATECMD(c_datafork,
-			DELETE FROM datafork WHERE CASE WHEN fileid = $1 
-			THEN lo_unlink(loid) = 1 ELSE false END, INT8OID);
-		error = simplecmd(xc, c_datafork, fileid);
+			WITH loids AS (DELETE FROM datafork WHERE fileid = $1 
+			RETURNING loid) SELECT lo_unlink(loid) FROM loids,
+			INT8OID);
+		error = sendcmd(xc, c_datafork, fileid);
 		if (error != 0) {
 			return error;
 		}
+		error = simplefetch(xc, INT4OID, ret);
+		if (error != 0) {
+			return error;
+		}
+		if (ret != 1) {
+			return EIO; /* lo_unlink failed */
+		}
 	}
 	CREATECMD(c, DELETE FROM file WHERE fileid = $1, INT8OID);
 	return simplecmd(xc, c, fileid);