/* * * schedinit - initialize conf struct and parse conf files * * argc - passed in from main * argv - passed in from main * * Returns Success/Failure * * */ int schedinit(int argc, char *argv[]) { init_config(); parse_config(CONFIG_FILE); parse_holidays(HOLIDAYS_FILE); time(&(cstat.current_time)); if (is_prime_time()) init_prime_time(); else init_non_prime_time(); parse_ded_file(DEDTIME_FILE); /* preload the static members to the fairshare tree */ preload_tree(); parse_group(RESGROUP_FILE); calc_fair_share_perc(conf.group_root -> child, UNSPECIFIED); if (conf.prime_fs || conf.non_prime_fs) { read_usage(); /* * initialize the last_decay to the current time, since we do not know when * the last decay happened */ last_sync = last_decay = cstat.current_time; } token_acct_open((char *)0); return 0; }
int schedule( int cmd, int sd) { switch (cmd) { case SCH_ERROR: case SCH_SCHEDULE_NULL: case SCH_RULESET: case SCH_SCHEDULE_RECYC: /* ignore and end cycle */ break; case SCH_SCHEDULE_NEW: case SCH_SCHEDULE_TERM: case SCH_SCHEDULE_FIRST: case SCH_SCHEDULE_CMD: case SCH_SCHEDULE_TIME: return(scheduling_cycle(sd)); /*NOTREACHED*/ break; case SCH_CONFIGURE: if (conf.prime_fs || conf.non_prime_fs) write_usage(); reinit_config(); parse_config(CONFIG_FILE); parse_holidays(HOLIDAYS_FILE); parse_ded_file(DEDTIME_FILE); preload_tree(); parse_group(RESGROUP_FILE); calc_fair_share_perc(conf.group_root -> child, UNSPECIFIED); if (conf.prime_fs || conf.non_prime_fs) read_usage(); break; case SCH_QUIT: if (conf.prime_fs || conf.non_prime_fs) write_usage(); return 1; /* have the scheduler exit nicely */ default: return 0; } return(0); } /* END schedule() */
/** * @brief * The entry point of pbsfs * * @return int * @retval 0 : success * @retval 1 : something is wrong! */ int main(int argc, char *argv[]) { char path_buf[256] = {0}; char sched_name[PBS_MAXSCHEDNAME + 1] = "default"; group_info *ginfo; group_info *ginfo2; int c; int flags = FS_PRINT; int flag1 = 0; double val; char *endp; char *testp; /* the real deal or output version and exit? */ PRINT_VERSION_AND_EXIT(argc, argv); set_msgdaemonname("pbsfs"); #ifdef WIN32 if (winsock_init()) { return 1; } #endif if (pbs_loadconf(0) <= 0) exit(1); while ((c = getopt(argc, argv, "sgptdceI:-:")) != -1) switch (c) { case 'g': flags = FS_GET; break; case 's': flags = FS_SET | FS_WRITE_FILE; break; case 'p': flags = FS_PRINT; break; case 't': flags = FS_PRINT_TREE; break; case 'd': flags = FS_DECAY | FS_WRITE_FILE; break; case 'c': flags = FS_COMP; break; case 'e': flags = FS_TRIM_TREE | FS_WRITE_FILE; break; case 'I': snprintf(sched_name, sizeof(sched_name), "%s", optarg); break; case '-': flag1 = 1; break; } if (flag1 == 1) { fprintf(stderr, "Usage: pbsfs --version\n"); exit(1); } if ((flags & (FS_PRINT | FS_PRINT_TREE)) && (argc - optind) != 0) { fprintf(stderr, "Usage: pbsfs -[ptdgcs] [-I sched_name]\n"); exit(1); } else if ((flags & FS_GET) && (argc - optind) != 1) { fprintf(stderr, "Usage: pbsfs [-I sched_name] -g <fairshare_entity>\n"); exit(1); } else if ((flags & FS_SET) && (argc - optind) != 2) { fprintf(stderr, "Usage: pbsfs [-I sched_name] -s <fairshare_entity> <usage>\n"); exit(1); } else if ((flags & FS_COMP) && (argc - optind) != 2) { fprintf(stderr, "Usage: pbsfs [-I sched_name] -c <entity1> <entity2>\n"); exit(1); } if (strcmp(sched_name, "default") != 0) { int pbs_sd; struct batch_status *bs; struct batch_status *cur_bs; pbs_sd = pbs_connect(NULL); if (pbs_sd < 0) { fprintf(stderr, "Can't connect to the server\n"); exit(1); } bs = pbs_statsched(pbs_sd, NULL, NULL); for (cur_bs = bs; cur_bs != NULL; cur_bs = cur_bs->next) { if (strcmp(cur_bs->name, sched_name) == 0) { struct attrl *cur_attrl; for (cur_attrl = cur_bs->attribs; cur_attrl != NULL; cur_attrl = cur_attrl->next) { if (strcmp(cur_attrl->name, ATTR_sched_priv) == 0) { strncpy(path_buf, cur_attrl->value, sizeof(path_buf)); path_buf[sizeof(path_buf) - 1] = '\0'; break; } } if (cur_attrl == NULL) { fprintf(stderr, "Scheduler %s does not have its sched_priv set\n", sched_name); exit(1); } break; } } if (cur_bs == NULL) { fprintf(stderr, "Scheduler %s does not exist\n", sched_name); exit(1); } pbs_disconnect(pbs_sd); } else snprintf(path_buf, sizeof(path_buf), "%s/sched_priv/", pbs_conf.pbs_home_path); if (chdir(path_buf) == -1) { perror("Unable to access fairshare data"); exit(1); } init_config(); parse_config(CONFIG_FILE); if ((conf.fairshare = preload_tree()) == NULL) { fprintf(stderr, "Error in preloading fairshare information\n"); return 1; } if (parse_group(RESGROUP_FILE, conf.fairshare->root) == 0) return 1; if (flags & FS_TRIM_TREE) read_usage(USAGE_FILE, FS_TRIM, conf.fairshare); else read_usage(USAGE_FILE, 0, conf.fairshare); calc_fair_share_perc(conf.fairshare->root->child, UNSPECIFIED); calc_usage_factor(conf.fairshare); if (flags & FS_PRINT_TREE) print_fairshare(conf.fairshare->root, 0); else if (flags & FS_PRINT ) { printf("Fairshare usage units are in: %s\n", conf.fairshare_res); print_fairshare(conf.fairshare->root, -1); } else if (flags & FS_DECAY) decay_fairshare_tree(conf.fairshare->root); else if (flags & (FS_GET | FS_SET | FS_COMP)) { ginfo = find_group_info(argv[optind], conf.fairshare->root); if (ginfo == NULL) { fprintf(stderr, "Fairshare Entity %s does not exist.\n", argv[optind]); return 1; } if (flags & FS_COMP) { ginfo2 = find_group_info(argv[optind + 1], conf.fairshare->root); if (ginfo2 == NULL) { fprintf(stderr, "Fairshare Entity %s does not exist.\n", argv[optind + 1]); return 1; } switch (compare_path(ginfo->gpath, ginfo2->gpath)) { case -1: printf("%s\n", ginfo->name); break; case 0: printf("%s == %s\n", ginfo->name, ginfo2->name); break; case 1: printf("%s\n", ginfo2->name); } } else if (flags & FS_GET) print_fairshare_entity(ginfo); else { testp = argv[optind + 1]; val = strtod(testp, &endp); if (*endp == '\0') ginfo->usage = val; } } if (flags & FS_WRITE_FILE) { FILE *fp; /* make backup of database file */ remove(USAGE_FILE ".bak"); if (rename(USAGE_FILE, USAGE_FILE ".bak") < 0) perror("Could not backup usage database."); write_usage(USAGE_FILE, conf.fairshare); if ((fp = fopen(USAGE_TOUCH, "w")) != NULL) fclose(fp); } return 0; }