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>
7 * iostat(1) -> global mountlist -> each mog_dev in each mog_svc
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;
19 iostat
->util
[0] = '-';
23 mog_mnt_update_util(iostat
);
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");
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];
56 struct mog_iostat
*iostat
= &mfd
->as
.iostat
;
58 assert(mfd
->fd
>= 0 && mfd
->fd_type
== MOG_FD_TYPE_IOSTAT
&&
61 r
= read(mfd
->fd
, buf
, sizeof(buf
));
63 switch (mog_iostat_parse(iostat
, buf
, r
)) {
64 case MOG_PARSER_ERROR
:
65 syslog(LOG_ERR
, "iostat parser error");
71 case MOG_PARSER_CONTINUE
:
75 /* iostat exits every 30s by default */
80 mog_idleq_push(iostat
->queue
, mfd
, MOG_QEV_RD
);
82 case EINTR
: goto retry
;
84 syslog(LOG_ERR
, "iostat read() failed: %m");