1 fs/ext3/super.c | 229 +++++++++++++++++++++++++++++++++++++++++++++
2 include/linux/ext3_fs.h | 2
3 include/linux/ext3_fs_sb.h | 10 +
4 3 files changed, 241 insertions(+)
6 --- linux-2.4.18-18.8.0-l15/fs/ext3/super.c~ext3-delete_thread-2.4.18 Tue Jun 3 17:26:21 2003
7 +++ linux-2.4.18-18.8.0-l15-adilger/fs/ext3/super.c Wed Jun 18 11:59:14 2003
8 @@ -396,6 +396,219 @@ static void dump_orphan_list(struct supe
12 +#ifdef EXT3_DELETE_THREAD
14 + * Delete inodes in a loop until there are no more to be deleted.
15 + * Normally, we run in the background doing the deletes and sleeping again,
16 + * and clients just add new inodes to be deleted onto the end of the list.
17 + * If someone is concerned about free space (e.g. block allocation or similar)
18 + * then they can sleep on s_delete_waiter_queue and be woken up when space
21 +int ext3_delete_thread(void *data)
23 + struct super_block *sb = data;
24 + struct ext3_sb_info *sbi = EXT3_SB(sb);
25 + struct task_struct *tsk = current;
27 + /* Almost like daemonize, but not quite */
32 + exit_files(current);
35 + sprintf(tsk->comm, "kdelext3-%s", kdevname(sb->s_dev));
36 + sigfillset(&tsk->blocked);
38 + /*tsk->flags |= PF_KERNTHREAD;*/
40 + INIT_LIST_HEAD(&sbi->s_delete_list);
41 + wake_up(&sbi->s_delete_waiter_queue);
42 + ext3_debug("delete thread on %s started\n", kdevname(sb->s_dev));
46 + wait_event_interruptible(sbi->s_delete_thread_queue,
47 + !list_empty(&sbi->s_delete_list) ||
48 + !test_opt(sb, ASYNCDEL));
49 + ext3_debug("%s woken up: %lu inodes, %lu blocks\n",
50 + tsk->comm,sbi->s_delete_inodes,sbi->s_delete_blocks);
52 + spin_lock(&sbi->s_delete_lock);
53 + if (list_empty(&sbi->s_delete_list)) {
54 + clear_opt(sbi->s_mount_opt, ASYNCDEL);
55 + memset(&sbi->s_delete_list, 0,
56 + sizeof(sbi->s_delete_list));
57 + spin_unlock(&sbi->s_delete_lock);
58 + ext3_debug("delete thread on %s exiting\n",
59 + kdevname(sb->s_dev));
60 + wake_up(&sbi->s_delete_waiter_queue);
64 + while (!list_empty(&sbi->s_delete_list)) {
65 + struct inode *inode=list_entry(sbi->s_delete_list.next,
66 + struct inode, i_dentry);
67 + unsigned long blocks = inode->i_blocks >>
68 + (inode->i_blkbits - 9);
70 + list_del_init(&inode->i_dentry);
71 + spin_unlock(&sbi->s_delete_lock);
72 + ext3_debug("%s delete ino %lu blk %lu\n",
73 + tsk->comm, inode->i_ino, blocks);
77 + spin_lock(&sbi->s_delete_lock);
78 + sbi->s_delete_blocks -= blocks;
79 + sbi->s_delete_inodes--;
81 + if (sbi->s_delete_blocks != 0 || sbi->s_delete_inodes != 0) {
82 + ext3_warning(sb, __FUNCTION__,
83 + "%lu blocks, %lu inodes on list?\n",
84 + sbi->s_delete_blocks,sbi->s_delete_inodes);
85 + sbi->s_delete_blocks = 0;
86 + sbi->s_delete_inodes = 0;
88 + spin_unlock(&sbi->s_delete_lock);
89 + wake_up(&sbi->s_delete_waiter_queue);
95 +static void ext3_start_delete_thread(struct super_block *sb)
97 + struct ext3_sb_info *sbi = EXT3_SB(sb);
100 + spin_lock_init(&sbi->s_delete_lock);
101 + init_waitqueue_head(&sbi->s_delete_thread_queue);
102 + init_waitqueue_head(&sbi->s_delete_waiter_queue);
104 + if (!test_opt(sb, ASYNCDEL))
107 + rc = kernel_thread(ext3_delete_thread, sb, CLONE_VM | CLONE_FILES);
109 + printk(KERN_ERR "EXT3-fs: cannot start delete thread: rc %d\n",
112 + wait_event(sbi->s_delete_waiter_queue, sbi->s_delete_list.next);
115 +static void ext3_stop_delete_thread(struct ext3_sb_info *sbi)
117 + if (sbi->s_delete_list.next == 0) /* thread never started */
120 + clear_opt(sbi->s_mount_opt, ASYNCDEL);
121 + wake_up(&sbi->s_delete_thread_queue);
122 + wait_event(sbi->s_delete_waiter_queue, list_empty(&sbi->s_delete_list));
125 +/* Instead of playing games with the inode flags, destruction, etc we just
126 + * create a new inode locally and put it on a list for the truncate thread.
127 + * We need large parts of the inode struct in order to complete the
128 + * truncate and unlink, so we may as well just have a real inode to do it.
130 + * If we have any problem deferring the delete, just delete it right away.
131 + * If we defer it, we also mark how many blocks it would free, so that we
132 + * can keep the statfs data correct, and we know if we should sleep on the
133 + * truncate thread when we run out of space.
135 + * In 2.5 this can be done much more cleanly by just registering a "drop"
136 + * method in the super_operations struct.
138 +static void ext3_delete_inode_thread(struct inode *old_inode)
140 + struct ext3_sb_info *sbi = EXT3_SB(old_inode->i_sb);
141 + struct inode *new_inode;
142 + unsigned long blocks = old_inode->i_blocks >> (old_inode->i_blkbits-9);
144 + if (is_bad_inode(old_inode)) {
145 + clear_inode(old_inode);
149 + if (!test_opt(old_inode->i_sb, ASYNCDEL)) {
150 + ext3_delete_inode(old_inode);
154 + /* We may want to delete the inode immediately and not defer it */
155 + if (IS_SYNC(old_inode) || blocks <= EXT3_NDIR_BLOCKS ||
156 + !sbi->s_delete_list.next) {
157 + ext3_delete_inode(old_inode);
161 + if ((EXT3_I(old_inode)->i_state & EXT3_STATE_DELETE) ||
162 + (EXT3_SB(old_inode->i_sb)->s_mount_state & EXT3_ORPHAN_FS)) {
163 + ext3_debug("doing deferred inode %lu delete (%lu blocks)\n",
164 + old_inode->i_ino, blocks);
165 + ext3_delete_inode(old_inode);
169 + /* We can iget this inode again here, because our caller has unhashed
170 + * old_inode, so new_inode will be in a different inode struct.
172 + * We need to ensure that the i_orphan pointers in the other inodes
173 + * point at the new inode copy instead of the old one so the orphan
174 + * list doesn't get corrupted when the old orphan inode is freed.
176 + down(&sbi->s_orphan_lock);
178 + EXT3_SB(old_inode->i_sb)->s_mount_state |= EXT3_ORPHAN_FS;
179 + new_inode = iget(old_inode->i_sb, old_inode->i_ino);
180 + EXT3_SB(old_inode->i_sb)->s_mount_state &= ~EXT3_ORPHAN_FS;
181 + if (is_bad_inode(new_inode)) {
182 + printk(KERN_WARNING "read bad inode %lu\n", old_inode->i_ino);
187 + up(&sbi->s_orphan_lock);
188 + ext3_debug("delete inode %lu directly (bad read)\n",
190 + ext3_delete_inode(old_inode);
193 + J_ASSERT(new_inode != old_inode);
195 + J_ASSERT(!list_empty(&EXT3_I(old_inode)->i_orphan));
196 + /* Ugh. We need to insert new_inode into the same spot on the list
197 + * as old_inode was, to ensure the in-memory orphan list is still
198 + * in the same order as the on-disk orphan list (badness otherwise).
200 + EXT3_I(new_inode)->i_orphan = EXT3_I(old_inode)->i_orphan;
201 + EXT3_I(new_inode)->i_orphan.next->prev = &EXT3_I(new_inode)->i_orphan;
202 + EXT3_I(new_inode)->i_orphan.prev->next = &EXT3_I(new_inode)->i_orphan;
203 + EXT3_I(new_inode)->i_state |= EXT3_STATE_DELETE;
204 + up(&sbi->s_orphan_lock);
206 + clear_inode(old_inode);
208 + spin_lock(&sbi->s_delete_lock);
209 + J_ASSERT(list_empty(&new_inode->i_dentry));
210 + list_add_tail(&new_inode->i_dentry, &sbi->s_delete_list);
211 + sbi->s_delete_blocks += blocks;
212 + sbi->s_delete_inodes++;
213 + spin_unlock(&sbi->s_delete_lock);
215 + ext3_debug("delete inode %lu (%lu blocks) by thread\n",
216 + new_inode->i_ino, blocks);
218 + wake_up(&sbi->s_delete_thread_queue);
221 +#define ext3_start_delete_thread(sbi) do {} while(0)
222 +#define ext3_stop_delete_thread(sbi) do {} while(0)
223 +#endif /* EXT3_DELETE_THREAD */
225 void ext3_put_super (struct super_block * sb)
227 struct ext3_sb_info *sbi = EXT3_SB(sb);
228 @@ -403,6 +615,7 @@ void ext3_put_super (struct super_block
229 kdev_t j_dev = sbi->s_journal->j_dev;
232 + ext3_stop_delete_thread(sbi);
233 ext3_xattr_put_super(sb);
234 journal_destroy(sbi->s_journal);
235 if (!(sb->s_flags & MS_RDONLY)) {
236 @@ -451,7 +664,11 @@ static struct super_operations ext3_sops
237 write_inode: ext3_write_inode, /* BKL not held. Don't need */
238 dirty_inode: ext3_dirty_inode, /* BKL not held. We take it */
239 put_inode: ext3_put_inode, /* BKL not held. Don't need */
240 +#ifdef EXT3_DELETE_THREAD
241 + delete_inode: ext3_delete_inode_thread,/* BKL not held. We take it */
243 delete_inode: ext3_delete_inode, /* BKL not held. We take it */
245 put_super: ext3_put_super, /* BKL held */
246 write_super: ext3_write_super, /* BKL held */
247 write_super_lockfs: ext3_write_super_lockfs, /* BKL not held. Take it */
248 @@ -511,6 +728,14 @@ static int parse_options (char * options
249 this_char = strtok (NULL, ",")) {
250 if ((value = strchr (this_char, '=')) != NULL)
252 +#ifdef EXT3_DELETE_THREAD
253 + if (!strcmp(this_char, "asyncdel"))
254 + set_opt(*mount_options, ASYNCDEL);
255 + else if (!strcmp(this_char, "noasyncdel"))
256 + clear_opt(*mount_options, ASYNCDEL);
260 if (!strcmp (this_char, "bsddf"))
261 clear_opt (*mount_options, MINIX_DF);
262 else if (!strcmp (this_char, "nouid32")) {
263 @@ -1206,6 +1431,7 @@ struct super_block * ext3_read_super (st
266 ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY);
267 + ext3_start_delete_thread(sb);
269 * akpm: core read_super() calls in here with the superblock locked.
270 * That deadlocks, because orphan cleanup needs to lock the superblock
271 @@ -1648,6 +1874,9 @@ int ext3_remount (struct super_block * s
272 if (!parse_options(data, &tmp, sbi, &tmp, 1))
275 + if (!test_opt(sb, ASYNCDEL) || (*flags & MS_RDONLY))
276 + ext3_stop_delete_thread(sbi);
278 if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
279 ext3_abort(sb, __FUNCTION__, "Abort forced by user");
281 --- linux-2.4.18-18.8.0-l15/include/linux/ext3_fs.h~ext3-delete_thread-2.4.18 Tue Jun 3 17:26:20 2003
282 +++ linux-2.4.18-18.8.0-l15-adilger/include/linux/ext3_fs.h Tue Jun 17 12:36:56 2003
283 @@ -190,6 +190,7 @@ struct ext3_group_desc
285 #define EXT3_STATE_JDATA 0x00000001 /* journaled data exists */
286 #define EXT3_STATE_NEW 0x00000002 /* inode is newly created */
287 +#define EXT3_STATE_DELETE 0x00000010 /* deferred delete inode */
291 @@ -317,6 +318,7 @@ struct ext3_inode {
292 #define EXT3_MOUNT_UPDATE_JOURNAL 0x1000 /* Update the journal format */
293 #define EXT3_MOUNT_NO_UID32 0x2000 /* Disable 32-bit UIDs */
294 #define EXT3_MOUNT_INDEX 0x4000 /* Enable directory index */
295 +#define EXT3_MOUNT_ASYNCDEL 0x20000 /* Delayed deletion */
297 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
298 #ifndef _LINUX_EXT2_FS_H
299 --- linux-2.4.18-18.8.0-l15/include/linux/ext3_fs_sb.h~ext3-delete_thread-2.4.18 Tue Jun 3 17:26:21 2003
300 +++ linux-2.4.18-18.8.0-l15-adilger/include/linux/ext3_fs_sb.h Tue Jun 17 12:36:56 2003
303 #define EXT3_MAX_GROUP_LOADED 32
305 +#define EXT3_DELETE_THREAD
308 * third extended-fs super-block data in memory
310 @@ -74,6 +76,14 @@ struct ext3_sb_info {
311 struct timer_list turn_ro_timer; /* For turning read-only (crash simulation) */
312 wait_queue_head_t ro_wait_queue; /* For people waiting for the fs to go read-only */
314 +#ifdef EXT3_DELETE_THREAD
315 + spinlock_t s_delete_lock;
316 + struct list_head s_delete_list;
317 + unsigned long s_delete_blocks;
318 + unsigned long s_delete_inodes;
319 + wait_queue_head_t s_delete_thread_queue;
320 + wait_queue_head_t s_delete_waiter_queue;
324 #endif /* _LINUX_EXT3_FS_SB */