cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / iostat.c
blob93f39cef935b5467983087155490262e45974e71
1 /*
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>
4 */
6 /*
7 * iostat(1) -> global mountlist -> each mog_dev in each mog_svc
8 */
9 #include "cmogstored.h"
11 /* called after a stats line for a single device is complete */
12 void mog_iostat_line_done(struct mog_iostat *iostat)
14 if (iostat->dev_tip < sizeof(iostat->dev)) {
15 iostat->dev[iostat->dev_tip] = 0;
16 if (iostat->util_tip < sizeof(iostat->util)) {
17 iostat->util[iostat->util_tip] = 0;
18 } else {
19 iostat->util[0] = '-';
20 iostat->util[1] = 0;
23 mog_mnt_update_util(iostat);
24 } else {
25 syslog(LOG_ERR, "device name from iostat too long");
29 /* called every second, after stats for each device line are out */
30 void mog_iostat_commit(void)
32 mog_svc_each(mog_svc_devstats_broadcast, NULL);
35 static void iostat_close(struct mog_fd *mfd)
37 assert(mfd->fd_type == MOG_FD_TYPE_IOSTAT && "bad fd_type");
38 mog_fd_put(mfd);
41 static void iostat_reset(struct mog_iostat *iostat)
43 bool ready = iostat->ready;
44 mog_iostat_init(iostat);
45 iostat->ready = ready;
48 void mog_iostat_queue_step(struct mog_fd *mfd)
51 * only one thread ever hits this function at once,
52 * no point in ever running multiple iostat(1) processes
54 static char buf[1024];
55 ssize_t r;
56 struct mog_iostat *iostat = &mfd->as.iostat;
58 assert(mfd->fd >= 0 && mfd->fd_type == MOG_FD_TYPE_IOSTAT &&
59 "bad iostat mfd");
60 retry:
61 r = read(mfd->fd, buf, sizeof(buf));
62 if (r > 0) {
63 switch (mog_iostat_parse(iostat, buf, r)) {
64 case MOG_PARSER_ERROR:
65 syslog(LOG_ERR, "iostat parser error");
66 iostat_close(mfd);
67 return;
68 case MOG_PARSER_DONE:
69 iostat_reset(iostat);
70 goto retry;
71 case MOG_PARSER_CONTINUE:
72 goto retry;
74 } else if (r == 0) {
75 /* iostat exits every 30s by default */
76 iostat_close(mfd);
77 } else {
78 switch (errno) {
79 case_EAGAIN:
80 mog_idleq_push(iostat->queue, mfd, MOG_QEV_RD);
81 return;
82 case EINTR: goto retry;
84 syslog(LOG_ERR, "iostat read() failed: %m");
85 iostat_close(mfd);