diff options
author | John Baldwin <jhb@FreeBSD.org> | 2010-10-26 19:11:09 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2010-10-26 19:11:09 +0000 |
commit | c02999d982778045d598fca278ad190db9dd47f8 (patch) | |
tree | e36599632f0916c8cd644998c49555ca4f9f9161 /usr.sbin/mfiutil/mfi_config.c | |
parent | 827f816c80346c08ffb23823987e8683206a51c4 (diff) | |
download | src-c02999d982778045d598fca278ad190db9dd47f8.tar.gz src-c02999d982778045d598fca278ad190db9dd47f8.zip |
- 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
Notes
Notes:
svn path=/head/; revision=214396
Diffstat (limited to 'usr.sbin/mfiutil/mfi_config.c')
-rw-r--r-- | usr.sbin/mfiutil/mfi_config.c | 91 |
1 files changed, 56 insertions, 35 deletions
diff --git a/usr.sbin/mfiutil/mfi_config.c b/usr.sbin/mfiutil/mfi_config.c index 2837694470a8..fc03aa7492ec 100644 --- a/usr.sbin/mfiutil/mfi_config.c +++ b/usr.sbin/mfiutil/mfi_config.c @@ -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 mfi_config_data *config); 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 *array_str, struct array_info *info) 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); |