예제 #1
0
/**
 * find_slot
 *
 * Searches through all slots and returns a pointer to the slot
 * whose location code matches the user input. If no slot is found,
 * an error message is displayed and the entire command is exited.
 *
 * This routine uses a common function "cmp_drcname" so that all routines
 * validating a slot name will compare on the same basis. A slot could be
 * found, but if the "skip" field of the slot structure is set, we
 * shouldn't use it.
 *
 * @returns pointer to slot on success, NULL otherwise
 */
static struct dr_node *
find_slot(char *drc_name, struct dr_node *all_nodes)
{
	struct dr_node *node;	/* working pointer */

	/* Search through all_nodes to see if the
	 * user-specified location exists.
	 */
	node = all_nodes;
	while (node != NULL) {
		if (cmp_drcname(node->drc_name, drc_name))
			break;
		else
			node = node->next;
	}

	if ((node == NULL) || (node->skip))
		say(ERROR, "The specified PCI slot is either invalid\n"
		    "or does not support hot plug operations.\n");

	return node;
}
예제 #2
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;
}
예제 #3
0
/**
 * 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;
}