platform.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /*
  2. * Persistent Storage - platform driver interface parts.
  3. *
  4. * Copyright (C) 2007-2008 Google, Inc.
  5. * Copyright (C) 2010 Intel Corporation <tony.luck@intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #define pr_fmt(fmt) "pstore: " fmt
  21. #include <linux/atomic.h>
  22. #include <linux/types.h>
  23. #include <linux/errno.h>
  24. #include <linux/init.h>
  25. #include <linux/kmsg_dump.h>
  26. #include <linux/console.h>
  27. #include <linux/module.h>
  28. #include <linux/pstore.h>
  29. #if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS)
  30. #include <linux/lzo.h>
  31. #endif
  32. #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
  33. #include <linux/lz4.h>
  34. #endif
  35. #include <linux/crypto.h>
  36. #include <linux/string.h>
  37. #include <linux/timer.h>
  38. #include <linux/slab.h>
  39. #include <linux/uaccess.h>
  40. #include <linux/jiffies.h>
  41. #include <linux/workqueue.h>
  42. #include "internal.h"
  43. /*
  44. * We defer making "oops" entries appear in pstore - see
  45. * whether the system is actually still running well enough
  46. * to let someone see the entry
  47. */
  48. static int pstore_update_ms = -1;
  49. module_param_named(update_ms, pstore_update_ms, int, 0600);
  50. MODULE_PARM_DESC(update_ms, "milliseconds before pstore updates its content "
  51. "(default is -1, which means runtime updates are disabled; "
  52. "enabling this option is not safe, it may lead to further "
  53. "corruption on Oopses)");
  54. static int pstore_new_entry;
  55. static void pstore_timefunc(struct timer_list *);
  56. static DEFINE_TIMER(pstore_timer, pstore_timefunc);
  57. static void pstore_dowork(struct work_struct *);
  58. static DECLARE_WORK(pstore_work, pstore_dowork);
  59. /*
  60. * pstore_lock just protects "psinfo" during
  61. * calls to pstore_register()
  62. */
  63. static DEFINE_SPINLOCK(pstore_lock);
  64. struct pstore_info *psinfo;
  65. static char *backend;
  66. static char *compress =
  67. #ifdef CONFIG_PSTORE_COMPRESS_DEFAULT
  68. CONFIG_PSTORE_COMPRESS_DEFAULT;
  69. #else
  70. NULL;
  71. #endif
  72. /* Compression parameters */
  73. static struct crypto_comp *tfm;
  74. struct pstore_zbackend {
  75. int (*zbufsize)(size_t size);
  76. const char *name;
  77. };
  78. static char *big_oops_buf;
  79. static size_t big_oops_buf_sz;
  80. /* How much of the console log to snapshot */
  81. unsigned long kmsg_bytes = PSTORE_DEFAULT_KMSG_BYTES;
  82. void pstore_set_kmsg_bytes(int bytes)
  83. {
  84. kmsg_bytes = bytes;
  85. }
  86. /* Tag each group of saved records with a sequence number */
  87. static int oopscount;
  88. static const char *get_reason_str(enum kmsg_dump_reason reason)
  89. {
  90. switch (reason) {
  91. case KMSG_DUMP_PANIC:
  92. return "Panic";
  93. case KMSG_DUMP_OOPS:
  94. return "Oops";
  95. case KMSG_DUMP_EMERG:
  96. return "Emergency";
  97. case KMSG_DUMP_RESTART:
  98. return "Restart";
  99. case KMSG_DUMP_HALT:
  100. return "Halt";
  101. case KMSG_DUMP_POWEROFF:
  102. return "Poweroff";
  103. default:
  104. return "Unknown";
  105. }
  106. }
  107. bool pstore_cannot_block_path(enum kmsg_dump_reason reason)
  108. {
  109. /*
  110. * In case of NMI path, pstore shouldn't be blocked
  111. * regardless of reason.
  112. */
  113. if (in_nmi())
  114. return true;
  115. switch (reason) {
  116. /* In panic case, other cpus are stopped by smp_send_stop(). */
  117. case KMSG_DUMP_PANIC:
  118. /* Emergency restart shouldn't be blocked by spin lock. */
  119. case KMSG_DUMP_EMERG:
  120. return true;
  121. default:
  122. return false;
  123. }
  124. }
  125. EXPORT_SYMBOL_GPL(pstore_cannot_block_path);
  126. #if IS_ENABLED(CONFIG_PSTORE_DEFLATE_COMPRESS)
  127. static int zbufsize_deflate(size_t size)
  128. {
  129. size_t cmpr;
  130. switch (size) {
  131. /* buffer range for efivars */
  132. case 1000 ... 2000:
  133. cmpr = 56;
  134. break;
  135. case 2001 ... 3000:
  136. cmpr = 54;
  137. break;
  138. case 3001 ... 3999:
  139. cmpr = 52;
  140. break;
  141. /* buffer range for nvram, erst */
  142. case 4000 ... 10000:
  143. cmpr = 45;
  144. break;
  145. default:
  146. cmpr = 60;
  147. break;
  148. }
  149. return (size * 100) / cmpr;
  150. }
  151. #endif
  152. #if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS)
  153. static int zbufsize_lzo(size_t size)
  154. {
  155. return lzo1x_worst_compress(size);
  156. }
  157. #endif
  158. #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
  159. static int zbufsize_lz4(size_t size)
  160. {
  161. return LZ4_compressBound(size);
  162. }
  163. #endif
  164. #if IS_ENABLED(CONFIG_PSTORE_842_COMPRESS)
  165. static int zbufsize_842(size_t size)
  166. {
  167. return size;
  168. }
  169. #endif
  170. static const struct pstore_zbackend *zbackend __ro_after_init;
  171. static const struct pstore_zbackend zbackends[] = {
  172. #if IS_ENABLED(CONFIG_PSTORE_DEFLATE_COMPRESS)
  173. {
  174. .zbufsize = zbufsize_deflate,
  175. .name = "deflate",
  176. },
  177. #endif
  178. #if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS)
  179. {
  180. .zbufsize = zbufsize_lzo,
  181. .name = "lzo",
  182. },
  183. #endif
  184. #if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS)
  185. {
  186. .zbufsize = zbufsize_lz4,
  187. .name = "lz4",
  188. },
  189. #endif
  190. #if IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS)
  191. {
  192. .zbufsize = zbufsize_lz4,
  193. .name = "lz4hc",
  194. },
  195. #endif
  196. #if IS_ENABLED(CONFIG_PSTORE_842_COMPRESS)
  197. {
  198. .zbufsize = zbufsize_842,
  199. .name = "842",
  200. },
  201. #endif
  202. { }
  203. };
  204. static int pstore_compress(const void *in, void *out,
  205. unsigned int inlen, unsigned int outlen)
  206. {
  207. int ret;
  208. ret = crypto_comp_compress(tfm, in, inlen, out, &outlen);
  209. if (ret) {
  210. pr_err("crypto_comp_compress failed, ret = %d!\n", ret);
  211. return ret;
  212. }
  213. return outlen;
  214. }
  215. static int pstore_decompress(void *in, void *out,
  216. unsigned int inlen, unsigned int outlen)
  217. {
  218. int ret;
  219. ret = crypto_comp_decompress(tfm, in, inlen, out, &outlen);
  220. if (ret) {
  221. pr_err("crypto_comp_decompress failed, ret = %d!\n", ret);
  222. return ret;
  223. }
  224. return outlen;
  225. }
  226. static void allocate_buf_for_compression(void)
  227. {
  228. if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !zbackend)
  229. return;
  230. if (!crypto_has_comp(zbackend->name, 0, 0)) {
  231. pr_err("No %s compression\n", zbackend->name);
  232. return;
  233. }
  234. big_oops_buf_sz = zbackend->zbufsize(psinfo->bufsize);
  235. if (big_oops_buf_sz <= 0)
  236. return;
  237. big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL);
  238. if (!big_oops_buf) {
  239. pr_err("allocate compression buffer error!\n");
  240. return;
  241. }
  242. tfm = crypto_alloc_comp(zbackend->name, 0, 0);
  243. if (IS_ERR_OR_NULL(tfm)) {
  244. kfree(big_oops_buf);
  245. big_oops_buf = NULL;
  246. pr_err("crypto_alloc_comp() failed!\n");
  247. return;
  248. }
  249. }
  250. static void free_buf_for_compression(void)
  251. {
  252. if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && !IS_ERR_OR_NULL(tfm))
  253. crypto_free_comp(tfm);
  254. kfree(big_oops_buf);
  255. big_oops_buf = NULL;
  256. big_oops_buf_sz = 0;
  257. }
  258. /*
  259. * Called when compression fails, since the printk buffer
  260. * would be fetched for compression calling it again when
  261. * compression fails would have moved the iterator of
  262. * printk buffer which results in fetching old contents.
  263. * Copy the recent messages from big_oops_buf to psinfo->buf
  264. */
  265. static size_t copy_kmsg_to_buffer(int hsize, size_t len)
  266. {
  267. size_t total_len;
  268. size_t diff;
  269. total_len = hsize + len;
  270. if (total_len > psinfo->bufsize) {
  271. diff = total_len - psinfo->bufsize + hsize;
  272. memcpy(psinfo->buf, big_oops_buf, hsize);
  273. memcpy(psinfo->buf + hsize, big_oops_buf + diff,
  274. psinfo->bufsize - hsize);
  275. total_len = psinfo->bufsize;
  276. } else
  277. memcpy(psinfo->buf, big_oops_buf, total_len);
  278. return total_len;
  279. }
  280. void pstore_record_init(struct pstore_record *record,
  281. struct pstore_info *psinfo)
  282. {
  283. memset(record, 0, sizeof(*record));
  284. record->psi = psinfo;
  285. /* Report zeroed timestamp if called before timekeeping has resumed. */
  286. record->time = ns_to_timespec64(ktime_get_real_fast_ns());
  287. }
  288. /*
  289. * callback from kmsg_dump. (s2,l2) has the most recently
  290. * written bytes, older bytes are in (s1,l1). Save as much
  291. * as we can from the end of the buffer.
  292. */
  293. static void pstore_dump(struct kmsg_dumper *dumper,
  294. enum kmsg_dump_reason reason)
  295. {
  296. unsigned long total = 0;
  297. const char *why;
  298. unsigned int part = 1;
  299. unsigned long flags = 0;
  300. int is_locked;
  301. int ret;
  302. why = get_reason_str(reason);
  303. if (pstore_cannot_block_path(reason)) {
  304. is_locked = spin_trylock_irqsave(&psinfo->buf_lock, flags);
  305. if (!is_locked) {
  306. pr_err("pstore dump routine blocked in %s path, may corrupt error record\n"
  307. , in_nmi() ? "NMI" : why);
  308. return;
  309. }
  310. } else {
  311. spin_lock_irqsave(&psinfo->buf_lock, flags);
  312. is_locked = 1;
  313. }
  314. oopscount++;
  315. while (total < kmsg_bytes) {
  316. char *dst;
  317. size_t dst_size;
  318. int header_size;
  319. int zipped_len = -1;
  320. size_t dump_size;
  321. struct pstore_record record;
  322. pstore_record_init(&record, psinfo);
  323. record.type = PSTORE_TYPE_DMESG;
  324. record.count = oopscount;
  325. record.reason = reason;
  326. record.part = part;
  327. record.buf = psinfo->buf;
  328. if (big_oops_buf && is_locked) {
  329. dst = big_oops_buf;
  330. dst_size = big_oops_buf_sz;
  331. } else {
  332. dst = psinfo->buf;
  333. dst_size = psinfo->bufsize;
  334. }
  335. /* Write dump header. */
  336. header_size = snprintf(dst, dst_size, "%s#%d Part%u\n", why,
  337. oopscount, part);
  338. dst_size -= header_size;
  339. /* Write dump contents. */
  340. if (!kmsg_dump_get_buffer(dumper, true, dst + header_size,
  341. dst_size, &dump_size))
  342. break;
  343. if (big_oops_buf && is_locked) {
  344. zipped_len = pstore_compress(dst, psinfo->buf,
  345. header_size + dump_size,
  346. psinfo->bufsize);
  347. if (zipped_len > 0) {
  348. record.compressed = true;
  349. record.size = zipped_len;
  350. } else {
  351. record.size = copy_kmsg_to_buffer(header_size,
  352. dump_size);
  353. }
  354. } else {
  355. record.size = header_size + dump_size;
  356. }
  357. ret = psinfo->write(&record);
  358. if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted())
  359. pstore_new_entry = 1;
  360. total += record.size;
  361. part++;
  362. }
  363. if (is_locked)
  364. spin_unlock_irqrestore(&psinfo->buf_lock, flags);
  365. }
  366. static struct kmsg_dumper pstore_dumper = {
  367. .dump = pstore_dump,
  368. };
  369. /*
  370. * Register with kmsg_dump to save last part of console log on panic.
  371. */
  372. static void pstore_register_kmsg(void)
  373. {
  374. kmsg_dump_register(&pstore_dumper);
  375. }
  376. static void pstore_unregister_kmsg(void)
  377. {
  378. kmsg_dump_unregister(&pstore_dumper);
  379. }
  380. #ifdef CONFIG_PSTORE_CONSOLE
  381. static void pstore_console_write(struct console *con, const char *s, unsigned c)
  382. {
  383. const char *e = s + c;
  384. while (s < e) {
  385. struct pstore_record record;
  386. unsigned long flags;
  387. pstore_record_init(&record, psinfo);
  388. record.type = PSTORE_TYPE_CONSOLE;
  389. if (c > psinfo->bufsize)
  390. c = psinfo->bufsize;
  391. if (oops_in_progress) {
  392. if (!spin_trylock_irqsave(&psinfo->buf_lock, flags))
  393. break;
  394. } else {
  395. spin_lock_irqsave(&psinfo->buf_lock, flags);
  396. }
  397. record.buf = (char *)s;
  398. record.size = c;
  399. psinfo->write(&record);
  400. spin_unlock_irqrestore(&psinfo->buf_lock, flags);
  401. s += c;
  402. c = e - s;
  403. }
  404. }
  405. static struct console pstore_console = {
  406. .name = "pstore",
  407. .write = pstore_console_write,
  408. .flags = CON_PRINTBUFFER | CON_ENABLED | CON_ANYTIME,
  409. .index = -1,
  410. };
  411. static void pstore_register_console(void)
  412. {
  413. register_console(&pstore_console);
  414. }
  415. static void pstore_unregister_console(void)
  416. {
  417. unregister_console(&pstore_console);
  418. }
  419. #else
  420. static void pstore_register_console(void) {}
  421. static void pstore_unregister_console(void) {}
  422. #endif
  423. static int pstore_write_user_compat(struct pstore_record *record,
  424. const char __user *buf)
  425. {
  426. int ret = 0;
  427. if (record->buf)
  428. return -EINVAL;
  429. record->buf = memdup_user(buf, record->size);
  430. if (IS_ERR(record->buf)) {
  431. ret = PTR_ERR(record->buf);
  432. goto out;
  433. }
  434. ret = record->psi->write(record);
  435. kfree(record->buf);
  436. out:
  437. record->buf = NULL;
  438. return unlikely(ret < 0) ? ret : record->size;
  439. }
  440. /*
  441. * platform specific persistent storage driver registers with
  442. * us here. If pstore is already mounted, call the platform
  443. * read function right away to populate the file system. If not
  444. * then the pstore mount code will call us later to fill out
  445. * the file system.
  446. */
  447. int pstore_register(struct pstore_info *psi)
  448. {
  449. struct module *owner = psi->owner;
  450. if (backend && strcmp(backend, psi->name)) {
  451. pr_warn("ignoring unexpected backend '%s'\n", psi->name);
  452. return -EPERM;
  453. }
  454. /* Sanity check flags. */
  455. if (!psi->flags) {
  456. pr_warn("backend '%s' must support at least one frontend\n",
  457. psi->name);
  458. return -EINVAL;
  459. }
  460. /* Check for required functions. */
  461. if (!psi->read || !psi->write) {
  462. pr_warn("backend '%s' must implement read() and write()\n",
  463. psi->name);
  464. return -EINVAL;
  465. }
  466. spin_lock(&pstore_lock);
  467. if (psinfo) {
  468. pr_warn("backend '%s' already loaded: ignoring '%s'\n",
  469. psinfo->name, psi->name);
  470. spin_unlock(&pstore_lock);
  471. return -EBUSY;
  472. }
  473. if (!psi->write_user)
  474. psi->write_user = pstore_write_user_compat;
  475. psinfo = psi;
  476. mutex_init(&psinfo->read_mutex);
  477. spin_unlock(&pstore_lock);
  478. if (owner && !try_module_get(owner)) {
  479. psinfo = NULL;
  480. return -EINVAL;
  481. }
  482. allocate_buf_for_compression();
  483. if (pstore_is_mounted())
  484. pstore_get_records(0);
  485. if (psi->flags & PSTORE_FLAGS_DMESG)
  486. pstore_register_kmsg();
  487. if (psi->flags & PSTORE_FLAGS_CONSOLE)
  488. pstore_register_console();
  489. if (psi->flags & PSTORE_FLAGS_FTRACE)
  490. pstore_register_ftrace();
  491. if (psi->flags & PSTORE_FLAGS_PMSG)
  492. pstore_register_pmsg();
  493. /* Start watching for new records, if desired. */
  494. if (pstore_update_ms >= 0) {
  495. pstore_timer.expires = jiffies +
  496. msecs_to_jiffies(pstore_update_ms);
  497. add_timer(&pstore_timer);
  498. }
  499. /*
  500. * Update the module parameter backend, so it is visible
  501. * through /sys/module/pstore/parameters/backend
  502. */
  503. backend = psi->name;
  504. pr_info("Registered %s as persistent store backend\n", psi->name);
  505. module_put(owner);
  506. return 0;
  507. }
  508. EXPORT_SYMBOL_GPL(pstore_register);
  509. void pstore_unregister(struct pstore_info *psi)
  510. {
  511. /* Stop timer and make sure all work has finished. */
  512. pstore_update_ms = -1;
  513. del_timer_sync(&pstore_timer);
  514. flush_work(&pstore_work);
  515. if (psi->flags & PSTORE_FLAGS_PMSG)
  516. pstore_unregister_pmsg();
  517. if (psi->flags & PSTORE_FLAGS_FTRACE)
  518. pstore_unregister_ftrace();
  519. if (psi->flags & PSTORE_FLAGS_CONSOLE)
  520. pstore_unregister_console();
  521. if (psi->flags & PSTORE_FLAGS_DMESG)
  522. pstore_unregister_kmsg();
  523. free_buf_for_compression();
  524. psinfo = NULL;
  525. backend = NULL;
  526. }
  527. EXPORT_SYMBOL_GPL(pstore_unregister);
  528. static void decompress_record(struct pstore_record *record)
  529. {
  530. int unzipped_len;
  531. char *decompressed;
  532. if (!record->compressed)
  533. return;
  534. /* Only PSTORE_TYPE_DMESG support compression. */
  535. if (record->type != PSTORE_TYPE_DMESG) {
  536. pr_warn("ignored compressed record type %d\n", record->type);
  537. return;
  538. }
  539. /* No compression method has created the common buffer. */
  540. if (!big_oops_buf) {
  541. pr_warn("no decompression buffer allocated\n");
  542. return;
  543. }
  544. unzipped_len = pstore_decompress(record->buf, big_oops_buf,
  545. record->size, big_oops_buf_sz);
  546. if (unzipped_len <= 0) {
  547. pr_err("decompression failed: %d\n", unzipped_len);
  548. return;
  549. }
  550. /* Build new buffer for decompressed contents. */
  551. decompressed = kmalloc(unzipped_len + record->ecc_notice_size,
  552. GFP_KERNEL);
  553. if (!decompressed) {
  554. pr_err("decompression ran out of memory\n");
  555. return;
  556. }
  557. memcpy(decompressed, big_oops_buf, unzipped_len);
  558. /* Append ECC notice to decompressed buffer. */
  559. memcpy(decompressed + unzipped_len, record->buf + record->size,
  560. record->ecc_notice_size);
  561. /* Swap out compresed contents with decompressed contents. */
  562. kfree(record->buf);
  563. record->buf = decompressed;
  564. record->size = unzipped_len;
  565. record->compressed = false;
  566. }
  567. /*
  568. * Read all the records from one persistent store backend. Create
  569. * files in our filesystem. Don't warn about -EEXIST errors
  570. * when we are re-scanning the backing store looking to add new
  571. * error records.
  572. */
  573. void pstore_get_backend_records(struct pstore_info *psi,
  574. struct dentry *root, int quiet)
  575. {
  576. int failed = 0;
  577. unsigned int stop_loop = 65536;
  578. if (!psi || !root)
  579. return;
  580. mutex_lock(&psi->read_mutex);
  581. if (psi->open && psi->open(psi))
  582. goto out;
  583. /*
  584. * Backend callback read() allocates record.buf. decompress_record()
  585. * may reallocate record.buf. On success, pstore_mkfile() will keep
  586. * the record.buf, so free it only on failure.
  587. */
  588. for (; stop_loop; stop_loop--) {
  589. struct pstore_record *record;
  590. int rc;
  591. record = kzalloc(sizeof(*record), GFP_KERNEL);
  592. if (!record) {
  593. pr_err("out of memory creating record\n");
  594. break;
  595. }
  596. pstore_record_init(record, psi);
  597. record->size = psi->read(record);
  598. /* No more records left in backend? */
  599. if (record->size <= 0) {
  600. kfree(record);
  601. break;
  602. }
  603. decompress_record(record);
  604. rc = pstore_mkfile(root, record);
  605. if (rc) {
  606. /* pstore_mkfile() did not take record, so free it. */
  607. kfree(record->buf);
  608. kfree(record);
  609. if (rc != -EEXIST || !quiet)
  610. failed++;
  611. }
  612. }
  613. if (psi->close)
  614. psi->close(psi);
  615. out:
  616. mutex_unlock(&psi->read_mutex);
  617. if (failed)
  618. pr_warn("failed to create %d record(s) from '%s'\n",
  619. failed, psi->name);
  620. if (!stop_loop)
  621. pr_err("looping? Too many records seen from '%s'\n",
  622. psi->name);
  623. }
  624. static void pstore_dowork(struct work_struct *work)
  625. {
  626. pstore_get_records(1);
  627. }
  628. static void pstore_timefunc(struct timer_list *unused)
  629. {
  630. if (pstore_new_entry) {
  631. pstore_new_entry = 0;
  632. schedule_work(&pstore_work);
  633. }
  634. if (pstore_update_ms >= 0)
  635. mod_timer(&pstore_timer,
  636. jiffies + msecs_to_jiffies(pstore_update_ms));
  637. }
  638. void __init pstore_choose_compression(void)
  639. {
  640. const struct pstore_zbackend *step;
  641. if (!compress)
  642. return;
  643. for (step = zbackends; step->name; step++) {
  644. if (!strcmp(compress, step->name)) {
  645. zbackend = step;
  646. pr_info("using %s compression\n", zbackend->name);
  647. return;
  648. }
  649. }
  650. }
  651. module_param(compress, charp, 0444);
  652. MODULE_PARM_DESC(compress, "Pstore compression to use");
  653. module_param(backend, charp, 0444);
  654. MODULE_PARM_DESC(backend, "Pstore backend to use");