Deleted Added
full compact
logpage.c (328709) logpage.c (328710)
1/*-
2 * Copyright (c) 2013 EMC Corp.
3 * All rights reserved.
4 *
5 * Copyright (C) 2012-2013 Intel Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

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
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2013 EMC Corp.
3 * All rights reserved.
4 *
5 * Copyright (C) 2012-2013 Intel Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

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
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: stable/11/sbin/nvmecontrol/logpage.c 328709 2018-02-01 19:31:39Z mav $");
31__FBSDID("$FreeBSD: stable/11/sbin/nvmecontrol/logpage.c 328710 2018-02-01 19:32:45Z mav $");
32
33#include <sys/param.h>
34#include <sys/ioccom.h>
35
36#include <ctype.h>
37#include <err.h>
38#include <fcntl.h>
39#include <stdbool.h>

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

788/*
789 * Table of log page printer / sizing.
790 *
791 * This includes Intel specific pages that are widely implemented. Not
792 * sure how best to switch between different vendors.
793 */
794static struct logpage_function {
795 uint8_t log_page;
32
33#include <sys/param.h>
34#include <sys/ioccom.h>
35
36#include <ctype.h>
37#include <err.h>
38#include <fcntl.h>
39#include <stdbool.h>

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

788/*
789 * Table of log page printer / sizing.
790 *
791 * This includes Intel specific pages that are widely implemented. Not
792 * sure how best to switch between different vendors.
793 */
794static struct logpage_function {
795 uint8_t log_page;
796 const char *vendor;
796 print_fn_t print_fn;
797 size_t size;
798} logfuncs[] = {
797 print_fn_t print_fn;
798 size_t size;
799} logfuncs[] = {
799 {NVME_LOG_ERROR, print_log_error,
800 {NVME_LOG_ERROR, NULL, print_log_error,
800 0},
801 0},
801 {NVME_LOG_HEALTH_INFORMATION, print_log_health,
802 {NVME_LOG_HEALTH_INFORMATION, NULL, print_log_health,
802 sizeof(struct nvme_health_information_page)},
803 sizeof(struct nvme_health_information_page)},
803 {NVME_LOG_FIRMWARE_SLOT, print_log_firmware,
804 {NVME_LOG_FIRMWARE_SLOT, NULL, print_log_firmware,
804 sizeof(struct nvme_firmware_page)},
805 sizeof(struct nvme_firmware_page)},
805 {INTEL_LOG_TEMP_STATS, print_intel_temp_stats,
806 {INTEL_LOG_TEMP_STATS, "intel", print_intel_temp_stats,
806 sizeof(struct intel_log_temp_stats)},
807 sizeof(struct intel_log_temp_stats)},
807 {INTEL_LOG_ADD_SMART, print_intel_add_smart,
808 {INTEL_LOG_ADD_SMART, "intel", print_intel_add_smart,
808 DEFAULT_SIZE},
809 DEFAULT_SIZE},
809 {HGST_INFO_LOG, print_hgst_info_log,
810 {HGST_INFO_LOG, "hgst", print_hgst_info_log,
810 DEFAULT_SIZE},
811 DEFAULT_SIZE},
811 {0, NULL,
812 0},
812 {0, NULL, NULL, 0},
813};
814
815static void
816logpage_usage(void)
817{
818 fprintf(stderr, "usage:\n");
819 fprintf(stderr, LOGPAGE_USAGE);
820 exit(1);

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

825{
826 int fd, nsid;
827 int log_page = 0, pageflag = false;
828 int hexflag = false, ns_specified;
829 char ch, *p;
830 char cname[64];
831 uint32_t size;
832 void *buf;
813};
814
815static void
816logpage_usage(void)
817{
818 fprintf(stderr, "usage:\n");
819 fprintf(stderr, LOGPAGE_USAGE);
820 exit(1);

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

825{
826 int fd, nsid;
827 int log_page = 0, pageflag = false;
828 int hexflag = false, ns_specified;
829 char ch, *p;
830 char cname[64];
831 uint32_t size;
832 void *buf;
833 const char *vendor = NULL;
833 struct logpage_function *f;
834 struct nvme_controller_data cdata;
835 print_fn_t print_fn;
836
834 struct logpage_function *f;
835 struct nvme_controller_data cdata;
836 print_fn_t print_fn;
837
837 while ((ch = getopt(argc, argv, "p:x")) != -1) {
838 while ((ch = getopt(argc, argv, "p:xv:")) != -1) {
838 switch (ch) {
839 case 'p':
840 /* TODO: Add human-readable ASCII page IDs */
841 log_page = strtol(optarg, &p, 0);
842 if (p != NULL && *p != '\0') {
843 fprintf(stderr,
844 "\"%s\" not valid log page id.\n",
845 optarg);
846 logpage_usage();
847 }
848 pageflag = true;
849 break;
850 case 'x':
851 hexflag = true;
852 break;
839 switch (ch) {
840 case 'p':
841 /* TODO: Add human-readable ASCII page IDs */
842 log_page = strtol(optarg, &p, 0);
843 if (p != NULL && *p != '\0') {
844 fprintf(stderr,
845 "\"%s\" not valid log page id.\n",
846 optarg);
847 logpage_usage();
848 }
849 pageflag = true;
850 break;
851 case 'x':
852 hexflag = true;
853 break;
854 case 'v':
855 vendor = optarg;
856 break;
853 }
854 }
855
856 if (!pageflag) {
857 printf("Missing page_id (-p).\n");
858 logpage_usage();
859 }
860

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

888 "controller does not support per namespace "
889 "smart/health information");
890 }
891
892 print_fn = print_hex;
893 size = DEFAULT_SIZE;
894 if (!hexflag) {
895 /*
857 }
858 }
859
860 if (!pageflag) {
861 printf("Missing page_id (-p).\n");
862 logpage_usage();
863 }
864

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

892 "controller does not support per namespace "
893 "smart/health information");
894 }
895
896 print_fn = print_hex;
897 size = DEFAULT_SIZE;
898 if (!hexflag) {
899 /*
896 * See if there is a pretty print function for the
897 * specified log page. If one isn't found, we
898 * just revert to the default (print_hex).
900 * See if there is a pretty print function for the specified log
901 * page. If one isn't found, we just revert to the default
902 * (print_hex). If there was a vendor specified bt the user, and
903 * the page is vendor specific, don't match the print function
904 * unless the vendors match.
899 */
905 */
900 f = logfuncs;
901 while (f->log_page > 0) {
902 if (log_page == f->log_page) {
903 print_fn = f->print_fn;
904 size = f->size;
905 break;
906 }
907 f++;
906 for (f = logfuncs; f->log_page > 0; f++) {
907 if (f->vendor != NULL && vendor != NULL &&
908 strcmp(f->vendor, vendor) != 0)
909 continue;
910 if (log_page != f->log_page)
911 continue;
912 print_fn = f->print_fn;
913 size = f->size;
914 break;
908 }
909 }
910
911 if (log_page == NVME_LOG_ERROR) {
912 size = sizeof(struct nvme_error_information_entry);
913 size *= (cdata.elpe + 1);
914 }
915
916 /* Read the log page */
917 buf = get_log_buffer(size);
918 read_logpage(fd, log_page, nsid, buf, size);
919 print_fn(buf, size);
920
921 close(fd);
922 exit(0);
923}
915 }
916 }
917
918 if (log_page == NVME_LOG_ERROR) {
919 size = sizeof(struct nvme_error_information_entry);
920 size *= (cdata.elpe + 1);
921 }
922
923 /* Read the log page */
924 buf = get_log_buffer(size);
925 read_logpage(fd, log_page, nsid, buf, size);
926 print_fn(buf, size);
927
928 close(fd);
929 exit(0);
930}