init.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * fs-verity module initialization and logging
  4. *
  5. * Copyright 2019 Google LLC
  6. */
  7. #include "fsverity_private.h"
  8. #include <linux/ratelimit.h>
  9. void fsverity_msg(const struct inode *inode, const char *level,
  10. const char *fmt, ...)
  11. {
  12. static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL,
  13. DEFAULT_RATELIMIT_BURST);
  14. struct va_format vaf;
  15. va_list args;
  16. if (!__ratelimit(&rs))
  17. return;
  18. va_start(args, fmt);
  19. vaf.fmt = fmt;
  20. vaf.va = &args;
  21. if (inode)
  22. printk("%sfs-verity (%s, inode %lu): %pV\n",
  23. level, inode->i_sb->s_id, inode->i_ino, &vaf);
  24. else
  25. printk("%sfs-verity: %pV\n", level, &vaf);
  26. va_end(args);
  27. }
  28. static int __init fsverity_init(void)
  29. {
  30. int err;
  31. fsverity_check_hash_algs();
  32. err = fsverity_init_info_cache();
  33. if (err)
  34. return err;
  35. err = fsverity_init_workqueue();
  36. if (err)
  37. goto err_exit_info_cache;
  38. err = fsverity_init_signature();
  39. if (err)
  40. goto err_exit_workqueue;
  41. pr_debug("Initialized fs-verity\n");
  42. return 0;
  43. err_exit_workqueue:
  44. fsverity_exit_workqueue();
  45. err_exit_info_cache:
  46. fsverity_exit_info_cache();
  47. return err;
  48. }
  49. late_initcall(fsverity_init)