| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved. | 
| Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 |  * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved. | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 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 | 
| Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 |  * of the GNU General Public License version 2. | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 |  */ | 
 | 9 |  | 
 | 10 | #include <linux/sched.h> | 
 | 11 | #include <linux/slab.h> | 
 | 12 | #include <linux/spinlock.h> | 
 | 13 | #include <linux/completion.h> | 
 | 14 | #include <linux/buffer_head.h> | 
 | 15 | #include <linux/kthread.h> | 
 | 16 | #include <linux/delay.h> | 
| Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 17 | #include <linux/gfs2_ondisk.h> | 
| Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 18 | #include <linux/lm_interface.h> | 
| Abhijith Das | b365762 | 2007-06-27 11:06:19 -0500 | [diff] [blame] | 19 | #include <linux/freezer.h> | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 20 |  | 
 | 21 | #include "gfs2.h" | 
| Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 22 | #include "incore.h" | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 23 | #include "daemon.h" | 
 | 24 | #include "glock.h" | 
 | 25 | #include "log.h" | 
 | 26 | #include "quota.h" | 
 | 27 | #include "recovery.h" | 
 | 28 | #include "super.h" | 
| Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 29 | #include "util.h" | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 30 |  | 
 | 31 | /* This uses schedule_timeout() instead of msleep() because it's good for | 
 | 32 |    the daemons to wake up more often than the timeout when unmounting so | 
 | 33 |    the user's unmount doesn't sit there forever. | 
| Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 34 |  | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 35 |    The kthread functions used to start these daemons block and flush signals. */ | 
 | 36 |  | 
 | 37 | /** | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 38 |  * gfs2_glockd - Reclaim unused glock structures | 
 | 39 |  * @sdp: Pointer to GFS2 superblock | 
 | 40 |  * | 
 | 41 |  * One or more of these daemons run, reclaiming glocks on sd_reclaim_list. | 
 | 42 |  * Number of daemons can be set by user, with num_glockd mount option. | 
 | 43 |  */ | 
 | 44 |  | 
 | 45 | int gfs2_glockd(void *data) | 
 | 46 | { | 
| Steven Whitehouse | b800a1c | 2006-04-24 13:13:56 -0400 | [diff] [blame] | 47 | 	struct gfs2_sbd *sdp = data; | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 48 |  | 
 | 49 | 	while (!kthread_should_stop()) { | 
 | 50 | 		while (atomic_read(&sdp->sd_reclaim_count)) | 
 | 51 | 			gfs2_reclaim_glock(sdp); | 
 | 52 |  | 
| Steven Whitehouse | b800a1c | 2006-04-24 13:13:56 -0400 | [diff] [blame] | 53 | 		wait_event_interruptible(sdp->sd_reclaim_wq, | 
 | 54 | 					 (atomic_read(&sdp->sd_reclaim_count) || | 
 | 55 | 					 kthread_should_stop())); | 
| Abhijith Das | b365762 | 2007-06-27 11:06:19 -0500 | [diff] [blame] | 56 | 		if (freezing(current)) | 
 | 57 | 			refrigerator(); | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 58 | 	} | 
 | 59 |  | 
 | 60 | 	return 0; | 
 | 61 | } | 
 | 62 |  | 
 | 63 | /** | 
 | 64 |  * gfs2_recoverd - Recover dead machine's journals | 
 | 65 |  * @sdp: Pointer to GFS2 superblock | 
 | 66 |  * | 
 | 67 |  */ | 
 | 68 |  | 
 | 69 | int gfs2_recoverd(void *data) | 
 | 70 | { | 
| Steven Whitehouse | b800a1c | 2006-04-24 13:13:56 -0400 | [diff] [blame] | 71 | 	struct gfs2_sbd *sdp = data; | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 72 | 	unsigned long t; | 
 | 73 |  | 
 | 74 | 	while (!kthread_should_stop()) { | 
 | 75 | 		gfs2_check_journals(sdp); | 
 | 76 | 		t = gfs2_tune_get(sdp,  gt_recoverd_secs) * HZ; | 
| Abhijith Das | b365762 | 2007-06-27 11:06:19 -0500 | [diff] [blame] | 77 | 		if (freezing(current)) | 
 | 78 | 			refrigerator(); | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 79 | 		schedule_timeout_interruptible(t); | 
 | 80 | 	} | 
 | 81 |  | 
 | 82 | 	return 0; | 
 | 83 | } | 
 | 84 |  | 
 | 85 | /** | 
 | 86 |  * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks | 
 | 87 |  * @sdp: Pointer to GFS2 superblock | 
 | 88 |  * | 
 | 89 |  * Also, periodically check to make sure that we're using the most recent | 
 | 90 |  * journal index. | 
 | 91 |  */ | 
 | 92 |  | 
 | 93 | int gfs2_logd(void *data) | 
 | 94 | { | 
| Steven Whitehouse | b800a1c | 2006-04-24 13:13:56 -0400 | [diff] [blame] | 95 | 	struct gfs2_sbd *sdp = data; | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 96 | 	struct gfs2_holder ji_gh; | 
 | 97 | 	unsigned long t; | 
| Steven Whitehouse | b004157 | 2006-11-23 10:51:34 -0500 | [diff] [blame] | 98 | 	int need_flush; | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 99 |  | 
 | 100 | 	while (!kthread_should_stop()) { | 
 | 101 | 		/* Advance the log tail */ | 
 | 102 |  | 
 | 103 | 		t = sdp->sd_log_flush_time + | 
 | 104 | 		    gfs2_tune_get(sdp, gt_log_flush_secs) * HZ; | 
 | 105 |  | 
 | 106 | 		gfs2_ail1_empty(sdp, DIO_ALL); | 
| Steven Whitehouse | b004157 | 2006-11-23 10:51:34 -0500 | [diff] [blame] | 107 | 		gfs2_log_lock(sdp); | 
 | 108 | 		need_flush = sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks); | 
 | 109 | 		gfs2_log_unlock(sdp); | 
 | 110 | 		if (need_flush || time_after_eq(jiffies, t)) { | 
| Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 111 | 			gfs2_log_flush(sdp, NULL); | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 112 | 			sdp->sd_log_flush_time = jiffies; | 
 | 113 | 		} | 
 | 114 |  | 
 | 115 | 		/* Check for latest journal index */ | 
 | 116 |  | 
 | 117 | 		t = sdp->sd_jindex_refresh_time + | 
 | 118 | 		    gfs2_tune_get(sdp, gt_jindex_refresh_secs) * HZ; | 
 | 119 |  | 
 | 120 | 		if (time_after_eq(jiffies, t)) { | 
 | 121 | 			if (!gfs2_jindex_hold(sdp, &ji_gh)) | 
 | 122 | 				gfs2_glock_dq_uninit(&ji_gh); | 
 | 123 | 			sdp->sd_jindex_refresh_time = jiffies; | 
 | 124 | 		} | 
 | 125 |  | 
 | 126 | 		t = gfs2_tune_get(sdp, gt_logd_secs) * HZ; | 
| Abhijith Das | b365762 | 2007-06-27 11:06:19 -0500 | [diff] [blame] | 127 | 		if (freezing(current)) | 
 | 128 | 			refrigerator(); | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 129 | 		schedule_timeout_interruptible(t); | 
 | 130 | 	} | 
 | 131 |  | 
 | 132 | 	return 0; | 
 | 133 | } | 
 | 134 |  | 
 | 135 | /** | 
 | 136 |  * gfs2_quotad - Write cached quota changes into the quota file | 
 | 137 |  * @sdp: Pointer to GFS2 superblock | 
 | 138 |  * | 
 | 139 |  */ | 
 | 140 |  | 
 | 141 | int gfs2_quotad(void *data) | 
 | 142 | { | 
| Steven Whitehouse | b800a1c | 2006-04-24 13:13:56 -0400 | [diff] [blame] | 143 | 	struct gfs2_sbd *sdp = data; | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 144 | 	unsigned long t; | 
 | 145 | 	int error; | 
 | 146 |  | 
 | 147 | 	while (!kthread_should_stop()) { | 
 | 148 | 		/* Update the master statfs file */ | 
 | 149 |  | 
 | 150 | 		t = sdp->sd_statfs_sync_time + | 
 | 151 | 		    gfs2_tune_get(sdp, gt_statfs_quantum) * HZ; | 
 | 152 |  | 
 | 153 | 		if (time_after_eq(jiffies, t)) { | 
 | 154 | 			error = gfs2_statfs_sync(sdp); | 
 | 155 | 			if (error && | 
 | 156 | 			    error != -EROFS && | 
 | 157 | 			    !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) | 
 | 158 | 				fs_err(sdp, "quotad: (1) error=%d\n", error); | 
 | 159 | 			sdp->sd_statfs_sync_time = jiffies; | 
 | 160 | 		} | 
 | 161 |  | 
 | 162 | 		/* Update quota file */ | 
 | 163 |  | 
 | 164 | 		t = sdp->sd_quota_sync_time + | 
 | 165 | 		    gfs2_tune_get(sdp, gt_quota_quantum) * HZ; | 
 | 166 |  | 
 | 167 | 		if (time_after_eq(jiffies, t)) { | 
 | 168 | 			error = gfs2_quota_sync(sdp); | 
 | 169 | 			if (error && | 
 | 170 | 			    error != -EROFS && | 
 | 171 | 			    !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) | 
 | 172 | 				fs_err(sdp, "quotad: (2) error=%d\n", error); | 
 | 173 | 			sdp->sd_quota_sync_time = jiffies; | 
 | 174 | 		} | 
 | 175 |  | 
 | 176 | 		gfs2_quota_scan(sdp); | 
 | 177 |  | 
 | 178 | 		t = gfs2_tune_get(sdp, gt_quotad_secs) * HZ; | 
| Abhijith Das | b365762 | 2007-06-27 11:06:19 -0500 | [diff] [blame] | 179 | 		if (freezing(current)) | 
 | 180 | 			refrigerator(); | 
| David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 181 | 		schedule_timeout_interruptible(t); | 
 | 182 | 	} | 
 | 183 |  | 
 | 184 | 	return 0; | 
 | 185 | } | 
 | 186 |  |