Deleted Added
full compact
mfi_config.c (214396) mfi_config.c (215526)
1/*-
2 * Copyright (c) 2008, 2009 Yahoo!, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
1/*-
2 * Copyright (c) 2008, 2009 Yahoo!, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/usr.sbin/mfiutil/mfi_config.c 214396 2010-10-26 19:11:09Z jhb $
29 * $FreeBSD: head/usr.sbin/mfiutil/mfi_config.c 215526 2010-11-19 15:39:59Z jhb $
30 */
31
32#include <sys/param.h>
33#ifdef DEBUG
34#include <sys/sysctl.h>
35#endif
36#include <err.h>
37#include <errno.h>

--- 285 unchanged lines hidden (view full) ---

323 "each array");
324 return (EINVAL);
325 }
326 break;
327 }
328
329 /* Validate each drive. */
330 info->drives = calloc(count, sizeof(struct mfi_pd_info));
30 */
31
32#include <sys/param.h>
33#ifdef DEBUG
34#include <sys/sysctl.h>
35#endif
36#include <err.h>
37#include <errno.h>

--- 285 unchanged lines hidden (view full) ---

323 "each array");
324 return (EINVAL);
325 }
326 break;
327 }
328
329 /* Validate each drive. */
330 info->drives = calloc(count, sizeof(struct mfi_pd_info));
331 if (info->drives == NULL) {
332 warnx("malloc failed");
333 return (ENOMEM);
334 }
331 info->drive_count = count;
332 for (pinfo = info->drives; (cp = strsep(&array_str, ",")) != NULL;
333 pinfo++) {
334 error = mfi_lookup_drive(fd, cp, &device_id);
335 if (error)
336 return (error);
337
338 if (mfi_pd_get_info(fd, device_id, pinfo, NULL) < 0) {

--- 294 unchanged lines hidden (view full) ---

633 if (narrays > MFI_MAX_SPAN_DEPTH) {
634 warnx("Volume spans more than %d arrays",
635 MFI_MAX_SPAN_DEPTH);
636 return (EINVAL);
637 }
638 break;
639 }
640 arrays = calloc(narrays, sizeof(*arrays));
335 info->drive_count = count;
336 for (pinfo = info->drives; (cp = strsep(&array_str, ",")) != NULL;
337 pinfo++) {
338 error = mfi_lookup_drive(fd, cp, &device_id);
339 if (error)
340 return (error);
341
342 if (mfi_pd_get_info(fd, device_id, pinfo, NULL) < 0) {

--- 294 unchanged lines hidden (view full) ---

637 if (narrays > MFI_MAX_SPAN_DEPTH) {
638 warnx("Volume spans more than %d arrays",
639 MFI_MAX_SPAN_DEPTH);
640 return (EINVAL);
641 }
642 break;
643 }
644 arrays = calloc(narrays, sizeof(*arrays));
645 if (arrays == NULL) {
646 warnx("malloc failed");
647 return (ENOMEM);
648 }
641 for (i = 0; i < narrays; i++) {
642 error = parse_array(fd, raid_type, av[i], &arrays[i]);
643 if (error)
644 return (error);
645 }
646
647 switch (raid_type) {
648 case RT_RAID10:

--- 19 unchanged lines hidden (view full) ---

668 return (error);
669 }
670 p = (char *)config->array;
671 state.array_ref = 0xffff;
672 state.target_id = 0xff;
673 state.array_count = config->array_count;
674 if (config->array_count > 0) {
675 state.arrays = calloc(config->array_count, sizeof(int));
649 for (i = 0; i < narrays; i++) {
650 error = parse_array(fd, raid_type, av[i], &arrays[i]);
651 if (error)
652 return (error);
653 }
654
655 switch (raid_type) {
656 case RT_RAID10:

--- 19 unchanged lines hidden (view full) ---

676 return (error);
677 }
678 p = (char *)config->array;
679 state.array_ref = 0xffff;
680 state.target_id = 0xff;
681 state.array_count = config->array_count;
682 if (config->array_count > 0) {
683 state.arrays = calloc(config->array_count, sizeof(int));
684 if (state.arrays == NULL) {
685 warnx("malloc failed");
686 return (ENOMEM);
687 }
676 for (i = 0; i < config->array_count; i++) {
677 ar = (struct mfi_array *)p;
678 state.arrays[i] = ar->array_ref;
679 p += config->array_size;
680 }
681 qsort(state.arrays, config->array_count, sizeof(int),
682 compare_int);
683 } else
684 state.arrays = NULL;
685 state.log_drv_count = config->log_drv_count;
686 if (config->log_drv_count) {
687 state.volumes = calloc(config->log_drv_count, sizeof(int));
688 for (i = 0; i < config->array_count; i++) {
689 ar = (struct mfi_array *)p;
690 state.arrays[i] = ar->array_ref;
691 p += config->array_size;
692 }
693 qsort(state.arrays, config->array_count, sizeof(int),
694 compare_int);
695 } else
696 state.arrays = NULL;
697 state.log_drv_count = config->log_drv_count;
698 if (config->log_drv_count) {
699 state.volumes = calloc(config->log_drv_count, sizeof(int));
700 if (state.volumes == NULL) {
701 warnx("malloc failed");
702 return (ENOMEM);
703 }
688 for (i = 0; i < config->log_drv_count; i++) {
689 ld = (struct mfi_ld_config *)p;
690 state.volumes[i] = ld->properties.ld.v.target_id;
691 p += config->log_drv_size;
692 }
693 qsort(state.volumes, config->log_drv_count, sizeof(int),
694 compare_int);
695 } else

--- 20 unchanged lines hidden (view full) ---

716 default:
717 /* Pacify gcc. */
718 abort();
719 }
720
721 config_size = sizeof(struct mfi_config_data) +
722 sizeof(struct mfi_ld_config) * nvolumes + MFI_ARRAY_SIZE * narrays;
723 config = calloc(1, config_size);
704 for (i = 0; i < config->log_drv_count; i++) {
705 ld = (struct mfi_ld_config *)p;
706 state.volumes[i] = ld->properties.ld.v.target_id;
707 p += config->log_drv_size;
708 }
709 qsort(state.volumes, config->log_drv_count, sizeof(int),
710 compare_int);
711 } else

--- 20 unchanged lines hidden (view full) ---

732 default:
733 /* Pacify gcc. */
734 abort();
735 }
736
737 config_size = sizeof(struct mfi_config_data) +
738 sizeof(struct mfi_ld_config) * nvolumes + MFI_ARRAY_SIZE * narrays;
739 config = calloc(1, config_size);
740 if (config == NULL) {
741 warnx("malloc failed");
742 return (ENOMEM);
743 }
724 config->size = config_size;
725 config->array_count = narrays;
726 config->array_size = MFI_ARRAY_SIZE; /* XXX: Firmware hardcode */
727 config->log_drv_count = nvolumes;
728 config->log_drv_size = sizeof(struct mfi_ld_config);
729 config->spares_count = 0;
730 config->spares_size = 40; /* XXX: Firmware hardcode */
731 cfg_arrays = (char *)config->array;

--- 165 unchanged lines hidden (view full) ---

897 if (mfi_config_read(fd, &config) < 0) {
898 error = errno;
899 warn("Failed to read configuration");
900 return (error);
901 }
902
903 spare = malloc(sizeof(struct mfi_spare) + sizeof(uint16_t) *
904 config->array_count);
744 config->size = config_size;
745 config->array_count = narrays;
746 config->array_size = MFI_ARRAY_SIZE; /* XXX: Firmware hardcode */
747 config->log_drv_count = nvolumes;
748 config->log_drv_size = sizeof(struct mfi_ld_config);
749 config->spares_count = 0;
750 config->spares_size = 40; /* XXX: Firmware hardcode */
751 cfg_arrays = (char *)config->array;

--- 165 unchanged lines hidden (view full) ---

917 if (mfi_config_read(fd, &config) < 0) {
918 error = errno;
919 warn("Failed to read configuration");
920 return (error);
921 }
922
923 spare = malloc(sizeof(struct mfi_spare) + sizeof(uint16_t) *
924 config->array_count);
925 if (spare == NULL) {
926 warnx("malloc failed");
927 return (ENOMEM);
928 }
905 bzero(spare, sizeof(struct mfi_spare));
906 spare->ref = info.ref;
907
908 if (ac == 2) {
909 /* Global spare backs all arrays. */
910 p = (char *)config->array;
911 for (i = 0; i < config->array_count; i++) {
912 ar = (struct mfi_array *)p;

--- 252 unchanged lines hidden (view full) ---

1165 error = errno;
1166 warn("Failed to read debug command");
1167 if (error == ENOENT)
1168 error = EOPNOTSUPP;
1169 return (error);
1170 }
1171
1172 config = malloc(len);
929 bzero(spare, sizeof(struct mfi_spare));
930 spare->ref = info.ref;
931
932 if (ac == 2) {
933 /* Global spare backs all arrays. */
934 p = (char *)config->array;
935 for (i = 0; i < config->array_count; i++) {
936 ar = (struct mfi_array *)p;

--- 252 unchanged lines hidden (view full) ---

1189 error = errno;
1190 warn("Failed to read debug command");
1191 if (error == ENOENT)
1192 error = EOPNOTSUPP;
1193 return (error);
1194 }
1195
1196 config = malloc(len);
1197 if (config == NULL) {
1198 warnx("malloc failed");
1199 return (ENOMEM);
1200 }
1173 if (sysctlbyname(buf, config, &len, NULL, 0) < 0) {
1174 error = errno;
1175 warn("Failed to read debug command");
1176 return (error);
1177 }
1178 dump_config(fd, config);
1179 free(config);
1180 close(fd);
1181
1182 return (0);
1183}
1184MFI_COMMAND(top, dump, dump);
1185#endif
1201 if (sysctlbyname(buf, config, &len, NULL, 0) < 0) {
1202 error = errno;
1203 warn("Failed to read debug command");
1204 return (error);
1205 }
1206 dump_config(fd, config);
1207 free(config);
1208 close(fd);
1209
1210 return (0);
1211}
1212MFI_COMMAND(top, dump, dump);
1213#endif