mcstat: Fix array of status strings
More error checks are added at the same time. Refs: #1223 Change-Id: I406066a6ba0853584d6e1820dde74721ce2682dd
This commit is contained in:
2
ihk
2
ihk
Submodule ihk updated: 4a8e719fa0...f5ab8770a4
@@ -14,6 +14,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <ihk/ihk_host_user.h>
|
#include <ihk/ihk_host_user.h>
|
||||||
#include <ihk/ihklib_private.h> // mcctrl_ioctl_getrusage_desc is defined here
|
#include <ihk/ihklib_private.h> // mcctrl_ioctl_getrusage_desc is defined here
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
struct mckernel_rusage rbuf;
|
struct mckernel_rusage rbuf;
|
||||||
|
|
||||||
static void mcstatistics(int idx, int once, int delay, int count);
|
static void mcstatistics(int idx, int once, int delay, int count);
|
||||||
static void mcstatus(int idx, int delay, int count);
|
static int mcstatus(int idx, int delay, int count);
|
||||||
static void mcosusage(int idx, int once, int delay, int count);
|
static void mcosusage(int idx, int once, int delay, int count);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -42,6 +43,7 @@ usage()
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
int opt;
|
int opt;
|
||||||
int idx = 0; /* index of OS instance */
|
int idx = 0; /* index of OS instance */
|
||||||
int sflag = 0; /* statistic option */
|
int sflag = 0; /* statistic option */
|
||||||
@@ -73,14 +75,19 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sflag) {
|
if (sflag) {
|
||||||
mcstatus(idx, delay, count);
|
if ((rc = mcstatus(idx, delay, count)) < 0) {
|
||||||
} else if (cflag) {
|
goto out;
|
||||||
mcosusage(idx, once, delay, count);
|
}
|
||||||
} else {
|
} else if (cflag) {
|
||||||
mcstatistics(idx, once, delay, count);
|
mcosusage(idx, once, delay, count);
|
||||||
}
|
} else {
|
||||||
return 0;
|
mcstatistics(idx, once, delay, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = 0;
|
||||||
|
out:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -175,39 +182,68 @@ mcstatistics(int idx, int once, int delay, int count)
|
|||||||
|
|
||||||
/* ihk_os_status enum is defined in ihk/linux/include/ihk/status.h */
|
/* ihk_os_status enum is defined in ihk/linux/include/ihk/status.h */
|
||||||
static char *charstat[] = {
|
static char *charstat[] = {
|
||||||
"None", /*IHK_OS_STATUS_NOT_BOOTED*/
|
[IHK_OS_STATUS_NOT_BOOTED] = "None",
|
||||||
"Booting", /*IHK_OS_STATUS_BOOTING*/
|
[IHK_OS_STATUS_BOOTING] = "Booting",
|
||||||
"Booted", /*IHK_OS_STATUS_BOOTED, OS booted and acked */
|
[IHK_OS_STATUS_BOOTED] = "Booted", /* OS booted and acked */
|
||||||
"Ready", /*IHK_OS_STATUS_READY, OS is ready and fully functional */
|
[IHK_OS_STATUS_READY] = "Ready", /* OS is ready and fully functional */
|
||||||
"Freezing", /*IHK_OS_STATUS_FREEZING, OS is freezing */
|
[IHK_OS_STATUS_RUNNING] = "Running", /* OS is running */
|
||||||
"Frozen", /*IHK_OS_STATUS_FROZEN, OS is frozen */
|
[IHK_OS_STATUS_FREEZING] = "Freezing", /* OS is freezing */
|
||||||
"Shutdown", /* IHK_OS_STATUS_SHUTDOWN, OS is shutting down */
|
[IHK_OS_STATUS_FROZEN] = "Frozen", /* OS is frozen */
|
||||||
"Stopped", /* IHK_OS_STATUS_STOPPED, OS stopped successfully */
|
[IHK_OS_STATUS_SHUTDOWN] = "Shutdown", /* OS is shutting down */
|
||||||
"Panic", /* IHK_OS_STATUS_FAILED, OS panics or failed to boot */
|
[IHK_OS_STATUS_STOPPED] = "Stopped", /* OS stopped successfully */
|
||||||
"Hangup", /* IHK_OS_STATUS_HUNGUP, OS is hungup */
|
[IHK_OS_STATUS_FAILED] = "Panic", /* OS panics or failed to boot */
|
||||||
|
[IHK_OS_STATUS_HUNGUP] = "Hangup", /* OS is hungup */
|
||||||
|
[IHK_OS_STATUS_COUNT] = NULL, /* End mark */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
/* Return value:
|
||||||
|
* Zero or positive: IHK_OS_STATUS value
|
||||||
|
* Negative: Error
|
||||||
|
*/
|
||||||
|
static int
|
||||||
mcstatus(int idx, int delay, int count)
|
mcstatus(int idx, int delay, int count)
|
||||||
{
|
{
|
||||||
int fd, rc;
|
int fd = -1, rc = 0;
|
||||||
|
|
||||||
for(;;) {
|
for (;;) {
|
||||||
if ((fd = devopen(idx)) < 0) {
|
if ((fd = devopen(idx)) == -1) {
|
||||||
printf("Devide is not created\n");
|
rc = -errno;
|
||||||
} else {
|
printf("Device not found\n");
|
||||||
rc = ioctl(fd, IHK_OS_STATUS, 0);
|
goto next;
|
||||||
close(fd);
|
}
|
||||||
printf("McKernel status: ");
|
|
||||||
if (rc >= IHK_OS_STATUS_NOT_BOOTED && rc <= IHK_OS_STATUS_HUNGUP) {
|
rc = ioctl(fd, IHK_OS_STATUS, 0);
|
||||||
printf("%s\n", charstat[rc]);
|
if (rc == -1) {
|
||||||
} else {
|
rc = -errno;
|
||||||
printf("ioctl error(IHK_OS_STATUS)\n");
|
printf("%s: error: IHK_OS_STATUS: %s\n",
|
||||||
}
|
__func__, strerror(-rc));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
fd = -1;
|
||||||
|
|
||||||
|
if (rc < 0 && rc >= IHK_OS_STATUS_COUNT) {
|
||||||
|
printf("%s: error: status (%d) out of range\n",
|
||||||
|
__func__, rc);
|
||||||
|
rc = -EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("McKernel status: %s\n",
|
||||||
|
charstat[rc] ? : "Unknown");
|
||||||
|
|
||||||
|
next:
|
||||||
|
if (count > 0 && --count == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sleep(delay);
|
||||||
}
|
}
|
||||||
if (count > 0 && --count == 0) break;
|
|
||||||
sleep(delay);
|
if (fd != -1) {
|
||||||
}
|
close(fd);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* status is not contiguous numbers */
|
/* status is not contiguous numbers */
|
||||||
|
|||||||
Reference in New Issue
Block a user