about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-06-26 02:16:15 +0000
committerEric Wong <normalperson@yhbt.net>2013-07-10 00:55:51 +0000
commitbb27afc702459d683a6b6ca5822b746142047acc (patch)
tree194ca8afe97c9d6d2e01976e8040ac00b1b34f40
parentad961733c0afb96a7ab44dc9837a0f8c8fa239a4 (diff)
downloadcmogstored-bb27afc702459d683a6b6ca5822b746142047acc.tar.gz
This will allow us to use control flow similar to the http client
handling code when we queue clients based on I/O channel.
-rw-r--r--cmogstored.h7
-rw-r--r--mgmt.c21
-rw-r--r--mgmt_parser.rl4
3 files changed, 30 insertions, 2 deletions
diff --git a/cmogstored.h b/cmogstored.h
index d7f37c9..f37a84c 100644
--- a/cmogstored.h
+++ b/cmogstored.h
@@ -126,6 +126,12 @@ enum mog_prio {
         MOG_PRIO_FSCK
 };
 
+enum mog_mgmt_method {
+        MOG_MGMT_METHOD_NONE = 0,
+        MOG_MGMT_METHOD_SIZE,
+        MOG_MGMT_METHOD_DIG
+};
+
 struct mog_mgmt;
 struct mog_mgmt {
         int cs;
@@ -138,6 +144,7 @@ struct mog_mgmt {
         struct mog_wbuf *wbuf; /* uncommonly needed */
         struct mog_svc *svc;
         enum Gc_hash alg;
+        enum mog_mgmt_method mgmt_method;
         LIST_ENTRY(mog_mgmt) subscribed;
 };
 
diff --git a/mgmt.c b/mgmt.c
index d64c1c0..16ec4c0 100644
--- a/mgmt.c
+++ b/mgmt.c
@@ -149,6 +149,24 @@ mgmt_defer_rbuf(struct mog_mgmt *mgmt, struct mog_rbuf *rbuf, size_t buf_len)
         mgmt->buf_off = 0;
 }
 
+static void mgmt_process_client(struct mog_fd *mfd, char *buf)
+{
+        struct mog_mgmt *mgmt = &mfd->as.mgmt;
+
+        switch (mgmt->mgmt_method) {
+        case MOG_MGMT_METHOD_NONE:
+                /* we handle filesystem-using commands inline in the parser */
+                return;
+        case MOG_MGMT_METHOD_SIZE:
+                mog_mgmt_fn_size(mgmt, buf);
+                break;
+        case MOG_MGMT_METHOD_DIG:
+                mog_mgmt_fn_digest(mgmt, buf);
+                break;
+        }
+        mgmt->mgmt_method = MOG_MGMT_METHOD_NONE;
+}
+
 /*
  * this is the main event callback and called whenever mgmt
  * is pulled out of a queue (either idle or active)
@@ -203,6 +221,9 @@ parse:
                         off = mgmt->buf_off;
                         goto reread;
                 case MOG_PARSER_DONE:
+                        mgmt_process_client(mfd, buf);
+                        if (mgmt->wbuf == MOG_WR_ERROR)
+                                return MOG_NEXT_CLOSE;
                         if (mgmt->forward == MOG_IOSTAT)
                                 return mgmt_iostat_forever(mgmt);
 
diff --git a/mgmt_parser.rl b/mgmt_parser.rl
index d8342a1..075a057 100644
--- a/mgmt_parser.rl
+++ b/mgmt_parser.rl
@@ -34,7 +34,7 @@ static void set_prio_fsck(struct mog_mgmt *mgmt)
         size = (
                 "size "(mog_path) > { mgmt->mark[0] = fpc - buf; }
                 eor > { mgmt->mark[1] = fpc - buf; }
-                @ { mog_mgmt_fn_size(mgmt, buf); fbreak; }
+                @ { mgmt->mgmt_method = MOG_MGMT_METHOD_SIZE; fbreak; }
         );
         digest = (
                 (
@@ -45,7 +45,7 @@ static void set_prio_fsck(struct mog_mgmt *mgmt)
                 " "
                 (mog_path) > { mgmt->mark[0] = fpc - buf; }
                 ( reason? eor) > { mgmt->mark[1] = fpc - buf; }
-                @ { mog_mgmt_fn_digest(mgmt, buf); fbreak; }
+                @ { mgmt->mgmt_method = MOG_MGMT_METHOD_DIG; fbreak; }
         );
         watch = "watch" eor @ {
                 static int have_iostat = 1;