4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * CDDL HEADER START
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * The contents of this file are subject to the terms of the
d7cd82522afdd890a66c7600b499590ad44e84bdtw * Common Development and Distribution License (the "License").
d7cd82522afdd890a66c7600b499590ad44e84bdtw * You may not use this file except in compliance with the License.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * See the License for the specific language governing permissions
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * and limitations under the License.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * When distributing Covered Code, include this CDDL HEADER in each
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If applicable, add the following below this CDDL HEADER, with the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * fields enclosed by brackets "[]" replaced with your own identifying
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * information: Portions Copyright [yyyy] [name of copyright owner]
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * CDDL HEADER END
d7cd82522afdd890a66c7600b499590ad44e84bdtw * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Use is subject to license terms.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Design Notes:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * All of the code in this file supports the addition of metastat -c output
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * for the verbose option of metaimport. Some of this code is also used by
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the command metastat for concise output(cmd/lvm/util/metastat.c).
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * The code is designed to produce the same output as metastat -c does for a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * given diskset--with a couple exceptions.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * The primary differences between the output for the metastat -c command and
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * metastat output for metaimport -v are:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - the set name is not printed next to each metadevice
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - top-level state information is not printed for some metadevices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - the percent that a disk has completed resyncing is not listed
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * in metaimport -v.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * The general layout of this file is as follows:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - report_metastat_info()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * This is the primary entry point for the functions in this file, with
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the exception of several functions that are also called from
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * report_metastat_info() calls functions to read in all the the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Directory blocks and Record blocks and then process the information
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * needed to print out the metadevice records in the same format as
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * metastat -c.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - read_all_mdrecords()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Reads in all the Directory blocks in the diskset and verifies their
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * validity. For each Directly block, it loops through all Directory
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Entries and for each one that contains a metadevice record calls
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * read_md_record(). Because the output is designed to imitate the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * output of metastat -c, we ignore metadevice records for
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * optimized resync, changelog, and translog.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - read_md_record()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Reads in a Directory Entry and its associated Record block. The
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * revision information for the Record block is checked and it is
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * determined whether or not it is a 64bit Record block or a 32bit record
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * block. For each valid Record block, it allocates an md_im_rec_t
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * structure and calls extract_mduser_data().
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - extract_mduser_data()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Populates the md_im_rec_t data structure with information about the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * record's associated metadevice. Also, the name of the metadevice is
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * either copied from the NM namespace(if it exists there) or is generated
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * from the record's un_self_id.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - process_toplevel_devices()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * For a given metadevice type, searchs through the md_im_rec_t **mdimpp,
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * list of all metadevices in the set, to find all records of the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * specified type that do not have a parent and puts them on a temp list.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * The temp list is then iterated through and the associated processing
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * function is called.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - process_(trans, hotspare, hotspare_pool, soft_part, mirror, stripe, raid)
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * These functions are called by using the dfunc field in the mdimpp list.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Each process function only understands its own type of metadevice. Once
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * it processes the metadevice it was called for, it then loops through
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * all of the underlying metadevices. After printing the name of the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * underlying metadevice, it puts in on a list to be processed. If the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * underlying device is a physical device, then print_physical_device is
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Once all information about the original metadevice is processed, it
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * loops through the list of underlying metadevices and calls the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * appropriate function to process them.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - process_toplevel_softparts()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * To match the output for metastat -c, all top-level softpartions
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * are printed out in groups based on their underlying metadevice--so that
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the underlying metadevice only needs to be processed once.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * - meta_get_(sm_state, raid_col_state, stripe_state, hs_state)
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * These functions are used to retrieve the metadevice state information.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * They are also used by the metastat concise routines in
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * md_im_rec is a doubly linked list used to store the rb_data for each
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * directory entry that corresponds to a metadevice.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * n_key: is set, if there is an associated entry in the NM namespace.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * dfunc: is set to point to the function that processes the particular
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * metadevice associated with the record.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * hs_record_id: is only set, if the metadevice is a hotspare.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * un_self_id: is set for all other records. This is also used to generate
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the name of the metadevice if there is no entry for the metadevice in
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the NM namespace--n_key is not set.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* pointer to the unit structure for the metadevice, e.g. rb_data[0] */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * md_im_list is used to group toplevel metadevices by type and to group
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the underlying devices for a particular metadevice.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * MAXSIZEMDRECNAME is the value that has historically been used to allocate
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * space for the metadevice name
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * strip_blacks()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Strip blanks from string. Used for size field in concise output.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic char *
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw for (p = s; *p; ) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw if (*p == ' ') {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw for (t = p; *t; t++) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw *t = *(t + 1);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw return (s);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * print_concise_entry()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Print properly indented metadevice name, type and size for concise output.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * This function is also called from: cmd/lvm/util/metastat.c.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwprint_concise_entry(int indent, char *name, diskaddr_t size, char mtype)
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw int width = NAMEWIDTH; /* minumum field width for name */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw for (i = 0; i < indent; i++)
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* set up minimum field width. negative for left justified */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw if (size == 0) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw sz = strip_blanks(meta_number_to_string(size, DEV_BSIZE));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (void) printf("%s%*s %c %6s", in, width, name, mtype, sz);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * free_mdrec_list_entry()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Removing entry from the list of metadevices in the diskset(mdimpp).
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * This function will not remove the dummy entry at the head of the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * list, so we don't have to set mdrec equal to NULL.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * ucomponent_append()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Appending entry to the underlying component list. The list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * is used to group all of the underlying devices before
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * processing them.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * free_md_im_list_entries()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Freeing entries on an md_im_list_t. This list is used to group
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * underlying components for processing and to group top-level metadevices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * by type.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * print_physical_device()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If a metadevice has an underlying component that is a physical
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * device, then this searches the pnm_rec_t list to match an entry's
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * n_key to the key for the underlying component. The ctd name of the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * physical device is printed on the same line as the metadevice.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * get_stripe_req_size()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Given a 64bit stripe unit, compute the size of the stripe unit.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * This function is a derivation of:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * common/lvm/md_convert.c:get_big_stripe_req_size()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * and any changes made to either this function or get_big_stripe_req_size()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * should be reviewed to make sure the functionality in both places is correct.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * total size of the 64bit stripe
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Compute the offset of the first component */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Requestor wants to have the total size, add the sizes of
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * all components
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * meta_get_sm_state()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Gets the state for the underlying components(submirrors) of a mirror.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * This function is also called from: cmd/lvm/util/metastat.c.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * string for state of the sub-mirror
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic char *
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* all is well */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* resyncing, needs repair */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* needs repair */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw if (state & (SMS_COMP_ERRED | SMS_ATTACHED | SMS_OFFLINE))
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* unknown */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * meta_get_raid_col_state()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Gets the state for the underlying components(columns) of a raid.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * This function is also called from: cmd/lvm/util/metastat.c.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * string for state of the raid column
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw switch (state) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /*FALLTHROUGH*/
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * meta_get_stripe_state()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Gets the state for the underlying components of a stripe.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * This function is also called from: cmd/lvm/util/metastat.c.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * string for state of the stripe
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw switch (state) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * meta_get_hs_state()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Gets the state for the underlying components(hotspares) of a hotspare pool.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * This function is also called from: cmd/lvm/util/metastat.c.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * string for state of the hotspare
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw switch (state) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* FALLTHROUGH */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_trans()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Prints unit information for a trans metadevice and calls the respective
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * functions to process the underlying metadevices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name, size, and type of metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Loops through md_im_rec_t **mdimpp list of all metadevices to find
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * record that matches the underlying device.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Trans devices can only have one underlying device, so once a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * match is found, we are done.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name of the underlying metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If a metadevice was not found, then the underlying device must be a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * physical device. Otherwise, call the functions to process the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * underlying devices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* process underlying component */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Removing the md_entry from the list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * of all metadevices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_hotspare()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Searches though list of physical devices to match hotspare record.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Prints physical device name and state of a hotspare unit.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw/*ARGSUSED*/
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Loops through physical namespace to find the device that matches
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the hotspare entry.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name of hotspare device */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Not removing entry, because it can be processed more than once. */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_hotspare_pool()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Prints concise unit information for a hotspare pool metadevice and calls a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * function to process each attached hotspare device.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Printing name, size, and type of metadevice. Setting size field to
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * 0, so that output is the as metastat -c.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Looping through list of attached hotspare devices. */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Looking for the matching record for the hotspare device. */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Calling function to print name of hotspare */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Removing the md_entry from the list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * of all metadevices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_raid()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Prints concise unit information for a raid metadevice and calls the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * respective functions to process the underlying metadevices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name, size, and type of metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Loops through raid columns to find underlying metadevices */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw for (i = 0, mc = &mr->un_column[0]; i < mr->un_totalcolumncnt;
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw i++, mc++) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Need to assume that underlying device is a physical device,
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * unless we find a matching metadevice record.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Loops through list of metadevices to find record that matches
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the underlying device.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* check if hotspare device enabled */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Find matching metadevice record
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * for the hotspare device.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* print name of hs */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* print name of underlying metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * An underlying hotspare must be a physical device.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If support is ever added for soft-partitions under
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * hotspare pools, then this code should be updated to
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * include a search for underlying metadevices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* process underlying components */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Removing the md_entry from the list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * of all metadevices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_mirror()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Prints concise unit information for a mirror metadevice and calls the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * respective functions to process the underlying metadevices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name, size, and type of metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Looping through sub-mirrors to find underlying devices */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw for (i = 0, sm = &mm->un_sm[0]; i < mm->un_nsm; i++, sm++) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * It is not possible to have an underlying physical device
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * for a submirror, so there is no need to search the phys_nm
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing the state for the submirror */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* process underlying components */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Removing the md_entry from the list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * of all metadevices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_stripe()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Prints concise unit information for a stripe metadevice and calls the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * respective functions to process the underlying metadevices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name, size, and type of metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Looping through stripe rows */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Looping through the components in each row to find the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * underlying devices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw for (comp = 0, c = mdr->un_icomp; (comp < mdr->un_ncomp);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Need to assume that underlying device is a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * physical device, unless we find a matching
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * metadevice record.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* if an underlying metadevice was not found */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * An underlying hotspare must be a physical device.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If support is ever added for soft-partitions under
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * hotspare pools, then this code should be updated to
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * include a search for underlying metadevices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Process underlying metadevices */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Removing the md_entry from the list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * of all metadevices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_softpart()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Prints concise unit information for a softpart metadevice and calls the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * respective functions to process the underlying metadevices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name, size, and type of metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Loops through md_im_rec_t **mdimpp list of all metadevices to find
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * record that matches the underlying device.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Softpartitions can only have one underlying device, so once a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * match is found, we are done.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name of the underlying metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* This is only executed if an underlying metadevice was not found */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Process underlying metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Removing the md_entry from the list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * of all metadevices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_toplevel_softparts()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Toplevel softpartions need to be grouped so that their underlying devices
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * can be printed just once.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw md_im_rec_t *comp_mdrec; /* pntr to underlying component's record */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Loops through md_im_rec_t **mdimpp list of all metadevices to find
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * all softpartions that are toplevel softpartitions(softparts w/out
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * a parent). Groups output for these entries so that the function to
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process the underlying metadevice is only called once.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw for (mdrec = *mdimpp; mdrec != NULL; mdrec = mdrec->next) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Printing name, size, and type of metadevice */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Looking for record that matches underlying
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * component.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Print name of underlying device */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Looking for any other toplevel softpartitions with
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * same underlying device. We know that all other
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * matching metadevices, that share the same underlying
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * metadevice, are also soft-partitions.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Need to advance so that will not lose
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * position after removing processed
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Removing the md_entry from the list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * of all metadevices.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Process the underlying device */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * process_toplevel_devices()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Search through list of metadevices for metadevices of md_type that do not
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * have a parent.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmwstatic void
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Need to group soft partitions so that common underlying device
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * are only processed once.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Search the list of metadevices to find all metadevices that match
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the type and don't have a parent. Put them on a separate list
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * that will be processed.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw for (mdrec = *mdimpp; mdrec != NULL; mdrec = mdrec->next) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw if ((mdrec->md_type == md_type)&&(mdrec->has_parent == 0)) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Loop through list and process all top-level metadevices of a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * given type.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * extract_mduser_data()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Converts or copies the (mddb_rb_t->rb_data) metadevice record to a 64bit
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Sets the dfunc field to point to the appropriate function to process the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * metadevice.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Sets the parent field for the metadevice.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Extracts the name from the NM namespace if it is available, otherwise
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * generates it from the metadevice's minor number.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * < 0 for failure
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * 0 for success
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /*LINTED*/
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw nm_record = (struct nm_rec *)((caddr_t)(&rbp_nm->rb_data));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Setting the un_self_id or the hs_self_id, in the case of hotspare
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * records, for each metadevice entry. Also setting has_parent and
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * setting dfunc so that it points to the correct function to process
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the record type.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If the record was stored ondisk in 32bit format, then it is
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * converted to the 64bits equivalent 64bit format and the memory
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * for the 32bit pointer is freed.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw sizeof (struct mp_ext));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw sizeof (struct mp_ext));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Ondisk and incore records are always same size.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw (sizeof (mddb_rb_t) - sizeof (int)));
d7cd82522afdd890a66c7600b499590ad44e84bdtw * If the hsp has descriptive name we'll get
d7cd82522afdd890a66c7600b499590ad44e84bdtw * the un_self_id
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* All valid cases have been dealt with */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw return (-1);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If metadevice record has an entry in the NM namespace
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * then it is copied into the mdrec->n_name field.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /*LINTED*/
d7cd82522afdd890a66c7600b499590ad44e84bdtw * Extract the metadevice/hsp name if it is
d7cd82522afdd890a66c7600b499590ad44e84bdtw * in the namespace.
d7cd82522afdd890a66c7600b499590ad44e84bdtw * If it is a hot spare pool we will find our
d7cd82522afdd890a66c7600b499590ad44e84bdtw * match by comparing the NM record's n_key
d7cd82522afdd890a66c7600b499590ad44e84bdtw * with the extracted key from the hsp_self_id
d7cd82522afdd890a66c7600b499590ad44e84bdtw * Else, match the un_self_id for the record
d7cd82522afdd890a66c7600b499590ad44e84bdtw * to the n_minor name in the NM record.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If the metadevice name is not in the namespace, then
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * then we will generate the name from the minor number
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * for the metadevice. In the case of records for a hotspare
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * pool we use hsp_self_id, otherwise we use un_self_id.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Generate the metadevice name for all other records
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * (except for hotspares, because hotspares can only
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * be physical devices.)
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw return (0);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * read_mdrecord()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Reads the mddb_rb32_od_t or mddb_rb_t and the associated metadevice record
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * from the disk. Runs magic, checksum, and revision checks on the record
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * < 0 for failure
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * 0 for success
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Read in the appropriate record and return configurations */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * The only place to discover whether or not the record is a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * 32bit or 64bit record is from the record's rb_revision field.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * The mddb_rb_t and mddb_rb32_t structures are identical for the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * following fields:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * rb_magic, rb_revision, rb_checksum, and rb_checksum_fiddle.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * So we can assume that the record is a 32bit structure when we
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * check the record's magic number and revision and when we calculate
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * the records checksum.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Checking the magic number for the record block.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Checking the revision for the record block. Must match either
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * revision for the current 64bit or 32bit record block. Also,
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * setting the flag for whether or not it is a 32bit record.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Calculating the checksum for this record block. Need
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * to skip the rb's checksum fiddle.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw skip->skip_offset = offsetof(mddb_rb_t, rb_checksum_fiddle);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw if (crcchk(rbp_32, &rbp_32->rb_checksum, dep->de_recsize, skip)) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* mddb_rb_t and mddb_rb32_t differ before the rb_timestamp field */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw if ((*lastaccess).tv_sec < rbp_32->rb_timestamp.tv_sec) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw if ((*lastaccess).tv_sec < rbp_64->rb_timestamp.tv_sec) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Populates the fields in md_im_rec_t *tmp_mdrec. */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw rval = extract_mduser_data(nm, tmp_mdrec, rbp, is_32bit_record, ep);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Adding record to the head of the list of all metadevices. */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Free the skip list */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * read_all_mdrecords()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Reads the directory block and directory entries.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Runs magic, checksum, and revision checks on the directory block.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * < 0 for failure
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * 0 for success
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /*LINTED*/
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Read in all directory blocks */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Set ep with error code for MDE_DB_NODB. This is the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * error code used in the kernel when there is a problem
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * with reading records in. Checks the magic number, the
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * revision, and the checksum for each directory block.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If db timestamp is more recent than the previously recorded
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * last modified timestamp, then update last modified.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw } else if ((*lastaccess).tv_sec == dbp->db_timestamp.tv_sec) {
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Creates dep list of all directory entries in the db */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* LINTED */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* LINTED */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Process all directory entries in the directory block.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * For each directory entry, read_mdrec is called to read
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * in the record data.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * de_flags is set to the type of metadevice.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If directory entry does not correspond to a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * specific metadevice then it is set to zero.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * All namespace records(NM, SHR_NM, DID_SHR_NM) have a
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * value of zero in their de_flags field.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * report_metastat_info()
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Generates the metastat -c output. Also, updates the global variable
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * for a last accessed timestamp.
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * Returns:
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * < 0 for failure
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * 0 for success
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* list of all metadevices in diskset */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Read in metadevice records and add entries to mdimp list. */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw rval = read_all_mdrecords(&mdimp, mb, lbp, nm, rsp, fd, lastaccess,
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Adding a fake record to the head of the list of all metadevices. */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw /* Calling functions to process all metadevices on mdimp list */
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw process_toplevel_devices(&mdimp, *pnm, MDDB_F_TRANS_MASTER);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw process_toplevel_devices(&mdimp, *pnm, MDDB_F_HOTSPARE_POOL);
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * If mdreclist is not null, then this will walk through all
4745263a792e84bbd9e36b3ceb07d1275762cf9bmw * elements and free them.