12 #include <linux/module.h>
13 #include <linux/sched.h>
18 #include <linux/xattr.h>
22 #include <linux/slab.h>
25 #define CACHEFILES_KEYBUF_SIZE 512
36 unsigned keylen, loop;
39 prefix, object->
fscache.debug_id);
49 prefix, object->
fscache.parent);
51 spin_lock(&object->
fscache.lock);
52 cookie =
object->fscache.cookie;
58 object->
fscache.cookie->netfs_data,
69 spin_unlock(&object->
fscache.lock);
73 for (loop = 0; loop < keylen; loop++)
74 printk(
"%02x", keybuf[loop]);
89 __cachefiles_printk_object(
object,
"", keybuf);
91 __cachefiles_printk_object(xobject,
"x", keybuf);
115 if (object->
dentry > dentry)
117 else if (object->
dentry < dentry)
129 kdebug(
"preemptive burial: OBJ%x [%s] %p",
134 if (object->
fscache.state < FSCACHE_OBJECT_DYING) {
137 " Can't preemptively bury live object\n");
138 cachefiles_printk_object(
object,
NULL);
141 " Object already preemptively buried\n");
145 _leave(
" [owner marked]");
156 struct dentry *dentry;
165 cachefiles_printk_object(
object,
NULL);
169 dentry =
object->dentry;
176 ASSERT(xobject !=
object);
178 if (xobject->
dentry > dentry)
180 else if (xobject->
dentry < dentry)
183 goto wait_for_old_object;
196 if (xobject->
fscache.state < FSCACHE_OBJECT_DYING) {
199 " Unexpected object collision\n");
200 cachefiles_printk_object(
object, xobject);
216 _debug(
"queue OBJ%x behind OBJ%x immediately",
233 }
while (timeout > 0 && !requeue);
238 _debug(
"queue OBJ%x behind OBJ%x after wait",
247 " wait for old active object to go away\n");
248 cachefiles_printk_object(
object, xobject);
277 struct dentry *grave, *
trap;
278 struct path path, path_to_graveyard;
279 char nbuffer[8 + 8 + 1];
282 _enter(
",'%*.*s','%*.*s'",
286 _debug(
"remove %p from %p", rep, dir);
290 _debug(
"unlink stale object");
294 ret = security_path_unlink(&
path, rep);
301 cachefiles_mark_object_buried(cache, rep);
314 _debug(
"move stale object to graveyard");
347 if (d_mountpoint(rep)) {
357 if (PTR_ERR(grave) == -
ENOMEM) {
375 if (d_mountpoint(grave)) {
393 path_to_graveyard.mnt = cache->
mnt;
394 path_to_graveyard.dentry = cache->
graveyard;
395 ret = security_path_rename(&
path, rep, &path_to_graveyard, grave);
401 if (ret != 0 && ret != -
ENOMEM)
403 "Rename failed with error %d", ret);
406 cachefiles_mark_object_buried(cache, rep);
437 _debug(
"object preemptively buried");
443 if (dir == object->
dentry->d_parent) {
444 ret = cachefiles_bury_object(cache, dir,
476 _enter(
"OBJ%x{%p},OBJ%x,%s,",
478 object->
fscache.debug_id, key);
489 _leave(
"looking up in none directory");
493 dir = dget(parent->
dentry);
501 key = key + nlen + 1;
507 _debug(
"lookup '%s'", name);
517 _debug(
"next -> %p %s", next, next->
d_inode ?
"positive" :
"negative");
537 ret = security_path_mkdir(&path, next, 0);
548 _debug(
"mkdir -> %p{%p{ino=%lu}}",
552 kerror(
"inode %lu is not a directory",
566 ret = security_path_mknod(&path, next,
S_IFREG, 0);
577 _debug(
"create -> %p{%p{ino=%lu}}",
583 kerror(
"inode %lu is not a file or directory",
601 object->dentry =
next;
606 _debug(
"validate '%*.*s'",
613 object->dentry =
NULL;
615 ret = cachefiles_bury_object(cache, dir, next,
true);
628 ret = cachefiles_mark_object_active(cache,
object);
635 goto mark_active_timed_out;
637 _debug(
"=== OBTAINED_OBJECT ===");
659 aops =
object->dentry->d_inode->i_mapping->a_ops;
663 object->backer =
object->dentry;
676 _debug(
"create error %d", ret);
681 mark_active_timed_out:
682 _debug(
"mark active timed out");
686 _debug(
"check error %d", ret);
694 object->dentry =
NULL;
698 _debug(
"delete error %d", ret);
702 _debug(
"lookup error %ld", PTR_ERR(next));
713 _leave(
" = error %d", -ret);
724 struct dentry *subdir;
737 if (IS_ERR(subdir)) {
738 if (PTR_ERR(subdir) == -
ENOMEM)
744 subdir, subdir->
d_inode ?
"positive" :
"negative");
756 ret = security_path_mkdir(&path, subdir, 0700);
765 _debug(
"mkdir -> %p{%p{ino=%lu}}",
777 kerror(
"%s is not a directory", dirname);
784 !subdir->
d_inode->i_op->setxattr ||
785 !subdir->
d_inode->i_op->getxattr ||
786 !subdir->
d_inode->i_op->lookup ||
787 !subdir->
d_inode->i_op->mkdir ||
788 !subdir->
d_inode->i_op->create ||
789 !subdir->
d_inode->i_op->rename ||
790 !subdir->
d_inode->i_op->rmdir ||
791 !subdir->
d_inode->i_op->unlink)
799 _leave(
" = %d [check]", ret);
805 kerror(
"mkdir %s failed with error %d", dirname, ret);
810 ret = PTR_ERR(subdir);
811 kerror(
"Lookup %s failed with error %d", dirname, ret);
826 static struct dentry *cachefiles_check_active(
struct cachefiles_cache *cache,
832 struct dentry *victim;
857 _leave(
" = -ENOENT [absent]");
869 if (object->
dentry > victim)
871 else if (object->
dentry < victim)
887 return ERR_PTR(-
EBUSY);
891 ret = PTR_ERR(victim);
894 _leave(
" = -ESTALE [absent]");
900 }
else if (ret != -
ENOMEM) {
901 kerror(
"Internal error: %d", ret);
916 struct dentry *victim;
922 victim = cachefiles_check_active(cache, dir, filename);
924 return PTR_ERR(victim);
927 victim, victim->
d_inode ?
"positive" :
"negative");
932 _debug(
"victim is cullable");
941 ret = cachefiles_bury_object(cache, dir, victim,
false);
955 _leave(
" = -ESTALE [absent]");
960 kerror(
"Internal error: %d", ret);
976 struct dentry *victim;
981 victim = cachefiles_check_active(cache, dir, filename);
983 return PTR_ERR(victim);