From 33a848aa2dcda073e0b07a315eae9e4a121727a7 Mon Sep 17 00:00:00 2001
From: Song Liu <songliubraving@fb.com>
Date: Thu, 11 Aug 2016 16:34:17 -0700
Subject: [PATCH] Add persistent option ",p" to wcreorder,on|off
Similar to wcache-sct, we can make wcreorder setting persistent
through SCT Feature Control.
---
trunk/smartmontools/ataprint.cpp | 5 +++--
trunk/smartmontools/ataprint.h | 2 ++
trunk/smartmontools/smartctl.8.in | 4 ++--
trunk/smartmontools/smartctl.cpp | 8 +++++---
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/trunk/smartmontools/ataprint.cpp b/trunk/smartmontools/ataprint.cpp
index aa81cf0..134635b 100644
a
|
b
|
int ataPrintMain (ata_device * device, const ata_print_options & options)
|
2941 | 2941 | pout("Write cache reordering %sable failed: SCT not supported if ATA Security is LOCKED\n", |
2942 | 2942 | (enable ? "en" : "dis")); |
2943 | 2943 | else if (ataGetSetSCTWriteCacheReordering(device, |
2944 | | enable, false /*persistent*/, true /*set*/) < 0) { |
| 2944 | enable, options.sct_wcache_reorder_set_pers, true /*set*/) < 0) { |
2945 | 2945 | pout("Write cache reordering %sable failed: %s\n", (enable ? "en" : "dis"), device->get_errmsg()); |
2946 | 2946 | returnval |= FAILSMART; |
2947 | 2947 | } |
2948 | 2948 | else |
2949 | | pout("Write cache reordering %sabled\n", (enable ? "en" : "dis")); |
| 2949 | pout("Write cache reordering %sabled (%s)\n", (enable ? "en" : "dis"), |
| 2950 | (options.sct_wcache_reorder_set_pers ? "persistent" : "volatile")); |
2950 | 2951 | } |
2951 | 2952 | |
2952 | 2953 | // Enable/Disable write cache in SCT |
diff --git a/trunk/smartmontools/ataprint.h b/trunk/smartmontools/ataprint.h
index 230ce22..d3459db 100644
a
|
b
|
struct ata_print_options
|
108 | 108 | int set_wcache; // disable(-1), enable(1) write cache |
109 | 109 | bool sct_wcache_reorder_get; // print write cache reordering status |
110 | 110 | int sct_wcache_reorder_set; // disable(-1), enable(1) write cache reordering |
| 111 | bool sct_wcache_reorder_set_pers; |
111 | 112 | bool sct_wcache_sct_get; // print SCT Feature Control of write cache status |
112 | 113 | int sct_wcache_sct_set; // determined by ata set features command(1), force enable(2), force disable(3) |
113 | 114 | bool sct_wcache_sct_set_pers; // persistent or volatile |
… |
… |
struct ata_print_options
|
149 | 150 | get_security(false), set_security_freeze(false), |
150 | 151 | get_wcache(false), set_wcache(0), |
151 | 152 | sct_wcache_reorder_get(false), sct_wcache_reorder_set(0), |
| 153 | sct_wcache_reorder_set_pers(false), |
152 | 154 | sct_wcache_sct_get(false), sct_wcache_sct_set(0), |
153 | 155 | sct_wcache_sct_set_pers(false) |
154 | 156 | { } |
diff --git a/trunk/smartmontools/smartctl.8.in b/trunk/smartmontools/smartctl.8.in
index 372f331..34db906 100644
a
|
b
|
the setting of wcache[,on|off] is ignored by the drive. SCT Feature Control
|
957 | 957 | usually sets write cache as "Controlled by ATA" by default. If ´,p´ is |
958 | 958 | specified, the setting is preserved across power cycles. |
959 | 959 | |
960 | | .I wcreorder[,on|off] |
| 960 | .I wcreorder[,on|off[,p]] |
961 | 961 | \- [ATA only] Gets/sets Write Cache Reordering. |
962 | 962 | If it is disabled (off), disk write scheduling is executed on a |
963 | 963 | first-in-first-out (FIFO) basis. If Write Cache Reordering is enabled (on), |
… |
… |
then disk write scheduling may be reordered by the drive. If write cache is
|
965 | 965 | disabled, the current Write Cache Reordering state is remembered but has |
966 | 966 | no effect on non-cached writes, which are always written in the order received. |
967 | 967 | The state of Write Cache Reordering has no effect on either NCQ or LCQ queued |
968 | | commands. |
| 968 | commands. If ´,p´ is specified, the setting is preserved across power cycles. |
969 | 969 | |
970 | 970 | .I rcache[,on|off] |
971 | 971 | \- [SCSI only] Gets/sets the \'Read Cache Disable\' (RCE) bit. |
diff --git a/trunk/smartmontools/smartctl.cpp b/trunk/smartmontools/smartctl.cpp
index 7660b9c..129b041 100644
a
|
b
|
static void Usage()
|
123 | 123 | " -s NAME[,VALUE], --set=NAME[,VALUE]\n" |
124 | 124 | " Enable/disable/change device setting: aam,[N|off], apm,[N|off],\n" |
125 | 125 | " lookahead,[on|off], security-freeze, standby,[N|off|now],\n" |
126 | | " wcache,[on|off], rcache,[on|off], wcreorder,[on|off]\n" |
| 126 | " wcache,[on|off], rcache,[on|off], wcreorder,[on|off[,p]]\n" |
127 | 127 | " wcache-sct,[ata|on|off[,p]]\n\n" |
128 | 128 | ); |
129 | 129 | printf( |
… |
… |
static std::string getvalidarglist(int opt)
|
225 | 225 | return "aam, apm, lookahead, security, wcache, rcache, wcreorder, wcache-sct"; |
226 | 226 | case opt_set: |
227 | 227 | return "aam,[N|off], apm,[N|off], lookahead,[on|off], security-freeze, " |
228 | | "standby,[N|off|now], wcache,[on|off], rcache,[on|off], wcreorder,[on|off], " |
| 228 | "standby,[N|off|now], wcache,[on|off], rcache,[on|off], wcreorder,[on|off[,p]], " |
229 | 229 | "wcache-sct,[ata|on|off[,p]]"; |
230 | 230 | case 's': |
231 | 231 | return getvalidarglist(opt_smart)+", "+getvalidarglist(opt_set); |
… |
… |
static const char * parse_options(int argc, char** argv,
|
872 | 872 | len2 = strlen(optarg+n2) - 2; |
873 | 873 | |
874 | 874 | // the ,p option only works for set of SCT Feature Control command |
875 | | if (strcmp(name, "wcache-sct") != 0) |
| 875 | if (strcmp(name, "wcache-sct") != 0 && |
| 876 | strcmp(name, "wcreorder") != 0) |
876 | 877 | badarg = true; |
877 | 878 | } |
878 | 879 | on = !strncmp(optarg+n2, "on", len2); |
… |
… |
static const char * parse_options(int argc, char** argv,
|
924 | 925 | badarg = true; |
925 | 926 | } |
926 | 927 | else if (!strcmp(name, "wcreorder")) { |
| 928 | ataopts.sct_wcache_reorder_set_pers = persistent; |
927 | 929 | if (get) { |
928 | 930 | ataopts.sct_wcache_reorder_get = true; |
929 | 931 | } |