From owner-svn-src-stable@FreeBSD.ORG Wed Nov 3 15:25:30 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B09741065679; Wed, 3 Nov 2010 15:25:30 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9D6AC8FC12; Wed, 3 Nov 2010 15:25:30 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oA3FPUcf024902; Wed, 3 Nov 2010 15:25:30 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oA3FPUuX024894; Wed, 3 Nov 2010 15:25:30 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201011031525.oA3FPUuX024894@svn.freebsd.org> From: John Baldwin Date: Wed, 3 Nov 2010 15:25:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r214742 - stable/8/usr.sbin/mfiutil X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Nov 2010 15:25:30 -0000 Author: jhb Date: Wed Nov 3 15:25:30 2010 New Revision: 214742 URL: http://svn.freebsd.org/changeset/base/214742 Log: MFC 213672,213674,214396: - Report subcommand handler errors in mfiutil so that tools that invoke the utilities can robustly report errors. - Fix compile with -DDEBUG by using the correct mfi_pd_ref union definition in mfireg.h. - Save errno values before calling warn(3) so that errors are correctly reported. - Use powerof2() from rather than a copy and paste version. Modified: stable/8/usr.sbin/mfiutil/mfi_config.c stable/8/usr.sbin/mfiutil/mfi_drive.c stable/8/usr.sbin/mfiutil/mfi_evt.c stable/8/usr.sbin/mfiutil/mfi_flash.c stable/8/usr.sbin/mfiutil/mfi_patrol.c stable/8/usr.sbin/mfiutil/mfi_show.c stable/8/usr.sbin/mfiutil/mfi_volume.c stable/8/usr.sbin/mfiutil/mfiutil.c Directory Properties: stable/8/usr.sbin/mfiutil/ (props changed) stable/8/usr.sbin/mfiutil/mfiutil.8 (props changed) Modified: stable/8/usr.sbin/mfiutil/mfi_config.c ============================================================================== --- stable/8/usr.sbin/mfiutil/mfi_config.c Wed Nov 3 15:24:25 2010 (r214741) +++ stable/8/usr.sbin/mfiutil/mfi_config.c Wed Nov 3 15:25:30 2010 (r214742) @@ -29,12 +29,12 @@ * $FreeBSD$ */ -#include +#include #ifdef DEBUG #include #endif -#include #include +#include #include #ifdef DEBUG #include @@ -52,8 +52,6 @@ static void dump_config(int fd, struct m static int add_spare(int ac, char **av); static int remove_spare(int ac, char **av); -#define powerof2(x) ((((x)-1)&(x))==0) - static long dehumanize(const char *value) { @@ -151,13 +149,14 @@ static int clear_config(int ac, char **av) { struct mfi_ld_list list; - int ch, fd; + int ch, error, fd; u_int i; fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (!mfi_reconfig_supported()) { @@ -167,8 +166,9 @@ clear_config(int ac, char **av) } if (mfi_ld_get_list(fd, &list, NULL) < 0) { + error = errno; warn("Failed to get volume list"); - return (errno); + return (error); } for (i = 0; i < list.ld_count; i++) { @@ -189,8 +189,9 @@ clear_config(int ac, char **av) } if (mfi_dcmd_command(fd, MFI_DCMD_CFG_CLEAR, NULL, 0, NULL, 0, NULL) < 0) { + error = errno; warn("Failed to clear configuration"); - return (errno); + return (error); } printf("mfi%d: Configuration cleared\n", mfi_unit); @@ -335,8 +336,9 @@ parse_array(int fd, int raid_type, char return (error); if (mfi_pd_get_info(fd, device_id, pinfo, NULL) < 0) { + error = errno; warn("Failed to fetch drive info for drive %s", cp); - return (errno); + return (error); } if (pinfo->fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) { @@ -548,8 +550,9 @@ create_volume(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (!mfi_reconfig_supported()) { @@ -660,8 +663,9 @@ create_volume(int ac, char **av) * array and volume identifiers. */ if (mfi_config_read(fd, &config) < 0) { + error = errno; warn("Failed to read configuration"); - return (errno); + return (error); } p = (char *)config->array; state.array_ref = 0xffff; @@ -745,14 +749,14 @@ create_volume(int ac, char **av) #ifdef DEBUG if (dump) dump_config(fd, config); - else #endif /* Send the new config to the controller. */ if (mfi_dcmd_command(fd, MFI_DCMD_CFG_ADD, config, config_size, NULL, 0, NULL) < 0) { + error = errno; warn("Failed to add volume"); - return (errno); + return (error); } /* Clean up. */ @@ -774,7 +778,7 @@ static int delete_volume(int ac, char **av) { struct mfi_ld_info info; - int fd; + int error, fd; uint8_t target_id, mbox[4]; /* @@ -799,8 +803,9 @@ delete_volume(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (!mfi_reconfig_supported()) { @@ -810,13 +815,15 @@ delete_volume(int ac, char **av) } if (mfi_lookup_volume(fd, av[1], &target_id) < 0) { + error = errno; warn("Invalid volume %s", av[1]); - return (errno); + return (error); } if (mfi_ld_get_info(fd, target_id, &info, NULL) < 0) { + error = errno; warn("Failed to get info for volume %d", target_id); - return (errno); + return (error); } if (mfi_volume_busy(fd, target_id)) { @@ -828,8 +835,9 @@ delete_volume(int ac, char **av) mbox_store_ldref(mbox, &info.ld_config.properties.ld); if (mfi_dcmd_command(fd, MFI_DCMD_LD_DELETE, NULL, 0, mbox, sizeof(mbox), NULL) < 0) { + error = errno; warn("Failed to delete volume"); - return (errno); + return (error); } close(fd); @@ -858,8 +866,9 @@ add_spare(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } error = mfi_lookup_drive(fd, av[1], &device_id); @@ -867,8 +876,9 @@ add_spare(int ac, char **av) return (error); if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) { + error = errno; warn("Failed to fetch drive info"); - return (errno); + return (error); } if (info.fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) { @@ -878,14 +888,16 @@ add_spare(int ac, char **av) if (ac > 2) { if (mfi_lookup_volume(fd, av[2], &target_id) < 0) { + error = errno; warn("Invalid volume %s", av[2]); - return (errno); + return (error); } } if (mfi_config_read(fd, &config) < 0) { + error = errno; warn("Failed to read configuration"); - return (errno); + return (error); } spare = malloc(sizeof(struct mfi_spare) + sizeof(uint16_t) * @@ -939,8 +951,9 @@ add_spare(int ac, char **av) if (mfi_dcmd_command(fd, MFI_DCMD_CFG_MAKE_SPARE, spare, sizeof(struct mfi_spare) + sizeof(uint16_t) * spare->array_count, NULL, 0, NULL) < 0) { + error = errno; warn("Failed to assign spare"); - return (errno); + return (error); } close(fd); @@ -964,8 +977,9 @@ remove_spare(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } error = mfi_lookup_drive(fd, av[1], &device_id); @@ -974,8 +988,9 @@ remove_spare(int ac, char **av) /* Get the info for this drive. */ if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) { + error = errno; warn("Failed to fetch info for drive %u", device_id); - return (errno); + return (error); } if (info.fw_state != MFI_PD_STATE_HOT_SPARE) { @@ -986,8 +1001,9 @@ remove_spare(int ac, char **av) mbox_store_pdref(mbox, &info.ref); if (mfi_dcmd_command(fd, MFI_DCMD_CFG_REMOVE_SPARE, NULL, 0, mbox, sizeof(mbox), NULL) < 0) { + error = errno; warn("Failed to delete spare"); - return (errno); + return (error); } close(fd); @@ -1024,7 +1040,7 @@ dump_config(int fd, struct mfi_config_da ar->num_drives); printf(" size = %ju\n", (uintmax_t)ar->size); for (j = 0; j < ar->num_drives; j++) { - device_id = ar->pd[j].ref.device_id; + device_id = ar->pd[j].ref.v.device_id; if (device_id == 0xffff) printf(" drive MISSING\n"); else { @@ -1080,7 +1096,7 @@ dump_config(int fd, struct mfi_config_da sp = (struct mfi_spare *)p; printf(" %s spare %u ", sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" : - "global", sp->ref.device_id); + "global", sp->ref.v.device_id); printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE)); printf(" backs:\n"); for (j = 0; j < sp->array_count; j++) @@ -1093,7 +1109,7 @@ static int debug_config(int ac, char **av) { struct mfi_config_data *config; - int fd; + int error, fd; if (ac != 1) { warnx("debug: extra arguments"); @@ -1102,14 +1118,16 @@ debug_config(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } /* Get the config from the controller. */ if (mfi_config_read(fd, &config) < 0) { + error = errno; warn("Failed to get config"); - return (errno); + return (error); } /* Dump out the configuration. */ @@ -1127,7 +1145,7 @@ dump(int ac, char **av) struct mfi_config_data *config; char buf[64]; size_t len; - int fd; + int error, fd; if (ac != 1) { warnx("dump: extra arguments"); @@ -1136,23 +1154,26 @@ dump(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } /* Get the stashed copy of the last dcmd from the driver. */ snprintf(buf, sizeof(buf), "dev.mfi.%d.debug_command", mfi_unit); if (sysctlbyname(buf, NULL, &len, NULL, 0) < 0) { + error = errno; warn("Failed to read debug command"); - if (errno == ENOENT) - errno = EOPNOTSUPP; - return (errno); + if (error == ENOENT) + error = EOPNOTSUPP; + return (error); } config = malloc(len); if (sysctlbyname(buf, config, &len, NULL, 0) < 0) { + error = errno; warn("Failed to read debug command"); - return (errno); + return (error); } dump_config(fd, config); free(config); Modified: stable/8/usr.sbin/mfiutil/mfi_drive.c ============================================================================== --- stable/8/usr.sbin/mfiutil/mfi_drive.c Wed Nov 3 15:24:25 2010 (r214741) +++ stable/8/usr.sbin/mfiutil/mfi_drive.c Wed Nov 3 15:25:30 2010 (r214742) @@ -79,10 +79,11 @@ int mfi_lookup_drive(int fd, char *drive, uint16_t *device_id) { struct mfi_pd_list *list; - uint8_t encl, slot; long val; + int error; u_int i; char *cp; + uint8_t encl, slot; /* Look for a raw device id first. */ val = strtol(drive, &cp, 0); @@ -118,8 +119,9 @@ mfi_lookup_drive(int fd, char *drive, ui slot = val; if (mfi_pd_get_list(fd, &list, NULL) < 0) { + error = errno; warn("Failed to fetch drive list"); - return (errno); + return (error); } for (i = 0; i < list->count; i++) { @@ -302,8 +304,9 @@ drive_set_state(char *drive, uint16_t ne fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } error = mfi_lookup_drive(fd, drive, &device_id); @@ -312,8 +315,9 @@ drive_set_state(char *drive, uint16_t ne /* Get the info for this drive. */ if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) { + error = errno; warn("Failed to fetch info for drive %u", device_id); - return (errno); + return (error); } /* Try to change the state. */ @@ -327,9 +331,10 @@ drive_set_state(char *drive, uint16_t ne mbox[5] = new_state >> 8; if (mfi_dcmd_command(fd, MFI_DCMD_PD_STATE_SET, NULL, 0, mbox, 6, NULL) < 0) { + error = errno; warn("Failed to set drive %u to %s", device_id, mfi_pdstate(new_state)); - return (errno); + return (error); } close(fd); @@ -395,8 +400,9 @@ start_rebuild(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } error = mfi_lookup_drive(fd, av[1], &device_id); @@ -405,13 +411,14 @@ start_rebuild(int ac, char **av) /* Get the info for this drive. */ if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) { + error = errno; warn("Failed to fetch info for drive %u", device_id); - return (errno); + return (error); } /* Check the state, must be REBUILD. */ if (info.fw_state != MFI_PD_STATE_REBUILD) { - warn("Drive %d is not in the REBUILD state", device_id); + warnx("Drive %d is not in the REBUILD state", device_id); return (EINVAL); } @@ -419,8 +426,9 @@ start_rebuild(int ac, char **av) mbox_store_pdref(&mbox[0], &info.ref); if (mfi_dcmd_command(fd, MFI_DCMD_PD_REBUILD_START, NULL, 0, mbox, 4, NULL) < 0) { + error = errno; warn("Failed to start rebuild on drive %u", device_id); - return (errno); + return (error); } close(fd); @@ -444,8 +452,9 @@ abort_rebuild(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } error = mfi_lookup_drive(fd, av[1], &device_id); @@ -454,8 +463,9 @@ abort_rebuild(int ac, char **av) /* Get the info for this drive. */ if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) { + error = errno; warn("Failed to fetch info for drive %u", device_id); - return (errno); + return (error); } /* Check the state, must be REBUILD. */ @@ -468,8 +478,9 @@ abort_rebuild(int ac, char **av) mbox_store_pdref(&mbox[0], &info.ref); if (mfi_dcmd_command(fd, MFI_DCMD_PD_REBUILD_ABORT, NULL, 0, mbox, 4, NULL) < 0) { + error = errno; warn("Failed to abort rebuild on drive %u", device_id); - return (errno); + return (error); } close(fd); @@ -492,8 +503,9 @@ drive_progress(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } error = mfi_lookup_drive(fd, av[1], &device_id); @@ -502,8 +514,9 @@ drive_progress(int ac, char **av) /* Get the info for this drive. */ if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) { + error = errno; warn("Failed to fetch info for drive %u", device_id); - return (errno); + return (error); } close(fd); @@ -551,8 +564,9 @@ drive_clear(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } error = mfi_lookup_drive(fd, av[1], &device_id); @@ -561,16 +575,18 @@ drive_clear(int ac, char **av) /* Get the info for this drive. */ if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) { + error = errno; warn("Failed to fetch info for drive %u", device_id); - return (errno); + return (error); } mbox_store_pdref(&mbox[0], &info.ref); if (mfi_dcmd_command(fd, opcode, NULL, 0, mbox, 4, NULL) < 0) { + error = errno; warn("Failed to %s clear on drive %u", opcode == MFI_DCMD_PD_CLEAR_START ? "start" : "stop", device_id); - return (errno); + return (error); } close(fd); @@ -604,8 +620,9 @@ drive_locate(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } error = mfi_lookup_drive(fd, av[1], &device_id); @@ -617,10 +634,11 @@ drive_locate(int ac, char **av) mbox[2] = 0; mbox[3] = 0; if (mfi_dcmd_command(fd, opcode, NULL, 0, mbox, 4, NULL) < 0) { + error = errno; warn("Failed to %s locate on drive %u", opcode == MFI_DCMD_PD_LOCATE_START ? "start" : "stop", device_id); - return (errno); + return (error); } close(fd); Modified: stable/8/usr.sbin/mfiutil/mfi_evt.c ============================================================================== --- stable/8/usr.sbin/mfiutil/mfi_evt.c Wed Nov 3 15:24:25 2010 (r214741) +++ stable/8/usr.sbin/mfiutil/mfi_evt.c Wed Nov 3 15:25:30 2010 (r214742) @@ -32,7 +32,6 @@ #include #include #include -//#include #include #include #include @@ -67,7 +66,7 @@ static int show_logstate(int ac, char **av) { struct mfi_evt_log_state info; - int fd; + int error, fd; if (ac != 1) { warnx("show logstate: extra arguments"); @@ -76,13 +75,15 @@ show_logstate(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (mfi_event_get_info(fd, &info, NULL) < 0) { + error = errno; warn("Failed to get event log info"); - return (errno); + return (error); } printf("mfi%d Event Log Sequence Numbers:\n", mfi_unit); @@ -536,18 +537,20 @@ show_events(int ac, char **av) ssize_t size; uint32_t seq, start, stop; uint8_t status; - int ch, fd, num_events, verbose; + int ch, error, fd, num_events, verbose; u_int i; fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (mfi_event_get_info(fd, &info, NULL) < 0) { + error = errno; warn("Failed to get event log info"); - return (errno); + return (error); } /* Default settings. */ @@ -565,14 +568,16 @@ show_events(int ac, char **av) switch (ch) { case 'c': if (parse_class(optarg, &filter.members.class) < 0) { + error = errno; warn("Error parsing event class"); - return (errno); + return (error); } break; case 'l': if (parse_locale(optarg, &filter.members.locale) < 0) { + error = errno; warn("Error parsing event locale"); - return (errno); + return (error); } break; case 'n': @@ -608,20 +613,23 @@ show_events(int ac, char **av) return (EINVAL); } if (ac > 0 && parse_seq(&info, av[0], &start) < 0) { + error = errno; warn("Error parsing starting sequence number"); - return (errno); + return (error); } if (ac > 1 && parse_seq(&info, av[1], &stop) < 0) { + error = errno; warn("Error parsing ending sequence number"); - return (errno); + return (error); } list = malloc(size); for (seq = start;;) { if (mfi_get_events(fd, list, num_events, filter, seq, &status) < 0) { + error = errno; warn("Failed to fetch events"); - return (errno); + return (error); } if (status == MFI_STAT_NOT_FOUND) { if (seq == start) Modified: stable/8/usr.sbin/mfiutil/mfi_flash.c ============================================================================== --- stable/8/usr.sbin/mfiutil/mfi_flash.c Wed Nov 3 15:24:25 2010 (r214741) +++ stable/8/usr.sbin/mfiutil/mfi_flash.c Wed Nov 3 15:25:30 2010 (r214742) @@ -72,16 +72,18 @@ display_firmware(struct mfi_info_compone fw_time_width, comp->build_time); } -static void +static int display_pending_firmware(int fd) { struct mfi_ctrl_info info; struct mfi_info_component header; + int error; u_int i; if (mfi_ctrl_get_info(fd, &info, NULL) < 0) { + error = errno; warn("Failed to get controller info"); - return; + return (error); } printf("mfi%d Pending Firmware Images:\n", mfi_unit); @@ -97,6 +99,8 @@ display_pending_firmware(int fd) display_firmware(&header); for (i = 0; i < info.pending_image_component_count; i++) display_firmware(&info.pending_image_component[i]); + + return (0); } static void @@ -117,7 +121,7 @@ flash_adapter(int ac, char **av) size_t nread; char *buf; struct stat sb; - int fd, flash; + int error, fd, flash; uint8_t mbox[4], status; if (ac != 2) { @@ -127,13 +131,15 @@ flash_adapter(int ac, char **av) flash = open(av[1], O_RDONLY); if (flash < 0) { + error = errno; warn("flash: Failed to open %s", av[1]); - return (errno); + return (error); } if (fstat(flash, &sb) < 0) { + error = errno; warn("fstat(%s)", av[1]); - return (errno); + return (error); } if (sb.st_size % 1024 != 0 || sb.st_size > 0x7fffffff) { warnx("Invalid flash file size"); @@ -142,8 +148,9 @@ flash_adapter(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } /* First, ask the firmware to allocate space for the flash file. */ @@ -190,10 +197,10 @@ flash_adapter(int ac, char **av) return (ENXIO); } printf("finished\n"); - display_pending_firmware(fd); + error = display_pending_firmware(fd); close(fd); - return (0); + return (error); } MFI_COMMAND(top, flash, flash_adapter); Modified: stable/8/usr.sbin/mfiutil/mfi_patrol.c ============================================================================== --- stable/8/usr.sbin/mfiutil/mfi_patrol.c Wed Nov 3 15:24:25 2010 (r214741) +++ stable/8/usr.sbin/mfiutil/mfi_patrol.c Wed Nov 3 15:25:30 2010 (r214742) @@ -62,11 +62,13 @@ mfi_get_time(int fd, uint32_t *at) static int patrol_get_props(int fd, struct mfi_pr_properties *prop) { + int error; if (mfi_dcmd_command(fd, MFI_DCMD_PR_GET_PROPERTIES, prop, sizeof(*prop), NULL, 0, NULL) < 0) { + error = errno; warn("Failed to get patrol read properties"); - return (-1); + return (error); } return (0); } @@ -81,19 +83,21 @@ show_patrol(int ac, char **av) char label[16]; time_t now; uint32_t at; - int fd; + int error, fd; u_int i; fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } time(&now); mfi_get_time(fd, &at); - if (patrol_get_props(fd, &prop) < 0) - return (errno); + error = patrol_get_props(fd, &prop); + if (error) + return (error); printf("Operation Mode: "); switch (prop.op_mode) { case MFI_PR_OPMODE_AUTO: @@ -122,8 +126,9 @@ show_patrol(int ac, char **av) if (mfi_dcmd_command(fd, MFI_DCMD_PR_GET_STATUS, &status, sizeof(status), NULL, 0, NULL) < 0) { + error = errno; warn("Failed to get patrol read properties"); - return (errno); + return (error); } printf("Runs Completed: %u\n", status.num_iteration); printf("Current State: "); @@ -146,8 +151,9 @@ show_patrol(int ac, char **av) } if (status.state == MFI_PR_STATE_ACTIVE) { if (mfi_pd_get_list(fd, &list, NULL) < 0) { + error = errno; warn("Failed to get drive list"); - return (errno); + return (error); } for (i = 0; i < list->count; i++) { @@ -156,9 +162,10 @@ show_patrol(int ac, char **av) if (mfi_pd_get_info(fd, list->addr[i].device_id, &info, NULL) < 0) { + error = errno; warn("Failed to fetch info for drive %u", list->addr[i].device_id); - return (errno); + return (error); } if (info.prog_info.active & MFI_PD_PROGRESS_PATROL) { snprintf(label, sizeof(label), " Drive %u", @@ -178,18 +185,20 @@ MFI_COMMAND(show, patrol, show_patrol); static int start_patrol(int ac, char **av) { - int fd; + int error, fd; fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (mfi_dcmd_command(fd, MFI_DCMD_PR_START, NULL, 0, NULL, 0, NULL) < 0) { + error = errno; warn("Failed to start patrol read"); - return (errno); + return (error); } close(fd); @@ -201,18 +210,20 @@ MFI_COMMAND(start, patrol, start_patrol) static int stop_patrol(int ac, char **av) { - int fd; + int error, fd; fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (mfi_dcmd_command(fd, MFI_DCMD_PR_STOP, NULL, 0, NULL, 0, NULL) < 0) { + error = errno; warn("Failed to stop patrol read"); - return (errno); + return (error); } close(fd); @@ -227,10 +238,10 @@ patrol_config(int ac, char **av) struct mfi_pr_properties prop; long val; time_t now; + int error, fd; uint32_t at, next_exec, exec_freq; char *cp; uint8_t op_mode; - int fd; exec_freq = 0; /* GCC too stupid */ next_exec = 0; @@ -272,12 +283,14 @@ patrol_config(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } - if (patrol_get_props(fd, &prop) < 0) - return (errno); + error = patrol_get_props(fd, &prop); + if (error) + return (error); prop.op_mode = op_mode; if (op_mode == MFI_PR_OPMODE_AUTO) { if (ac > 2) @@ -294,8 +307,9 @@ patrol_config(int ac, char **av) } if (mfi_dcmd_command(fd, MFI_DCMD_PR_SET_PROPERTIES, &prop, sizeof(prop), NULL, 0, NULL) < 0) { + error = errno; warn("Failed to set patrol read properties"); - return (errno); + return (error); } close(fd); Modified: stable/8/usr.sbin/mfiutil/mfi_show.c ============================================================================== --- stable/8/usr.sbin/mfiutil/mfi_show.c Wed Nov 3 15:24:25 2010 (r214741) +++ stable/8/usr.sbin/mfiutil/mfi_show.c Wed Nov 3 15:25:30 2010 (r214742) @@ -54,7 +54,7 @@ show_adapter(int ac, char **av) { struct mfi_ctrl_info info; char stripe[5]; - int fd, comma; + int error, fd, comma; if (ac != 1) { warnx("show adapter: extra arguments"); @@ -63,13 +63,15 @@ show_adapter(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (mfi_ctrl_get_info(fd, &info, NULL) < 0) { + error = errno; warn("Failed to get controller info"); - return (errno); + return (error); } printf("mfi%d Adapter:\n", mfi_unit); printf(" Product Name: %.80s\n", info.product_name); @@ -137,7 +139,7 @@ show_battery(int ac, char **av) struct mfi_bbu_capacity_info cap; struct mfi_bbu_design_info design; uint8_t status; - int fd; + int error, fd; if (ac != 1) { warnx("show battery: extra arguments"); @@ -146,8 +148,9 @@ show_battery(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_CAPACITY_INFO, &cap, @@ -156,14 +159,16 @@ show_battery(int ac, char **av) printf("mfi%d: No battery present\n", mfi_unit); return (0); } + error = errno; warn("Failed to get capacity info"); - return (errno); + return (error); } if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_DESIGN_INFO, &design, sizeof(design), NULL, 0, NULL) < 0) { + error = errno; warn("Failed to get design info"); - return (errno); + return (error); } printf("mfi%d: Battery State:\n", mfi_unit); @@ -242,7 +247,7 @@ show_config(int ac, char **av) struct mfi_pd_info pinfo; uint16_t device_id; char *p; - int fd, i, j; + int error, fd, i, j; if (ac != 1) { warnx("show config: extra arguments"); @@ -251,14 +256,16 @@ show_config(int ac, char **av) fd = mfi_open(mfi_unit); if (fd < 0) { + error = errno; warn("mfi_open"); - return (errno); + return (error); } /* Get the config from the controller. */ if (mfi_config_read(fd, &config) < 0) { + error = errno; warn("Failed to get config"); - return (errno); + return (error); } /* Dump out the configuration. */ @@ -337,8 +344,8 @@ show_volumes(int ac, char **av) { *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***