struct dr_node * get_node_by_name(const char *drc_name, uint32_t node_type) { struct dr_node *node, *all_nodes; struct dr_node *prev_node = NULL; int child_found = 0; all_nodes = get_dlpar_nodes(node_type); if (all_nodes == NULL) { say(ERROR, "There are no DR capable slots on this system\n"); return NULL; } print_node_list(all_nodes); for (node = all_nodes; node; node = node->next) { struct dr_node *child; uint32_t drc_index; if (strcmp(node->drc_name, drc_name) == 0) break; /* See if the drc index was specified */ drc_index = strtoul(drc_name, NULL, 0); if (node->drc_index == drc_index) continue; for (child = node->children; child; child = child->next) { if (strcmp(drc_name, child->drc_name) == 0) child_found = 1; if (child->drc_index == drc_index) child_found = 1; } if (child_found) break; prev_node = node; } if (node) { if (prev_node) prev_node->next = node->next; else /* First in list */ all_nodes = all_nodes->next; node->next = NULL; } free_node(all_nodes); return node; }
/** * lsslot_chrp_phb * @brief Main entry point for handling lsslot_chrp_phb command * * @param opts pointer to cmd_opts struct * @returns 0 on success, !0 otherwise */ int lsslot_chrp_phb(struct cmd_opts *opts) { struct dr_node *phb_list; struct dr_node *phb; phb_list = get_dlpar_nodes(PHB_NODES); if (phb_list == NULL) return -1; /* display header */ printf("%-10s%-20s %s\n", "PHB name", "OFDT Name", "Slot(s) Connected"); for (phb = phb_list; phb; phb = phb->next) { struct dr_node *child; char *name; int printed_count = 0; if ((opts->s_name != NULL) && (strcmp(opts->s_name, phb->drc_name))) continue; name = strstr(phb->ofdt_path, "/pci"); printf("%-10s%-20s ", phb->drc_name, name); for (child = phb->children; child; child = child->next) { if (! child->is_owned) continue; if (printed_count == 0) printf("%s\n", child->drc_name); else printf("%-30s %s\n", "", child->drc_name); printed_count++; } if (printed_count) printf("\n"); else printf("\n\n"); } free_node(phb_list); return 0; }
/** * lsslot_chrp_port * @brief Print LHEA ports based on command line options * * @param opts * @returns 0 on success, !0 otherwise */ int lsslot_chrp_port(struct cmd_opts *opts) { struct dr_node *all_nodes; /* Pointer to list of all node info */ struct dr_node *node; /* Used to traverse list of node info */ struct dr_node *child; /* Used to traverse list of children */ char fmt[128]; struct print_node *p; char *sheading = "LHEA port name"; /* Used in printing headers */ char *dheading = "Description"; /* Used in printing headers */ int rc = 0; /* Set initial column sizes */ max_sname = MAX(max_sname, strlen(sheading)); max_desc = MAX(max_desc, strlen(dheading)); all_nodes = get_dlpar_nodes(HEA_NODES); /* If nothing returned, then no hot plug node */ if (all_nodes == NULL) { say(ERROR, "There are no LHEA ports on this system.\n"); return 1; } print_node_list(all_nodes); /* Otherwise, run through the node list looking for the nodes * we want to print */ for (node = all_nodes; node; node = node->next) { if (node->skip) continue; for (child = node->children; child; child = child->next) { if (child->skip) continue; /* If there is a search parameter, add matching ports. * If there is no search, add all the ports. */ if (opts->s_name != NULL) { if (cmp_drcname(child->drc_name, opts->s_name)) insert_print_node(child); } else insert_print_node(child); } } if (print_list == NULL) { /* If nothing to print, display message based on if * user specified a slot or a device name. */ if (opts->s_name != NULL) { say(ERROR, "The specified port was not found.\n"); rc = 1; } goto lsslot_port_exit; } /* This creates a format string so that port name and description * prints out in the required field width. When the -F flag is * specified, the format string contains the delimiting character * which the user specified at the command line. */ if (opts->delim != NULL) sprintf(fmt, "%s%s%s\n", "%s", opts->delim, "%s"); else { sprintf(fmt, "%%-%ds%%-%ds\n", max_sname + 2, max_desc + 2); /* Print out the header. */ printf(fmt, sheading, dheading); } /* Now run through the list of ports we actually want to print */ for (p = print_list; p != NULL; p = p->next) { printf(fmt, p->node->drc_name, p->desc); } lsslot_port_exit: free_print_list(); free_node(all_nodes); return rc; }
/** * lsslot_chrp_pci * @brief main entry point for lsslot command * * @param opts * @returns 0 on success, !0 otherwise */ int lsslot_chrp_pci(struct cmd_opts *opts) { struct dr_node *all_nodes; /* Pointer to list of all node info */ struct dr_node *node; /* Used to traverse list of node info */ char fmt[128]; struct print_node *p; char *sheading = "# Slot"; /* Used in printing headers */ char *dheading = "Description"; /* Used in printing headers */ char *lheading = "Device(s)"; /* Used in printing headers */ char *lname_header = "Linux Name"; int rc = 0; /* Set initial column sizes */ max_sname = MAX(max_sname, strlen(sheading)); max_desc = MAX(max_desc, strlen(dheading)); /* Get all of node(logical DR or PCI) node information */ if (opts->slot_type == PCI) all_nodes = get_hp_nodes(); else all_nodes = get_dlpar_nodes(PCI_NODES | VIO_NODES | HEA_NODES); /* If nothing returned, then no hot plug node */ if (all_nodes == NULL) { if (opts->slot_type == PCI) say(ERROR, "There are no PCI hot plug slots on " "this system.\n"); else say(ERROR, "There are no DR slots on this system.\n"); return 0; } print_node_list(all_nodes); /* Otherwise, run through the node list looking for the nodes * we want to print */ for (node = all_nodes; node; node = node->next) { if (! node->is_owned || node->skip) continue; if (opts->s_name != NULL) { if (cmp_drcname(node->drc_name, opts->s_name)) insert_print_node(node); } /* If aflag and slot is empty, then format the slot */ else if (opts->a_flag && (node->children == NULL)) insert_print_node(node); /* If oflag and slot occupied, then format the slot */ else if (opts->o_flag && (node->children != NULL)) insert_print_node(node); } if (print_list == NULL) { /* If nothing to print, display message based on if * user specified a slot or a device name. */ if (opts->s_name != NULL) { say(ERROR, "The specified PCI slot is either invalid\n" "or does not support hot plug operations.\n"); rc = 1; } goto lsslot_pci_exit; } /* This creates a format string so that slot name and description * prints out in the required field width. When the -F flag is * specified, the format string contains the delimiting character * which the user specified at the command line. */ if (opts->slot_type == SLOT) { if (opts->delim != NULL) sprintf(fmt, "%s%s%s%s%s%s", "%s", opts->delim, "%s", opts->delim, "%s", opts->delim); else { sprintf(fmt, "%%-%ds%%-%ds%%-%ds", max_sname + 2, max_desc + 2, LNAME_SIZE + 2); /* Print out the header. */ printf(fmt, sheading, dheading, lname_header); printf("%s\n", lheading); } } else { if (opts->delim != NULL) sprintf(fmt, "%s%s%s%s", "%s", opts->delim, "%s", opts->delim); else { sprintf(fmt, "%%-%ds%%-%ds", max_sname + 2, max_desc + 2); /* Print out the header. */ printf(fmt, sheading, dheading); printf("%s\n", lheading); } } /* Now run through the list of slots we actually want to print */ for (p = print_list; p != NULL; p = p->next) { if (! p->node->is_owned) { /* skip it, because the partition doesn't own it */ continue; } if (opts->slot_type == SLOT) print_drslot_line(p, fmt); else print_phpslot_line(p, fmt); } lsslot_pci_exit: free_print_list(); free_node(all_nodes); return rc; }