/* * Dump contents of resource */ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock) { URES *res = (URES *)reshdr; bool recurse = true; if (res == NULL) { printf(_("No record for %d %s\n"), type, res_to_str(type)); return; } if (type < 0) { /* no recursion */ type = - type; recurse = false; } switch (type) { case R_DIRECTOR: printf(_("Director: name=%s address=%s DIRport=%d\n"), reshdr->name, res->dir_res.address, res->dir_res.DIRport); break; case R_CONSOLE: printf(_("Console: name=%s\n"), reshdr->name); break; case R_CONSOLE_FONT: printf(_("ConsoleFont: name=%s font face=%s\n"), reshdr->name, NPRT(res->con_font.fontface)); break; default: printf(_("Unknown resource type %d\n"), type); } if (recurse && res->dir_res.hdr.next) { dump_resource(type, res->dir_res.hdr.next, sendit, sock); } }
/* * Dump contents of resource */ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock, bool hide_sensitive_data) { POOL_MEM buf; URES *res = (URES *)reshdr; BRSRES *resclass; bool recurse = true; if (res == NULL) { sendit(sock, _("Warning: no \"%s\" resource (%d) defined.\n"), res_to_str(type), type); return; } if (type < 0) { /* no recursion */ type = - type; recurse = false; } switch (type) { default: resclass = (BRSRES *)reshdr; resclass->print_config(buf); break; } sendit(sock, "%s", buf.c_str()); if (recurse && res->res_dir.hdr.next) { dump_resource(type, res->res_dir.hdr.next, sendit, sock, hide_sensitive_data); } }
/* Dump contents of resource */ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock) { URES *res = (URES *)reshdr; bool recurse = true; if (res == NULL) { printf(_("No record for %d %s\n"), type, res_to_str(type)); return; } if (type < 0) { /* no recursion */ type = - type; recurse = false; } switch (type) { case R_CONSOLE: printf(_("Console: name=%s rcfile=%s histfile=%s histsize=%d\n"), reshdr->name, res->res_cons.rc_file, res->res_cons.history_file, res->res_cons.history_length); break; case R_DIRECTOR: printf(_("Director: name=%s address=%s DIRport=%d\n"), reshdr->name, res->res_dir.address, res->res_dir.DIRport); break; default: printf(_("Unknown resource type %d\n"), type); } if (recurse && res->res_dir.hdr.next) { dump_resource(type, res->res_dir.hdr.next, sendit, sock); } }
bool CONFIG::remove_resource(int type, const char *name) { int rindex = type - m_r_first; RES *last; /* * Remove resource from list. * * Note: this is intended for removing a resource that has just been added, * but proven to be incorrect (added by console command "configure add"). * For a general approach, a check if this resource is referenced by other resources must be added. * If it is referenced, don't remove it. */ last = NULL; for (RES *res = m_res_head[rindex]; res; res = res->next) { if (bstrcmp(res->name, name)) { if (!last) { Dmsg2(900, _("removing resource %s, name=%s (first resource in list)\n"), res_to_str(type), name); m_res_head[rindex] = res->next; } else { Dmsg2(900, _("removing resource %s, name=%s\n"), res_to_str(type), name); last->next = res->next; } res->next = NULL; free_resource(res, type); return true; } last = res; } /* * Resource with this name not found */ return false; }
/* * Dump contents of resource */ void dump_resource(int type, RES *reshdr, void sendit(void *sock, const char *fmt, ...), void *sock) { URES *res = (URES *)reshdr; bool recurse = true; char ed1[100], ed2[100]; if (res == NULL) { sendit(sock, _("No %s resource defined\n"), res_to_str(type)); return; } if (type < 0) { /* no recursion */ type = - type; recurse = false; } switch (type) { case R_MONITOR: sendit(sock, _("Monitor: name=%s FDtimeout=%s SDtimeout=%s\n"), reshdr->name, edit_uint64(res->res_monitor.FDConnectTimeout, ed1), edit_uint64(res->res_monitor.SDConnectTimeout, ed2)); break; case R_DIRECTOR: sendit(sock, _("Director: name=%s address=%s FDport=%d\n"), res->res_dir.hdr.name, res->res_dir.address, res->res_dir.DIRport); break; case R_CLIENT: sendit(sock, _("Client: name=%s address=%s FDport=%d\n"), res->res_client.hdr.name, res->res_client.address, res->res_client.FDport); break; case R_STORAGE: sendit(sock, _("Storage: name=%s address=%s SDport=%d\n"), res->res_store.hdr.name, res->res_store.address, res->res_store.SDport); break; case R_CONSOLE_FONT: sendit(sock, _("ConsoleFont: name=%s font face=%s\n"), reshdr->name, NPRT(res->con_font.fontface)); break; default: sendit(sock, _("Unknown resource type %d in dump_resource.\n"), type); break; } if (recurse && res->res_monitor.hdr.next) { dump_resource(type, res->res_monitor.hdr.next, sendit, sock); } }
/** * @brief * create a select from an nspec array to place chunks back on the * same nodes as before * * @param[in] nspec_array - npsec array to convert * * @return converted select string */ char * create_select_from_nspec(nspec **nspec_array) { char *select_spec = NULL; int selsize = 0; char buf[1024]; resource_req *req; int i; if (nspec_array == NULL || nspec_array[0] == NULL) return NULL; /* convert form (node:foo=X:bar=Y) into 1:vnode=node:foo=X:bay=Y*/ for (i = 0; nspec_array[i] != NULL; i++) { /* Don't add exclhost chunks into our select. They will be added back when * we call eval_selspec() with the original place=exclhost. If we added * them, we'd have issues placing chunks w/o resources */ if (nspec_array[i]->resreq != NULL) { snprintf(buf, sizeof(buf), "1:vnode=%s", nspec_array[i]->ninfo->name); if (pbs_strcat(&select_spec, &selsize, buf) == NULL) { if (selsize > 0) free(select_spec); return NULL; } for (req = nspec_array[i]->resreq; req != NULL; req = req->next) { snprintf(buf, sizeof(buf), ":%s=%s", req->name, res_to_str(req, RF_REQUEST)); if (pbs_strcat(&select_spec, &selsize, buf) == NULL) { if (selsize > 0) free(select_spec); return NULL; } } if (pbs_strcat(&select_spec, &selsize, "+") == NULL) { if (selsize > 0) free(select_spec); return NULL; } } } /* get rid of trailing '+' */ select_spec[strlen(select_spec)-1] = '\0'; return select_spec; }
/* * Save the new resource by chaining it into the head list for * the resource. If this is pass 2, we update any resource * pointers (currently only in the Job resource). */ void save_resource(int type, RES_ITEM *items, int pass) { URES *res; int rindex = type - r_first; int i, size = 0; int error = 0; /* * Ensure that all required items are present */ for (i=0; items[i].name; i++) { if (items[i].flags & ITEM_REQUIRED) { if (!bit_is_set(i, res_all.dir_res.hdr.item_present)) { Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"), items[i].name, resources[rindex]); } } } /* * During pass 2, we looked up pointers to all the resources * referrenced in the current resource, , now we * must copy their address from the static record to the allocated * record. */ if (pass == 2) { switch (type) { /* * Resources not containing a resource */ case R_DIRECTOR: break; case R_CONSOLE: case R_CONSOLE_FONT: break; default: Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type); error = 1; break; } /* * Note, the resoure name was already saved during pass 1, * so here, we can just release it. */ if (res_all.dir_res.hdr.name) { free(res_all.dir_res.hdr.name); res_all.dir_res.hdr.name = NULL; } if (res_all.dir_res.hdr.desc) { free(res_all.dir_res.hdr.desc); res_all.dir_res.hdr.desc = NULL; } return; } /* * The following code is only executed during pass 1 */ switch (type) { case R_DIRECTOR: size = sizeof(DIRRES); break; case R_CONSOLE_FONT: size = sizeof(CONFONTRES); break; case R_CONSOLE: size = sizeof(CONRES); break; default: printf(_("Unknown resource type %d\n"), type); error = 1; break; } /* * Common */ if (!error) { res = (URES *)malloc(size); memcpy(res, &res_all, size); if (!res_head[rindex]) { res_head[rindex] = (RES *)res; /* store first entry */ } else { RES *next, *last; /* * Add new res to end of chain */ for (last=next=res_head[rindex]; next; next=next->next) { last = next; if (strcmp(next->name, res->dir_res.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), resources[rindex].name, res->dir_res.hdr.name); } } last->next = (RES *)res; Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->dir_res.hdr.name); } } }
/* * Save the new resource by chaining it into the head list for * the resource. If this is pass 2, we update any resource * pointers because they may not have been defined until * later in pass 1. */ void save_resource(int type, RES_ITEM *items, int pass) { URES *res; int rindex = type - R_FIRST; int i; int error = 0; /* * Ensure that all required items are present */ for (i = 0; items[i].name; i++) { if (items[i].flags & CFG_ITEM_REQUIRED) { if (!bit_is_set(i, res_all.res_monitor.hdr.item_present)) { Emsg2(M_ERROR_TERM, 0, _("%s item is required in %s resource, but not found.\n"), items[i].name, resources[rindex]); } } /* If this triggers, take a look at lib/parse_conf.h */ if (i >= MAX_RES_ITEMS) { Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), resources[rindex]); } } /* * During pass 2 in each "store" routine, we looked up pointers * to all the resources referrenced in the current resource, now we * must copy their addresses from the static record to the allocated * record. */ if (pass == 2) { switch (type) { /* * Resources not containing a resource */ case R_MONITOR: case R_CLIENT: case R_STORAGE: case R_DIRECTOR: case R_CONSOLE_FONT: break; default: Emsg1(M_ERROR, 0, _("Unknown resource type %d in save_resource.\n"), type); error = 1; break; } /* * Note, the resource name was already saved during pass 1, * so here, we can just release it. */ if (res_all.res_monitor.hdr.name) { free(res_all.res_monitor.hdr.name); res_all.res_monitor.hdr.name = NULL; } if (res_all.res_monitor.hdr.desc) { free(res_all.res_monitor.hdr.desc); res_all.res_monitor.hdr.desc = NULL; } return; } /* * Common */ if (!error) { res = (URES *)malloc(resources[rindex].size); memcpy(res, &res_all, resources[rindex].size); if (!res_head[rindex]) { res_head[rindex] = (RES *)res; /* store first entry */ Dmsg3(900, "Inserting first %s res: %s index=%d\n", res_to_str(type), res->res_monitor.hdr.name, rindex); } else { RES *next, *last; /* * Add new res to end of chain */ for (last = next = res_head[rindex]; next; next=next->next) { last = next; if (strcmp(next->name, res->res_monitor.hdr.name) == 0) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), resources[rindex].name, res->res_monitor.hdr.name); } } last->next = (RES *)res; Dmsg4(900, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(type), res->res_monitor.hdr.name, rindex, pass); } } }
/* * Save the new resource by chaining it into the head list for * the resource. If this is pass 2, we update any resource * pointers (currently only in the Job resource). */ bool save_resource(int type, RES_ITEM *items, int pass) { URES *res; int rindex = type - R_FIRST; int i; int error = 0; /* * Ensure that all required items are present */ for (i = 0; items[i].name; i++) { if (items[i].flags & CFG_ITEM_REQUIRED) { if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) { Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"), items[i].name, resources[rindex]); } } } /* * During pass 2, we looked up pointers to all the resources * referrenced in the current resource, , now we * must copy their address from the static record to the allocated * record. */ if (pass == 2) { switch (type) { case R_CONSOLE: if ((res = (URES *)GetResWithName(R_CONSOLE, res_all.res_cons.name())) == NULL) { Emsg1(M_ABORT, 0, _("Cannot find Console resource %s\n"), res_all.res_cons.name()); } else { res->res_cons.tls.allowed_cns = res_all.res_cons.tls.allowed_cns; } break; case R_DIRECTOR: if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.name())) == NULL) { Emsg1(M_ABORT, 0, _("Cannot find Director resource %s\n"), res_all.res_dir.name()); } else { res->res_dir.tls.allowed_cns = res_all.res_dir.tls.allowed_cns; } break; default: Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type); error = 1; break; } /* * Note, the resoure name was already saved during pass 1, * so here, we can just release it. */ if (res_all.res_dir.hdr.name) { free(res_all.res_dir.hdr.name); res_all.res_dir.hdr.name = NULL; } if (res_all.res_dir.hdr.desc) { free(res_all.res_dir.hdr.desc); res_all.res_dir.hdr.desc = NULL; } return (error == 0); } /* * Common */ if (!error) { res = (URES *)malloc(resources[rindex].size); memcpy(res, &res_all, resources[rindex].size); if (!res_head[rindex]) { res_head[rindex] = (RES *)res; /* store first entry */ } else { RES *next, *last; for (last=next=res_head[rindex]; next; next=next->next) { last = next; if (bstrcmp(next->name, res->res_dir.name())) { Emsg2(M_ERROR_TERM, 0, _("Attempt to define second %s resource named \"%s\" is not permitted.\n"), resources[rindex].name, res->res_dir.name()); } } last->next = (RES *)res; Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.name()); } } return (error == 0); }