2 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
5 #include "cmogstored.h"
9 * only set fsck prio if we're still accepting connections, graceful
10 * shutdown in single-threaded mode uses normal (fair) prio
12 static void set_prio_fsck(struct mog_mgmt *mgmt)
14 if (mgmt->svc->mgmt_mfd)
15 mgmt->prio = MOG_PRIO_FSCK;
20 include path_parser "path_parser.rl";
23 reason = ' '("fsck" @ { set_prio_fsck(mgmt); } | [a-zA-Z0-9_]+);
26 ([^ \t\r]+) > { mgmt->mark[0] = fpc - buf; }
27 (any-'\n')* > { mgmt->mark[1] = fpc - buf; }
30 mog_mgmt_fn_unknown(mgmt, buf);
35 "size "(mog_path) > { mgmt->mark[0] = fpc - buf; }
36 eor > { mgmt->mark[1] = fpc - buf; }
37 @ { mgmt->mgmt_method = MOG_MGMT_METHOD_SIZE; fbreak; }
41 "MD5" @ { mgmt->alg = GC_MD5; }
43 "SHA-1" @ { mgmt->alg = GC_SHA1; }
46 (mog_path) > { mgmt->mark[0] = fpc - buf; }
47 ( reason? eor) > { mgmt->mark[1] = fpc - buf; }
48 @ { mgmt->mgmt_method = MOG_MGMT_METHOD_DIG; fbreak; }
50 watch = "watch" eor @ {
51 static int have_iostat = 1;
54 mgmt->forward = MOG_IOSTAT;
56 mog_mgmt_fn_watch_err(mgmt);
60 "server aio_threads"i ' '?'='(' ')?
61 (digit+) > { mgmt->mark[0] = fpc - buf; }
62 eor > { mgmt->mark[1] = fpc - buf; }
63 @ { mog_mgmt_fn_aio_threads(mgmt, buf); fbreak; }
66 true_val = ('1'|'true'|'yes'|'on');
67 false_val = ('0'|'false'|'no'|'off');
70 "set mogstored.persist_client"i ' '?'='(' ')?
72 (true_val) @ { mgmt->svc->persist_client = true; }
74 (false_val) @ { mgmt->svc->persist_client = false; }
78 mog_mgmt_fn_blank(mgmt);
82 blank = [ \t]* eor @ { mog_mgmt_fn_blank(mgmt); fbreak; };
83 shutdown = "shutdown" (" "+"graceful")? eor @ {
88 command = (digest|size|watch|aio_threads|persist_client|shutdown|blank);
98 void mog_mgmt_reset_parser(struct mog_mgmt *mgmt)
103 mgmt->mark[0] = mgmt->mark[1] = 0;
106 void mog_mgmt_init(struct mog_mgmt *mgmt, struct mog_svc *svc)
108 memset(mgmt, 0, sizeof(struct mog_mgmt));
109 mog_mgmt_reset_parser(mgmt);
113 enum mog_parser_state
114 mog_mgmt_parse(struct mog_mgmt *mgmt, char *buf, size_t len)
116 char *p, *pe, *eof = NULL;
119 size_t off = mgmt->buf_off;
120 uint32_t *mog_devid = &mgmt->mog_devid;
122 assert(mgmt->wbuf == NULL && "unwritten data in buffer");
123 assert(off <= len && "mgmt offset past end of buffer");
128 assert((void *)(pe - p) == (void *)(len - off) &&
129 "pointers aren't same distance");
134 cs = mgmt_parser_first_final;
137 mgmt->buf_off = p - buf;
139 if (cs == mgmt_parser_error)
140 return MOG_PARSER_ERROR;
142 assert(p <= pe && "buffer overflow after mgmt parse");
143 assert(mgmt->buf_off <= len && "offset longer than len");
145 if (mgmt->cs == mgmt_parser_first_final) return MOG_PARSER_DONE;
146 return MOG_PARSER_CONTINUE;