Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Apr 2011 19:50:38 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r220666 - stable/7/usr.sbin/mfiutil
Message-ID:  <201104151950.p3FJocCo079950@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Fri Apr 15 19:50:38 2011
New Revision: 220666
URL: http://svn.freebsd.org/changeset/base/220666

Log:
  MFC 219717,220363:
  - Add more details to the 'show battery' command including more raw
    capacity values, charge cycle count, temperature, and more detailed
    status.
  - Add the ability to manage the state of write caching when the battery
    back-up is missing or dead.  The current state of this field is reported
    in 'mfiutil cache <volume>' and can be adjusted via
    'mfiutil cache <volume> bad-bbu-write-cache <enable|disable>'.  This
    setting should generally be disabled to avoid data loss.

Modified:
  stable/7/usr.sbin/mfiutil/mfi_show.c
  stable/7/usr.sbin/mfiutil/mfi_volume.c
  stable/7/usr.sbin/mfiutil/mfiutil.8
Directory Properties:
  stable/7/usr.sbin/mfiutil/   (props changed)

Modified: stable/7/usr.sbin/mfiutil/mfi_show.c
==============================================================================
--- stable/7/usr.sbin/mfiutil/mfi_show.c	Fri Apr 15 19:50:25 2011	(r220665)
+++ stable/7/usr.sbin/mfiutil/mfi_show.c	Fri Apr 15 19:50:38 2011	(r220666)
@@ -138,8 +138,9 @@ show_battery(int ac, char **av)
 {
 	struct mfi_bbu_capacity_info cap;
 	struct mfi_bbu_design_info design;
+	struct mfi_bbu_status stat;
 	uint8_t status;
-	int error, fd;
+	int comma, error, fd;
 
 	if (ac != 1) {
 		warnx("show battery: extra arguments");
@@ -171,16 +172,57 @@ show_battery(int ac, char **av)
 		return (error);
 	}
 
+	if (mfi_dcmd_command(fd, MFI_DCMD_BBU_GET_STATUS, &stat, sizeof(stat),
+	    NULL, 0, NULL) < 0) {
+		warn("Failed to get status");
+		return (errno);
+	}
+
 	printf("mfi%d: Battery State:\n", mfi_unit);
-	printf(" Manufacture Date: %d/%d/%d\n", design.mfg_date >> 5 & 0x0f,
+	printf("     Manufacture Date: %d/%d/%d\n", design.mfg_date >> 5 & 0x0f,
 	    design.mfg_date & 0x1f, design.mfg_date >> 9 & 0xffff);
-	printf("    Serial Number: %d\n", design.serial_number);
-	printf("     Manufacturer: %s\n", design.mfg_name);
-	printf("            Model: %s\n", design.device_name);
-	printf("        Chemistry: %s\n", design.device_chemistry);
-	printf("  Design Capacity: %d mAh\n", design.design_capacity);
-	printf("   Design Voltage: %d mV\n", design.design_voltage);
-	printf("   Current Charge: %d%%\n", cap.relative_charge);
+	printf("        Serial Number: %d\n", design.serial_number);
+	printf("         Manufacturer: %s\n", design.mfg_name);
+	printf("                Model: %s\n", design.device_name);
+	printf("            Chemistry: %s\n", design.device_chemistry);
+	printf("      Design Capacity: %d mAh\n", design.design_capacity);
+	printf(" Full Charge Capacity: %d mAh\n", cap.full_charge_capacity);
+	printf("     Current Capacity: %d mAh\n", cap.remaining_capacity);
+	printf("        Charge Cycles: %d\n", cap.cycle_count);
+	printf("       Current Charge: %d%%\n", cap.relative_charge);
+	printf("       Design Voltage: %d mV\n", design.design_voltage);
+	printf("      Current Voltage: %d mV\n", stat.voltage);
+	printf("          Temperature: %d C\n", stat.temperature);
+	printf("               Status:");
+	comma = 0;
+	if (stat.fw_status & MFI_BBU_STATE_PACK_MISSING) {
+		printf(" PACK_MISSING");
+		comma = 1;
+	}
+	if (stat.fw_status & MFI_BBU_STATE_VOLTAGE_LOW) {
+		printf("%s VOLTAGE_LOW", comma ? "," : "");
+		comma = 1;
+	}
+	if (stat.fw_status & MFI_BBU_STATE_TEMPERATURE_HIGH) {
+		printf("%s TEMPERATURE_HIGH", comma ? "," : "");
+		comma = 1;
+	}
+	if (stat.fw_status & MFI_BBU_STATE_CHARGE_ACTIVE) {
+		printf("%s CHARGING", comma ? "," : "");
+		comma = 1;
+	}
+	if (stat.fw_status & MFI_BBU_STATE_DISCHARGE_ACTIVE) {
+		printf("%s DISCHARGING", comma ? "," : "");
+	}
+	if (!comma)
+		printf(" normal");
+	printf("\n");
+	switch (stat.battery_type) {
+	case MFI_BBU_TYPE_BBU:
+		printf("      State of Health: %s\n",
+		    stat.detail.bbu.is_SOH_good ? "good" : "bad");
+		break;
+	}
 
 	close(fd);
 

Modified: stable/7/usr.sbin/mfiutil/mfi_volume.c
==============================================================================
--- stable/7/usr.sbin/mfiutil/mfi_volume.c	Fri Apr 15 19:50:25 2011	(r220665)
+++ stable/7/usr.sbin/mfiutil/mfi_volume.c	Fri Apr 15 19:50:38 2011	(r220666)
@@ -138,6 +138,10 @@ update_cache_policy(int fd, struct mfi_l
 		    policy & MR_LD_CACHE_READ_AHEAD ?
 		    (policy & MR_LD_CACHE_READ_ADAPTIVE ?
 		    "adaptive" : "always") : "none");
+	if (changes & MR_LD_CACHE_WRITE_CACHE_BAD_BBU)
+		printf("%s write caching with bad BBU\n",
+		    policy & MR_LD_CACHE_WRITE_CACHE_BAD_BBU ? "Enabling" :
+		    "Disabling");
 
 	props->default_cache_policy = policy;
 	if (mfi_ld_set_props(fd, props) < 0) {
@@ -182,7 +186,7 @@ volume_cache(int ac, char **av)
 	if (ac == 2) {
 		printf("mfi%u volume %s cache settings:\n", mfi_unit,
 		    mfi_volume_name(fd, target_id));
-		printf("      I/O caching: ");
+		printf("             I/O caching: ");
 		switch (props.default_cache_policy &
 		    (MR_LD_CACHE_ALLOW_WRITE_CACHE |
 		    MR_LD_CACHE_ALLOW_READ_CACHE)) {
@@ -200,14 +204,17 @@ volume_cache(int ac, char **av)
 			printf("writes and reads\n");
 			break;
 		}
-		printf("    write caching: %s\n",
+		printf("           write caching: %s\n",
 		    props.default_cache_policy & MR_LD_CACHE_WRITE_BACK ?
 		    "write-back" : "write-through");
-		printf("       read ahead: %s\n",
+		printf("write cache with bad BBU: %s\n",
+		    props.default_cache_policy &
+		    MR_LD_CACHE_WRITE_CACHE_BAD_BBU ? "enabled" : "disabled");
+		printf("              read ahead: %s\n",
 		    props.default_cache_policy & MR_LD_CACHE_READ_AHEAD ?
 		    (props.default_cache_policy & MR_LD_CACHE_READ_ADAPTIVE ?
 		    "adaptive" : "always") : "none");
-		printf("drive write cache: ");
+		printf("       drive write cache: ");
 		switch (props.disk_cache_policy) {
 		case MR_PD_CACHE_UNCHANGED:
 			printf("default\n");
@@ -273,6 +280,21 @@ volume_cache(int ac, char **av)
 			error = update_cache_policy(fd, &props, policy,
 			    MR_LD_CACHE_READ_AHEAD |
 			    MR_LD_CACHE_READ_ADAPTIVE);
+		} else if (strcmp(av[2], "bad-bbu-write-cache") == 0) {
+			if (ac < 4) {
+				warnx("cache: bad BBU setting required");
+				return (EINVAL);
+			}
+			if (strcmp(av[3], "enable") == 0)
+				policy = MR_LD_CACHE_WRITE_CACHE_BAD_BBU;
+			else if (strcmp(av[3], "disable") == 0)
+				policy = 0;
+			else {
+				warnx("cache: invalid bad BBU setting");
+				return (EINVAL);
+			}
+			error = update_cache_policy(fd, &props, policy,
+			    MR_LD_CACHE_WRITE_CACHE_BAD_BBU);
 		} else if (strcmp(av[2], "write-cache") == 0) {
 			if (ac < 4) {
 				warnx("cache: write-cache setting required");

Modified: stable/7/usr.sbin/mfiutil/mfiutil.8
==============================================================================
--- stable/7/usr.sbin/mfiutil/mfiutil.8	Fri Apr 15 19:50:25 2011	(r220665)
+++ stable/7/usr.sbin/mfiutil/mfiutil.8	Fri Apr 15 19:50:38 2011	(r220666)
@@ -27,7 +27,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd August 16, 2009
+.Dd April 5, 2011
 .Dt MFIUTIL 8
 .Os
 .Sh NAME
@@ -367,7 +367,7 @@ Enable caching only for write I/O operat
 Use write-back policy for cached writes.
 .It Cm write-through
 Use write-through policy for cached writes.
-.It Cm read-ahead Op Ar value
+.It Cm read-ahead Ar value
 Set the read ahead policy for cached reads.
 The
 .Ar value
@@ -376,7 +376,18 @@ argument can be set to either
 .Dq adaptive ,
 or
 .Dq always .
-.It Cm write-cache Op Ar value
+.It Cm bad-bbu-write-cache Ar value
+Control the behavior of I/O write caching if the battery is dead or
+missing.
+The
+.Ar value
+argument can be set to either
+.Dq disable
+or
+.Dq enable .
+In general this setting should be left disabled to avoid data loss when
+the system loses power.
+.It Cm write-cache Ar value
 Control the write caches on the physical drives backing
 .Ar volume .
 The



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104151950.p3FJocCo079950>