1 |
commit: 539248ba464c744f81d3c297ee20a061d31e88c1 |
2 |
Author: Gwendal Grignou <gwendal <AT> chromium <DOT> org> |
3 |
AuthorDate: Thu May 31 18:39:17 2018 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu May 31 18:40:05 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=539248ba |
7 |
|
8 |
sys-apps/smartmontools: add upstream fix for broadcast nsid on nvme devices |
9 |
|
10 |
.../smartmontools-6.6-set-broadcast-nsid.patch | 104 ++++++++++++++ |
11 |
sys-apps/smartmontools/smartmontools-6.6-r1.ebuild | 155 +++++++++++++++++++++ |
12 |
2 files changed, 259 insertions(+) |
13 |
|
14 |
diff --git a/sys-apps/smartmontools/files/smartmontools-6.6-set-broadcast-nsid.patch b/sys-apps/smartmontools/files/smartmontools-6.6-set-broadcast-nsid.patch |
15 |
new file mode 100644 |
16 |
index 00000000000..e65504d43c6 |
17 |
--- /dev/null |
18 |
+++ b/sys-apps/smartmontools/files/smartmontools-6.6-set-broadcast-nsid.patch |
19 |
@@ -0,0 +1,104 @@ |
20 |
+fix from upstream |
21 |
+ |
22 |
+https://www.smartmontools.org/changeset?new=4671@/&old=4670@/ |
23 |
+ |
24 |
+Index: trunk/smartmontools-6.6/ChangeLog |
25 |
+=================================================================== |
26 |
+ 2017-12-27 Douglas Gilbert <dgilbert@××××××××.com> |
27 |
+ |
28 |
++ nvmecmds.cpp: according to NVMe 1.3a spec, the SMART/ |
29 |
++ health information log page is global and should take |
30 |
++ the global nsid (all ff_s). It also says the Error |
31 |
++ info lpage is "global. Broke WD Black PCIe (NVMe) |
32 |
++ SSD but worked on Intel SSDs. Fix; could break others. |
33 |
++ |
34 |
++2017-12-27 Douglas Gilbert <dgilbert@××××××××.com> |
35 |
++ |
36 |
+ os_freebsd.cpp: on error was setting set_nvme_err() to 1, |
37 |
+ not the actual NVMe status value; fix. |
38 |
+ |
39 |
+Index: trunk/smartmontools-6.6/nvmecmds.cpp |
40 |
+=================================================================== |
41 |
+diff --git smartmontools-6.6/nvmecmds.cpp smartmontools-6.6/nvmecmds.cpp |
42 |
+--- smartmontools-6.6/nvmecmds.cpp (revision 4670) |
43 |
++++ smartmontools-6.6/nvmecmds.cpp (revision 4671) |
44 |
+@@ -196,7 +196,8 @@ |
45 |
+ } |
46 |
+ |
47 |
+ // Read NVMe log page with identifier LID. |
48 |
+-bool nvme_read_log_page(nvme_device * device, unsigned char lid, void * data, unsigned size) |
49 |
++bool nvme_read_log_page(nvme_device * device, unsigned char lid, void * data, |
50 |
++ unsigned size, bool broadcast_nsid) |
51 |
+ { |
52 |
+ if (!(4 <= size && size <= 0x4000 && (size % 4) == 0)) |
53 |
+ throw std::logic_error("nvme_read_log_page(): invalid size"); |
54 |
+@@ -204,7 +205,7 @@ |
55 |
+ memset(data, 0, size); |
56 |
+ nvme_cmd_in in; |
57 |
+ in.set_data_in(nvme_admin_get_log_page, data, size); |
58 |
+- in.nsid = device->get_nsid(); |
59 |
++ in.nsid = broadcast_nsid ? 0xffffffff : device->get_nsid(); |
60 |
+ in.cdw10 = lid | (((size / 4) - 1) << 16); |
61 |
+ |
62 |
+ return nvme_pass_through(device, in); |
63 |
+@@ -213,7 +214,7 @@ |
64 |
+ // Read NVMe Error Information Log. |
65 |
+ bool nvme_read_error_log(nvme_device * device, nvme_error_log_page * error_log, unsigned num_entries) |
66 |
+ { |
67 |
+- if (!nvme_read_log_page(device, 0x01, error_log, num_entries * sizeof(*error_log))) |
68 |
++ if (!nvme_read_log_page(device, 0x01, error_log, num_entries * sizeof(*error_log), true)) |
69 |
+ return false; |
70 |
+ |
71 |
+ if (isbigendian()) { |
72 |
+@@ -234,7 +235,7 @@ |
73 |
+ // Read NVMe SMART/Health Information log. |
74 |
+ bool nvme_read_smart_log(nvme_device * device, nvme_smart_log & smart_log) |
75 |
+ { |
76 |
+- if (!nvme_read_log_page(device, 0x02, &smart_log, sizeof(smart_log))) |
77 |
++ if (!nvme_read_log_page(device, 0x02, &smart_log, sizeof(smart_log), true)) |
78 |
+ return false; |
79 |
+ |
80 |
+ if (isbigendian()) { |
81 |
+Index: trunk/smartmontools-6.6/nvmecmds.h |
82 |
+=================================================================== |
83 |
+diff --git smartmontools-6.6/nvmecmds.h smartmontools-6.6/nvmecmds.h |
84 |
+--- smartmontools-6.6/nvmecmds.h (revision 4670) |
85 |
++++ smartmontools-6.6/nvmecmds.h (revision 4671) |
86 |
+@@ -248,7 +248,8 @@ |
87 |
+ bool nvme_read_id_ns(nvme_device * device, unsigned nsid, smartmontools::nvme_id_ns & id_ns); |
88 |
+ |
89 |
+ // Read NVMe log page with identifier LID. |
90 |
+-bool nvme_read_log_page(nvme_device * device, unsigned char lid, void * data, unsigned size); |
91 |
++bool nvme_read_log_page(nvme_device * device, unsigned char lid, void * data, |
92 |
++ unsigned size, bool broadcast_nsid); |
93 |
+ |
94 |
+ // Read NVMe Error Information Log. |
95 |
+ bool nvme_read_error_log(nvme_device * device, smartmontools::nvme_error_log_page * error_log, |
96 |
+Index: trunk/smartmontools-6.6/nvmeprint.cpp |
97 |
+=================================================================== |
98 |
+diff --git smartmontools-6.6/nvmeprint.cpp smartmontools-6.6/nvmeprint.cpp |
99 |
+--- smartmontools-6.6/nvmeprint.cpp (revision 4670) |
100 |
++++ smartmontools-6.6/nvmeprint.cpp (revision 4671) |
101 |
+@@ -473,9 +473,21 @@ |
102 |
+ if (options.log_page_size) { |
103 |
+ // Align size to dword boundary |
104 |
+ unsigned size = ((options.log_page_size + 4-1) / 4) * 4; |
105 |
++ bool broadcast_nsid; |
106 |
+ raw_buffer log_buf(size); |
107 |
+ |
108 |
+- if (!nvme_read_log_page(device, options.log_page, log_buf.data(), size)) { |
109 |
++ switch (options.log_page) { |
110 |
++ case 1: |
111 |
++ case 2: |
112 |
++ case 3: |
113 |
++ broadcast_nsid = true; |
114 |
++ break; |
115 |
++ default: |
116 |
++ broadcast_nsid = false; |
117 |
++ break; |
118 |
++ } |
119 |
++ if (!nvme_read_log_page(device, options.log_page, log_buf.data(), |
120 |
++ size, broadcast_nsid)) { |
121 |
+ pout("Read NVMe Log 0x%02x failed: %s\n\n", options.log_page, device->get_errmsg()); |
122 |
+ return retval | FAILSMART; |
123 |
+ } |
124 |
|
125 |
diff --git a/sys-apps/smartmontools/smartmontools-6.6-r1.ebuild b/sys-apps/smartmontools/smartmontools-6.6-r1.ebuild |
126 |
new file mode 100644 |
127 |
index 00000000000..06a1bd943db |
128 |
--- /dev/null |
129 |
+++ b/sys-apps/smartmontools/smartmontools-6.6-r1.ebuild |
130 |
@@ -0,0 +1,155 @@ |
131 |
+# Copyright 1999-2018 Gentoo Foundation |
132 |
+# Distributed under the terms of the GNU General Public License v2 |
133 |
+ |
134 |
+EAPI="6" |
135 |
+ |
136 |
+inherit autotools flag-o-matic systemd |
137 |
+if [[ ${PV} == "9999" ]] ; then |
138 |
+ ESVN_REPO_URI="https://svn.code.sf.net/p/smartmontools/code/trunk/smartmontools" |
139 |
+ ESVN_PROJECT="smartmontools" |
140 |
+ inherit subversion |
141 |
+else |
142 |
+ SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz" |
143 |
+ KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~sparc ~x86 ~x86-fbsd ~amd64-linux ~arm-linux ~x86-linux ~x64-macos" |
144 |
+fi |
145 |
+ |
146 |
+DESCRIPTION="Tools to monitor storage systems to provide advanced warning of disk degradation" |
147 |
+HOMEPAGE="https://www.smartmontools.org" |
148 |
+ |
149 |
+LICENSE="GPL-2" |
150 |
+SLOT="0" |
151 |
+IUSE="caps +daemon selinux static update_drivedb" |
152 |
+ |
153 |
+DEPEND=" |
154 |
+ caps? ( |
155 |
+ static? ( sys-libs/libcap-ng[static-libs] ) |
156 |
+ !static? ( sys-libs/libcap-ng ) |
157 |
+ ) |
158 |
+ kernel_FreeBSD? ( |
159 |
+ sys-freebsd/freebsd-lib[usb] |
160 |
+ ) |
161 |
+ selinux? ( |
162 |
+ sys-libs/libselinux |
163 |
+ )" |
164 |
+RDEPEND="${DEPEND} |
165 |
+ daemon? ( virtual/mailx ) |
166 |
+ selinux? ( sec-policy/selinux-smartmon ) |
167 |
+ update_drivedb? ( |
168 |
+ app-crypt/gnupg |
169 |
+ || ( |
170 |
+ net-misc/curl |
171 |
+ net-misc/wget |
172 |
+ www-client/lynx |
173 |
+ dev-vcs/subversion |
174 |
+ ) |
175 |
+ ) |
176 |
+" |
177 |
+ |
178 |
+REQUIRED_USE="( caps? ( daemon ) )" |
179 |
+ |
180 |
+PATCHES=( |
181 |
+ "${FILESDIR}"/${P}-fix-build-on-musl.patch |
182 |
+ "${FILESDIR}"/${P}-set-broadcast-nsid.patch |
183 |
+) |
184 |
+ |
185 |
+src_prepare() { |
186 |
+ default |
187 |
+ |
188 |
+ eautoreconf |
189 |
+} |
190 |
+ |
191 |
+src_configure() { |
192 |
+ use static && append-ldflags -static |
193 |
+ # The build installs /etc/init.d/smartd, but we clobber it |
194 |
+ # in our src_install, so no need to manually delete it. |
195 |
+ myeconfargs=( |
196 |
+ --docdir="${EPREFIX}/usr/share/doc/${PF}" |
197 |
+ --with-drivedbdir="${EPREFIX}/var/db/${PN}" #575292 |
198 |
+ --with-initscriptdir="${EPREFIX}/etc/init.d" |
199 |
+ $(use_with caps libcap-ng) |
200 |
+ $(use_with selinux) |
201 |
+ --with-systemdsystemunitdir="$(systemd_get_systemunitdir)" |
202 |
+ $(use_with update_drivedb gnupg) |
203 |
+ $(use_with update_drivedb update-smart-drivedb) |
204 |
+ ) |
205 |
+ econf "${myeconfargs[@]}" |
206 |
+} |
207 |
+ |
208 |
+src_install() { |
209 |
+ local db_path="/var/db/${PN}" |
210 |
+ |
211 |
+ if use daemon; then |
212 |
+ default |
213 |
+ |
214 |
+ newinitd "${FILESDIR}"/smartd-r1.rc smartd |
215 |
+ newconfd "${FILESDIR}"/smartd.confd smartd |
216 |
+ systemd_newunit "${FILESDIR}"/smartd.systemd smartd.service |
217 |
+ else |
218 |
+ dosbin smartctl |
219 |
+ doman smartctl.8 |
220 |
+ |
221 |
+ local DOCS=( AUTHORS ChangeL* COPYING INSTALL NEWS README TODO ) |
222 |
+ einstalldocs |
223 |
+ fi |
224 |
+ |
225 |
+ if use update_drivedb ; then |
226 |
+ if ! use daemon; then |
227 |
+ dosbin "${S}"/update-smart-drivedb |
228 |
+ fi |
229 |
+ |
230 |
+ exeinto /etc/cron.monthly |
231 |
+ doexe "${FILESDIR}/${PN}-update-drivedb" |
232 |
+ fi |
233 |
+ |
234 |
+ if use daemon || use update_drivedb; then |
235 |
+ keepdir "${db_path}" |
236 |
+ |
237 |
+ # Install a copy of the initial drivedb.h to /usr/share/${PN} |
238 |
+ # so that we can access that file later in pkg_postinst |
239 |
+ # even when dealing with binary packages (bug #575292) |
240 |
+ insinto /usr/share/${PN} |
241 |
+ doins "${S}"/drivedb.h |
242 |
+ fi |
243 |
+ |
244 |
+ # Make sure we never install drivedb.h into the db location |
245 |
+ # of the acutal image so we don't record hashes because user |
246 |
+ # can modify that file |
247 |
+ rm -f "${ED%/}${db_path}/drivedb.h" || die |
248 |
+ |
249 |
+ # Bug #622072 |
250 |
+ find "${ED%/}"/usr/share/doc -type f -exec chmod a-x '{}' \; || die |
251 |
+} |
252 |
+ |
253 |
+pkg_postinst() { |
254 |
+ if use daemon || use update_drivedb; then |
255 |
+ local initial_db_file="${EPREFIX%/}/usr/share/${PN}/drivedb.h" |
256 |
+ local db_path="${EPREFIX%/}/var/db/${PN}" |
257 |
+ |
258 |
+ if [[ ! -f "${db_path}/drivedb.h" ]] ; then |
259 |
+ # No initial database found |
260 |
+ cp "${initial_db_file}" "${db_path}" || die |
261 |
+ einfo "Default drive database which was shipped with this release of ${PN}" |
262 |
+ einfo "has been installed to '${db_path}'." |
263 |
+ else |
264 |
+ ewarn "WARNING: There's already a drive database in '${db_path}'!" |
265 |
+ ewarn "Because we cannot determine if this database is untouched" |
266 |
+ ewarn "or was modified by the user you have to manually update the" |
267 |
+ ewarn "drive database:" |
268 |
+ ewarn "" |
269 |
+ ewarn "a) Replace '${db_path}/drivedb.h' by the database shipped with this" |
270 |
+ ewarn " release which can be found in '${initial_db_file}', i.e." |
271 |
+ ewarn "" |
272 |
+ ewarn " cp \"${initial_db_file}\" \"${db_path}\"" |
273 |
+ ewarn "" |
274 |
+ ewarn "b) Run the following command as root:" |
275 |
+ ewarn "" |
276 |
+ ewarn " /usr/sbin/update-smart-drivedb" |
277 |
+ |
278 |
+ if ! use update_drivedb ; then |
279 |
+ ewarn "" |
280 |
+ ewarn "However, 'update-smart-drivedb' requires that you re-emerge ${PN}" |
281 |
+ ewarn "with USE='update_drivedb'." |
282 |
+ fi |
283 |
+ fi |
284 |
+ fi |
285 |
+} |