OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [fs/] [inode.c] - Blame information for rev 1275

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * linux/fs/inode.c
3
 *
4
 * (C) 1997 Linus Torvalds
5
 */
6
 
7
#include <linux/config.h>
8
#include <linux/fs.h>
9
#include <linux/string.h>
10
#include <linux/mm.h>
11
#include <linux/dcache.h>
12
#include <linux/init.h>
13
#include <linux/quotaops.h>
14
#include <linux/slab.h>
15
#include <linux/cache.h>
16
#include <linux/swap.h>
17
#include <linux/swapctl.h>
18
#include <linux/prefetch.h>
19
#include <linux/locks.h>
20
 
21
/*
22
 * New inode.c implementation.
23
 *
24
 * This implementation has the basic premise of trying
25
 * to be extremely low-overhead and SMP-safe, yet be
26
 * simple enough to be "obviously correct".
27
 *
28
 * Famous last words.
29
 */
30
 
31
/* inode dynamic allocation 1999, Andrea Arcangeli <andrea@suse.de> */
32
 
33
/* #define INODE_PARANOIA 1 */
34
/* #define INODE_DEBUG 1 */
35
 
36
/*
37
 * Inode lookup is no longer as critical as it used to be:
38
 * most of the lookups are going to be through the dcache.
39
 */
40
#define I_HASHBITS      i_hash_shift
41
#define I_HASHMASK      i_hash_mask
42
 
43
static unsigned int i_hash_mask;
44
static unsigned int i_hash_shift;
45
 
46
/*
47
 * Each inode can be on two separate lists. One is
48
 * the hash list of the inode, used for lookups. The
49
 * other linked list is the "type" list:
50
 *  "in_use" - valid inode, i_count > 0, i_nlink > 0
51
 *  "dirty"  - as "in_use" but also dirty
52
 *  "unused" - valid inode, i_count = 0, no pages in the pagecache
53
 *  "unused_pagecache" - valid inode, i_count = 0, data in the pagecache
54
 *
55
 * A "dirty" list is maintained for each super block,
56
 * allowing for low-overhead inode sync() operations.
57
 */
58
 
59
static LIST_HEAD(inode_in_use);
60
static LIST_HEAD(inode_unused);
61
static LIST_HEAD(inode_unused_pagecache);
62
static struct list_head *inode_hashtable;
63
static LIST_HEAD(anon_hash_chain); /* for inodes with NULL i_sb */
64
 
65
/*
66
 * A simple spinlock to protect the list manipulations.
67
 *
68
 * NOTE! You also have to own the lock if you change
69
 * the i_state of an inode while it is in use..
70
 */
71
static spinlock_t inode_lock = SPIN_LOCK_UNLOCKED;
72
 
73
/*
74
 * Statistics gathering..
75
 */
76
struct inodes_stat_t inodes_stat;
77
 
78
static kmem_cache_t * inode_cachep;
79
 
80
static struct inode *alloc_inode(struct super_block *sb)
81
{
82
        static struct address_space_operations empty_aops;
83
        static struct inode_operations empty_iops;
84
        static struct file_operations empty_fops;
85
        struct inode *inode;
86
 
87
        if (sb->s_op->alloc_inode)
88
                inode = sb->s_op->alloc_inode(sb);
89
        else {
90
                inode = (struct inode *) kmem_cache_alloc(inode_cachep, SLAB_KERNEL);
91
                /* will die */
92
                if (inode)
93
                        memset(&inode->u, 0, sizeof(inode->u));
94
        }
95
 
96
        if (inode) {
97
                struct address_space * const mapping = &inode->i_data;
98
 
99
                inode->i_sb = sb;
100
                inode->i_dev = sb->s_dev;
101
                inode->i_blkbits = sb->s_blocksize_bits;
102
                inode->i_flags = 0;
103
                atomic_set(&inode->i_count, 1);
104
                inode->i_sock = 0;
105
                inode->i_op = &empty_iops;
106
                inode->i_fop = &empty_fops;
107
                inode->i_nlink = 1;
108
                atomic_set(&inode->i_writecount, 0);
109
                inode->i_size = 0;
110
                inode->i_blocks = 0;
111
                inode->i_bytes = 0;
112
                inode->i_generation = 0;
113
                memset(&inode->i_dquot, 0, sizeof(inode->i_dquot));
114
                inode->i_pipe = NULL;
115
                inode->i_bdev = NULL;
116
                inode->i_cdev = NULL;
117
 
118
                mapping->a_ops = &empty_aops;
119
                mapping->host = inode;
120
                mapping->gfp_mask = GFP_HIGHUSER;
121
                inode->i_mapping = mapping;
122
        }
123
        return inode;
124
}
125
 
126
static void destroy_inode(struct inode *inode)
127
{
128
        if (inode_has_buffers(inode))
129
                BUG();
130
        /* Reinitialise the waitqueue head because __wait_on_freeing_inode()
131
           may have left stale entries on it which it can't remove (since
132
           it knows we're freeing the inode right now */
133
        init_waitqueue_head(&inode->i_wait);
134
        if (inode->i_sb->s_op->destroy_inode)
135
                inode->i_sb->s_op->destroy_inode(inode);
136
        else
137
                kmem_cache_free(inode_cachep, inode);
138
}
139
 
140
 
141
/*
142
 * These are initializations that only need to be done
143
 * once, because the fields are idempotent across use
144
 * of the inode, so let the slab aware of that.
145
 */
146
void inode_init_once(struct inode *inode)
147
{
148
        memset(inode, 0, sizeof(*inode));
149
        __inode_init_once(inode);
150
}
151
 
152
void __inode_init_once(struct inode *inode)
153
{
154
        init_waitqueue_head(&inode->i_wait);
155
        INIT_LIST_HEAD(&inode->i_hash);
156
        INIT_LIST_HEAD(&inode->i_data.clean_pages);
157
        INIT_LIST_HEAD(&inode->i_data.dirty_pages);
158
        INIT_LIST_HEAD(&inode->i_data.locked_pages);
159
        INIT_LIST_HEAD(&inode->i_dentry);
160
        INIT_LIST_HEAD(&inode->i_dirty_buffers);
161
        INIT_LIST_HEAD(&inode->i_dirty_data_buffers);
162
        INIT_LIST_HEAD(&inode->i_devices);
163
        sema_init(&inode->i_sem, 1);
164
        sema_init(&inode->i_zombie, 1);
165
        init_rwsem(&inode->i_alloc_sem);
166
        spin_lock_init(&inode->i_data.i_shared_lock);
167
}
168
 
169
static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
170
{
171
        struct inode * inode = (struct inode *) foo;
172
 
173
        if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
174
            SLAB_CTOR_CONSTRUCTOR)
175
                inode_init_once(inode);
176
}
177
 
178
/*
179
 * Put the inode on the super block's dirty list.
180
 *
181
 * CAREFUL! We mark it dirty unconditionally, but
182
 * move it onto the dirty list only if it is hashed.
183
 * If it was not hashed, it will never be added to
184
 * the dirty list even if it is later hashed, as it
185
 * will have been marked dirty already.
186
 *
187
 * In short, make sure you hash any inodes _before_
188
 * you start marking them dirty..
189
 */
190
 
191
/**
192
 *      __mark_inode_dirty -    internal function
193
 *      @inode: inode to mark
194
 *      @flags: what kind of dirty (i.e. I_DIRTY_SYNC)
195
 *      Mark an inode as dirty. Callers should use mark_inode_dirty or
196
 *      mark_inode_dirty_sync.
197
 */
198
 
199
void __mark_inode_dirty(struct inode *inode, int flags)
200
{
201
        struct super_block * sb = inode->i_sb;
202
 
203
        if (!sb)
204
                return;
205
 
206
        /* Don't do this for I_DIRTY_PAGES - that doesn't actually dirty the inode itself */
207
        if (flags & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {
208
                if (sb->s_op && sb->s_op->dirty_inode)
209
                        sb->s_op->dirty_inode(inode);
210
        }
211
 
212
        /* avoid the locking if we can */
213
        if ((inode->i_state & flags) == flags)
214
                return;
215
 
216
        spin_lock(&inode_lock);
217
        if ((inode->i_state & flags) != flags) {
218
                inode->i_state |= flags;
219
                /* Only add valid (ie hashed) inodes to the dirty list */
220
                if (!(inode->i_state & (I_LOCK|I_FREEING|I_CLEAR)) &&
221
                    !list_empty(&inode->i_hash)) {
222
                        list_del(&inode->i_list);
223
                        list_add(&inode->i_list, &sb->s_dirty);
224
                }
225
        }
226
        spin_unlock(&inode_lock);
227
}
228
 
229
static void __wait_on_inode(struct inode * inode)
230
{
231
        DECLARE_WAITQUEUE(wait, current);
232
 
233
        add_wait_queue(&inode->i_wait, &wait);
234
repeat:
235
        set_current_state(TASK_UNINTERRUPTIBLE);
236
        if (inode->i_state & I_LOCK) {
237
                schedule();
238
                goto repeat;
239
        }
240
        remove_wait_queue(&inode->i_wait, &wait);
241
        current->state = TASK_RUNNING;
242
}
243
 
244
static inline void wait_on_inode(struct inode *inode)
245
{
246
        if (inode->i_state & I_LOCK)
247
                __wait_on_inode(inode);
248
}
249
 
250
/*
251
 * If we try to find an inode in the inode hash while it is being deleted, we
252
 * have to wait until the filesystem completes its deletion before reporting
253
 * that it isn't found.  This is because iget will immediately call
254
 * ->read_inode, and we want to be sure that evidence of the deletion is found
255
 * by ->read_inode.
256
 *
257
 * Unlike the 2.6 version, this call call cannot return early, since inodes
258
 * do not share wait queue. Therefore, we don't call remove_wait_queue(); it
259
 * would be dangerous to do so since the inode may have already been freed,
260
 * and it's unnecessary, since the inode is definitely going to get freed.
261
 *
262
 * This is called with inode_lock held.
263
 */
264
static void __wait_on_freeing_inode(struct inode *inode)
265
{
266
        DECLARE_WAITQUEUE(wait, current);
267
 
268
        add_wait_queue(&inode->i_wait, &wait);
269
        set_current_state(TASK_UNINTERRUPTIBLE);
270
        spin_unlock(&inode_lock);
271
        schedule();
272
 
273
        spin_lock(&inode_lock);
274
}
275
 
276
static inline void write_inode(struct inode *inode, int sync)
277
{
278
        if (inode->i_sb && inode->i_sb->s_op && inode->i_sb->s_op->write_inode && !is_bad_inode(inode))
279
                inode->i_sb->s_op->write_inode(inode, sync);
280
}
281
 
282
static inline void __iget(struct inode * inode)
283
{
284
        if (atomic_read(&inode->i_count)) {
285
                atomic_inc(&inode->i_count);
286
                return;
287
        }
288
        atomic_inc(&inode->i_count);
289
        if (!(inode->i_state & (I_DIRTY|I_LOCK))) {
290
                list_del(&inode->i_list);
291
                list_add(&inode->i_list, &inode_in_use);
292
        }
293
        inodes_stat.nr_unused--;
294
}
295
 
296
static inline void __refile_inode(struct inode *inode)
297
{
298
        struct list_head *to;
299
 
300
        if (inode->i_state & I_FREEING)
301
                return;
302
        if (list_empty(&inode->i_hash))
303
                return;
304
 
305
        if (inode->i_state & I_DIRTY)
306
                to = &inode->i_sb->s_dirty;
307
        else if (atomic_read(&inode->i_count))
308
                to = &inode_in_use;
309
        else if (inode->i_data.nrpages)
310
                to = &inode_unused_pagecache;
311
        else
312
                to = &inode_unused;
313
        list_del(&inode->i_list);
314
        list_add(&inode->i_list, to);
315
}
316
 
317
void refile_inode(struct inode *inode)
318
{
319
        if (!inode)
320
                return;
321
        spin_lock(&inode_lock);
322
        if (!(inode->i_state & I_LOCK))
323
                __refile_inode(inode);
324
        spin_unlock(&inode_lock);
325
}
326
 
327
static inline void __sync_one(struct inode *inode, int sync)
328
{
329
        unsigned dirty;
330
 
331
        list_del(&inode->i_list);
332
        list_add(&inode->i_list, &inode->i_sb->s_locked_inodes);
333
 
334
        if (inode->i_state & (I_LOCK|I_FREEING))
335
                BUG();
336
 
337
        /* Set I_LOCK, reset I_DIRTY */
338
        dirty = inode->i_state & I_DIRTY;
339
        inode->i_state |= I_LOCK;
340
        inode->i_state &= ~I_DIRTY;
341
        spin_unlock(&inode_lock);
342
 
343
        filemap_fdatasync(inode->i_mapping);
344
 
345
        /* Don't write the inode if only I_DIRTY_PAGES was set */
346
        if (dirty & (I_DIRTY_SYNC | I_DIRTY_DATASYNC))
347
                write_inode(inode, sync);
348
 
349
        filemap_fdatawait(inode->i_mapping);
350
 
351
        spin_lock(&inode_lock);
352
        inode->i_state &= ~I_LOCK;
353
        __refile_inode(inode);
354
        wake_up(&inode->i_wait);
355
}
356
 
357
static inline void sync_one(struct inode *inode, int sync)
358
{
359
        while (inode->i_state & I_LOCK) {
360
                __iget(inode);
361
                spin_unlock(&inode_lock);
362
                __wait_on_inode(inode);
363
                iput(inode);
364
                spin_lock(&inode_lock);
365
        }
366
 
367
        __sync_one(inode, sync);
368
}
369
 
370
static inline void sync_list(struct list_head *head)
371
{
372
        struct list_head * tmp;
373
 
374
        while ((tmp = head->prev) != head)
375
                __sync_one(list_entry(tmp, struct inode, i_list), 0);
376
}
377
 
378
static inline void wait_on_locked(struct list_head *head)
379
{
380
        struct list_head * tmp;
381
        while ((tmp = head->prev) != head) {
382
                struct inode *inode = list_entry(tmp, struct inode, i_list);
383
                __iget(inode);
384
                spin_unlock(&inode_lock);
385
                __wait_on_inode(inode);
386
                iput(inode);
387
                spin_lock(&inode_lock);
388
        }
389
}
390
 
391
static inline int try_to_sync_unused_list(struct list_head *head, int nr_inodes)
392
{
393
        struct list_head *tmp = head;
394
        struct inode *inode;
395
 
396
        while (nr_inodes && (tmp = tmp->prev) != head) {
397
                inode = list_entry(tmp, struct inode, i_list);
398
 
399
                if (!atomic_read(&inode->i_count)) {
400
                        __sync_one(inode, 0);
401
                        nr_inodes--;
402
 
403
                        /*
404
                         * __sync_one moved the inode to another list,
405
                         * so we have to start looking from the list head.
406
                         */
407
                        tmp = head;
408
                }
409
        }
410
 
411
        return nr_inodes;
412
}
413
 
414
void sync_inodes_sb(struct super_block *sb)
415
{
416
        spin_lock(&inode_lock);
417
        while (!list_empty(&sb->s_dirty)||!list_empty(&sb->s_locked_inodes)) {
418
                sync_list(&sb->s_dirty);
419
                wait_on_locked(&sb->s_locked_inodes);
420
        }
421
        spin_unlock(&inode_lock);
422
}
423
 
424
/*
425
 * Note:
426
 * We don't need to grab a reference to superblock here. If it has non-empty
427
 * ->s_dirty it's hadn't been killed yet and kill_super() won't proceed
428
 * past sync_inodes_sb() until both ->s_dirty and ->s_locked_inodes are
429
 * empty. Since __sync_one() regains inode_lock before it finally moves
430
 * inode from superblock lists we are OK.
431
 */
432
 
433
void sync_unlocked_inodes(void)
434
{
435
        struct super_block * sb;
436
        spin_lock(&inode_lock);
437
        spin_lock(&sb_lock);
438
        sb = sb_entry(super_blocks.next);
439
        for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.next)) {
440
                if (!list_empty(&sb->s_dirty)) {
441
                        spin_unlock(&sb_lock);
442
                        sync_list(&sb->s_dirty);
443
                        spin_lock(&sb_lock);
444
                }
445
        }
446
        spin_unlock(&sb_lock);
447
        spin_unlock(&inode_lock);
448
}
449
 
450
/*
451
 * Find a superblock with inodes that need to be synced
452
 */
453
 
454
static struct super_block *get_super_to_sync(void)
455
{
456
        struct list_head *p;
457
restart:
458
        spin_lock(&inode_lock);
459
        spin_lock(&sb_lock);
460
        list_for_each(p, &super_blocks) {
461
                struct super_block *s = list_entry(p,struct super_block,s_list);
462
                if (list_empty(&s->s_dirty) && list_empty(&s->s_locked_inodes))
463
                        continue;
464
                s->s_count++;
465
                spin_unlock(&sb_lock);
466
                spin_unlock(&inode_lock);
467
                down_read(&s->s_umount);
468
                if (!s->s_root) {
469
                        drop_super(s);
470
                        goto restart;
471
                }
472
                return s;
473
        }
474
        spin_unlock(&sb_lock);
475
        spin_unlock(&inode_lock);
476
        return NULL;
477
}
478
 
479
/**
480
 *      sync_inodes
481
 *      @dev: device to sync the inodes from.
482
 *
483
 *      sync_inodes goes through the super block's dirty list,
484
 *      writes them out, and puts them back on the normal list.
485
 */
486
 
487
void sync_inodes(kdev_t dev)
488
{
489
        struct super_block * s;
490
 
491
        /*
492
         * Search the super_blocks array for the device(s) to sync.
493
         */
494
        if (dev) {
495
                if ((s = get_super(dev)) != NULL) {
496
                        sync_inodes_sb(s);
497
                        drop_super(s);
498
                }
499
        } else {
500
                while ((s = get_super_to_sync()) != NULL) {
501
                        sync_inodes_sb(s);
502
                        drop_super(s);
503
                }
504
        }
505
}
506
 
507
static void try_to_sync_unused_inodes(void * arg)
508
{
509
        struct super_block * sb;
510
        int nr_inodes = inodes_stat.nr_unused;
511
 
512
        spin_lock(&inode_lock);
513
        spin_lock(&sb_lock);
514
        sb = sb_entry(super_blocks.next);
515
        for (; nr_inodes && sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.next)) {
516
                if (list_empty(&sb->s_dirty))
517
                        continue;
518
                spin_unlock(&sb_lock);
519
                nr_inodes = try_to_sync_unused_list(&sb->s_dirty, nr_inodes);
520
                spin_lock(&sb_lock);
521
        }
522
        spin_unlock(&sb_lock);
523
        spin_unlock(&inode_lock);
524
}
525
 
526
static struct tq_struct unused_inodes_flush_task;
527
 
528
/**
529
 *      write_inode_now -       write an inode to disk
530
 *      @inode: inode to write to disk
531
 *      @sync: whether the write should be synchronous or not
532
 *
533
 *      This function commits an inode to disk immediately if it is
534
 *      dirty. This is primarily needed by knfsd.
535
 */
536
 
537
void write_inode_now(struct inode *inode, int sync)
538
{
539
        struct super_block * sb = inode->i_sb;
540
 
541
        if (sb) {
542
                spin_lock(&inode_lock);
543
                while (inode->i_state & I_DIRTY)
544
                        sync_one(inode, sync);
545
                spin_unlock(&inode_lock);
546
                if (sync)
547
                        wait_on_inode(inode);
548
        }
549
        else
550
                printk(KERN_ERR "write_inode_now: no super block\n");
551
}
552
 
553
/**
554
 * generic_osync_inode - flush all dirty data for a given inode to disk
555
 * @inode: inode to write
556
 * @datasync: if set, don't bother flushing timestamps
557
 *
558
 * This can be called by file_write functions for files which have the
559
 * O_SYNC flag set, to flush dirty writes to disk.
560
 */
561
 
562
int generic_osync_inode(struct inode *inode, int what)
563
{
564
        int err = 0, err2 = 0, need_write_inode_now = 0;
565
 
566
        /*
567
         * WARNING
568
         *
569
         * Currently, the filesystem write path does not pass the
570
         * filp down to the low-level write functions.  Therefore it
571
         * is impossible for (say) __block_commit_write to know if
572
         * the operation is O_SYNC or not.
573
         *
574
         * Ideally, O_SYNC writes would have the filesystem call
575
         * ll_rw_block as it went to kick-start the writes, and we
576
         * could call osync_inode_buffers() here to wait only for
577
         * those IOs which have already been submitted to the device
578
         * driver layer.  As it stands, if we did this we'd not write
579
         * anything to disk since our writes have not been queued by
580
         * this point: they are still on the dirty LRU.
581
         *
582
         * So, currently we will call fsync_inode_buffers() instead,
583
         * to flush _all_ dirty buffers for this inode to disk on
584
         * every O_SYNC write, not just the synchronous I/Os.  --sct
585
         */
586
 
587
        if (what & OSYNC_METADATA)
588
                err = fsync_inode_buffers(inode);
589
        if (what & OSYNC_DATA)
590
                err2 = fsync_inode_data_buffers(inode);
591
        if (!err)
592
                err = err2;
593
 
594
        spin_lock(&inode_lock);
595
        if ((inode->i_state & I_DIRTY) &&
596
            ((what & OSYNC_INODE) || (inode->i_state & I_DIRTY_DATASYNC)))
597
                need_write_inode_now = 1;
598
        spin_unlock(&inode_lock);
599
 
600
        if (need_write_inode_now)
601
                write_inode_now(inode, 1);
602
        else
603
                wait_on_inode(inode);
604
 
605
        return err;
606
}
607
 
608
/**
609
 * clear_inode - clear an inode
610
 * @inode: inode to clear
611
 *
612
 * This is called by the filesystem to tell us
613
 * that the inode is no longer useful. We just
614
 * terminate it with extreme prejudice.
615
 */
616
 
617
void clear_inode(struct inode *inode)
618
{
619
        invalidate_inode_buffers(inode);
620
 
621
        if (inode->i_data.nrpages)
622
                BUG();
623
        if (!(inode->i_state & I_FREEING))
624
                BUG();
625
        if (inode->i_state & I_CLEAR)
626
                BUG();
627
        wait_on_inode(inode);
628
        DQUOT_DROP(inode);
629
        if (inode->i_sb && inode->i_sb->s_op && inode->i_sb->s_op->clear_inode)
630
                inode->i_sb->s_op->clear_inode(inode);
631
        if (inode->i_bdev)
632
                bd_forget(inode);
633
        else if (inode->i_cdev) {
634
                cdput(inode->i_cdev);
635
                inode->i_cdev = NULL;
636
        }
637
        inode->i_state = I_CLEAR;
638
}
639
 
640
/*
641
 * Dispose-list gets a local list with local inodes in it, so it doesn't
642
 * need to worry about list corruption and SMP locks.
643
 */
644
static void dispose_list(struct list_head *head)
645
{
646
        int nr_disposed = 0;
647
 
648
        while (!list_empty(head)) {
649
                struct inode *inode;
650
 
651
                inode = list_entry(head->next, struct inode, i_list);
652
                list_del(&inode->i_list);
653
 
654
                if (inode->i_data.nrpages)
655
                        truncate_inode_pages(&inode->i_data, 0);
656
                clear_inode(inode);
657
                spin_lock(&inode_lock);
658
                list_del(&inode->i_hash);
659
                INIT_LIST_HEAD(&inode->i_hash);
660
                spin_unlock(&inode_lock);
661
                wake_up(&inode->i_wait);
662
                destroy_inode(inode);
663
                nr_disposed++;
664
        }
665
        spin_lock(&inode_lock);
666
        inodes_stat.nr_inodes -= nr_disposed;
667
        spin_unlock(&inode_lock);
668
}
669
 
670
/*
671
 * Invalidate all inodes for a device.
672
 */
673
static int invalidate_list(struct list_head *head, struct super_block * sb, struct list_head * dispose)
674
{
675
        struct list_head *next;
676
        int busy = 0, count = 0;
677
 
678
        next = head->next;
679
        for (;;) {
680
                struct list_head * tmp = next;
681
                struct inode * inode;
682
 
683
                next = next->next;
684
                if (tmp == head)
685
                        break;
686
                inode = list_entry(tmp, struct inode, i_list);
687
                if (inode->i_sb != sb)
688
                        continue;
689
                invalidate_inode_buffers(inode);
690
                if (!atomic_read(&inode->i_count)) {
691
                        list_del_init(&inode->i_hash);
692
                        list_del(&inode->i_list);
693
                        list_add(&inode->i_list, dispose);
694
                        inode->i_state |= I_FREEING;
695
                        count++;
696
                        continue;
697
                }
698
                busy = 1;
699
        }
700
        /* only unused inodes may be cached with i_count zero */
701
        inodes_stat.nr_unused -= count;
702
        return busy;
703
}
704
 
705
/*
706
 * This is a two-stage process. First we collect all
707
 * offending inodes onto the throw-away list, and in
708
 * the second stage we actually dispose of them. This
709
 * is because we don't want to sleep while messing
710
 * with the global lists..
711
 */
712
 
713
/**
714
 *      invalidate_inodes       - discard the inodes on a device
715
 *      @sb: superblock
716
 *
717
 *      Discard all of the inodes for a given superblock. If the discard
718
 *      fails because there are busy inodes then a non zero value is returned.
719
 *      If the discard is successful all the inodes have been discarded.
720
 */
721
 
722
int invalidate_inodes(struct super_block * sb)
723
{
724
        int busy;
725
        LIST_HEAD(throw_away);
726
 
727
        spin_lock(&inode_lock);
728
        busy = invalidate_list(&inode_in_use, sb, &throw_away);
729
        busy |= invalidate_list(&inode_unused, sb, &throw_away);
730
        busy |= invalidate_list(&inode_unused_pagecache, sb, &throw_away);
731
        busy |= invalidate_list(&sb->s_dirty, sb, &throw_away);
732
        busy |= invalidate_list(&sb->s_locked_inodes, sb, &throw_away);
733
        spin_unlock(&inode_lock);
734
 
735
        dispose_list(&throw_away);
736
 
737
        return busy;
738
}
739
 
740
int invalidate_device(kdev_t dev, int do_sync)
741
{
742
        struct super_block *sb;
743
        int res;
744
 
745
        if (do_sync)
746
                fsync_dev(dev);
747
 
748
        res = 0;
749
        sb = get_super(dev);
750
        if (sb) {
751
                /*
752
                 * no need to lock the super, get_super holds the
753
                 * read semaphore so the filesystem cannot go away
754
                 * under us (->put_super runs with the write lock
755
                 * hold).
756
                 */
757
                shrink_dcache_sb(sb);
758
                res = invalidate_inodes(sb);
759
                drop_super(sb);
760
        }
761
        invalidate_buffers(dev);
762
        return res;
763
}
764
 
765
 
766
/*
767
 * This is called with the inode lock held. It searches
768
 * the in-use for freeable inodes, which are moved to a
769
 * temporary list and then placed on the unused list by
770
 * dispose_list.
771
 *
772
 * We don't expect to have to call this very often.
773
 *
774
 * We leave the inode in the inode hash table until *after*
775
 * the filesystem's ->delete_inode (in dispose_list) completes.
776
 * This ensures that an iget (such as nfsd might instigate) will
777
 * always find up-to-date information either in the hash or on disk.
778
 *
779
 * I_FREEING is set so that no-one will take a new reference
780
 * to the inode while it is being deleted.
781
 *
782
 * N.B. The spinlock is released during the call to
783
 *      dispose_list.
784
 */
785
#define CAN_UNUSE(inode) \
786
        ((((inode)->i_state | (inode)->i_data.nrpages) == 0)  && \
787
         !inode_has_buffers(inode))
788
#define INODE(entry)    (list_entry(entry, struct inode, i_list))
789
 
790
void prune_icache(int goal)
791
{
792
        LIST_HEAD(list);
793
        struct list_head *entry, *freeable = &list;
794
        int count;
795
#ifdef CONFIG_HIGHMEM
796
        int avg_pages;
797
#endif
798
        struct inode * inode;
799
 
800
        spin_lock(&inode_lock);
801
 
802
        count = 0;
803
        entry = inode_unused.prev;
804
        while (entry != &inode_unused)
805
        {
806
                struct list_head *tmp = entry;
807
 
808
                entry = entry->prev;
809
                inode = INODE(tmp);
810
                if (inode->i_state & (I_FREEING|I_CLEAR|I_LOCK))
811
                        continue;
812
                if (!CAN_UNUSE(inode))
813
                        continue;
814
                if (atomic_read(&inode->i_count))
815
                        continue;
816
                list_del(tmp);
817
                list_add(tmp, freeable);
818
                inode->i_state |= I_FREEING;
819
                count++;
820
                if (--goal <= 0)
821
                        break;
822
        }
823
        inodes_stat.nr_unused -= count;
824
        spin_unlock(&inode_lock);
825
 
826
        dispose_list(freeable);
827
 
828
        /*
829
         * If we didn't freed enough clean inodes schedule
830
         * a sync of the dirty inodes, we cannot do it
831
         * from here or we're either synchronously dogslow
832
         * or we deadlock with oom.
833
         */
834
        if (goal > 0)
835
                schedule_task(&unused_inodes_flush_task);
836
 
837
#ifdef CONFIG_HIGHMEM
838
        /*
839
         * On highmem machines it is possible to have low memory
840
         * filled with inodes that cannot be reclaimed because they
841
         * have page cache pages in highmem attached to them.
842
         * This could deadlock the system if the memory used by
843
         * inodes is significant compared to the amount of freeable
844
         * low memory.  In that case we forcefully remove the page
845
         * cache pages from the inodes we want to reclaim.
846
         *
847
         * Note that this loop doesn't actually reclaim the inodes;
848
         * once the last pagecache pages belonging to the inode is
849
         * gone it will be placed on the inode_unused list and the
850
         * loop above will prune it the next time prune_icache() is
851
         * called.
852
         */
853
        if (goal <= 0)
854
                return;
855
        if (inodes_stat.nr_unused * sizeof(struct inode) * 10 <
856
                                freeable_lowmem() * PAGE_SIZE)
857
                return;
858
 
859
        wakeup_bdflush();
860
 
861
        avg_pages = page_cache_size;
862
        avg_pages -= atomic_read(&buffermem_pages) + swapper_space.nrpages;
863
        avg_pages = avg_pages / (inodes_stat.nr_inodes + 1);
864
        spin_lock(&inode_lock);
865
        while (goal-- > 0) {
866
                if (list_empty(&inode_unused_pagecache))
867
                        break;
868
                entry = inode_unused_pagecache.prev;
869
                list_del(entry);
870
                list_add(entry, &inode_unused_pagecache);
871
 
872
                inode = INODE(entry);
873
                /* Don't nuke inodes with lots of page cache attached. */
874
                if (inode->i_mapping->nrpages > 5 * avg_pages)
875
                        continue;
876
                /* Because of locking we grab the inode and unlock the list .*/
877
                if (inode->i_state & I_LOCK)
878
                        continue;
879
                inode->i_state |= I_LOCK;
880
                spin_unlock(&inode_lock);
881
 
882
                /*
883
                 * If the inode has clean pages only, we can free all its
884
                 * pagecache memory; the inode will automagically be refiled
885
                 * onto the unused_list.  The wakeup_bdflush above makes
886
                 * sure that all inodes become clean eventually.
887
                 */
888
                if (list_empty(&inode->i_mapping->dirty_pages) &&
889
                                !inode_has_buffers(inode))
890
                        invalidate_inode_pages(inode);
891
 
892
                /* Release the inode again. */
893
                spin_lock(&inode_lock);
894
                inode->i_state &= ~I_LOCK;
895
                wake_up(&inode->i_wait);
896
        }
897
        spin_unlock(&inode_lock);
898
#endif /* CONFIG_HIGHMEM */
899
}
900
 
901
int shrink_icache_memory(int priority, int gfp_mask)
902
{
903
        int count = 0;
904
 
905
        /*
906
         * Nasty deadlock avoidance..
907
         *
908
         * We may hold various FS locks, and we don't
909
         * want to recurse into the FS that called us
910
         * in clear_inode() and friends..
911
         */
912
        if (!(gfp_mask & __GFP_FS))
913
                return 0;
914
 
915
        count = inodes_stat.nr_unused / priority;
916
 
917
        prune_icache(count);
918
        return kmem_cache_shrink(inode_cachep);
919
}
920
 
921
/*
922
 * Called with the inode lock held.
923
 * NOTE: we are not increasing the inode-refcount, you must call __iget()
924
 * by hand after calling find_inode now! This simplifies iunique and won't
925
 * add any additional branch in the common code.
926
 */
927
static struct inode * find_inode(struct super_block * sb, unsigned long ino, struct list_head *head, find_inode_t find_actor, void *opaque)
928
{
929
        struct list_head *tmp;
930
        struct inode * inode;
931
 
932
repeat:
933
        tmp = head;
934
        for (;;) {
935
                tmp = tmp->next;
936
                inode = NULL;
937
                if (tmp == head)
938
                        break;
939
                inode = list_entry(tmp, struct inode, i_hash);
940
                if (inode->i_ino != ino)
941
                        continue;
942
                if (inode->i_sb != sb)
943
                        continue;
944
                if (find_actor && !find_actor(inode, ino, opaque))
945
                        continue;
946
                if (inode->i_state & (I_FREEING|I_CLEAR)) {
947
                        __wait_on_freeing_inode(inode);
948
                        goto repeat;
949
                }
950
                break;
951
        }
952
        return inode;
953
}
954
 
955
/**
956
 *      new_inode       - obtain an inode
957
 *      @sb: superblock
958
 *
959
 *      Allocates a new inode for given superblock.
960
 */
961
 
962
struct inode * new_inode(struct super_block *sb)
963
{
964
        static unsigned long last_ino;
965
        struct inode * inode;
966
 
967
        spin_lock_prefetch(&inode_lock);
968
 
969
        inode = alloc_inode(sb);
970
        if (inode) {
971
                spin_lock(&inode_lock);
972
                inodes_stat.nr_inodes++;
973
                list_add(&inode->i_list, &inode_in_use);
974
                inode->i_ino = ++last_ino;
975
                inode->i_state = 0;
976
                spin_unlock(&inode_lock);
977
        }
978
        return inode;
979
}
980
 
981
void unlock_new_inode(struct inode *inode)
982
{
983
        /*
984
         * This is special!  We do not need the spinlock
985
         * when clearing I_LOCK, because we're guaranteed
986
         * that nobody else tries to do anything about the
987
         * state of the inode when it is locked, as we
988
         * just created it (so there can be no old holders
989
         * that haven't tested I_LOCK).
990
         */
991
        inode->i_state &= ~(I_LOCK|I_NEW);
992
        wake_up(&inode->i_wait);
993
}
994
 
995
/*
996
 * This is called without the inode lock held.. Be careful.
997
 *
998
 * We no longer cache the sb_flags in i_flags - see fs.h
999
 *      -- rmk@arm.uk.linux.org
1000
 */
1001
static struct inode * get_new_inode(struct super_block *sb, unsigned long ino, struct list_head *head, find_inode_t find_actor, void *opaque)
1002
{
1003
        struct inode * inode;
1004
 
1005
        inode = alloc_inode(sb);
1006
        if (inode) {
1007
                struct inode * old;
1008
 
1009
                spin_lock(&inode_lock);
1010
                /* We released the lock, so.. */
1011
                old = find_inode(sb, ino, head, find_actor, opaque);
1012
                if (!old) {
1013
                        inodes_stat.nr_inodes++;
1014
                        list_add(&inode->i_list, &inode_in_use);
1015
                        list_add(&inode->i_hash, head);
1016
                        inode->i_ino = ino;
1017
                        inode->i_state = I_LOCK|I_NEW;
1018
                        spin_unlock(&inode_lock);
1019
 
1020
                        /*
1021
                         * Return the locked inode with I_NEW set, the
1022
                         * caller is responsible for filling in the contents
1023
                         */
1024
                        return inode;
1025
                }
1026
 
1027
                /*
1028
                 * Uhhuh, somebody else created the same inode under
1029
                 * us. Use the old inode instead of the one we just
1030
                 * allocated.
1031
                 */
1032
                __iget(old);
1033
                spin_unlock(&inode_lock);
1034
                destroy_inode(inode);
1035
                inode = old;
1036
                wait_on_inode(inode);
1037
        }
1038
        return inode;
1039
}
1040
 
1041
static inline unsigned long hash(struct super_block *sb, unsigned long i_ino)
1042
{
1043
        unsigned long tmp = i_ino + ((unsigned long) sb / L1_CACHE_BYTES);
1044
        tmp = tmp + (tmp >> I_HASHBITS);
1045
        return tmp & I_HASHMASK;
1046
}
1047
 
1048
/* Yeah, I know about quadratic hash. Maybe, later. */
1049
 
1050
/**
1051
 *      iunique - get a unique inode number
1052
 *      @sb: superblock
1053
 *      @max_reserved: highest reserved inode number
1054
 *
1055
 *      Obtain an inode number that is unique on the system for a given
1056
 *      superblock. This is used by file systems that have no natural
1057
 *      permanent inode numbering system. An inode number is returned that
1058
 *      is higher than the reserved limit but unique.
1059
 *
1060
 *      BUGS:
1061
 *      With a large number of inodes live on the file system this function
1062
 *      currently becomes quite slow.
1063
 */
1064
 
1065
ino_t iunique(struct super_block *sb, ino_t max_reserved)
1066
{
1067
        static ino_t counter = 0;
1068
        struct inode *inode;
1069
        struct list_head * head;
1070
        ino_t res;
1071
        spin_lock(&inode_lock);
1072
retry:
1073
        if (counter > max_reserved) {
1074
                head = inode_hashtable + hash(sb,counter);
1075
                inode = find_inode(sb, res = counter++, head, NULL, NULL);
1076
                if (!inode) {
1077
                        spin_unlock(&inode_lock);
1078
                        return res;
1079
                }
1080
        } else {
1081
                counter = max_reserved + 1;
1082
        }
1083
        goto retry;
1084
 
1085
}
1086
 
1087
/**
1088
 *      ilookup - search for an inode in the inode cache
1089
 *      @sb:         super block of file system to search
1090
 *      @ino:        inode number to search for
1091
 *
1092
 *      If the inode is in the cache, the inode is returned with an
1093
 *      incremented reference count.
1094
 *
1095
 *      Otherwise, %NULL is returned.
1096
 *
1097
 *      This is almost certainly not the function you are looking for.
1098
 *      If you think you need to use this, consult an expert first.
1099
 */
1100
struct inode *ilookup(struct super_block *sb, unsigned long ino)
1101
{
1102
        struct list_head * head = inode_hashtable + hash(sb,ino);
1103
        struct inode * inode;
1104
 
1105
        spin_lock(&inode_lock);
1106
        inode = find_inode(sb, ino, head, NULL, NULL);
1107
        if (inode) {
1108
                __iget(inode);
1109
                spin_unlock(&inode_lock);
1110
                wait_on_inode(inode);
1111
                return inode;
1112
        }
1113
        spin_unlock(&inode_lock);
1114
 
1115
        return inode;
1116
}
1117
 
1118
struct inode *igrab(struct inode *inode)
1119
{
1120
        spin_lock(&inode_lock);
1121
        if (!(inode->i_state & I_FREEING))
1122
                __iget(inode);
1123
        else
1124
                /*
1125
                 * Handle the case where s_op->clear_inode is not been
1126
                 * called yet, and somebody is calling igrab
1127
                 * while the inode is getting freed.
1128
                 */
1129
                inode = NULL;
1130
        spin_unlock(&inode_lock);
1131
        return inode;
1132
}
1133
 
1134
struct inode *iget4_locked(struct super_block *sb, unsigned long ino, find_inode_t find_actor, void *opaque)
1135
{
1136
        struct list_head * head = inode_hashtable + hash(sb,ino);
1137
        struct inode * inode;
1138
 
1139
        spin_lock(&inode_lock);
1140
        inode = find_inode(sb, ino, head, find_actor, opaque);
1141
        if (inode) {
1142
                __iget(inode);
1143
                spin_unlock(&inode_lock);
1144
                wait_on_inode(inode);
1145
                return inode;
1146
        }
1147
        spin_unlock(&inode_lock);
1148
 
1149
        /*
1150
         * get_new_inode() will do the right thing, re-trying the search
1151
         * in case it had to block at any point.
1152
         */
1153
        return get_new_inode(sb, ino, head, find_actor, opaque);
1154
}
1155
 
1156
/**
1157
 *      insert_inode_hash - hash an inode
1158
 *      @inode: unhashed inode
1159
 *
1160
 *      Add an inode to the inode hash for this superblock. If the inode
1161
 *      has no superblock it is added to a separate anonymous chain.
1162
 */
1163
 
1164
void insert_inode_hash(struct inode *inode)
1165
{
1166
        struct list_head *head = &anon_hash_chain;
1167
        if (inode->i_sb)
1168
                head = inode_hashtable + hash(inode->i_sb, inode->i_ino);
1169
        spin_lock(&inode_lock);
1170
        list_add(&inode->i_hash, head);
1171
        spin_unlock(&inode_lock);
1172
}
1173
 
1174
/**
1175
 *      remove_inode_hash - remove an inode from the hash
1176
 *      @inode: inode to unhash
1177
 *
1178
 *      Remove an inode from the superblock or anonymous hash.
1179
 */
1180
 
1181
void remove_inode_hash(struct inode *inode)
1182
{
1183
        spin_lock(&inode_lock);
1184
        list_del(&inode->i_hash);
1185
        INIT_LIST_HEAD(&inode->i_hash);
1186
        spin_unlock(&inode_lock);
1187
}
1188
 
1189
/**
1190
 *      iput    - put an inode
1191
 *      @inode: inode to put
1192
 *
1193
 *      Puts an inode, dropping its usage count. If the inode use count hits
1194
 *      zero the inode is also then freed and may be destroyed.
1195
 */
1196
 
1197
void iput(struct inode *inode)
1198
{
1199
        if (inode) {
1200
                struct super_block *sb = inode->i_sb;
1201
                struct super_operations *op = NULL;
1202
 
1203
                if (inode->i_state == I_CLEAR)
1204
                        BUG();
1205
 
1206
                if (sb && sb->s_op)
1207
                        op = sb->s_op;
1208
                if (op && op->put_inode)
1209
                        op->put_inode(inode);
1210
 
1211
                if (!atomic_dec_and_lock(&inode->i_count, &inode_lock))
1212
                        return;
1213
 
1214
                if (!inode->i_nlink) {
1215
                        list_del(&inode->i_list);
1216
                        INIT_LIST_HEAD(&inode->i_list);
1217
                        inode->i_state|=I_FREEING;
1218
                        inodes_stat.nr_inodes--;
1219
                        spin_unlock(&inode_lock);
1220
 
1221
                        if (inode->i_data.nrpages)
1222
                                truncate_inode_pages(&inode->i_data, 0);
1223
 
1224
                        if (op && op->delete_inode) {
1225
                                void (*delete)(struct inode *) = op->delete_inode;
1226
                                if (!is_bad_inode(inode))
1227
                                        DQUOT_INIT(inode);
1228
                                /* s_op->delete_inode internally recalls clear_inode() */
1229
                                delete(inode);
1230
                        } else
1231
                                clear_inode(inode);
1232
                        spin_lock(&inode_lock);
1233
                        list_del(&inode->i_hash);
1234
                        INIT_LIST_HEAD(&inode->i_hash);
1235
                        spin_unlock(&inode_lock);
1236
                        wake_up(&inode->i_wait);
1237
                        if (inode->i_state != I_CLEAR)
1238
                                BUG();
1239
                } else {
1240
                        if (!list_empty(&inode->i_hash)) {
1241
                                if (!(inode->i_state & (I_DIRTY|I_LOCK)))
1242
                                        __refile_inode(inode);
1243
                                inodes_stat.nr_unused++;
1244
                                spin_unlock(&inode_lock);
1245
                                if (!sb || (sb->s_flags & MS_ACTIVE))
1246
                                        return;
1247
                                write_inode_now(inode, 1);
1248
                                spin_lock(&inode_lock);
1249
                                inodes_stat.nr_unused--;
1250
                                list_del_init(&inode->i_hash);
1251
                        }
1252
                        list_del_init(&inode->i_list);
1253
                        inode->i_state|=I_FREEING;
1254
                        inodes_stat.nr_inodes--;
1255
                        spin_unlock(&inode_lock);
1256
                        if (inode->i_data.nrpages)
1257
                                truncate_inode_pages(&inode->i_data, 0);
1258
                        clear_inode(inode);
1259
                }
1260
                destroy_inode(inode);
1261
        }
1262
}
1263
 
1264
void force_delete(struct inode *inode)
1265
{
1266
        /*
1267
         * Kill off unused inodes ... iput() will unhash and
1268
         * delete the inode if we set i_nlink to zero.
1269
         */
1270
        if (atomic_read(&inode->i_count) == 1)
1271
                inode->i_nlink = 0;
1272
}
1273
 
1274
/**
1275
 *      bmap    - find a block number in a file
1276
 *      @inode: inode of file
1277
 *      @block: block to find
1278
 *
1279
 *      Returns the block number on the device holding the inode that
1280
 *      is the disk block number for the block of the file requested.
1281
 *      That is, asked for block 4 of inode 1 the function will return the
1282
 *      disk block relative to the disk start that holds that block of the
1283
 *      file.
1284
 */
1285
 
1286
int bmap(struct inode * inode, int block)
1287
{
1288
        int res = 0;
1289
        if (inode->i_mapping->a_ops->bmap)
1290
                res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block);
1291
        return res;
1292
}
1293
 
1294
/*
1295
 * Initialize the hash tables.
1296
 */
1297
void __init inode_init(unsigned long mempages)
1298
{
1299
        struct list_head *head;
1300
        unsigned long order;
1301
        unsigned int nr_hash;
1302
        int i;
1303
 
1304
        mempages >>= (14 - PAGE_SHIFT);
1305
        mempages *= sizeof(struct list_head);
1306
        for (order = 0; ((1UL << order) << PAGE_SHIFT) < mempages; order++)
1307
                ;
1308
 
1309
        do {
1310
                unsigned long tmp;
1311
 
1312
                nr_hash = (1UL << order) * PAGE_SIZE /
1313
                        sizeof(struct list_head);
1314
                i_hash_mask = (nr_hash - 1);
1315
 
1316
                tmp = nr_hash;
1317
                i_hash_shift = 0;
1318
                while ((tmp >>= 1UL) != 0UL)
1319
                        i_hash_shift++;
1320
 
1321
                inode_hashtable = (struct list_head *)
1322
                        __get_free_pages(GFP_ATOMIC, order);
1323
        } while (inode_hashtable == NULL && --order >= 0);
1324
 
1325
        printk(KERN_INFO "Inode cache hash table entries: %d (order: %ld, %ld bytes)\n",
1326
                        nr_hash, order, (PAGE_SIZE << order));
1327
 
1328
        if (!inode_hashtable)
1329
                panic("Failed to allocate inode hash table\n");
1330
 
1331
        head = inode_hashtable;
1332
        i = nr_hash;
1333
        do {
1334
                INIT_LIST_HEAD(head);
1335
                head++;
1336
                i--;
1337
        } while (i);
1338
 
1339
        /* inode slab cache */
1340
        inode_cachep = kmem_cache_create("inode_cache", sizeof(struct inode),
1341
                                         0, SLAB_HWCACHE_ALIGN, init_once,
1342
                                         NULL);
1343
        if (!inode_cachep)
1344
                panic("cannot create inode slab cache");
1345
 
1346
        unused_inodes_flush_task.routine = try_to_sync_unused_inodes;
1347
}
1348
 
1349
/**
1350
 *      update_atime    -       update the access time
1351
 *      @inode: inode accessed
1352
 *
1353
 *      Update the accessed time on an inode and mark it for writeback.
1354
 *      This function automatically handles read only file systems and media,
1355
 *      as well as the "noatime" flag and inode specific "noatime" markers.
1356
 */
1357
 
1358
void update_atime (struct inode *inode)
1359
{
1360
        if (inode->i_atime == CURRENT_TIME)
1361
                return;
1362
        if (IS_NOATIME(inode))
1363
                return;
1364
        if (IS_NODIRATIME(inode) && S_ISDIR(inode->i_mode))
1365
                return;
1366
        if (IS_RDONLY(inode))
1367
                return;
1368
        inode->i_atime = CURRENT_TIME;
1369
        mark_inode_dirty_sync (inode);
1370
}
1371
 
1372
/**
1373
 *      update_mctime   -       update the mtime and ctime
1374
 *      @inode: inode accessed
1375
 *
1376
 *      Update the modified and changed times on an inode for writes to special
1377
 *      files such as fifos.  No change is forced if the timestamps are already
1378
 *      up-to-date or if the filesystem is readonly.
1379
 */
1380
 
1381
void update_mctime (struct inode *inode)
1382
{
1383
        if (inode->i_mtime == CURRENT_TIME && inode->i_ctime == CURRENT_TIME)
1384
                return;
1385
        if (IS_RDONLY(inode))
1386
                return;
1387
        inode->i_ctime = inode->i_mtime = CURRENT_TIME;
1388
        mark_inode_dirty (inode);
1389
}
1390
 
1391
 
1392
/*
1393
 *      Quota functions that want to walk the inode lists..
1394
 */
1395
#ifdef CONFIG_QUOTA
1396
 
1397
/* Functions back in dquot.c */
1398
void put_dquot_list(struct list_head *);
1399
int remove_inode_dquot_ref(struct inode *, short, struct list_head *);
1400
 
1401
void remove_dquot_ref(struct super_block *sb, short type)
1402
{
1403
        struct inode *inode;
1404
        struct list_head *act_head;
1405
        LIST_HEAD(tofree_head);
1406
 
1407
        if (!sb->dq_op)
1408
                return; /* nothing to do */
1409
        /* We have to be protected against other CPUs */
1410
        lock_kernel();          /* This lock is for quota code */
1411
        spin_lock(&inode_lock); /* This lock is for inodes code */
1412
 
1413
        list_for_each(act_head, &inode_in_use) {
1414
                inode = list_entry(act_head, struct inode, i_list);
1415
                if (inode->i_sb == sb && IS_QUOTAINIT(inode))
1416
                        remove_inode_dquot_ref(inode, type, &tofree_head);
1417
        }
1418
        list_for_each(act_head, &inode_unused) {
1419
                inode = list_entry(act_head, struct inode, i_list);
1420
                if (inode->i_sb == sb && IS_QUOTAINIT(inode))
1421
                        remove_inode_dquot_ref(inode, type, &tofree_head);
1422
        }
1423
        list_for_each(act_head, &inode_unused_pagecache) {
1424
                inode = list_entry(act_head, struct inode, i_list);
1425
                if (inode->i_sb == sb && IS_QUOTAINIT(inode))
1426
                        remove_inode_dquot_ref(inode, type, &tofree_head);
1427
        }
1428
        list_for_each(act_head, &sb->s_dirty) {
1429
                inode = list_entry(act_head, struct inode, i_list);
1430
                if (IS_QUOTAINIT(inode))
1431
                        remove_inode_dquot_ref(inode, type, &tofree_head);
1432
        }
1433
        list_for_each(act_head, &sb->s_locked_inodes) {
1434
                inode = list_entry(act_head, struct inode, i_list);
1435
                if (IS_QUOTAINIT(inode))
1436
                        remove_inode_dquot_ref(inode, type, &tofree_head);
1437
        }
1438
        spin_unlock(&inode_lock);
1439
        unlock_kernel();
1440
 
1441
        put_dquot_list(&tofree_head);
1442
}
1443
 
1444
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.