Author: jhb
Date: Tue Oct 26 19:11:09 2010
New Revision: 214396
URL: http://svn.freebsd.org/changeset/base/214396

Log:
  - Save errno values before calling warn(3) so that errors are correctly
    reported.
  - Use powerof2() from <sys/param.h> rather than a copy and paste version.
  
  Submitted by: gcooper
  MFC after:    1 week

Modified:
  head/usr.sbin/mfiutil/mfi_config.c
  head/usr.sbin/mfiutil/mfi_drive.c
  head/usr.sbin/mfiutil/mfi_evt.c
  head/usr.sbin/mfiutil/mfi_flash.c
  head/usr.sbin/mfiutil/mfi_patrol.c
  head/usr.sbin/mfiutil/mfi_show.c
  head/usr.sbin/mfiutil/mfi_volume.c

Modified: head/usr.sbin/mfiutil/mfi_config.c
==============================================================================
--- head/usr.sbin/mfiutil/mfi_config.c  Tue Oct 26 19:10:59 2010        
(r214395)
+++ head/usr.sbin/mfiutil/mfi_config.c  Tue Oct 26 19:11:09 2010        
(r214396)
@@ -29,12 +29,12 @@
  * $FreeBSD$
  */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #ifdef DEBUG
 #include <sys/sysctl.h>
 #endif
-#include <sys/errno.h>
 #include <err.h>
+#include <errno.h>
 #include <libutil.h>
 #ifdef DEBUG
 #include <stdint.h>
@@ -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);
@@ -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: head/usr.sbin/mfiutil/mfi_drive.c
==============================================================================
--- head/usr.sbin/mfiutil/mfi_drive.c   Tue Oct 26 19:10:59 2010        
(r214395)
+++ head/usr.sbin/mfiutil/mfi_drive.c   Tue Oct 26 19:11:09 2010        
(r214396)
@@ -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: head/usr.sbin/mfiutil/mfi_evt.c
==============================================================================
--- head/usr.sbin/mfiutil/mfi_evt.c     Tue Oct 26 19:10:59 2010        
(r214395)
+++ head/usr.sbin/mfiutil/mfi_evt.c     Tue Oct 26 19:11:09 2010        
(r214396)
@@ -32,7 +32,6 @@
 #include <sys/types.h>
 #include <sys/errno.h>
 #include <err.h>
-//#include <libutil.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <strings.h>
@@ -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: head/usr.sbin/mfiutil/mfi_flash.c
==============================================================================
--- head/usr.sbin/mfiutil/mfi_flash.c   Tue Oct 26 19:10:59 2010        
(r214395)
+++ head/usr.sbin/mfiutil/mfi_flash.c   Tue Oct 26 19:11:09 2010        
(r214396)
@@ -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: head/usr.sbin/mfiutil/mfi_patrol.c
==============================================================================
--- head/usr.sbin/mfiutil/mfi_patrol.c  Tue Oct 26 19:10:59 2010        
(r214395)
+++ head/usr.sbin/mfiutil/mfi_patrol.c  Tue Oct 26 19:11:09 2010        
(r214396)
@@ -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: head/usr.sbin/mfiutil/mfi_show.c
==============================================================================
--- head/usr.sbin/mfiutil/mfi_show.c    Tue Oct 26 19:10:59 2010        
(r214395)
+++ head/usr.sbin/mfiutil/mfi_show.c    Tue Oct 26 19:11:09 2010        
(r214396)
@@ -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)
 {
        struct mfi_ld_list list;
        struct mfi_ld_info info;
+       int error, fd;
        u_int i, len, state_len;
-       int fd;
 
        if (ac != 1) {
                warnx("show volumes: extra arguments");
@@ -347,14 +354,16 @@ show_volumes(int ac, char **av)
 
        fd = mfi_open(mfi_unit);
        if (fd < 0) {
+               error = errno;
                warn("mfi_open");
-               return (errno);
+               return (error);
        }
 

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to