2 * OBDFS Super operations - also used for Lustre file system
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
7 * Copryright (C) 1999 Seagate Technology Inc.
10 #define __NO_VERSION__
11 #include <linux/module.h>
12 #include <linux/sched.h>
14 #include <linux/malloc.h>
15 #include <linux/locks.h>
16 #include <linux/errno.h>
17 #include <linux/swap.h>
18 #include <linux/smp_lock.h>
19 #include <linux/vmalloc.h>
20 #include <linux/blkdev.h>
21 #include <linux/sysrq.h>
22 #include <linux/file.h>
23 #include <linux/init.h>
24 #include <linux/quotaops.h>
25 #include <linux/iobuf.h>
26 #include <linux/highmem.h>
28 #include <asm/uaccess.h>
30 #include <asm/bitops.h>
31 #include <asm/mmu_context.h>
33 #include <linux/obd_support.h>
34 #include <linux/obd_class.h>
35 #include <linux/obdfs.h>
40 int nfract; /* Percentage of buffer cache dirty to
42 int ndirty; /* Maximum number of dirty blocks to write out per
44 int nrefill; /* Number of clean buffers to try to obtain
45 each time we call refill */
46 int nref_dirt; /* Dirty buffer threshold for activating bdflush
47 when trying to refill buffers. */
48 int interval; /* jiffies delay between kupdate flushes */
49 int age_buffer; /* Time for normal buffer to age before we flush it */
50 int age_super; /* Time for superblock to age before we flush it */
51 } pupd_prm = {40, 500, 64, 256, 5*HZ, 30*HZ, 5*HZ };
53 /* static void obdfs_flush_reqs(struct obdfs_super_info *sbi, int wait,
56 static void obdfs_flush_reqs(struct obdfs_super_info *sbi, int check_time)
59 struct obdfs_pgrq *req;
62 while ( (wr = wr->next) != &sbi->s_wr_head ) {
63 req = list_entry(wr, struct obdfs_pgrq, rq_list);
66 req->rq_jiffies <= (jiffies - pupd_prm.age_buffer)) {
67 /* write request out to disk */
68 obdfs_do_writepage(req->rq_inode, req->rq_page, 1);
76 static void obdfs_flush_dirty_pages(int check_time)
79 struct obdfs_super_info *sbi;
81 sl = &obdfs_super_list;
82 while ( (sl = sl->next) != &obdfs_super_list ) {
83 struct obdfs_super_entry *entry =
84 list_entry(sl, struct obdfs_super_entry, sl_chain);
87 /* walk write requests here */
88 obdfs_flush_reqs(sbi, jiffies);
91 /* again, but now we wait for completion */
92 sl = &obdfs_super_list;
93 while ( (sl = sl->next) != &obdfs_super_list ) {
94 struct obdfs_super_entry *entry =
95 list_entry(sl, struct obdfs_super_entry, sl_chain);
98 /* walk write requests here */
99 /* XXX should jiffies be 0 here? */
100 obdfs_flush_reqs(sbi, jiffies);
104 static struct task_struct *pupdated;
106 static int pupdate(void *unused)
108 struct task_struct * tsk = current;
118 sprintf(tsk->comm, "pupd");
121 printk("pupdate() activated...\n");
123 /* sigstop and sigcont will stop and wakeup pupdate */
124 spin_lock_irq(&tsk->sigmask_lock);
125 sigfillset(&tsk->blocked);
126 siginitsetinv(&tsk->blocked, sigmask(SIGCONT) | sigmask(SIGSTOP));
127 recalc_sigpending(tsk);
128 spin_unlock_irq(&tsk->sigmask_lock);
131 /* update interval */
132 interval = pupd_prm.interval;
135 tsk->state = TASK_INTERRUPTIBLE;
136 schedule_timeout(interval);
141 printk("pupdate() stopped...\n");
142 tsk->state = TASK_STOPPED;
144 printk("RETURN from PUPD\n");
147 /* check for sigstop */
148 if (signal_pending(tsk))
151 spin_lock_irq(&tsk->sigmask_lock);
152 if (sigismember(&tsk->signal, SIGTERM))
154 sigdelset(&tsk->signal, SIGTERM);
157 recalc_sigpending(tsk);
158 spin_unlock_irq(&tsk->sigmask_lock);
162 /* flush_inodes(); */
163 obdfs_flush_dirty_pages(1);
168 int flushd_init(void)
170 /* kernel_thread(bdflush, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND); */
172 kernel_thread(pupdate, NULL, 0);
173 printk("flushd inited\n");
177 int flushd_cleanup(void)
179 /* this should deliver a signal to */
182 /* XXX Andreas, we will do this later, for now, you must kill
183 pupdated with a SIGSTOP from userland, before unloading obdfs.o
186 /* send updated a STOP signal */
187 /* then let it run at least once, before continuing */