| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
#include <linux/config.h> |
|---|
| 18 |
#include <linux/string.h> |
|---|
| 19 |
#include <linux/mm.h> |
|---|
| 20 |
#include <linux/fs.h> |
|---|
| 21 |
#include <linux/slab.h> |
|---|
| 22 |
#include <linux/init.h> |
|---|
| 23 |
#include <linux/smp_lock.h> |
|---|
| 24 |
#include <linux/hash.h> |
|---|
| 25 |
#include <linux/cache.h> |
|---|
| 26 |
#include <linux/module.h> |
|---|
| 27 |
#include <linux/mount.h> |
|---|
| 28 |
#include <linux/file.h> |
|---|
| 29 |
#include <asm/uaccess.h> |
|---|
| 30 |
#include <linux/security.h> |
|---|
| 31 |
#include <linux/seqlock.h> |
|---|
| 32 |
#include <linux/swap.h> |
|---|
| 33 |
|
|---|
| 34 |
#define DCACHE_PARANOIA 1 |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
spinlock_t dcache_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED; |
|---|
| 38 |
seqlock_t rename_lock __cacheline_aligned_in_smp = SEQLOCK_UNLOCKED; |
|---|
| 39 |
|
|---|
| 40 |
EXPORT_SYMBOL(dcache_lock); |
|---|
| 41 |
|
|---|
| 42 |
static kmem_cache_t *dentry_cache; |
|---|
| 43 |
|
|---|
| 44 |
#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname)) |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
#define D_HASHBITS d_hash_shift |
|---|
| 55 |
#define D_HASHMASK d_hash_mask |
|---|
| 56 |
|
|---|
| 57 |
static unsigned int d_hash_mask; |
|---|
| 58 |
static unsigned int d_hash_shift; |
|---|
| 59 |
static struct hlist_head *dentry_hashtable; |
|---|
| 60 |
static LIST_HEAD(dentry_unused); |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
struct dentry_stat_t dentry_stat = { |
|---|
| 64 |
.age_limit = 45, |
|---|
| 65 |
}; |
|---|
| 66 |
|
|---|
| 67 |
static void d_callback(void *arg) |
|---|
| 68 |
{ |
|---|
| 69 |
struct dentry * dentry = (struct dentry *)arg; |
|---|
| 70 |
|
|---|
| 71 |
if (dname_external(dentry)) |
|---|
| 72 |
kfree(dentry->d_name.name); |
|---|
| 73 |
kmem_cache_free(dentry_cache, dentry); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
static void d_free(struct dentry *dentry) |
|---|
| 81 |
{ |
|---|
| 82 |
if (dentry->d_op && dentry->d_op->d_release) |
|---|
| 83 |
dentry->d_op->d_release(dentry); |
|---|
| 84 |
call_rcu(&dentry->d_rcu, d_callback, dentry); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
static inline void dentry_iput(struct dentry * dentry) |
|---|
| 93 |
{ |
|---|
| 94 |
struct inode *inode = dentry->d_inode; |
|---|
| 95 |
if (inode) { |
|---|
| 96 |
dentry->d_inode = NULL; |
|---|
| 97 |
list_del_init(&dentry->d_alias); |
|---|
| 98 |
spin_unlock(&dentry->d_lock); |
|---|
| 99 |
spin_unlock(&dcache_lock); |
|---|
| 100 |
if (dentry->d_op && dentry->d_op->d_iput) |
|---|
| 101 |
dentry->d_op->d_iput(dentry, inode); |
|---|
| 102 |
else |
|---|
| 103 |
iput(inode); |
|---|
| 104 |
} else { |
|---|
| 105 |
spin_unlock(&dentry->d_lock); |
|---|
| 106 |
spin_unlock(&dcache_lock); |
|---|
| 107 |
} |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
void dput(struct dentry *dentry) |
|---|
| 140 |
{ |
|---|
| 141 |
if (!dentry) |
|---|
| 142 |
return; |
|---|
| 143 |
|
|---|
| 144 |
repeat: |
|---|
| 145 |
if (!atomic_dec_and_lock(&dentry->d_count, &dcache_lock)) |
|---|
| 146 |
return; |
|---|
| 147 |
|
|---|
| 148 |
spin_lock(&dentry->d_lock); |
|---|
| 149 |
if (atomic_read(&dentry->d_count)) { |
|---|
| 150 |
spin_unlock(&dentry->d_lock); |
|---|
| 151 |
spin_unlock(&dcache_lock); |
|---|
| 152 |
return; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
if (dentry->d_op && dentry->d_op->d_delete) { |
|---|
| 159 |
if (dentry->d_op->d_delete(dentry)) |
|---|
| 160 |
goto unhash_it; |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
if (d_unhashed(dentry)) |
|---|
| 164 |
goto kill_it; |
|---|
| 165 |
if (list_empty(&dentry->d_lru)) { |
|---|
| 166 |
dentry->d_flags |= DCACHE_REFERENCED; |
|---|
| 167 |
list_add(&dentry->d_lru, &dentry_unused); |
|---|
| 168 |
dentry_stat.nr_unused++; |
|---|
| 169 |
} |
|---|
| 170 |
spin_unlock(&dentry->d_lock); |
|---|
| 171 |
spin_unlock(&dcache_lock); |
|---|
| 172 |
return; |
|---|
| 173 |
|
|---|
| 174 |
unhash_it: |
|---|
| 175 |
__d_drop(dentry); |
|---|
| 176 |
|
|---|
| 177 |
kill_it: { |
|---|
| 178 |
struct dentry *parent; |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
if (!list_empty(&dentry->d_lru)) { |
|---|
| 184 |
list_del(&dentry->d_lru); |
|---|
| 185 |
dentry_stat.nr_unused--; |
|---|
| 186 |
} |
|---|
| 187 |
list_del(&dentry->d_child); |
|---|
| 188 |
dentry_stat.nr_dentry--; |
|---|
| 189 |
|
|---|
| 190 |
dentry_iput(dentry); |
|---|
| 191 |
parent = dentry->d_parent; |
|---|
| 192 |
d_free(dentry); |
|---|
| 193 |
if (dentry == parent) |
|---|
| 194 |
return; |
|---|
| 195 |
dentry = parent; |
|---|
| 196 |
goto repeat; |
|---|
| 197 |
} |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
int d_invalidate(struct dentry * dentry) |
|---|
| 213 |
{ |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
spin_lock(&dcache_lock); |
|---|
| 218 |
if (d_unhashed(dentry)) { |
|---|
| 219 |
spin_unlock(&dcache_lock); |
|---|
| 220 |
return 0; |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
if (!list_empty(&dentry->d_subdirs)) { |
|---|
| 227 |
spin_unlock(&dcache_lock); |
|---|
| 228 |
shrink_dcache_parent(dentry); |
|---|
| 229 |
spin_lock(&dcache_lock); |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
spin_lock(&dentry->d_lock); |
|---|
| 243 |
if (atomic_read(&dentry->d_count) > 1) { |
|---|
| 244 |
if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) { |
|---|
| 245 |
spin_unlock(&dentry->d_lock); |
|---|
| 246 |
spin_unlock(&dcache_lock); |
|---|
| 247 |
return -EBUSY; |
|---|
| 248 |
} |
|---|
| 249 |
} |
|---|
| 250 |
|
|---|
| 251 |
__d_drop(dentry); |
|---|
| 252 |
spin_unlock(&dentry->d_lock); |
|---|
| 253 |
spin_unlock(&dcache_lock); |
|---|
| 254 |
return 0; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
static inline struct dentry * __dget_locked(struct dentry *dentry) |
|---|
| 260 |
{ |
|---|
| 261 |
atomic_inc(&dentry->d_count); |
|---|
| 262 |
if (!list_empty(&dentry->d_lru)) { |
|---|
| 263 |
dentry_stat.nr_unused--; |
|---|
| 264 |
list_del_init(&dentry->d_lru); |
|---|
| 265 |
} |
|---|
| 266 |
return dentry; |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
struct dentry * dget_locked(struct dentry *dentry) |
|---|
| 270 |
{ |
|---|
| 271 |
return __dget_locked(dentry); |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
struct dentry * d_find_alias(struct inode *inode) |
|---|
| 288 |
{ |
|---|
| 289 |
struct list_head *head, *next, *tmp; |
|---|
| 290 |
struct dentry *alias, *discon_alias=NULL; |
|---|
| 291 |
|
|---|
| 292 |
spin_lock(&dcache_lock); |
|---|
| 293 |
head = &inode->i_dentry; |
|---|
| 294 |
next = inode->i_dentry.next; |
|---|
| 295 |
while (next != head) { |
|---|
| 296 |
tmp = next; |
|---|
| 297 |
next = tmp->next; |
|---|
| 298 |
prefetch(next); |
|---|
| 299 |
alias = list_entry(tmp, struct dentry, d_alias); |
|---|
| 300 |
if (!d_unhashed(alias)) { |
|---|
| 301 |
if (alias->d_flags & DCACHE_DISCONNECTED) |
|---|
| 302 |
discon_alias = alias; |
|---|
| 303 |
else { |
|---|
| 304 |
__dget_locked(alias); |
|---|
| 305 |
spin_unlock(&dcache_lock); |
|---|
| 306 |
return alias; |
|---|
| 307 |
} |
|---|
| 308 |
} |
|---|
| 309 |
} |
|---|
| 310 |
if (discon_alias) |
|---|
| 311 |
__dget_locked(discon_alias); |
|---|
| 312 |
spin_unlock(&dcache_lock); |
|---|
| 313 |
return discon_alias; |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
void d_prune_aliases(struct inode *inode) |
|---|
| 321 |
{ |
|---|
| 322 |
struct list_head *tmp, *head = &inode->i_dentry; |
|---|
| 323 |
restart: |
|---|
| 324 |
spin_lock(&dcache_lock); |
|---|
| 325 |
tmp = head; |
|---|
| 326 |
while ((tmp = tmp->next) != head) { |
|---|
| 327 |
struct dentry *dentry = list_entry(tmp, struct dentry, d_alias); |
|---|
| 328 |
if (!atomic_read(&dentry->d_count)) { |
|---|
| 329 |
__dget_locked(dentry); |
|---|
| 330 |
__d_drop(dentry); |
|---|
| 331 |
spin_unlock(&dcache_lock); |
|---|
| 332 |
dput(dentry); |
|---|
| 333 |
goto restart; |
|---|
| 334 |
} |
|---|
| 335 |
} |
|---|
| 336 |
spin_unlock(&dcache_lock); |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
static inline void prune_one_dentry(struct dentry * dentry) |
|---|
| 346 |
{ |
|---|
| 347 |
struct dentry * parent; |
|---|
| 348 |
|
|---|
| 349 |
__d_drop(dentry); |
|---|
| 350 |
list_del(&dentry->d_child); |
|---|
| 351 |
dentry_stat.nr_dentry--; |
|---|
| 352 |
dentry_iput(dentry); |
|---|
| 353 |
parent = dentry->d_parent; |
|---|
| 354 |
d_free(dentry); |
|---|
| 355 |
if (parent != dentry) |
|---|
| 356 |
dput(parent); |
|---|
| 357 |
spin_lock(&dcache_lock); |
|---|
| 358 |
} |
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 |
|
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
static void prune_dcache(int count) |
|---|
| 374 |
{ |
|---|
| 375 |
spin_lock(&dcache_lock); |
|---|
| 376 |
for (; count ; count--) { |
|---|
| 377 |
struct dentry *dentry; |
|---|
| 378 |
struct list_head *tmp; |
|---|
| 379 |
|
|---|
| 380 |
tmp = dentry_unused.prev; |
|---|
| 381 |
if (tmp == &dentry_unused) |
|---|
| 382 |
break; |
|---|
| 383 |
list_del_init(tmp); |
|---|
| 384 |
prefetch(dentry_unused.prev); |
|---|
| 385 |
dentry_stat.nr_unused--; |
|---|
| 386 |
dentry = list_entry(tmp, struct dentry, d_lru); |
|---|
| 387 |
|
|---|
| 388 |
spin_lock(&dentry->d_lock); |
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
if (atomic_read(&dentry->d_count)) { |
|---|
| 395 |
spin_unlock(&dentry->d_lock); |
|---|
| 396 |
continue; |
|---|
| 397 |
} |
|---|
| 398 |
|
|---|
| 399 |
if (dentry->d_flags & DCACHE_REFERENCED) { |
|---|
| 400 |
dentry->d_flags &= ~DCACHE_REFERENCED; |
|---|
| 401 |
list_add(&dentry->d_lru, &dentry_unused); |
|---|
| 402 |
dentry_stat.nr_unused++; |
|---|
| 403 |
spin_unlock(&dentry->d_lock); |
|---|
| 404 |
continue; |
|---|
| 405 |
} |
|---|
| 406 |
prune_one_dentry(dentry); |
|---|
| 407 |
} |
|---|
| 408 |
spin_unlock(&dcache_lock); |
|---|
| 409 |
} |
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
void shrink_dcache_sb(struct super_block * sb) |
|---|
| 434 |
{ |
|---|
| 435 |
struct list_head *tmp, *next; |
|---|
| 436 |
struct dentry *dentry; |
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 |
spin_lock(&dcache_lock); |
|---|
| 443 |
next = dentry_unused.next; |
|---|
| 444 |
while (next != &dentry_unused) { |
|---|
| 445 |
tmp = next; |
|---|
| 446 |
next = tmp->next; |
|---|
| 447 |
dentry = list_entry(tmp, struct dentry, d_lru); |
|---|
| 448 |
if (dentry->d_sb != sb) |
|---|
| 449 |
continue; |
|---|
| 450 |
list_del(tmp); |
|---|
| 451 |
list_add(tmp, &dentry_unused); |
|---|
| 452 |
} |
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
repeat: |
|---|
| 458 |
next = dentry_unused.next; |
|---|
| 459 |
while (next != &dentry_unused) { |
|---|
| 460 |
tmp = next; |
|---|
| 461 |
next = tmp->next; |
|---|
| 462 |
dentry = list_entry(tmp, struct dentry, d_lru); |
|---|
| 463 |
if (dentry->d_sb != sb) |
|---|
| 464 |
continue; |
|---|
| 465 |
dentry_stat.nr_unused--; |
|---|
| 466 |
list_del_init(tmp); |
|---|
| 467 |
spin_lock(&dentry->d_lock); |
|---|
| 468 |
if (atomic_read(&dentry->d_count)) { |
|---|
| 469 |
spin_unlock(&dentry->d_lock); |
|---|
| 470 |
continue; |
|---|
| 471 |
} |
|---|
| 472 |
prune_one_dentry(dentry); |
|---|
| 473 |
goto repeat; |
|---|
| 474 |
} |
|---|
| 475 |
spin_unlock(&dcache_lock); |
|---|
| 476 |
} |
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
int have_submounts(struct dentry *parent) |
|---|
| 493 |
{ |
|---|
| 494 |
struct dentry *this_parent = parent; |
|---|
| 495 |
struct list_head *next; |
|---|
| 496 |
|
|---|
| 497 |
spin_lock(&dcache_lock); |
|---|
| 498 |
if (d_mountpoint(parent)) |
|---|
| 499 |
goto positive; |
|---|
| 500 |
repeat: |
|---|
| 501 |
next = this_parent->d_subdirs.next; |
|---|
| 502 |
resume: |
|---|
| 503 |
while (next != &this_parent->d_subdirs) { |
|---|
| 504 |
struct list_head *tmp = next; |
|---|
| 505 |
struct dentry *dentry = list_entry(tmp, struct dentry, d_child); |
|---|
| 506 |
next = tmp->next; |
|---|
| 507 |
|
|---|
| 508 |
if (d_mountpoint(dentry)) |
|---|
| 509 |
goto positive; |
|---|
| 510 |
if (!list_empty(&dentry->d_subdirs)) { |
|---|
| 511 |
this_parent = dentry; |
|---|
| 512 |
goto repeat; |
|---|
| 513 |
} |
|---|
| 514 |
} |
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 |
if (this_parent != parent) { |
|---|
| 519 |
next = this_parent->d_child.next; |
|---|
| 520 |
this_parent = this_parent->d_parent; |
|---|
| 521 |
goto resume; |
|---|
| 522 |
} |
|---|
| 523 |
spin_unlock(&dcache_lock); |
|---|
| 524 |
return 0; |
|---|
| 525 |
positive: |
|---|
| 526 |
spin_unlock(&dcache_lock); |
|---|
| 527 |
return 1; |
|---|
| 528 |
} |
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
static int select_parent(struct dentry * parent) |
|---|
| 538 |
{ |
|---|
| 539 |
struct dentry *this_parent = parent; |
|---|
| 540 |
struct list_head *next; |
|---|
| 541 |
int found = 0; |
|---|
| 542 |
|
|---|
| 543 |
spin_lock(&dcache_lock); |
|---|
| 544 |
repeat: |
|---|
| 545 |
next = this_parent->d_subdirs.next; |
|---|
| 546 |
resume: |
|---|
| 547 |
while (next != &this_parent->d_subdirs) { |
|---|
| 548 |
struct list_head *tmp = next; |
|---|
| 549 |
struct dentry *dentry = list_entry(tmp, struct dentry, d_child); |
|---|
| 550 |
next = tmp->next; |
|---|
| 551 |
|
|---|
| 552 |
if (!list_empty(&dentry->d_lru)) { |
|---|
| 553 |
dentry_stat.nr_unused--; |
|---|
| 554 |
list_del_init(&dentry->d_lru); |
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
if (!atomic_read(&dentry->d_count)) { |
|---|
| 561 |
list_add(&dentry->d_lru, dentry_unused.prev); |
|---|
| 562 |
dentry_stat.nr_unused++; |
|---|
| 563 |
found++; |
|---|
| 564 |
} |
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
if (!list_empty(&dentry->d_subdirs)) { |
|---|
| 569 |
this_parent = dentry; |
|---|
| 570 |
#ifdef DCACHE_DEBUG |
|---|
| 571 |
printk(KERN_DEBUG "select_parent: descending to %s/%s, found=%d\n", |
|---|
| 572 |
dentry->d_parent->d_name.name, dentry->d_name.name, found); |
|---|
| 573 |
#endif |
|---|
| 574 |
goto repeat; |
|---|
| 575 |
} |
|---|
| 576 |
} |
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
if (this_parent != parent) { |
|---|
| 581 |
next = this_parent->d_child.next; |
|---|
| 582 |
this_parent = this_parent->d_parent; |
|---|
| 583 |
#ifdef DCACHE_DEBUG |
|---|
| 584 |
printk(KERN_DEBUG "select_parent: ascending to %s/%s, found=%d\n", |
|---|
| 585 |
this_parent->d_parent->d_name.name, this_parent->d_name.name, found); |
|---|
| 586 |
#endif |
|---|
| 587 |
goto resume; |
|---|
| 588 |
} |
|---|
| 589 |
spin_unlock(&dcache_lock); |
|---|
| 590 |
return found; |
|---|
| 591 |
} |
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
void shrink_dcache_parent(struct dentry * parent) |
|---|
| 601 |
{ |
|---|
| 602 |
int found; |
|---|
| 603 |
|
|---|
| 604 |
while ((found = select_parent(parent)) != 0) |
|---|
| 605 |
prune_dcache(found); |
|---|
| 606 |
} |
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
void shrink_dcache_anon(struct hlist_head *head) |
|---|
| 619 |
{ |
|---|
| 620 |
struct hlist_node *lp; |
|---|
| 621 |
int found; |
|---|
| 622 |
do { |
|---|
| 623 |
found = 0; |
|---|
| 624 |
spin_lock(&dcache_lock); |
|---|
| 625 |
hlist_for_each(lp, head) { |
|---|
| 626 |
struct dentry *this = hlist_entry(lp, struct dentry, d_hash); |
|---|
| 627 |
if (!list_empty(&this->d_lru)) { |
|---|
| 628 |
dentry_stat.nr_unused--; |
|---|
| 629 |
list_del(&this->d_lru); |
|---|
| 630 |
} |
|---|
| 631 |
|
|---|
| 632 |
|
|---|
| 633 |
|
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
if (!atomic_read(&this->d_count)) { |
|---|
| 637 |
list_add_tail(&this->d_lru, &dentry_unused); |
|---|
| 638 |
dentry_stat.nr_unused++; |
|---|
| 639 |
found++; |
|---|
| 640 |
} |
|---|
| 641 |
} |
|---|
| 642 |
spin_unlock(&dcache_lock); |
|---|
| 643 |
prune_dcache(found); |
|---|
| 644 |
} while(found); |
|---|
| 645 |
} |
|---|
| 646 |
|
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
|
|---|
| 650 |
|
|---|
| 651 |
|
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
static int shrink_dcache_memory(int nr, unsigned int gfp_mask) |
|---|
| 660 |
{ |
|---|
| 661 |
if (nr) { |
|---|
| 662 |
if (!(gfp_mask & __GFP_FS)) |
|---|
| 663 |
return -1; |
|---|
| 664 |
prune_dcache(nr); |
|---|
| 665 |
} |
|---|
| 666 |
return dentry_stat.nr_unused; |
|---|
| 667 |
} |
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
|
|---|
| 676 |
|
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) |
|---|
| 680 |
{ |
|---|
| 681 |
struct dentry *dentry; |
|---|
| 682 |
char *dname; |
|---|
| 683 |
|
|---|
| 684 |
dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); |
|---|
| 685 |
if (!dentry) |
|---|
| 686 |
return NULL; |
|---|
| 687 |
|
|---|
| 688 |
if (name->len > DNAME_INLINE_LEN-1) { |
|---|
| 689 |
dname = kmalloc(name->len + 1, GFP_KERNEL); |
|---|
| 690 |
if (!dname) { |
|---|
| 691 |
kmem_cache_free(dentry_cache, dentry); |
|---|
| 692 |
return NULL; |
|---|
| 693 |
} |
|---|
| 694 |
} else { |
|---|
| 695 |
dname = dentry->d_iname; |
|---|
| 696 |
} |
|---|
| 697 |
dentry->d_name.name = dname; |
|---|
| 698 |
|
|---|
| 699 |
dentry->d_name.len = name->len; |
|---|
| 700 |
dentry->d_name.hash = name->hash; |
|---|
| 701 |
memcpy(dname, name->name, name->len); |
|---|
| 702 |
dname[name->len] = 0; |
|---|
| 703 |
|
|---|
| 704 |
atomic_set(&dentry->d_count, 1); |
|---|
| 705 |
dentry->d_flags = DCACHE_UNHASHED; |
|---|
| 706 |
dentry->d_lock = SPIN_LOCK_UNLOCKED; |
|---|
| 707 |
dentry->d_inode = NULL; |
|---|
| 708 |
dentry->d_parent = NULL; |
|---|
| 709 |
dentry->d_sb = NULL; |
|---|
| 710 |
dentry->d_op = NULL; |
|---|
| 711 |
dentry->d_fsdata = NULL; |
|---|
| 712 |
dentry->d_mounted = 0; |
|---|
| 713 |
dentry->d_cookie = NULL; |
|---|
| 714 |
dentry->d_bucket = NULL; |
|---|
| 715 |
INIT_HLIST_NODE(&dentry->d_hash); |
|---|
| 716 |
INIT_LIST_HEAD(&dentry->d_lru); |
|---|
| 717 |
INIT_LIST_HEAD(&dentry->d_subdirs); |
|---|
| 718 |
INIT_LIST_HEAD(&dentry->d_alias); |
|---|
| 719 |
|
|---|
| 720 |
if (parent) { |
|---|
| 721 |
dentry->d_parent = dget(parent); |
|---|
| 722 |
dentry->d_sb = parent->d_sb; |
|---|
| 723 |
} else { |
|---|
| 724 |
INIT_LIST_HEAD(&dentry->d_child); |
|---|
| 725 |
} |
|---|
| 726 |
|
|---|
| 727 |
spin_lock(&dcache_lock); |
|---|
| 728 |
if (parent) |
|---|
| 729 |
list_add(&dentry->d_child, &parent->d_subdirs); |
|---|
| 730 |
dentry_stat.nr_dentry++; |
|---|
| 731 |
spin_unlock(&dcache_lock); |
|---|
| 732 |
|
|---|
| 733 |
return dentry; |
|---|
| 734 |
} |
|---|
| 735 |
|
|---|
| 736 |
|
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 |
|
|---|
| 742 |
|
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 |
|
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
void d_instantiate(struct dentry *entry, struct inode * inode) |
|---|
| 752 |
{ |
|---|
| 753 |
if (!list_empty(&entry->d_alias)) BUG(); |
|---|
| 754 |
spin_lock(&dcache_lock); |
|---|
| 755 |
if (inode) |
|---|
| 756 |
list_add(&entry->d_alias, &inode->i_dentry); |
|---|
| 757 |
entry->d_inode = inode; |
|---|
| 758 |
spin_unlock(&dcache_lock); |
|---|
| 759 |
security_d_instantiate(entry, inode); |
|---|
| 760 |
} |
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 |
|
|---|
| 766 |
|
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
|
|---|
| 771 |
struct dentry * d_alloc_root(struct inode * root_inode) |
|---|
| 772 |
{ |
|---|
| 773 |
struct dentry *res = NULL; |
|---|
| 774 |
|
|---|
| 775 |
if (root_inode) { |
|---|
| 776 |
static const struct qstr name = { .name = "/", .len = 1 }; |
|---|
| 777 |
|
|---|
| 778 |
res = d_alloc(NULL, &name); |
|---|
| 779 |
if (res) { |
|---|
| 780 |
res->d_sb = root_inode->i_sb; |
|---|
| 781 |
res->d_parent = res; |
|---|
| 782 |
d_instantiate(res, root_inode); |
|---|
| 783 |
} |
|---|
| 784 |
} |
|---|
| 785 |
return res; |
|---|
| 786 |
} |
|---|
| 787 |
|
|---|
| 788 |
static inline struct hlist_head *d_hash(struct dentry *parent, |
|---|
| 789 |
unsigned long hash) |
|---|
| 790 |
{ |
|---|
| 791 |
hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES; |
|---|
| 792 |
hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS); |
|---|
| 793 |
return dentry_hashtable + (hash & D_HASHMASK); |
|---|
| 794 |
} |
|---|
| 795 |
|
|---|
| 796 |
|
|---|
| 797 |
|
|---|
| 798 |
|
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 |
|
|---|
| 803 |
|
|---|
| 804 |
|
|---|
| 805 |
|
|---|
| 806 |
|
|---|
| 807 |
|
|---|
| 808 |
|
|---|
| 809 |
|
|---|
| 810 |
|
|---|
| 811 |
|
|---|
| 812 |
|
|---|
| 813 |
|
|---|
| 814 |
|
|---|
| 815 |
|
|---|
| 816 |
struct dentry * d_alloc_anon(struct inode *inode) |
|---|
| 817 |
{ |
|---|
| 818 |
static const struct qstr anonstring = { .name = "" }; |
|---|
| 819 |
struct dentry *tmp; |
|---|
| 820 |
struct dentry *res; |
|---|
| 821 |
|
|---|
| 822 |
if ((res = d_find_alias(inode))) { |
|---|
| 823 |
iput(inode); |
|---|
| 824 |
return res; |
|---|
| 825 |
} |
|---|
| 826 |
|
|---|
| 827 |
tmp = d_alloc(NULL, &anonstring); |
|---|
| 828 |
if (!tmp) |
|---|
| 829 |
return NULL; |
|---|
| 830 |
|
|---|
| 831 |
tmp->d_parent = tmp; |
|---|
| 832 |
|
|---|
| 833 |
spin_lock(&dcache_lock); |
|---|
| 834 |
if (S_ISDIR(inode->i_mode) && !list_empty(&inode->i_dentry)) { |
|---|
| 835 |
|
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
res = list_entry(inode->i_dentry.next, struct dentry, d_alias); |
|---|
| 839 |
__dget_locked(res); |
|---|
| 840 |
} else { |
|---|
| 841 |
|
|---|
| 842 |
res = tmp; |
|---|
| 843 |
tmp = NULL; |
|---|
| 844 |
if (res) { |
|---|
| 845 |
spin_lock(&res->d_lock); |
|---|
| 846 |
res->d_sb = inode->i_sb; |
|---|
| 847 |
res->d_parent = res; |
|---|
| 848 |
res->d_inode = inode; |
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
|
|---|
| 854 |
res->d_bucket = NULL; |
|---|
| 855 |
res->d_flags |= DCACHE_DISCONNECTED; |
|---|
| 856 |
res->d_flags &= ~DCACHE_UNHASHED; |
|---|
| 857 |
list_add(&res->d_alias, &inode->i_dentry); |
|---|
| 858 |
hlist_add_head(&res->d_hash, &inode->i_sb->s_anon); |
|---|
| 859 |
spin_unlock(&res->d_lock); |
|---|
| 860 |
} |
|---|
| 861 |
inode = NULL; |
|---|
| 862 |
} |
|---|
| 863 |
spin_unlock(&dcache_lock); |
|---|
| 864 |
|
|---|
| 865 |
if (inode) |
|---|
| 866 |
iput(inode); |
|---|
| 867 |
if (tmp) |
|---|
| 868 |
dput(tmp); |
|---|
| 869 |
return res; |
|---|
| 870 |
} |
|---|
| 871 |
|
|---|
| 872 |
|
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 |
|
|---|
| 876 |
|
|---|
| 877 |
|
|---|
| 878 |
|
|---|
| 879 |
|
|---|
| 880 |
|
|---|
| 881 |
|
|---|
| 882 |
|
|---|
| 883 |
|
|---|
| 884 |
|
|---|
| 885 |
|
|---|
| 886 |
|
|---|
| 887 |
|
|---|
| 888 |
|
|---|
| 889 |
struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) |
|---|
| 890 |
{ |
|---|
| 891 |
struct dentry *new = NULL; |
|---|
| 892 |
|
|---|
| 893 |
if (inode && S_ISDIR(inode->i_mode)) { |
|---|
| 894 |
spin_lock(&dcache_lock); |
|---|
| 895 |
if (!list_empty(&inode->i_dentry)) { |
|---|
| 896 |
new = list_entry(inode->i_dentry.next, struct dentry, d_alias); |
|---|
| 897 |
__dget_locked(new); |
|---|
| 898 |
spin_unlock(&dcache_lock); |
|---|
| 899 |
security_d_instantiate(new, inode); |
|---|
| 900 |
d_rehash(dentry); |
|---|
| 901 |
d_move(new, dentry); |
|---|
| 902 |
iput(inode); |
|---|
| 903 |
} else { |
|---|
| 904 |
|
|---|
| 905 |
list_add(&dentry->d_alias, &inode->i_dentry); |
|---|
| 906 |
dentry->d_inode = inode; |
|---|
| 907 |
spin_unlock(&dcache_lock); |
|---|
| 908 |
security_d_instantiate(dentry, inode); |
|---|
| 909 |
d_rehash(dentry); |
|---|
| 910 |
} |
|---|
| 911 |
} else |
|---|
| 912 |
d_add(dentry, inode); |
|---|
| 913 |
return new; |
|---|
| 914 |
} |
|---|
| 915 |
|
|---|
| 916 |
|
|---|
| 917 |
|
|---|
| 918 |
|
|---|
| 919 |
|
|---|
| 920 |
|
|---|
| 921 |
|
|---|
| 922 |
|
|---|
| 923 |
|
|---|
| 924 |
|
|---|
| 925 |
|
|---|
| 926 |
|
|---|
| 927 |
|
|---|
| 928 |
|
|---|
| 929 |
|
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 |
|
|---|
| 933 |
|
|---|
| 934 |
|
|---|
| 935 |
|
|---|
| 936 |
|
|---|
| 937 |
|
|---|
| 938 |
|
|---|
| 939 |
|
|---|
| 940 |
|
|---|
| 941 |
|
|---|
| 942 |
|
|---|
| 943 |
|
|---|
| 944 |
|
|---|
| 945 |
|
|---|
| 946 |
struct dentry * d_lookup(struct dentry * parent, struct qstr * name) |
|---|
| 947 |
{ |
|---|
| 948 |
struct dentry * dentry = NULL; |
|---|
| 949 |
unsigned long seq; |
|---|
| 950 |
|
|---|
| 951 |
do { |
|---|
| 952 |
seq = read_seqbegin(&rename_lock); |
|---|
| 953 |
dentry = __d_lookup(parent, name); |
|---|
| 954 |
if (dentry) |
|---|
| 955 |
break; |
|---|
| 956 |
} while (read_seqretry(&rename_lock, seq)); |
|---|
| 957 |
return dentry; |
|---|
| 958 |
} |
|---|
| 959 |
|
|---|
| 960 |
struct dentry * __d_lookup(struct dentry * parent, struct qstr * name) |
|---|
| 961 |
{ |
|---|
| 962 |
unsigned int len = name->len; |
|---|
| 963 |
unsigned int hash = name->hash; |
|---|
| 964 |
const unsigned char *str = name->name; |
|---|
| 965 |
struct hlist_head *head = d_hash(parent,hash); |
|---|
| 966 |
struct dentry *found = NULL; |
|---|
| 967 |
struct hlist_node *node; |
|---|
| 968 |
|
|---|
| 969 |
rcu_read_lock(); |
|---|
| 970 |
|
|---|
| 971 |
hlist_for_each (node, head) { |
|---|
| 972 |
struct dentry *dentry; |
|---|
| 973 |
struct qstr *qstr; |
|---|
| 974 |
|
|---|
| 975 |
smp_read_barrier_depends(); |
|---|
| 976 |
dentry = hlist_entry(node, struct dentry, d_hash); |
|---|
| 977 |
|
|---|
| 978 |
smp_rmb(); |
|---|
| 979 |
|
|---|
| 980 |
if (dentry->d_name.hash != hash) |
|---|
| 981 |
continue; |
|---|
| 982 |
if (dentry->d_parent != parent) |
|---|
| 983 |
continue; |
|---|
| 984 |
|
|---|
| 985 |
spin_lock(&dentry->d_lock); |
|---|
| 986 |
|
|---|
| 987 |
|
|---|
| 988 |
|
|---|
| 989 |
|
|---|
| 990 |
|
|---|
| 991 |
if (unlikely(dentry->d_bucket != head)) |
|---|
| 992 |
goto terminate; |
|---|
| 993 |
|
|---|
| 994 |
|
|---|
| 995 |
|
|---|
| 996 |
|
|---|
| 997 |
|
|---|
| 998 |
|
|---|
| 999 |
if (dentry->d_parent != parent) |
|---|
| 1000 |
goto next; |
|---|
| 1001 |
|
|---|
| 1002 |
qstr = &dentry->d_name; |
|---|
| 1003 |
smp_read_barrier_depends(); |
|---|
| 1004 |
if (parent->d_op && parent->d_op->d_compare) { |
|---|
| 1005 |
if (parent->d_op->d_compare(parent, qstr, name)) |
|---|
| 1006 |
goto next; |
|---|
| 1007 |
} else { |
|---|
| 1008 |
if (qstr->len != len) |
|---|
| 1009 |
goto next; |
|---|
| 1010 |
if (memcmp(qstr->name, str, len)) |
|---|
| 1011 |
goto next; |
|---|
| 1012 |
} |
|---|
| 1013 |
|
|---|
| 1014 |
if (!d_unhashed(dentry)) { |
|---|
| 1015 |
atomic_inc(&dentry->d_count); |
|---|
| 1016 |
found = dentry; |
|---|
| 1017 |
} |
|---|
| 1018 |
terminate: |
|---|
| 1019 |
spin_unlock(&dentry->d_lock); |
|---|
| 1020 |
break; |
|---|
| 1021 |
next: |
|---|
| 1022 |
spin_unlock(&dentry->d_lock); |
|---|
| 1023 |
} |
|---|
| 1024 |
rcu_read_unlock(); |
|---|
| 1025 |
|
|---|
| 1026 |
return found; |
|---|
| 1027 |
} |
|---|
| 1028 |
|
|---|
| 1029 |
|
|---|
| 1030 |
|
|---|
| 1031 |
|
|---|
| 1032 |
|
|---|
| 1033 |
|
|---|
| 1034 |
|
|---|
| 1035 |
|
|---|
| 1036 |
|
|---|
| 1037 |
|
|---|
| 1038 |
|
|---|
| 1039 |
|
|---|
| 1040 |
|
|---|
| 1041 |
int d_validate(struct dentry *dentry, struct dentry *dparent) |
|---|
| 1042 |
{ |
|---|
| 1043 |
struct hlist_head *base; |
|---|
| 1044 |
struct hlist_node *lhp; |
|---|
| 1045 |
|
|---|
| 1046 |
|
|---|
| 1047 |
if (!kmem_ptr_validate(dentry_cache, dentry)) |
|---|
| 1048 |
goto out; |
|---|
| 1049 |
|
|---|
| 1050 |
if (dentry->d_parent != dparent) |
|---|
| 1051 |
goto out; |
|---|
| 1052 |
|
|---|
| 1053 |
spin_lock(&dcache_lock); |
|---|
| 1054 |
base = d_hash(dparent, dentry->d_name.hash); |
|---|
| 1055 |
hlist_for_each(lhp,base) { |
|---|
| 1056 |
|
|---|
| 1057 |
|
|---|
| 1058 |
|
|---|
| 1059 |
if (dentry == hlist_entry(lhp, struct dentry, d_hash)) { |
|---|
| 1060 |
__dget_locked(dentry); |
|---|
| 1061 |
spin_unlock(&dcache_lock); |
|---|
| 1062 |
return 1; |
|---|
| 1063 |
} |
|---|
| 1064 |
} |
|---|
| 1065 |
spin_unlock(&dcache_lock); |
|---|
| 1066 |
out: |
|---|
| 1067 |
return 0; |
|---|
| 1068 |
} |
|---|
| 1069 |
|
|---|
| 1070 |
|
|---|
| 1071 |
|
|---|
| 1072 |
|
|---|
| 1073 |
|
|---|
| 1074 |
|
|---|
| 1075 |
|
|---|
| 1076 |
|
|---|
| 1077 |
|
|---|
| 1078 |
|
|---|
| 1079 |
|
|---|
| 1080 |
|
|---|
| 1081 |
|
|---|
| 1082 |
|
|---|
| 1083 |
|
|---|
| 1084 |
|
|---|
| 1085 |
|
|---|
| 1086 |
|
|---|
| 1087 |
|
|---|
| 1088 |
|
|---|
| 1089 |
|
|---|
| 1090 |
|
|---|
| 1091 |
void d_delete(struct dentry * dentry) |
|---|
| 1092 |
{ |
|---|
| 1093 |
|
|---|
| 1094 |
|
|---|
| 1095 |
|
|---|
| 1096 |
spin_lock(&dcache_lock); |
|---|
| 1097 |
spin_lock(&dentry->d_lock); |
|---|
| 1098 |
if (atomic_read(&dentry->d_count) == 1) { |
|---|
| 1099 |
dentry_iput(dentry); |
|---|
| 1100 |
return; |
|---|
| 1101 |
} |
|---|
| 1102 |
|
|---|
| 1103 |
if (!d_unhashed(dentry)) |
|---|
| 1104 |
__d_drop(dentry); |
|---|
| 1105 |
|
|---|
| 1106 |
spin_unlock(&dentry->d_lock); |
|---|
| 1107 |
spin_unlock(&dcache_lock); |
|---|
| 1108 |
} |
|---|
| 1109 |
|
|---|
| 1110 |
|
|---|
| 1111 |
|
|---|
| 1112 |
|
|---|
| 1113 |
|
|---|
| 1114 |
|
|---|
| 1115 |
|
|---|
| 1116 |
|
|---|
| 1117 |
void d_rehash(struct dentry * entry) |
|---|
| 1118 |
{ |
|---|
| 1119 |
struct hlist_head *list = d_hash(entry->d_parent, entry->d_name.hash); |
|---|
| 1120 |
|
|---|
| 1121 |
spin_lock(&dcache_lock); |
|---|
| 1122 |
spin_lock(&entry->d_lock); |
|---|
| 1123 |
entry->d_flags &= ~DCACHE_UNHASHED; |
|---|
| 1124 |
spin_unlock(&entry->d_lock); |
|---|
| 1125 |
entry->d_bucket = list; |
|---|
| 1126 |
hlist_add_head_rcu(&entry->d_hash, list); |
|---|
| 1127 |
spin_unlock(&dcache_lock); |
|---|
| 1128 |
} |
|---|
| 1129 |
|
|---|
| 1130 |
#define do_switch(x,y) do { \ |
|---|
| 1131 |
__typeof__ (x) __tmp = x; \ |
|---|
| 1132 |
x = y; y = __tmp; } while (0) |
|---|
| 1133 |
|
|---|
| 1134 |
|
|---|
| 1135 |
|
|---|
| 1136 |
|
|---|
| 1137 |
|
|---|
| 1138 |
|
|---|
| 1139 |
|
|---|
| 1140 |
|
|---|
| 1141 |
|
|---|
| 1142 |
|
|---|
| 1143 |
|
|---|
| 1144 |
|
|---|
| 1145 |
static void switch_names(struct dentry *dentry, struct dentry *target) |
|---|
| 1146 |
{ |
|---|
| 1147 |
if (dname_external(target)) { |
|---|
| 1148 |
if (dname_external(dentry)) { |
|---|
| 1149 |
|
|---|
| 1150 |
|
|---|
| 1151 |
|
|---|
| 1152 |
do_switch(target->d_name.name, dentry->d_name.name); |
|---|
| 1153 |
} else { |
|---|
| 1154 |
|
|---|
| 1155 |
|
|---|
| 1156 |
|
|---|
| 1157 |
|
|---|
| 1158 |
dentry->d_name.name = target->d_name.name; |
|---|
| 1159 |
target->d_name.name = target->d_iname; |
|---|
| 1160 |
} |
|---|
| 1161 |
} else { |
|---|
| 1162 |
if (dname_external(dentry)) { |
|---|
| 1163 |
|
|---|
| 1164 |
|
|---|
| 1165 |
|
|---|
| 1166 |
|
|---|
| 1167 |
memcpy(dentry->d_iname, target->d_name.name, |
|---|
| 1168 |
target->d_name.len + 1); |
|---|
| 1169 |
target->d_name.name = dentry->d_name.name; |
|---|
| 1170 |
dentry->d_name.name = dentry->d_iname; |
|---|
| 1171 |
} else { |
|---|
| 1172 |
|
|---|
| 1173 |
|
|---|
| 1174 |
|
|---|
| 1175 |
memcpy(dentry->d_iname, target->d_name.name, |
|---|
| 1176 |
target->d_name.len + 1); |
|---|
| 1177 |
} |
|---|
| 1178 |
} |
|---|
| 1179 |
} |
|---|
| 1180 |
|
|---|
| 1181 |
|
|---|
| 1182 |
|
|---|
| 1183 |
|
|---|
| 1184 |
|
|---|
| 1185 |
|
|---|
| 1186 |
|
|---|
| 1187 |
|
|---|
| 1188 |
|
|---|
| 1189 |
|
|---|
| 1190 |
|
|---|
| 1191 |
|
|---|
| 1192 |
|
|---|
| 1193 |
|
|---|
| 1194 |
|
|---|
| 1195 |
|
|---|
| 1196 |
|
|---|
| 1197 |
|
|---|
| 1198 |
|
|---|
| 1199 |
|
|---|
| 1200 |
|
|---|
| 1201 |
|
|---|
| 1202 |
void d_move(struct dentry * dentry, struct dentry * target) |
|---|
| 1203 |
{ |
|---|
| 1204 |
if (!dentry->d_inode) |
|---|
| 1205 |
printk(KERN_WARNING "VFS: moving negative dcache entry\n"); |
|---|
| 1206 |
|
|---|
| 1207 |
spin_lock(&dcache_lock); |
|---|
| 1208 |
write_seqlock(&rename_lock); |
|---|
| 1209 |
|
|---|
| 1210 |
|
|---|
| 1211 |
|
|---|
| 1212 |
if (target < dentry) { |
|---|
| 1213 |
spin_lock(&target->d_lock); |
|---|
| 1214 |
spin_lock(&dentry->d_lock); |
|---|
| 1215 |
} else { |
|---|
| 1216 |
spin_lock(&dentry->d_lock); |
|---|
| 1217 |
spin_lock(&target->d_lock); |
|---|
| 1218 |
} |
|---|
| 1219 |
|
|---|
| 1220 |
|
|---|
| 1221 |
if (dentry->d_flags & DCACHE_UNHASHED) |
|---|
| 1222 |
goto already_unhashed; |
|---|
| 1223 |
if (dentry->d_bucket != target->d_bucket) { |
|---|
| 1224 |
hlist_del_rcu(&dentry->d_hash); |
|---|
| 1225 |
already_unhashed: |
|---|
| 1226 |
dentry->d_bucket = target->d_bucket; |
|---|
| 1227 |
hlist_add_head_rcu(&dentry->d_hash, target->d_bucket); |
|---|
| 1228 |
dentry->d_flags &= ~DCACHE_UNHASHED; |
|---|
| 1229 |
} |
|---|
| 1230 |
|
|---|
| 1231 |
|
|---|
| 1232 |
__d_drop(target); |
|---|
| 1233 |
|
|---|
| 1234 |
list_del(&dentry->d_child); |
|---|
| 1235 |
list_del(&target->d_child); |
|---|
| 1236 |
|
|---|
| 1237 |
|
|---|
| 1238 |
switch_names(dentry, target); |
|---|
| 1239 |
smp_wmb(); |
|---|
| 1240 |
do_switch(dentry->d_name.len, target->d_name.len); |
|---|
| 1241 |
do_switch(dentry->d_name.hash, target->d_name.hash); |
|---|
| 1242 |
|
|---|
| 1243 |
|
|---|
| 1244 |
if (IS_ROOT(dentry)) { |
|---|
| 1245 |
dentry->d_parent = target->d_parent; |
|---|
| 1246 |
target->d_parent = target; |
|---|
| 1247 |
INIT_LIST_HEAD(&target->d_child); |
|---|
| 1248 |
} else { |
|---|
| 1249 |
do_switch(dentry->d_parent, target->d_parent); |
|---|
| 1250 |
|
|---|
| 1251 |
|
|---|
| 1252 |
list_add(&target->d_child, &target->d_parent->d_subdirs); |
|---|
| 1253 |
} |
|---|
| 1254 |
|
|---|
| 1255 |
list_add(&dentry->d_child, &dentry->d_parent->d_subdirs); |
|---|
| 1256 |
spin_unlock(&target->d_lock); |
|---|
| 1257 |
spin_unlock(&dentry->d_lock); |
|---|
| 1258 |
write_sequnlock(&rename_lock); |
|---|
| 1259 |
spin_unlock(&dcache_lock); |
|---|
| 1260 |
} |
|---|
| 1261 |
|
|---|
| 1262 |
|
|---|
| 1263 |
|
|---|
| 1264 |
|
|---|
| 1265 |
|
|---|
| 1266 |
|
|---|
| 1267 |
|
|---|
| 1268 |
|
|---|
| 1269 |
|
|---|
| 1270 |
|
|---|
| 1271 |
|
|---|
| 1272 |
|
|---|
| 1273 |
|
|---|
| 1274 |
|
|---|
| 1275 |
|
|---|
| 1276 |
|
|---|
| 1277 |
|
|---|
| 1278 |
static char * __d_path( struct dentry *dentry, struct vfsmount *vfsmnt, |
|---|
| 1279 |
struct dentry *root, struct vfsmount *rootmnt, |
|---|
| 1280 |
char *buffer, int buflen) |
|---|
| 1281 |
{ |
|---|
| 1282 |
char * end = buffer+buflen; |
|---|
| 1283 |
char * retval; |
|---|
| 1284 |
int namelen; |
|---|
| 1285 |
|
|---|
| 1286 |
*--end = '\0'; |
|---|
| 1287 |
buflen--; |
|---|
| 1288 |
if (!IS_ROOT(dentry) && d_unhashed(dentry)) { |
|---|
| 1289 |
buflen -= 10; |
|---|
| 1290 |
end -= 10; |
|---|
| 1291 |
if (buflen < 0) |
|---|
| 1292 |
goto Elong; |
|---|
| 1293 |
memcpy(end, " (deleted)", 10); |
|---|
| 1294 |
} |
|---|
| 1295 |
|
|---|
| 1296 |
if (buflen < 1) |
|---|
| 1297 |
goto Elong; |
|---|
| 1298 |
|
|---|
| 1299 |
retval = end-1; |
|---|
| 1300 |
*retval = '/'; |
|---|
| 1301 |
|
|---|
| 1302 |
for (;;) { |
|---|
| 1303 |
struct dentry * parent; |
|---|
| 1304 |
|
|---|
| 1305 |
if (dentry == root && vfsmnt == rootmnt) |
|---|
| 1306 |
break; |
|---|
| 1307 |
if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { |
|---|
| 1308 |
|
|---|
| 1309 |
spin_lock(&vfsmount_lock); |
|---|
| 1310 |
if (vfsmnt->mnt_parent == vfsmnt) { |
|---|
| 1311 |
spin_unlock(&vfsmount_lock); |
|---|
| 1312 |
goto global_root; |
|---|
| 1313 |
} |
|---|
| 1314 |
dentry = vfsmnt->mnt_mountpoint; |
|---|
| 1315 |
vfsmnt = vfsmnt->mnt_parent; |
|---|
| 1316 |
spin_unlock(&vfsmount_lock); |
|---|
| 1317 |
continue; |
|---|
| 1318 |
} |
|---|
| 1319 |
parent = dentry->d_parent; |
|---|
| 1320 |
prefetch(parent); |
|---|
| 1321 |
namelen = dentry->d_name.len; |
|---|
| 1322 |
buflen -= namelen + 1; |
|---|
| 1323 |
if (buflen < 0) |
|---|
| 1324 |
goto Elong; |
|---|
| 1325 |
end -= namelen; |
|---|
| 1326 |
memcpy(end, dentry->d_name.name, namelen); |
|---|
| 1327 |
*--end = '/'; |
|---|
| 1328 |
retval = end; |
|---|
| 1329 |
dentry = parent; |
|---|
| 1330 |
} |
|---|
| 1331 |
|
|---|
| 1332 |
return retval; |
|---|
| 1333 |
|
|---|
| 1334 |
global_root: |
|---|
| 1335 |
namelen = dentry->d_name.len; |
|---|
| 1336 |
buflen -= namelen; |
|---|
| 1337 |
if (buflen < 0) |
|---|
| 1338 |
goto Elong; |
|---|
| 1339 |
retval -= namelen-1; |
|---|
| 1340 |
memcpy(retval, dentry->d_name.name, namelen); |
|---|
| 1341 |
return retval; |
|---|
| 1342 |
Elong: |
|---|
| 1343 |
return ERR_PTR(-ENAMETOOLONG); |
|---|
| 1344 |
} |
|---|
| 1345 |
|
|---|
| 1346 |
|
|---|
| 1347 |
char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt, |
|---|
| 1348 |
char *buf, int buflen) |
|---|
| 1349 |
{ |
|---|
| 1350 |
char *res; |
|---|
| 1351 |
struct vfsmount *rootmnt; |
|---|
| 1352 |
struct dentry *root; |
|---|
| 1353 |
|
|---|
| 1354 |
read_lock(¤t->fs->lock); |
|---|
| 1355 |
rootmnt = mntget(current->fs->rootmnt); |
|---|
| 1356 |
root = dget(current->fs->root); |
|---|
| 1357 |
read_unlock(¤t->fs->lock); |
|---|
| 1358 |
spin_lock(&dcache_lock); |
|---|
| 1359 |
res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen); |
|---|
| 1360 |
spin_unlock(&dcache_lock); |
|---|
| 1361 |
dput(root); |
|---|
| 1362 |
mntput(rootmnt); |
|---|
| 1363 |
return res; |
|---|
| 1364 |
} |
|---|
| 1365 |
|
|---|
| 1366 |
|
|---|
| 1367 |
|
|---|
| 1368 |
|
|---|
| 1369 |
|
|---|
| 1370 |
|
|---|
| 1371 |
|
|---|
| 1372 |
|
|---|
| 1373 |
|
|---|
| 1374 |
|
|---|
| 1375 |
|
|---|
| 1376 |
|
|---|
| 1377 |
|
|---|
| 1378 |
|
|---|
| 1379 |
|
|---|
| 1380 |
|
|---|
| 1381 |
|
|---|
| 1382 |
|
|---|
| 1383 |
|
|---|
| 1384 |
asmlinkage long sys_getcwd(char __user *buf, unsigned long size) |
|---|
| 1385 |
{ |
|---|
| 1386 |
int error; |
|---|
| 1387 |
struct vfsmount *pwdmnt, *rootmnt; |
|---|
| 1388 |
struct dentry *pwd, *root; |
|---|
| 1389 |
char *page = (char *) __get_free_page(GFP_USER); |
|---|
| 1390 |
|
|---|
| 1391 |
if (!page) |
|---|
| 1392 |
return -ENOMEM; |
|---|
| 1393 |
|
|---|
| 1394 |
read_lock(¤t->fs->lock); |
|---|
| 1395 |
pwdmnt = mntget(current->fs->pwdmnt); |
|---|
| 1396 |
pwd = dget(current->fs->pwd); |
|---|
| 1397 |
rootmnt = mntget(current->fs->rootmnt); |
|---|
| 1398 |
root = dget(current->fs->root); |
|---|
| 1399 |
read_unlock(¤t->fs->lock); |
|---|
| 1400 |
|
|---|
| 1401 |
error = -ENOENT; |
|---|
| 1402 |
|
|---|
| 1403 |
spin_lock(&dcache_lock); |
|---|
| 1404 |
if (pwd->d_parent == pwd || !d_unhashed(pwd)) { |
|---|
| 1405 |
unsigned long len; |
|---|
| 1406 |
char * cwd; |
|---|
| 1407 |
|
|---|
| 1408 |
cwd = __d_path(pwd, pwdmnt, root, rootmnt, page, PAGE_SIZE); |
|---|
| 1409 |
spin_unlock(&dcache_lock); |
|---|
| 1410 |
|
|---|
| 1411 |
error = PTR_ERR(cwd); |
|---|
| 1412 |
if (IS_ERR(cwd)) |
|---|
| 1413 |
goto out; |
|---|
| 1414 |
|
|---|
| 1415 |
error = -ERANGE; |
|---|
| 1416 |
len = PAGE_SIZE + page - cwd; |
|---|
| 1417 |
if (len <= size) { |
|---|
| 1418 |
error = len; |
|---|
| 1419 |
if (copy_to_user(buf, cwd, len)) |
|---|
| 1420 |
error = -EFAULT; |
|---|
| 1421 |
} |
|---|
| 1422 |
} else |
|---|
| 1423 |
spin_unlock(&dcache_lock); |
|---|
| 1424 |
|
|---|
| 1425 |
out: |
|---|
| 1426 |
dput(pwd); |
|---|
| 1427 |
mntput(pwdmnt); |
|---|
| 1428 |
dput(root); |
|---|
| 1429 |
mntput(rootmnt); |
|---|
| 1430 |
free_page((unsigned long) page); |
|---|
| 1431 |
return error; |
|---|
| 1432 |
} |
|---|
| 1433 |
|
|---|
| 1434 |
|
|---|
| 1435 |
|
|---|
| 1436 |
|
|---|
| 1437 |
|
|---|
| 1438 |
|
|---|
| 1439 |
|
|---|
| 1440 |
|
|---|
| 1441 |
|
|---|
| 1442 |
|
|---|
| 1443 |
|
|---|
| 1444 |
|
|---|
| 1445 |
|
|---|
| 1446 |
|
|---|
| 1447 |
|
|---|
| 1448 |
|
|---|
| 1449 |
|
|---|
| 1450 |
int is_subdir(struct dentry * new_dentry, struct dentry * old_dentry) |
|---|
| 1451 |
{ |
|---|
| 1452 |
int result; |
|---|
| 1453 |
struct dentry * saved = new_dentry; |
|---|
| 1454 |
unsigned long seq; |
|---|
| 1455 |
|
|---|
| 1456 |
result = 0; |
|---|
| 1457 |
|
|---|
| 1458 |
|
|---|
| 1459 |
|
|---|
| 1460 |
rcu_read_lock(); |
|---|
| 1461 |
do { |
|---|
| 1462 |
|
|---|
| 1463 |
new_dentry = saved; |
|---|
| 1464 |
seq = read_seqbegin(&rename_lock); |
|---|
| 1465 |
for (;;) { |
|---|
| 1466 |
if (new_dentry != old_dentry) { |
|---|
| 1467 |
struct dentry * parent = new_dentry->d_parent; |
|---|
| 1468 |
if (parent == new_dentry) |
|---|
| 1469 |
break; |
|---|
| 1470 |
new_dentry = parent; |
|---|
| 1471 |
continue; |
|---|
| 1472 |
} |
|---|
| 1473 |
result = 1; |
|---|
| 1474 |
break; |
|---|
| 1475 |
} |
|---|
| 1476 |
} while (read_seqretry(&rename_lock, seq)); |
|---|
| 1477 |
rcu_read_unlock(); |
|---|
| 1478 |
|
|---|
| 1479 |
return result; |
|---|
| 1480 |
} |
|---|
| 1481 |
|
|---|
| 1482 |
void d_genocide(struct dentry *root) |
|---|
| 1483 |
{ |
|---|
| 1484 |
struct dentry *this_parent = root; |
|---|
| 1485 |
struct list_head *next; |
|---|
| 1486 |
|
|---|
| 1487 |
spin_lock(&dcache_lock); |
|---|
| 1488 |
repeat: |
|---|
| 1489 |
next = this_parent->d_subdirs.next; |
|---|
| 1490 |
resume: |
|---|
| 1491 |
while (next != &this_parent->d_subdirs) { |
|---|
| 1492 |
struct list_head *tmp = next; |
|---|
| 1493 |
struct dentry *dentry = list_entry(tmp, struct dentry, d_child); |
|---|
| 1494 |
next = tmp->next; |
|---|
| 1495 |
if (d_unhashed(dentry)||!dentry->d_inode) |
|---|
| 1496 |
continue; |
|---|
| 1497 |
if (!list_empty(&dentry->d_subdirs)) { |
|---|
| 1498 |
this_parent = dentry; |
|---|
| 1499 |
goto repeat; |
|---|
| 1500 |
} |
|---|
| 1501 |
atomic_dec(&dentry->d_count); |
|---|
| 1502 |
} |
|---|
| 1503 |
if (this_parent != root) { |
|---|
| 1504 |
next = this_parent->d_child.next; |
|---|
| 1505 |
atomic_dec(&this_parent->d_count); |
|---|
| 1506 |
this_parent = this_parent->d_parent; |
|---|
| 1507 |
goto resume; |
|---|
| 1508 |
} |
|---|
| 1509 |
spin_unlock(&dcache_lock); |
|---|
| 1510 |
} |
|---|
| 1511 |
|
|---|
| 1512 |
|
|---|
| 1513 |
|
|---|
| 1514 |
|
|---|
| 1515 |
|
|---|
| 1516 |
|
|---|
| 1517 |
|
|---|
| 1518 |
|
|---|
| 1519 |
|
|---|
| 1520 |
|
|---|
| 1521 |
|
|---|
| 1522 |
|
|---|
| 1523 |
|
|---|
| 1524 |
|
|---|
| 1525 |
|
|---|
| 1526 |
ino_t find_inode_number(struct dentry *dir, struct qstr *name) |
|---|
| 1527 |
{ |
|---|
| 1528 |
struct dentry * dentry; |
|---|
| 1529 |
ino_t ino = 0; |
|---|
| 1530 |
|
|---|
| 1531 |
|
|---|
| 1532 |
|
|---|
| 1533 |
|
|---|
| 1534 |
|
|---|
| 1535 |
|
|---|
| 1536 |
name->hash = full_name_hash(name->name, name->len); |
|---|
| 1537 |
if (dir->d_op && dir->d_op->d_hash) |
|---|
| 1538 |
{ |
|---|
| 1539 |
if (dir->d_op->d_hash(dir, name) != 0) |
|---|
| 1540 |
goto out; |
|---|
| 1541 |
} |
|---|
| 1542 |
|
|---|
| 1543 |
dentry = d_lookup(dir, name); |
|---|
| 1544 |
if (dentry) |
|---|
| 1545 |
{ |
|---|
| 1546 |
if (dentry->d_inode) |
|---|
| 1547 |
ino = dentry->d_inode->i_ino; |
|---|
| 1548 |
dput(dentry); |
|---|
| 1549 |
} |
|---|
| 1550 |
out: |
|---|
| 1551 |
return ino; |
|---|
| 1552 |
} |
|---|
| 1553 |
|
|---|
| 1554 |
static __initdata unsigned long dhash_entries; |
|---|
| 1555 |
static int __init set_dhash_entries(char *str) |
|---|
| 1556 |
{ |
|---|
| 1557 |
if (!str) |
|---|
| 1558 |
return 0; |
|---|
| 1559 |
dhash_entries = simple_strtoul(str, &str, 0); |
|---|
| 1560 |
return 1; |
|---|
| 1561 |
} |
|---|
| 1562 |
__setup("dhash_entries=", set_dhash_entries); |
|---|
| 1563 |
|
|---|
| 1564 |
static void __init dcache_init(unsigned long mempages) |
|---|
| 1565 |
{ |
|---|
| 1566 |
struct hlist_head *d; |
|---|
| 1567 |
unsigned long order; |
|---|
| 1568 |
unsigned int nr_hash; |
|---|
| 1569 |
int i; |
|---|
| 1570 |
|
|---|
| 1571 |
|
|---|
| 1572 |
|
|---|
| 1573 |
|
|---|
| 1574 |
|
|---|
| 1575 |
|
|---|
| 1576 |
dentry_cache = kmem_cache_create("dentry_cache", |
|---|
| 1577 |
sizeof(struct dentry), |
|---|
| 1578 |
0, |
|---|
| 1579 |
SLAB_RECLAIM_ACCOUNT|SLAB_PANIC, |
|---|
| 1580 |
NULL, NULL); |
|---|
| 1581 |
|
|---|
| 1582 |
set_shrinker(DEFAULT_SEEKS, shrink_dcache_memory); |
|---|
| 1583 |
|
|---|
| 1584 |
if (!dhash_entries) |
|---|
| 1585 |
dhash_entries = PAGE_SHIFT < 13 ? |
|---|
| 1586 |
mempages >> (13 - PAGE_SHIFT) : |
|---|
| 1587 |
mempages << (PAGE_SHIFT - 13); |
|---|
| 1588 |
|
|---|
| 1589 |
dhash_entries *= sizeof(struct hlist_head); |
|---|
| 1590 |
for (order = 0; ((1UL << order) << PAGE_SHIFT) < dhash_entries; order++) |
|---|
| 1591 |
; |
|---|
| 1592 |
|
|---|
| 1593 |
do { |
|---|
| 1594 |
unsigned long tmp; |
|---|
| 1595 |
|
|---|
| 1596 |
nr_hash = (1UL << order) * PAGE_SIZE / |
|---|
| 1597 |
sizeof(struct hlist_head); |
|---|
| 1598 |
d_hash_mask = (nr_hash - 1); |
|---|
| 1599 |
|
|---|
| 1600 |
tmp = nr_hash; |
|---|
| 1601 |
d_hash_shift = 0; |
|---|
| 1602 |
while ((tmp >>= 1UL) != 0UL) |
|---|
| 1603 |
d_hash_shift++; |
|---|
| 1604 |
|
|---|
| 1605 |
dentry_hashtable = (struct hlist_head *) |
|---|
| 1606 |
__get_free_pages(GFP_ATOMIC, order); |
|---|
| 1607 |
} while (dentry_hashtable == NULL && --order >= 0); |
|---|
| 1608 |
|
|---|
| 1609 |
printk(KERN_INFO "Dentry cache hash table entries: %d (order: %ld, %ld bytes)\n", |
|---|
| 1610 |
nr_hash, order, (PAGE_SIZE << order)); |
|---|
| 1611 |
|
|---|
| 1612 |
if (!dentry_hashtable) |
|---|
| 1613 |
panic("Failed to allocate dcache hash table\n"); |
|---|
| 1614 |
|
|---|
| 1615 |
d = dentry_hashtable; |
|---|
| 1616 |
i = nr_hash; |
|---|
| 1617 |
do { |
|---|
| 1618 |
INIT_HLIST_HEAD(d); |
|---|
| 1619 |
d++; |
|---|
| 1620 |
i--; |
|---|
| 1621 |
} while (i); |
|---|
| 1622 |
} |
|---|
| 1623 |
|
|---|
| 1624 |
|
|---|
| 1625 |
kmem_cache_t *names_cachep; |
|---|
| 1626 |
|
|---|
| 1627 |
|
|---|
| 1628 |
kmem_cache_t *filp_cachep; |
|---|
| 1629 |
|
|---|
| 1630 |
EXPORT_SYMBOL(d_genocide); |
|---|
| 1631 |
|
|---|
| 1632 |
extern void bdev_cache_init(void); |
|---|
| 1633 |
extern void chrdev_init(void); |
|---|
| 1634 |
|
|---|
| 1635 |
void __init vfs_caches_init(unsigned long mempages) |
|---|
| 1636 |
{ |
|---|
| 1637 |
unsigned long reserve; |
|---|
| 1638 |
|
|---|
| 1639 |
|
|---|
| 1640 |
|
|---|
| 1641 |
|
|---|
| 1642 |
reserve = min((mempages - nr_free_pages()) * 3/2, mempages - 1); |
|---|
| 1643 |
mempages -= reserve; |
|---|
| 1644 |
|
|---|
| 1645 |
names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0, |
|---|
| 1646 |
SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); |
|---|
| 1647 |
|
|---|
| 1648 |
filp_cachep = kmem_cache_create("filp", sizeof(struct file), 0, |
|---|
| 1649 |
SLAB_HWCACHE_ALIGN|SLAB_PANIC, filp_ctor, filp_dtor); |
|---|
| 1650 |
|
|---|
| 1651 |
dcache_init(mempages); |
|---|
| 1652 |
inode_init(mempages); |
|---|
| 1653 |
files_init(mempages); |
|---|
| 1654 |
mnt_init(mempages); |
|---|
| 1655 |
bdev_cache_init(); |
|---|
| 1656 |
chrdev_init(); |
|---|
| 1657 |
} |
|---|
| 1658 |
|
|---|
| 1659 |
EXPORT_SYMBOL(d_alloc); |
|---|
| 1660 |
EXPORT_SYMBOL(d_alloc_anon); |
|---|
| 1661 |
EXPORT_SYMBOL(d_alloc_root); |
|---|
| 1662 |
EXPORT_SYMBOL(d_delete); |
|---|
| 1663 |
EXPORT_SYMBOL(d_find_alias); |
|---|
| 1664 |
EXPORT_SYMBOL(d_instantiate); |
|---|
| 1665 |
EXPORT_SYMBOL(d_invalidate); |
|---|
| 1666 |
EXPORT_SYMBOL(d_lookup); |
|---|
| 1667 |
EXPORT_SYMBOL(d_move); |
|---|
| 1668 |
EXPORT_SYMBOL(d_path); |
|---|
| 1669 |
EXPORT_SYMBOL(d_prune_aliases); |
|---|
| 1670 |
EXPORT_SYMBOL(d_rehash); |
|---|
| 1671 |
EXPORT_SYMBOL(d_splice_alias); |
|---|
| 1672 |
EXPORT_SYMBOL(d_validate); |
|---|
| 1673 |
EXPORT_SYMBOL(dget_locked); |
|---|
| 1674 |
EXPORT_SYMBOL(dput); |
|---|
| 1675 |
EXPORT_SYMBOL(find_inode_number); |
|---|
| 1676 |
EXPORT_SYMBOL(have_submounts); |
|---|
| 1677 |
EXPORT_SYMBOL(is_subdir); |
|---|
| 1678 |
EXPORT_SYMBOL(names_cachep); |
|---|
| 1679 |
EXPORT_SYMBOL(shrink_dcache_anon); |
|---|
| 1680 |
EXPORT_SYMBOL(shrink_dcache_parent); |
|---|
| 1681 |
EXPORT_SYMBOL(shrink_dcache_sb); |
|---|