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 abuse application_name to show the...



details:   https://anonhg.NetBSD.org/src/rev/5661f516c72c
branches:  trunk
changeset: 778735:5661f516c72c
user:      yamt <yamt%NetBSD.org@localhost>
date:      Wed Apr 11 14:26:44 2012 +0000

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

diffstat:

 share/examples/puffs/pgfs/pgfs_db.c    |  52 ++++++++++++++++++++++++++++++---
 share/examples/puffs/pgfs/pgfs_db.h    |   6 +-
 share/examples/puffs/pgfs/pgfs_puffs.c |  44 ++++++++++++++--------------
 3 files changed, 71 insertions(+), 31 deletions(-)

diffs (truncated from 337 to 300 lines):

diff -r a28ee49a6dfc -r 5661f516c72c share/examples/puffs/pgfs/pgfs_db.c
--- a/share/examples/puffs/pgfs/pgfs_db.c       Wed Apr 11 14:26:19 2012 +0000
+++ b/share/examples/puffs/pgfs/pgfs_db.c       Wed Apr 11 14:26:44 2012 +0000
@@ -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 @@
        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 @@
 }
 
 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 @@
                assert(error == 0);
        }
        DPRINTF("xc %p rollback %p\n", xc, xc->owner);
+       setlabel(xc, NULL);
        relxc(xc);
 }
 
@@ -717,6 +756,7 @@
 
        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 @@
                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 @@
        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);
diff -r a28ee49a6dfc -r 5661f516c72c share/examples/puffs/pgfs/pgfs_db.h
--- a/share/examples/puffs/pgfs/pgfs_db.h       Wed Apr 11 14:26:19 2012 +0000
+++ b/share/examples/puffs/pgfs/pgfs_db.h       Wed Apr 11 14:26:44 2012 +0000
@@ -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 @@
 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 *);
diff -r a28ee49a6dfc -r 5661f516c72c share/examples/puffs/pgfs/pgfs_puffs.c
--- a/share/examples/puffs/pgfs/pgfs_puffs.c    Wed Apr 11 14:26:19 2012 +0000
+++ b/share/examples/puffs/pgfs/pgfs_puffs.c    Wed Apr 11 14:26:44 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pgfs_puffs.c,v 1.3 2012/04/11 14:26:19 yamt Exp $      */
+/*     $NetBSD: pgfs_puffs.c,v 1.4 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_puffs.c,v 1.3 2012/04/11 14:26:19 yamt Exp $");
+__RCSID("$NetBSD: pgfs_puffs.c,v 1.4 2012/04/11 14:26:44 yamt Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -91,7 +91,7 @@
        DPRINTF("%llu\n", fileid);
        lock = fileid_lock(fileid, puffs_cc_getcc(pu));
 retry:
-       xc = begin_readonly(pu);
+       xc = begin_readonly(pu, "getattr");
        error = getattr(xc, fileid, va, GETATTR_ALL);
        if (error != 0) {
                goto got_error;
@@ -156,7 +156,7 @@
        if (offset == PGFS_DIRCOOKIE_DOTDOT) {
                if (parent_fileid != PGFS_ROOT_FILEID) {
                        if (xc == NULL) {
-                               xc = begin(pu);
+                               xc = begin(pu, "readdir1");
                        }
                        error = lookupp(xc, parent_fileid, &child_fileid);
                        if (error != 0) {
@@ -177,7 +177,7 @@
        }
        /* offset > PGFS_DIRCOOKIE_EOD; normal entries */
        if (xc == NULL) {
-               xc = begin(pu);
+               xc = begin(pu, "readdir2");
        }
        if (!fetching) {
                static struct cmd *c;
@@ -264,7 +264,7 @@
        }
        if (xc == NULL) {
 retry:
-               xc = begin(pu);
+               xc = begin(pu, "readdir3");
        }
        error = update_atime(xc, parent_fileid);
        if (error != 0) {
@@ -303,7 +303,7 @@
        DPRINTF("%llu %s\n", parent_fileid, name);
        assert(strcmp(name, ".")); /* . is handled by framework */
 retry:
-       xc = begin_readonly(pu);
+       xc = begin_readonly(pu, "lookup");
        error = getattr(xc, parent_fileid, &dva,
            GETATTR_TYPE|GETATTR_MODE|GETATTR_UID|GETATTR_GID);
        if (error != 0) {
@@ -331,7 +331,7 @@
 
                CREATECMD(c, "SELECT child_fileid "
                        "FROM dirent "
-                       "WHERE parent_fileid = $1 AND name = $2;",
+                       "WHERE parent_fileid = $1 AND name = $2",
                        INT8OID, TEXTOID);
                error = sendcmd(xc, c, parent_fileid, name);
                if (error != 0) {
@@ -394,7 +394,7 @@
                return errno;
        }
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "mkdir");
        error = mklinkfile(xc, parent_fileid, pcn->pcn_name, VDIR,
            va->va_mode, uid, gid, &new_fileid);
        if (error == 0) {
@@ -436,7 +436,7 @@
                return errno;
        }
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "create");
        error = mklinkfile_lo(xc, parent_fileid, pcn->pcn_name, VREG,
            va->va_mode,
            uid, gid, &new_fileid, NULL);
@@ -477,7 +477,7 @@
        }
        lock = fileid_lock(fileid, puffs_cc_getcc(pu));
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "write");
        error = update_mctime(xc, fileid);
        if (error != 0) {
                goto got_error;
@@ -546,7 +546,7 @@
        DPRINTF("%llu off %" PRIu64 " sz %zu\n",
            fileid, (uint64_t)offset, *resid);
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "read");
        /*
         * try to update atime first as it's prune to conflict with other
         * transactions.  eg. read-ahead requests can conflict each other.
@@ -597,7 +597,7 @@
 
        DPRINTF("%llu %llu %s\n", dir_fileid, targ_fileid, pcn->pcn_name);
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "link");
        error = getattr(xc, targ_fileid, &va, GETATTR_TYPE);
        if (error != 0) {
                goto got_error;
@@ -638,7 +638,7 @@
        int error;
 
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "remove");
        error = getattr(xc, targ_fileid, &va, GETATTR_TYPE);
        if (error != 0) {
                goto got_error;
@@ -677,7 +677,7 @@
        int error;
 
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "rmdir");
        error = getattr(xc, targ_fileid, &va, GETATTR_TYPE);
        if (error != 0) {
                goto got_error;
@@ -732,7 +732,7 @@
 
        DPRINTF("%llu\n", fileid);
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "inactive");
        error = cleanupfile(xc, fileid);
        if (error != 0) {
                goto got_error;
@@ -780,7 +780,7 @@
        }
        lock = fileid_lock(fileid, puffs_cc_getcc(pu));
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "setattr");
        error = getattr(xc, fileid, &ova, attrs);
        if (error != 0) {
                goto got_error;
@@ -963,7 +963,7 @@
        DPRINTF("%llu %llu %llu %llu\n", fileid_src_dir, fileid_src,
            fileid_targ_dir, fileid_targ);
 retry:
-       xc = begin(pu);
+       xc = begin(pu, "rename");
        error = getattr(xc, fileid_src, &va_src, GETATTR_TYPE);
        if (error != 0) {



Home | Main Index | Thread Index | Old Index