~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/dcache.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <linux/hardirq.h>
36
36
#include <linux/bit_spinlock.h>
37
37
#include <linux/rculist_bl.h>
 
38
#include <linux/prefetch.h>
38
39
#include "internal.h"
39
40
 
40
41
/*
99
100
static unsigned int d_hash_mask __read_mostly;
100
101
static unsigned int d_hash_shift __read_mostly;
101
102
 
102
 
struct dcache_hash_bucket {
103
 
        struct hlist_bl_head head;
104
 
};
105
 
static struct dcache_hash_bucket *dentry_hashtable __read_mostly;
 
103
static struct hlist_bl_head *dentry_hashtable __read_mostly;
106
104
 
107
 
static inline struct dcache_hash_bucket *d_hash(struct dentry *parent,
 
105
static inline struct hlist_bl_head *d_hash(struct dentry *parent,
108
106
                                        unsigned long hash)
109
107
{
110
108
        hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
112
110
        return dentry_hashtable + (hash & D_HASHMASK);
113
111
}
114
112
 
115
 
static inline void spin_lock_bucket(struct dcache_hash_bucket *b)
116
 
{
117
 
        bit_spin_lock(0, (unsigned long *)&b->head.first);
118
 
}
119
 
 
120
 
static inline void spin_unlock_bucket(struct dcache_hash_bucket *b)
121
 
{
122
 
        __bit_spin_unlock(0, (unsigned long *)&b->head.first);
123
 
}
124
 
 
125
113
/* Statistics gathering. */
126
114
struct dentry_stat_t dentry_stat = {
127
115
        .age_limit = 45,
167
155
        if (dentry->d_op && dentry->d_op->d_release)
168
156
                dentry->d_op->d_release(dentry);
169
157
 
170
 
        /* if dentry was never inserted into hash, immediate free is OK */
171
 
        if (hlist_bl_unhashed(&dentry->d_hash))
 
158
        /* if dentry was never visible to RCU, immediate free is OK */
 
159
        if (!(dentry->d_flags & DCACHE_RCUACCESS))
172
160
                __d_free(&dentry->d_u.d_rcu);
173
161
        else
174
162
                call_rcu(&dentry->d_u.d_rcu, __d_free);
330
318
 */
331
319
void __d_drop(struct dentry *dentry)
332
320
{
333
 
        if (!(dentry->d_flags & DCACHE_UNHASHED)) {
334
 
                if (unlikely(dentry->d_flags & DCACHE_DISCONNECTED)) {
335
 
                        bit_spin_lock(0,
336
 
                                (unsigned long *)&dentry->d_sb->s_anon.first);
337
 
                        dentry->d_flags |= DCACHE_UNHASHED;
338
 
                        hlist_bl_del_init(&dentry->d_hash);
339
 
                        __bit_spin_unlock(0,
340
 
                                (unsigned long *)&dentry->d_sb->s_anon.first);
341
 
                } else {
342
 
                        struct dcache_hash_bucket *b;
 
321
        if (!d_unhashed(dentry)) {
 
322
                struct hlist_bl_head *b;
 
323
                if (unlikely(dentry->d_flags & DCACHE_DISCONNECTED))
 
324
                        b = &dentry->d_sb->s_anon;
 
325
                else
343
326
                        b = d_hash(dentry->d_parent, dentry->d_name.hash);
344
 
                        spin_lock_bucket(b);
345
 
                        /*
346
 
                         * We may not actually need to put DCACHE_UNHASHED
347
 
                         * manipulations under the hash lock, but follow
348
 
                         * the principle of least surprise.
349
 
                         */
350
 
                        dentry->d_flags |= DCACHE_UNHASHED;
351
 
                        hlist_bl_del_rcu(&dentry->d_hash);
352
 
                        spin_unlock_bucket(b);
353
 
                        dentry_rcuwalk_barrier(dentry);
354
 
                }
 
327
 
 
328
                hlist_bl_lock(b);
 
329
                __hlist_bl_del(&dentry->d_hash);
 
330
                dentry->d_hash.pprev = NULL;
 
331
                hlist_bl_unlock(b);
 
332
 
 
333
                dentry_rcuwalk_barrier(dentry);
355
334
        }
356
335
}
357
336
EXPORT_SYMBOL(__d_drop);
1241
1220
EXPORT_SYMBOL(shrink_dcache_parent);
1242
1221
 
1243
1222
/*
1244
 
 * Scan `nr' dentries and return the number which remain.
 
1223
 * Scan `sc->nr_slab_to_reclaim' dentries and return the number which remain.
1245
1224
 *
1246
1225
 * We need to avoid reentering the filesystem if the caller is performing a
1247
1226
 * GFP_NOFS allocation attempt.  One example deadlock is:
1252
1231
 *
1253
1232
 * In this case we return -1 to tell the caller that we baled.
1254
1233
 */
1255
 
static int shrink_dcache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask)
 
1234
static int shrink_dcache_memory(struct shrinker *shrink,
 
1235
                                struct shrink_control *sc)
1256
1236
{
 
1237
        int nr = sc->nr_to_scan;
 
1238
        gfp_t gfp_mask = sc->gfp_mask;
 
1239
 
1257
1240
        if (nr) {
1258
1241
                if (!(gfp_mask & __GFP_FS))
1259
1242
                        return -1;
1304
1287
        dname[name->len] = 0;
1305
1288
 
1306
1289
        dentry->d_count = 1;
1307
 
        dentry->d_flags = DCACHE_UNHASHED;
 
1290
        dentry->d_flags = 0;
1308
1291
        spin_lock_init(&dentry->d_lock);
1309
1292
        seqcount_init(&dentry->d_seq);
1310
1293
        dentry->d_inode = NULL;
1606
1589
        tmp->d_inode = inode;
1607
1590
        tmp->d_flags |= DCACHE_DISCONNECTED;
1608
1591
        list_add(&tmp->d_alias, &inode->i_dentry);
1609
 
        bit_spin_lock(0, (unsigned long *)&tmp->d_sb->s_anon.first);
1610
 
        tmp->d_flags &= ~DCACHE_UNHASHED;
 
1592
        hlist_bl_lock(&tmp->d_sb->s_anon);
1611
1593
        hlist_bl_add_head(&tmp->d_hash, &tmp->d_sb->s_anon);
1612
 
        __bit_spin_unlock(0, (unsigned long *)&tmp->d_sb->s_anon.first);
 
1594
        hlist_bl_unlock(&tmp->d_sb->s_anon);
1613
1595
        spin_unlock(&tmp->d_lock);
1614
1596
        spin_unlock(&inode->i_lock);
1615
1597
        security_d_instantiate(tmp, inode);
1789
1771
        unsigned int len = name->len;
1790
1772
        unsigned int hash = name->hash;
1791
1773
        const unsigned char *str = name->name;
1792
 
        struct dcache_hash_bucket *b = d_hash(parent, hash);
 
1774
        struct hlist_bl_head *b = d_hash(parent, hash);
1793
1775
        struct hlist_bl_node *node;
1794
1776
        struct dentry *dentry;
1795
1777
 
1811
1793
         * false-negative result. d_lookup() protects against concurrent
1812
1794
         * renames using rename_lock seqlock.
1813
1795
         *
1814
 
         * See Documentation/vfs/dcache-locking.txt for more details.
 
1796
         * See Documentation/filesystems/path-lookup.txt for more details.
1815
1797
         */
1816
 
        hlist_bl_for_each_entry_rcu(dentry, node, &b->head, d_hash) {
 
1798
        hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) {
1817
1799
                struct inode *i;
1818
1800
                const char *tname;
1819
1801
                int tlen;
1908
1890
        unsigned int len = name->len;
1909
1891
        unsigned int hash = name->hash;
1910
1892
        const unsigned char *str = name->name;
1911
 
        struct dcache_hash_bucket *b = d_hash(parent, hash);
 
1893
        struct hlist_bl_head *b = d_hash(parent, hash);
1912
1894
        struct hlist_bl_node *node;
1913
1895
        struct dentry *found = NULL;
1914
1896
        struct dentry *dentry;
1931
1913
         * false-negative result. d_lookup() protects against concurrent
1932
1914
         * renames using rename_lock seqlock.
1933
1915
         *
1934
 
         * See Documentation/vfs/dcache-locking.txt for more details.
 
1916
         * See Documentation/filesystems/path-lookup.txt for more details.
1935
1917
         */
1936
1918
        rcu_read_lock();
1937
1919
        
1938
 
        hlist_bl_for_each_entry_rcu(dentry, node, &b->head, d_hash) {
 
1920
        hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) {
1939
1921
                const char *tname;
1940
1922
                int tlen;
1941
1923
 
2086
2068
}
2087
2069
EXPORT_SYMBOL(d_delete);
2088
2070
 
2089
 
static void __d_rehash(struct dentry * entry, struct dcache_hash_bucket *b)
 
2071
static void __d_rehash(struct dentry * entry, struct hlist_bl_head *b)
2090
2072
{
2091
2073
        BUG_ON(!d_unhashed(entry));
2092
 
        spin_lock_bucket(b);
2093
 
        entry->d_flags &= ~DCACHE_UNHASHED;
2094
 
        hlist_bl_add_head_rcu(&entry->d_hash, &b->head);
2095
 
        spin_unlock_bucket(b);
 
2074
        hlist_bl_lock(b);
 
2075
        entry->d_flags |= DCACHE_RCUACCESS;
 
2076
        hlist_bl_add_head_rcu(&entry->d_hash, b);
 
2077
        hlist_bl_unlock(b);
2096
2078
}
2097
2079
 
2098
2080
static void _d_rehash(struct dentry * entry)
2131
2113
 */
2132
2114
void dentry_update_name_case(struct dentry *dentry, struct qstr *name)
2133
2115
{
2134
 
        BUG_ON(!mutex_is_locked(&dentry->d_inode->i_mutex));
 
2116
        BUG_ON(!mutex_is_locked(&dentry->d_parent->d_inode->i_mutex));
2135
2117
        BUG_ON(dentry->d_name.len != name->len); /* d_lookup gives this */
2136
2118
 
2137
2119
        spin_lock(&dentry->d_lock);
2231
2213
 * The hash value has to match the hash queue that the dentry is on..
2232
2214
 */
2233
2215
/*
2234
 
 * d_move - move a dentry
 
2216
 * __d_move - move a dentry
2235
2217
 * @dentry: entry to move
2236
2218
 * @target: new dentry
2237
2219
 *
2238
2220
 * Update the dcache to reflect the move of a file name. Negative
2239
 
 * dcache entries should not be moved in this way.
 
2221
 * dcache entries should not be moved in this way.  Caller hold
 
2222
 * rename_lock.
2240
2223
 */
2241
 
void d_move(struct dentry * dentry, struct dentry * target)
 
2224
static void __d_move(struct dentry * dentry, struct dentry * target)
2242
2225
{
2243
2226
        if (!dentry->d_inode)
2244
2227
                printk(KERN_WARNING "VFS: moving negative dcache entry\n");
2246
2229
        BUG_ON(d_ancestor(dentry, target));
2247
2230
        BUG_ON(d_ancestor(target, dentry));
2248
2231
 
2249
 
        write_seqlock(&rename_lock);
2250
 
 
2251
2232
        dentry_lock_for_move(dentry, target);
2252
2233
 
2253
2234
        write_seqcount_begin(&dentry->d_seq);
2293
2274
        spin_unlock(&target->d_lock);
2294
2275
        fsnotify_d_move(dentry);
2295
2276
        spin_unlock(&dentry->d_lock);
 
2277
}
 
2278
 
 
2279
/*
 
2280
 * d_move - move a dentry
 
2281
 * @dentry: entry to move
 
2282
 * @target: new dentry
 
2283
 *
 
2284
 * Update the dcache to reflect the move of a file name. Negative
 
2285
 * dcache entries should not be moved in this way.
 
2286
 */
 
2287
void d_move(struct dentry *dentry, struct dentry *target)
 
2288
{
 
2289
        write_seqlock(&rename_lock);
 
2290
        __d_move(dentry, target);
2296
2291
        write_sequnlock(&rename_lock);
2297
2292
}
2298
2293
EXPORT_SYMBOL(d_move);
2320
2315
 * This helper attempts to cope with remotely renamed directories
2321
2316
 *
2322
2317
 * It assumes that the caller is already holding
2323
 
 * dentry->d_parent->d_inode->i_mutex and the inode->i_lock
 
2318
 * dentry->d_parent->d_inode->i_mutex, inode->i_lock and rename_lock
2324
2319
 *
2325
2320
 * Note: If ever the locking in lock_rename() changes, then please
2326
2321
 * remember to update this too...
2335
2330
        if (alias->d_parent == dentry->d_parent)
2336
2331
                goto out_unalias;
2337
2332
 
2338
 
        /* Check for loops */
2339
 
        ret = ERR_PTR(-ELOOP);
2340
 
        if (d_ancestor(alias, dentry))
2341
 
                goto out_err;
2342
 
 
2343
2333
        /* See lock_rename() */
2344
2334
        ret = ERR_PTR(-EBUSY);
2345
2335
        if (!mutex_trylock(&dentry->d_sb->s_vfs_rename_mutex))
2349
2339
                goto out_err;
2350
2340
        m2 = &alias->d_parent->d_inode->i_mutex;
2351
2341
out_unalias:
2352
 
        d_move(alias, dentry);
 
2342
        __d_move(alias, dentry);
2353
2343
        ret = alias;
2354
2344
out_err:
2355
2345
        spin_unlock(&inode->i_lock);
2434
2424
                alias = __d_find_alias(inode, 0);
2435
2425
                if (alias) {
2436
2426
                        actual = alias;
2437
 
                        /* Is this an anonymous mountpoint that we could splice
2438
 
                         * into our tree? */
2439
 
                        if (IS_ROOT(alias)) {
 
2427
                        write_seqlock(&rename_lock);
 
2428
 
 
2429
                        if (d_ancestor(alias, dentry)) {
 
2430
                                /* Check for loops */
 
2431
                                actual = ERR_PTR(-ELOOP);
 
2432
                        } else if (IS_ROOT(alias)) {
 
2433
                                /* Is this an anonymous mountpoint that we
 
2434
                                 * could splice into our tree? */
2440
2435
                                __d_materialise_dentry(dentry, alias);
 
2436
                                write_sequnlock(&rename_lock);
2441
2437
                                __d_drop(alias);
2442
2438
                                goto found;
 
2439
                        } else {
 
2440
                                /* Nope, but we must(!) avoid directory
 
2441
                                 * aliasing */
 
2442
                                actual = __d_unalias(inode, dentry, alias);
2443
2443
                        }
2444
 
                        /* Nope, but we must(!) avoid directory aliasing */
2445
 
                        actual = __d_unalias(inode, dentry, alias);
 
2444
                        write_sequnlock(&rename_lock);
2446
2445
                        if (IS_ERR(actual))
2447
2446
                                dput(alias);
2448
2447
                        goto out_nolock;
3025
3024
 
3026
3025
        dentry_hashtable =
3027
3026
                alloc_large_system_hash("Dentry cache",
3028
 
                                        sizeof(struct dcache_hash_bucket),
 
3027
                                        sizeof(struct hlist_bl_head),
3029
3028
                                        dhash_entries,
3030
3029
                                        13,
3031
3030
                                        HASH_EARLY,
3034
3033
                                        0);
3035
3034
 
3036
3035
        for (loop = 0; loop < (1 << d_hash_shift); loop++)
3037
 
                INIT_HLIST_BL_HEAD(&dentry_hashtable[loop].head);
 
3036
                INIT_HLIST_BL_HEAD(dentry_hashtable + loop);
3038
3037
}
3039
3038
 
3040
3039
static void __init dcache_init(void)
3057
3056
 
3058
3057
        dentry_hashtable =
3059
3058
                alloc_large_system_hash("Dentry cache",
3060
 
                                        sizeof(struct dcache_hash_bucket),
 
3059
                                        sizeof(struct hlist_bl_head),
3061
3060
                                        dhash_entries,
3062
3061
                                        13,
3063
3062
                                        0,
3066
3065
                                        0);
3067
3066
 
3068
3067
        for (loop = 0; loop < (1 << d_hash_shift); loop++)
3069
 
                INIT_HLIST_BL_HEAD(&dentry_hashtable[loop].head);
 
3068
                INIT_HLIST_BL_HEAD(dentry_hashtable + loop);
3070
3069
}
3071
3070
 
3072
3071
/* SLAB cache for __getname() consumers */