masklog.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * Copyright (C) 2004, 2005 Oracle. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  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 GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public
  17. * License along with this program; if not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 021110-1307, USA.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/proc_fs.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/string.h>
  26. #include <asm/uaccess.h>
  27. #include "masklog.h"
  28. struct mlog_bits mlog_and_bits = MLOG_BITS_RHS(MLOG_INITIAL_AND_MASK);
  29. EXPORT_SYMBOL_GPL(mlog_and_bits);
  30. struct mlog_bits mlog_not_bits = MLOG_BITS_RHS(0);
  31. EXPORT_SYMBOL_GPL(mlog_not_bits);
  32. static ssize_t mlog_mask_show(u64 mask, char *buf)
  33. {
  34. char *state;
  35. if (__mlog_test_u64(mask, mlog_and_bits))
  36. state = "allow";
  37. else if (__mlog_test_u64(mask, mlog_not_bits))
  38. state = "deny";
  39. else
  40. state = "off";
  41. return snprintf(buf, PAGE_SIZE, "%s\n", state);
  42. }
  43. static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
  44. {
  45. if (!strnicmp(buf, "allow", 5)) {
  46. __mlog_set_u64(mask, mlog_and_bits);
  47. __mlog_clear_u64(mask, mlog_not_bits);
  48. } else if (!strnicmp(buf, "deny", 4)) {
  49. __mlog_set_u64(mask, mlog_not_bits);
  50. __mlog_clear_u64(mask, mlog_and_bits);
  51. } else if (!strnicmp(buf, "off", 3)) {
  52. __mlog_clear_u64(mask, mlog_not_bits);
  53. __mlog_clear_u64(mask, mlog_and_bits);
  54. } else
  55. return -EINVAL;
  56. return count;
  57. }
  58. struct mlog_attribute {
  59. struct attribute attr;
  60. u64 mask;
  61. };
  62. #define to_mlog_attr(_attr) container_of(_attr, struct mlog_attribute, attr)
  63. #define define_mask(_name) { \
  64. .attr = { \
  65. .name = #_name, \
  66. .mode = S_IRUGO | S_IWUSR, \
  67. }, \
  68. .mask = ML_##_name, \
  69. }
  70. static struct mlog_attribute mlog_attrs[MLOG_MAX_BITS] = {
  71. define_mask(TCP),
  72. define_mask(MSG),
  73. define_mask(SOCKET),
  74. define_mask(HEARTBEAT),
  75. define_mask(HB_BIO),
  76. define_mask(DLMFS),
  77. define_mask(DLM),
  78. define_mask(DLM_DOMAIN),
  79. define_mask(DLM_THREAD),
  80. define_mask(DLM_MASTER),
  81. define_mask(DLM_RECOVERY),
  82. define_mask(DLM_GLUE),
  83. define_mask(VOTE),
  84. define_mask(CONN),
  85. define_mask(QUORUM),
  86. define_mask(BASTS),
  87. define_mask(CLUSTER),
  88. define_mask(ERROR),
  89. define_mask(NOTICE),
  90. define_mask(KTHREAD),
  91. };
  92. static struct attribute *mlog_attr_ptrs[MLOG_MAX_BITS] = {NULL, };
  93. static ssize_t mlog_show(struct kobject *obj, struct attribute *attr,
  94. char *buf)
  95. {
  96. struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
  97. return mlog_mask_show(mlog_attr->mask, buf);
  98. }
  99. static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
  100. const char *buf, size_t count)
  101. {
  102. struct mlog_attribute *mlog_attr = to_mlog_attr(attr);
  103. return mlog_mask_store(mlog_attr->mask, buf, count);
  104. }
  105. static const struct sysfs_ops mlog_attr_ops = {
  106. .show = mlog_show,
  107. .store = mlog_store,
  108. };
  109. static struct kobj_type mlog_ktype = {
  110. .default_attrs = mlog_attr_ptrs,
  111. .sysfs_ops = &mlog_attr_ops,
  112. };
  113. static struct kset mlog_kset = {
  114. .kobj = {.ktype = &mlog_ktype},
  115. };
  116. int mlog_sys_init(struct kset *o2cb_kset)
  117. {
  118. int i = 0;
  119. while (mlog_attrs[i].attr.mode) {
  120. mlog_attr_ptrs[i] = &mlog_attrs[i].attr;
  121. i++;
  122. }
  123. mlog_attr_ptrs[i] = NULL;
  124. kobject_set_name(&mlog_kset.kobj, "logmask");
  125. mlog_kset.kobj.kset = o2cb_kset;
  126. return kset_register(&mlog_kset);
  127. }
  128. void mlog_sys_shutdown(void)
  129. {
  130. kset_unregister(&mlog_kset);
  131. }