📄 mosctl.c
字号:
#error Please set KERNELMAINVER to 2.4 or 2.6#endif if (na < 2 || na > 5) { Usage: fprintf (stderr, "Usage: %s command\n", argv[0]); fprintf (stderr, "Available commands: stay/nostay, lstay/nolstay, block/noblock, quiet/noquiet,\n"); fprintf (stderr, " mfs/nomfs, expel, bring, gettune, getdecay,\n");#if _KERNELMAINVERI == 240 fprintf (stderr, " whois [mosix_no|IP|hostname], isup [node-number]\n"); fprintf (stderr, " getload [node-number], getspeed [node-number],\n"); fprintf (stderr, " status [node-number], getmem [node-number],\n"); fprintf (stderr, " getfree [node-number], getutil [node-number],\n");#elif _KERNELMAINVERI == 260 fprintf (stderr, " whois [IP|hostname], isup [IP|hostname]\n"); fprintf (stderr, " getload [IP|hostname], getspeed [IP|hostname],\n"); fprintf (stderr, " status [IP|hostname], getmem [IP|hostname],\n"); fprintf (stderr, " getfree [IP|hostname], getutil [IP|hostname],\n");#endif fprintf (stderr, " getyard, setyard [node-type], setspeed speed,\n"); fprintf (stderr, " setdecay interval(seconds) slow(/%d) fast(/%d)\n", DECAY_QUOTIENT, DECAY_QUOTIENT);/* fprintf(stderr, " isup [node-number], settune [file_name].\n"); */ exit (1); } for (x = argv[1]; *x; x++) if (*x >= 'A' && *x <= 'Z') *x += 'a' - 'A'; for (c = coms; c->com; c++) if (!strcmp (c->com, argv[1])) break; if (!c->com) { printf ("%s: No such option.\n", argv[0]); exit (1); } if (c->no == D_SETDECAY) { if (na != 5) goto Usage; arg = (int) &dec; if (sscanf (argv[2], "%d", &dec.interval) != 1 || sscanf (argv[3], "%d", &dec.slow) != 1 || sscanf (argv[4], "%d", &dec.fast) != 1) goto Usage; } else if (c->no == D_GETLOAD || c->no == D_GETSPEED || c->no == D_GETSTAT || c->no == D_GETMEM || c->no == D_GETRMEM || c->no == D_GETUTIL) { if (na > 3) goto Usage; if (na == 3) arg = atoi (argv[2]); } else if (c->no == D_SETSPEED) { if (na != 3) goto Usage; for (u = argv[2]; *u; u++) if (*u < '0' || *u > '9') goto Usage; arg = atoi (argv[2]); } else if (c->no == D_SETSSPEED) { if (na > 3) goto Usage; if (na == 2) { Usage2: fprintf (stderr, "Recognised Processor Types:\n\n"); for (arg = 0, sp = speeds; sp->mach[0]; sp++, arg++) { if (arg) { fprintf (stderr, ", "); if (arg % 6 == 0) fprintf (stderr, "\n"); } fprintf (stderr, "%s", sp->mach[0]); } fprintf (stderr, "\n\nInstead, you may also specify a number, where %d represents OpenMosix's standard\n", STD_SPD); fprintf (stderr, "processor speed (eg. %s).\n", MOSIX_STANDARD); fprintf (stderr, "You may also set the local processor's speed as the standard using 'this'.\n"); exit (1); } arg = 0; for (u = argv[2]; *u; u++) { if (*u >= 'a' && *u <= 'z') *u += 'A' - 'a'; if (*u == '-' || *u == '_') *u = '/'; if (*u < '0' || *u > '9') arg = 1; } if (arg == 0) { arg = atoi (argv[2]); } else if (!strcasecmp (argv[2], "THIS")) {#if _KERNELMAINVERI == 240 arg = msxctl (D_GETSPEED, (int64_t) 0, NULL, 0);#else arg = om_control (D_GETSPEED, (int64_t) 0, NULL, 0, "localhost");#endif if (arg == -1) { perror ("Failed to get local speed"); exit (1); } } else { for (sp = speeds; sp->mach[0]; sp++) for (n = 0; n < MAXNICK && sp->mach[n]; n++) if (!strcmp (argv[2], sp->mach[n])) goto fnd; fnd: if (!sp->mach[0]) goto Usage2; arg = sp->spd; } } else if (na == 3 && c->no == D_MOSIX_TO_IP) { for (u = argv[2]; *u; u++) if (*u < '0' || *u > '9') break; if (*u) { if (sscanf (argv[2], "%lui.%lui.%lui.%lui%c", &i1, &i2, &i3, &i4, &stop) != 4) { if (!(he = gethostbyname (argv[2]))) { fprintf (stderr, "%s: No Such Host-Name\n", argv[2]); exit (1); } bcopy (he->h_addr, &addr, sizeof (addr)); arg = ntohl (addr); } else { arg = (i1 << 24) | (i2 << 16) | (i3 << 8) | i4; } c->no = D_IP_TO_MOSIX; } else { resp = address; arg = atoi (argv[2]); } } else if (na == 2 && c->no == D_MOSIX_TO_IP) c->no = D_IP_TO_MOSIX; else if (na != 2) goto Usage; if (c->no == D_GETTUNE) {#if _KERNELMAINVERI == 240 overheads_num = msxctl (D_GETNTUNE, (int64_t) 0, NULL, 0);#else overheads_num = om_control (D_GETNTUNE , (int64_t) 0, NULL, 0, "localhost");#endif if (overheads_num <= 0 || (costs = malloc ((long int) overheads_num * sizeof (int))) == NULL) { perror ("Getting tune values"); exit (1); } resp = costs; length = overheads_num * sizeof (int); } else if (c->no == D_GETDECAY) resp = &dec; else if (c->no == D_GETMEM || c->no == D_GETRMEM) resp = &tot;#if _KERNELMAINVERI == 240 ans = msxctl (c->no, arg, resp, (int) length);#else ans = om_control (c->no, (int64_t) 0,resp, (int) length,arg);#endif if (ans == -1) { if (c->no == D_GETLOAD || c->no == D_GETSPEED || c->no == D_GETMEM || c->no == D_GETSTAT || c->no == D_GETRMEM || c->no == D_GETUTIL) switch (errno) { case EINVAL: fprintf (stderr, "Error: Improper node number\n"); break; case EWOULDBLOCK: case EHOSTDOWN: if (!strcmp (c->com, "isup")) fprintf (stderr, "no (it seems)\n"); else fprintf (stderr, "Error: no response\n"); break; case ENOENT: fprintf (stderr, "Node #%s is not configured\n", argv[2]); break; default: perror ("Error"); } else if (c->no == D_SETDECAY && errno == EINVAL) fprintf (stderr, "Error: Improper value\n"); else if (errno == ENOENT && c->no == D_IP_TO_MOSIX) fprintf (stderr, "Node at %s is not configured\n", argv[2]); else if (errno == ENOENT && c->no == D_MOSIX_TO_IP) fprintf (stderr, "Node #%s is not configured\n", argv[2]); else perror ("Error"); } else switch (c->no) { case D_GETLOAD: printf ("load=%lld\n", ans); break; case D_GETSPEED: { struct utsname un; printf ("speed=%lld", ans); if (!arg && uname (&un) == 0) { n = 1000000; for (sp = &speeds[0]; sp->mach[0]; sp++) if (!strcmp (un.machine, sp->model) && n >= iabs (sp->spd - ans)) { n = iabs (sp->spd - ans); bestsp = sp; } if (n <= bestsp->spd * 0.06) printf (" (%s%s)", n ? "close to " : "", bestsp->mach[0]); } printf (".\n"); break; } case D_MOSIX_TO_IP: printf ("%s\n", (char *) resp); break; case D_IP_TO_MOSIX: printf ("%s is OpenMosix #%lld\n", na == 3 ? argv[2] : "This", ans); break; case D_SETSSPEED: ans = arg; case D_GETSSPEED: { struct utsname un; printf ("Yardstick speed %sset to %lld", c->no == D_GETSSPEED ? "currently " : "", ans); if (uname (&un) != 0) goto anything; bestsp = speeds; n = 1000000; for (sp = &speeds[0]; sp->mach[0]; sp++) if (!strcmp (un.machine, sp->model) && n >= iabs (sp->spd - ans)) { n = iabs (sp->spd - ans); bestsp = sp; } if (n <= bestsp->spd * 0.06) printf (" (%s a %s processor)", n ? "probably" : "matching", bestsp->mach[0]); else { anything: n = iabs (speeds[0].spd - ans); for (sp = &speeds[1]; sp->mach[0]; sp++) if (n >= iabs (sp->spd - ans)) { n = iabs (sp->spd - ans); bestsp = sp; } if (n <= bestsp->spd * 0.06) printf (" (%s a %s processor)", n ? "probably" : "matching", bestsp->mach[0]); } printf (".\n"); break; } case D_EXPEL: printf ("All remote processes were expelled and no further remote processes accepted.\n"); break; case D_BRING: printf ("All local processes were brought back and will stay here.\n"); break; case D_STAY: printf (ans ? "Automatic load-balancing already disabled.\n" : "Automatic load-balancing disabled: no processes will leave This node\n(except by an explicit request)\n"); break; case D_NOSTAY: printf (ans ? "automatic load-balancing re-enabled.\n" : "automatic load-balancing already enabled.\n"); break; case D_LSTAY: printf (ans ? "Local processes already not leaving the node automatically.\n" : "No local processes will leave the node automatically.\n"); break; case D_NOLSTAY: printf (ans ? "Local processes may now leave the node automatically.\n" : "Local processes already allowed to leave automatically.\n"); break; case D_BLOCK: printf (ans ? "Remote processes already not allowed here.\n" : "Remote processes will not be allowed in here.\n"); break; case D_NOBLOCK: printf (ans ? "Remote processes now allowed in.\n" : "Remote processes already allowed in.\n"); break; case D_QUIET: printf (ans ? "Load-balancing activity already shut-down.\n" : "Load-balancing activity is now shut-down (for fine-timing measurements)\n"); break; case D_NOQUIET: printf (ans ? "Load balancing activity now resumed.\n" : "Load balancing already active.\n"); break; case D_NOMFS: printf (ans ? "MFS access already disallowed to this node.\n" : "MFS access to this node now disallowed.\n"); break; case D_MFS: printf (ans ? "MFS access to this node now allowed.\n" : "MFS access already enabled.\n"); break; case D_GETTUNE: { int group, last = 0; printf ("\n[1mOpenMosix Kernel Tuning Parameters (microseconds)[0m:\n\n\n");#if _KERNELMAINVERI == 240 n = (msxctl (D_GETNTUNE, (int64_t) 0, NULL, 0) +2) / 16 ;#else n = (om_control (D_GETNTUNE , (int64_t) 0, NULL, 0, "localhost") +2) / 16;#endif for (group = 0; group < n; group++) { if (costs[group * 16 + 14] == 0) { if (group) printf ("[1mThe following parameters apply to all the remainning OpenMosix nodes:[0m\n\n"); last = 1; } else if (costs[group * 16 + 14] <= costs[group * 16 + 15]) printf ("[1mThe following parameters apply to all OpenMosix nodes between %d and %d:[0m\n\n", costs[group * 16 + 14], costs[group * 16 + 15]); else if (costs[group * 16 + 14] != 0 && costs[group * 16 + 15] == 0) printf ("[1mThe following parameters apply to all OpenMosix nodes except %d:[0m\n\n", costs[group * 16 + 14]); else if (costs[group * 16 + 14] > costs[group * 16 + 15]) printf ("[1mThe following parameters apply to all OpenMosix nodes NOT between %d and %d:[0m\n\n", costs[group * 16 + 15], costs[group * 16 + 14]); for (n = group * 16; n < group * 16 + 14; n++) printf ("\t%-47s = %d\n", cdesc[n % 16], costs[n]); printf ("\n\n"); if (last) { break; } } printf ("\n"); break; } case D_GETMEM: printf ("free memory = %lld of %lld\n", ans, tot); break; case D_GETRMEM: printf ("raw free memory = %lld of %lld\n", ans, tot); break; case D_GETUTIL:#if _KERNELMAINVERI == 240 n = msxctl (D_GETCPUS, arg, NULL, 0); printf ("Utilizability = %lld%%", ans); if (n > 1) printf (" (of %lld%%)", 100 * n); printf ("\n");#else /* TODO: depends of the pertenence */ printf("Not yet implemented.\n");#endif break; case D_GETSTAT: if (!strcmp (c->com, "isup")) { printf ((ans & DS_MOSIX_UP) ? "yes\n" : "no\n"); break; } printf ((ans & DS_MOSIX_UP) ? "up" : "down"); if (ans & DS_STAY) printf (",stay"); if (ans & DS_LSTAY) printf (",lstay"); if (ans & DS_BLOCK) printf (",block"); if (ans & DS_QUIET) printf (",quiet"); if (ans & DS_NOMFS) printf (",nomfs"); printf (".\n"); break; case D_GETDECAY: printf ("Decaying statistics of active processes occurs every %d second%s.\n", dec.interval, dec.interval > 1 ? "s" : ""); printf ("Slow decay leaves %d/%d.\n", dec.slow, DECAY_QUOTIENT); printf ("Fast decay leaves %d/%d.\n", dec.fast, DECAY_QUOTIENT); break; } exit (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -