daemon.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/kthread.h>
  15. #include <linux/delay.h>
  16. #include <linux/gfs2_ondisk.h>
  17. #include <linux/lm_interface.h>
  18. #include "gfs2.h"
  19. #include "incore.h"
  20. #include "daemon.h"
  21. #include "glock.h"
  22. #include "log.h"
  23. #include "quota.h"
  24. #include "recovery.h"
  25. #include "super.h"
  26. #include "util.h"
  27. /* This uses schedule_timeout() instead of msleep() because it's good for
  28. the daemons to wake up more often than the timeout when unmounting so
  29. the user's unmount doesn't sit there forever.
  30. The kthread functions used to start these daemons block and flush signals. */
  31. /**
  32. * gfs2_scand - Look for cached glocks and inodes to toss from memory
  33. * @sdp: Pointer to GFS2 superblock
  34. *
  35. * One of these daemons runs, finding candidates to add to sd_reclaim_list.
  36. * See gfs2_glockd()
  37. */
  38. int gfs2_scand(void *data)
  39. {
  40. struct gfs2_sbd *sdp = data;
  41. unsigned long t;
  42. while (!kthread_should_stop()) {
  43. gfs2_scand_internal(sdp);
  44. t = gfs2_tune_get(sdp, gt_scand_secs) * HZ;
  45. schedule_timeout_interruptible(t);
  46. }
  47. return 0;
  48. }
  49. /**
  50. * gfs2_glockd - Reclaim unused glock structures
  51. * @sdp: Pointer to GFS2 superblock
  52. *
  53. * One or more of these daemons run, reclaiming glocks on sd_reclaim_list.
  54. * Number of daemons can be set by user, with num_glockd mount option.
  55. */
  56. int gfs2_glockd(void *data)
  57. {
  58. struct gfs2_sbd *sdp = data;
  59. while (!kthread_should_stop()) {
  60. while (atomic_read(&sdp->sd_reclaim_count))
  61. gfs2_reclaim_glock(sdp);
  62. wait_event_interruptible(sdp->sd_reclaim_wq,
  63. (atomic_read(&sdp->sd_reclaim_count) ||
  64. kthread_should_stop()));
  65. }
  66. return 0;
  67. }
  68. /**
  69. * gfs2_recoverd - Recover dead machine's journals
  70. * @sdp: Pointer to GFS2 superblock
  71. *
  72. */
  73. int gfs2_recoverd(void *data)
  74. {
  75. struct gfs2_sbd *sdp = data;
  76. unsigned long t;
  77. while (!kthread_should_stop()) {
  78. gfs2_check_journals(sdp);
  79. t = gfs2_tune_get(sdp, gt_recoverd_secs) * HZ;
  80. schedule_timeout_interruptible(t);
  81. }
  82. return 0;
  83. }
  84. /**
  85. * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
  86. * @sdp: Pointer to GFS2 superblock
  87. *
  88. * Also, periodically check to make sure that we're using the most recent
  89. * journal index.
  90. */
  91. int gfs2_logd(void *data)
  92. {
  93. struct gfs2_sbd *sdp = data;
  94. struct gfs2_holder ji_gh;
  95. unsigned long t;
  96. while (!kthread_should_stop()) {
  97. /* Advance the log tail */
  98. t = sdp->sd_log_flush_time +
  99. gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
  100. gfs2_ail1_empty(sdp, DIO_ALL);
  101. if (time_after_eq(jiffies, t)) {
  102. gfs2_log_flush(sdp, NULL);
  103. sdp->sd_log_flush_time = jiffies;
  104. }
  105. /* Check for latest journal index */
  106. t = sdp->sd_jindex_refresh_time +
  107. gfs2_tune_get(sdp, gt_jindex_refresh_secs) * HZ;
  108. if (time_after_eq(jiffies, t)) {
  109. if (!gfs2_jindex_hold(sdp, &ji_gh))
  110. gfs2_glock_dq_uninit(&ji_gh);
  111. sdp->sd_jindex_refresh_time = jiffies;
  112. }
  113. t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
  114. schedule_timeout_interruptible(t);
  115. }
  116. return 0;
  117. }
  118. /**
  119. * gfs2_quotad - Write cached quota changes into the quota file
  120. * @sdp: Pointer to GFS2 superblock
  121. *
  122. */
  123. int gfs2_quotad(void *data)
  124. {
  125. struct gfs2_sbd *sdp = data;
  126. unsigned long t;
  127. int error;
  128. while (!kthread_should_stop()) {
  129. /* Update the master statfs file */
  130. t = sdp->sd_statfs_sync_time +
  131. gfs2_tune_get(sdp, gt_statfs_quantum) * HZ;
  132. if (time_after_eq(jiffies, t)) {
  133. error = gfs2_statfs_sync(sdp);
  134. if (error &&
  135. error != -EROFS &&
  136. !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  137. fs_err(sdp, "quotad: (1) error=%d\n", error);
  138. sdp->sd_statfs_sync_time = jiffies;
  139. }
  140. /* Update quota file */
  141. t = sdp->sd_quota_sync_time +
  142. gfs2_tune_get(sdp, gt_quota_quantum) * HZ;
  143. if (time_after_eq(jiffies, t)) {
  144. error = gfs2_quota_sync(sdp);
  145. if (error &&
  146. error != -EROFS &&
  147. !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  148. fs_err(sdp, "quotad: (2) error=%d\n", error);
  149. sdp->sd_quota_sync_time = jiffies;
  150. }
  151. gfs2_quota_scan(sdp);
  152. t = gfs2_tune_get(sdp, gt_quotad_secs) * HZ;
  153. schedule_timeout_interruptible(t);
  154. }
  155. return 0;
  156. }