1 /* CacheFiles path walking and related routines
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/sched.h>
14 #include <linux/file.h>
16 #include <linux/fsnotify.h>
17 #include <linux/quotaops.h>
18 #include <linux/xattr.h>
19 #include <linux/mount.h>
20 #include <linux/namei.h>
21 #include <linux/security.h>
22 #include <linux/slab.h>
25 #define CACHEFILES_KEYBUF_SIZE 512
28 * dump debugging info about an object
31 void __cachefiles_printk_object(struct cachefiles_object
*object
,
35 struct fscache_cookie
*cookie
;
36 unsigned keylen
, loop
;
38 printk(KERN_ERR
"%sobject: OBJ%x\n",
39 prefix
, object
->fscache
.debug_id
);
40 printk(KERN_ERR
"%sobjstate=%s fl=%lx swfl=%lx ev=%lx[%lx]\n",
41 prefix
, fscache_object_states
[object
->fscache
.state
],
42 object
->fscache
.flags
, object
->fscache
.work
.flags
,
43 object
->fscache
.events
,
44 object
->fscache
.event_mask
& FSCACHE_OBJECT_EVENTS_MASK
);
45 printk(KERN_ERR
"%sops=%u inp=%u exc=%u\n",
46 prefix
, object
->fscache
.n_ops
, object
->fscache
.n_in_progress
,
47 object
->fscache
.n_exclusive
);
48 printk(KERN_ERR
"%sparent=%p\n",
49 prefix
, object
->fscache
.parent
);
51 spin_lock(&object
->fscache
.lock
);
52 cookie
= object
->fscache
.cookie
;
54 printk(KERN_ERR
"%scookie=%p [pr=%p nd=%p fl=%lx]\n",
56 object
->fscache
.cookie
,
57 object
->fscache
.cookie
->parent
,
58 object
->fscache
.cookie
->netfs_data
,
59 object
->fscache
.cookie
->flags
);
61 keylen
= cookie
->def
->get_key(cookie
->netfs_data
, keybuf
,
62 CACHEFILES_KEYBUF_SIZE
);
66 printk(KERN_ERR
"%scookie=NULL\n", prefix
);
69 spin_unlock(&object
->fscache
.lock
);
72 printk(KERN_ERR
"%skey=[%u] '", prefix
, keylen
);
73 for (loop
= 0; loop
< keylen
; loop
++)
74 printk("%02x", keybuf
[loop
]);
80 * dump debugging info about a pair of objects
82 static noinline
void cachefiles_printk_object(struct cachefiles_object
*object
,
83 struct cachefiles_object
*xobject
)
87 keybuf
= kmalloc(CACHEFILES_KEYBUF_SIZE
, GFP_NOIO
);
89 __cachefiles_printk_object(object
, "", keybuf
);
91 __cachefiles_printk_object(xobject
, "x", keybuf
);
96 * mark the owner of a dentry, if there is one, to indicate that that dentry
97 * has been preemptively deleted
98 * - the caller must hold the i_mutex on the dentry's parent as required to
99 * call vfs_unlink(), vfs_rmdir() or vfs_rename()
101 static void cachefiles_mark_object_buried(struct cachefiles_cache
*cache
,
102 struct dentry
*dentry
)
104 struct cachefiles_object
*object
;
108 dentry
->d_name
.len
, dentry
->d_name
.len
, dentry
->d_name
.name
);
110 write_lock(&cache
->active_lock
);
112 p
= cache
->active_nodes
.rb_node
;
114 object
= rb_entry(p
, struct cachefiles_object
, active_node
);
115 if (object
->dentry
> dentry
)
117 else if (object
->dentry
< dentry
)
123 write_unlock(&cache
->active_lock
);
124 _leave(" [no owner]");
127 /* found the dentry for */
129 kdebug("preemptive burial: OBJ%x [%s] %p",
130 object
->fscache
.debug_id
,
131 fscache_object_states
[object
->fscache
.state
],
134 if (object
->fscache
.state
< FSCACHE_OBJECT_DYING
) {
135 printk(KERN_ERR
"\n");
136 printk(KERN_ERR
"CacheFiles: Error:"
137 " Can't preemptively bury live object\n");
138 cachefiles_printk_object(object
, NULL
);
139 } else if (test_and_set_bit(CACHEFILES_OBJECT_BURIED
, &object
->flags
)) {
140 printk(KERN_ERR
"CacheFiles: Error:"
141 " Object already preemptively buried\n");
144 write_unlock(&cache
->active_lock
);
145 _leave(" [owner marked]");
149 * record the fact that an object is now active
151 static int cachefiles_mark_object_active(struct cachefiles_cache
*cache
,
152 struct cachefiles_object
*object
)
154 struct cachefiles_object
*xobject
;
155 struct rb_node
**_p
, *_parent
= NULL
;
156 struct dentry
*dentry
;
158 _enter(",%p", object
);
161 write_lock(&cache
->active_lock
);
163 if (test_and_set_bit(CACHEFILES_OBJECT_ACTIVE
, &object
->flags
)) {
164 printk(KERN_ERR
"CacheFiles: Error: Object already active\n");
165 cachefiles_printk_object(object
, NULL
);
169 dentry
= object
->dentry
;
170 _p
= &cache
->active_nodes
.rb_node
;
173 xobject
= rb_entry(_parent
,
174 struct cachefiles_object
, active_node
);
176 ASSERT(xobject
!= object
);
178 if (xobject
->dentry
> dentry
)
179 _p
= &(*_p
)->rb_left
;
180 else if (xobject
->dentry
< dentry
)
181 _p
= &(*_p
)->rb_right
;
183 goto wait_for_old_object
;
186 rb_link_node(&object
->active_node
, _parent
, _p
);
187 rb_insert_color(&object
->active_node
, &cache
->active_nodes
);
189 write_unlock(&cache
->active_lock
);
193 /* an old object from a previous incarnation is hogging the slot - we
194 * need to wait for it to be destroyed */
196 if (xobject
->fscache
.state
< FSCACHE_OBJECT_DYING
) {
197 printk(KERN_ERR
"\n");
198 printk(KERN_ERR
"CacheFiles: Error:"
199 " Unexpected object collision\n");
200 cachefiles_printk_object(object
, xobject
);
203 atomic_inc(&xobject
->usage
);
204 write_unlock(&cache
->active_lock
);
206 if (test_bit(CACHEFILES_OBJECT_ACTIVE
, &xobject
->flags
)) {
207 wait_queue_head_t
*wq
;
209 signed long timeout
= 60 * HZ
;
213 /* if the object we're waiting for is queued for processing,
214 * then just put ourselves on the queue behind it */
215 if (slow_work_is_queued(&xobject
->fscache
.work
)) {
216 _debug("queue OBJ%x behind OBJ%x immediately",
217 object
->fscache
.debug_id
,
218 xobject
->fscache
.debug_id
);
222 /* otherwise we sleep until either the object we're waiting for
223 * is done, or the slow-work facility wants the thread back to
225 wq
= bit_waitqueue(&xobject
->flags
, CACHEFILES_OBJECT_ACTIVE
);
229 prepare_to_wait(wq
, &wait
, TASK_UNINTERRUPTIBLE
);
230 if (!test_bit(CACHEFILES_OBJECT_ACTIVE
, &xobject
->flags
))
232 requeue
= slow_work_sleep_till_thread_needed(
233 &object
->fscache
.work
, &timeout
);
234 } while (timeout
> 0 && !requeue
);
235 finish_wait(wq
, &wait
);
238 test_bit(CACHEFILES_OBJECT_ACTIVE
, &xobject
->flags
)) {
239 _debug("queue OBJ%x behind OBJ%x after wait",
240 object
->fscache
.debug_id
,
241 xobject
->fscache
.debug_id
);
246 printk(KERN_ERR
"\n");
247 printk(KERN_ERR
"CacheFiles: Error: Overlong"
248 " wait for old active object to go away\n");
249 cachefiles_printk_object(object
, xobject
);
254 ASSERT(!test_bit(CACHEFILES_OBJECT_ACTIVE
, &xobject
->flags
));
256 cache
->cache
.ops
->put_object(&xobject
->fscache
);
260 clear_bit(CACHEFILES_OBJECT_ACTIVE
, &object
->flags
);
261 cache
->cache
.ops
->put_object(&xobject
->fscache
);
262 _leave(" = -ETIMEDOUT");
267 * delete an object representation from the cache
268 * - file backed objects are unlinked
269 * - directory backed objects are stuffed into the graveyard for userspace to
271 * - unlocks the directory mutex
273 static int cachefiles_bury_object(struct cachefiles_cache
*cache
,
278 struct dentry
*grave
, *trap
;
279 char nbuffer
[8 + 8 + 1];
282 _enter(",'%*.*s','%*.*s'",
283 dir
->d_name
.len
, dir
->d_name
.len
, dir
->d_name
.name
,
284 rep
->d_name
.len
, rep
->d_name
.len
, rep
->d_name
.name
);
286 _debug("remove %p from %p", rep
, dir
);
288 /* non-directories can just be unlinked */
289 if (!S_ISDIR(rep
->d_inode
->i_mode
)) {
290 _debug("unlink stale object");
291 ret
= vfs_unlink(dir
->d_inode
, rep
);
294 cachefiles_mark_object_buried(cache
, rep
);
296 mutex_unlock(&dir
->d_inode
->i_mutex
);
299 cachefiles_io_error(cache
, "Unlink failed");
301 _leave(" = %d", ret
);
305 /* directories have to be moved to the graveyard */
306 _debug("move stale object to graveyard");
307 mutex_unlock(&dir
->d_inode
->i_mutex
);
310 /* first step is to make up a grave dentry in the graveyard */
311 sprintf(nbuffer
, "%08x%08x",
312 (uint32_t) get_seconds(),
313 (uint32_t) atomic_inc_return(&cache
->gravecounter
));
315 /* do the multiway lock magic */
316 trap
= lock_rename(cache
->graveyard
, dir
);
318 /* do some checks before getting the grave dentry */
319 if (rep
->d_parent
!= dir
) {
320 /* the entry was probably culled when we dropped the parent dir
322 unlock_rename(cache
->graveyard
, dir
);
323 _leave(" = 0 [culled?]");
327 if (!S_ISDIR(cache
->graveyard
->d_inode
->i_mode
)) {
328 unlock_rename(cache
->graveyard
, dir
);
329 cachefiles_io_error(cache
, "Graveyard no longer a directory");
334 unlock_rename(cache
->graveyard
, dir
);
335 cachefiles_io_error(cache
, "May not make directory loop");
339 if (d_mountpoint(rep
)) {
340 unlock_rename(cache
->graveyard
, dir
);
341 cachefiles_io_error(cache
, "Mountpoint in cache");
345 grave
= lookup_one_len(nbuffer
, cache
->graveyard
, strlen(nbuffer
));
347 unlock_rename(cache
->graveyard
, dir
);
349 if (PTR_ERR(grave
) == -ENOMEM
) {
350 _leave(" = -ENOMEM");
354 cachefiles_io_error(cache
, "Lookup error %ld",
359 if (grave
->d_inode
) {
360 unlock_rename(cache
->graveyard
, dir
);
367 if (d_mountpoint(grave
)) {
368 unlock_rename(cache
->graveyard
, dir
);
370 cachefiles_io_error(cache
, "Mountpoint in graveyard");
374 /* target should not be an ancestor of source */
376 unlock_rename(cache
->graveyard
, dir
);
378 cachefiles_io_error(cache
, "May not make directory loop");
382 /* attempt the rename */
383 ret
= vfs_rename(dir
->d_inode
, rep
, cache
->graveyard
->d_inode
, grave
);
384 if (ret
!= 0 && ret
!= -ENOMEM
)
385 cachefiles_io_error(cache
, "Rename failed with error %d", ret
);
388 cachefiles_mark_object_buried(cache
, rep
);
390 unlock_rename(cache
->graveyard
, dir
);
397 * delete an object representation from the cache
399 int cachefiles_delete_object(struct cachefiles_cache
*cache
,
400 struct cachefiles_object
*object
)
405 _enter(",OBJ%x{%p}", object
->fscache
.debug_id
, object
->dentry
);
407 ASSERT(object
->dentry
);
408 ASSERT(object
->dentry
->d_inode
);
409 ASSERT(object
->dentry
->d_parent
);
411 dir
= dget_parent(object
->dentry
);
413 mutex_lock_nested(&dir
->d_inode
->i_mutex
, I_MUTEX_PARENT
);
415 if (test_bit(CACHEFILES_OBJECT_BURIED
, &object
->flags
)) {
416 /* object allocation for the same key preemptively deleted this
417 * object's file so that it could create its own file */
418 _debug("object preemptively buried");
419 mutex_unlock(&dir
->d_inode
->i_mutex
);
422 /* we need to check that our parent is _still_ our parent - it
423 * may have been renamed */
424 if (dir
== object
->dentry
->d_parent
) {
425 ret
= cachefiles_bury_object(cache
, dir
,
426 object
->dentry
, false);
428 /* it got moved, presumably by cachefilesd culling it,
429 * so it's no longer in the key path and we can ignore
431 mutex_unlock(&dir
->d_inode
->i_mutex
);
437 _leave(" = %d", ret
);
442 * walk from the parent object to the child object through the backing
443 * filesystem, creating directories as we go
445 int cachefiles_walk_to_object(struct cachefiles_object
*parent
,
446 struct cachefiles_object
*object
,
448 struct cachefiles_xattr
*auxdata
)
450 struct cachefiles_cache
*cache
;
451 struct dentry
*dir
, *next
= NULL
;
456 _enter("OBJ%x{%p},OBJ%x,%s,",
457 parent
->fscache
.debug_id
, parent
->dentry
,
458 object
->fscache
.debug_id
, key
);
460 cache
= container_of(parent
->fscache
.cache
,
461 struct cachefiles_cache
, cache
);
463 ASSERT(parent
->dentry
);
464 ASSERT(parent
->dentry
->d_inode
);
466 if (!(S_ISDIR(parent
->dentry
->d_inode
->i_mode
))) {
467 // TODO: convert file to dir
468 _leave("looking up in none directory");
472 dir
= dget(parent
->dentry
);
475 /* attempt to transit the first directory component */
479 /* key ends in a double NUL */
480 key
= key
+ nlen
+ 1;
485 /* search the current directory for the element name */
486 _debug("lookup '%s'", name
);
488 mutex_lock_nested(&dir
->d_inode
->i_mutex
, I_MUTEX_PARENT
);
491 next
= lookup_one_len(name
, dir
, nlen
);
492 cachefiles_hist(cachefiles_lookup_histogram
, start
);
496 _debug("next -> %p %s", next
, next
->d_inode
? "positive" : "negative");
499 object
->new = !next
->d_inode
;
501 /* if this element of the path doesn't exist, then the lookup phase
502 * failed, and we can release any readers in the certain knowledge that
503 * there's nothing for them to actually read */
505 fscache_object_lookup_negative(&object
->fscache
);
507 /* we need to create the object if it's negative */
508 if (key
|| object
->type
== FSCACHE_COOKIE_TYPE_INDEX
) {
509 /* index objects and intervening tree levels must be subdirs */
510 if (!next
->d_inode
) {
511 ret
= cachefiles_has_space(cache
, 1, 0);
516 ret
= vfs_mkdir(dir
->d_inode
, next
, 0);
517 cachefiles_hist(cachefiles_mkdir_histogram
, start
);
521 ASSERT(next
->d_inode
);
523 _debug("mkdir -> %p{%p{ino=%lu}}",
524 next
, next
->d_inode
, next
->d_inode
->i_ino
);
526 } else if (!S_ISDIR(next
->d_inode
->i_mode
)) {
527 kerror("inode %lu is not a directory",
528 next
->d_inode
->i_ino
);
534 /* non-index objects start out life as files */
535 if (!next
->d_inode
) {
536 ret
= cachefiles_has_space(cache
, 1, 0);
541 ret
= vfs_create(dir
->d_inode
, next
, S_IFREG
, NULL
);
542 cachefiles_hist(cachefiles_create_histogram
, start
);
546 ASSERT(next
->d_inode
);
548 _debug("create -> %p{%p{ino=%lu}}",
549 next
, next
->d_inode
, next
->d_inode
->i_ino
);
551 } else if (!S_ISDIR(next
->d_inode
->i_mode
) &&
552 !S_ISREG(next
->d_inode
->i_mode
)
554 kerror("inode %lu is not a file or directory",
555 next
->d_inode
->i_ino
);
561 /* process the next component */
564 mutex_unlock(&dir
->d_inode
->i_mutex
);
571 /* we've found the object we were looking for */
572 object
->dentry
= next
;
574 /* if we've found that the terminal object exists, then we need to
575 * check its attributes and delete it if it's out of date */
577 _debug("validate '%*.*s'",
578 next
->d_name
.len
, next
->d_name
.len
, next
->d_name
.name
);
580 ret
= cachefiles_check_object_xattr(object
, auxdata
);
581 if (ret
== -ESTALE
) {
582 /* delete the object (the deleter drops the directory
584 object
->dentry
= NULL
;
586 ret
= cachefiles_bury_object(cache
, dir
, next
, true);
593 _debug("redo lookup");
598 /* note that we're now using this object */
599 ret
= cachefiles_mark_object_active(cache
, object
);
601 mutex_unlock(&dir
->d_inode
->i_mutex
);
605 if (ret
== -ETIMEDOUT
)
606 goto mark_active_timed_out
;
608 _debug("=== OBTAINED_OBJECT ===");
611 /* attach data to a newly constructed terminal object */
612 ret
= cachefiles_set_object_xattr(object
, auxdata
);
616 /* always update the atime on an object we've just looked up
617 * (this is used to keep track of culling, and atimes are only
618 * updated by read, write and readdir but not lookup or
620 touch_atime(cache
->mnt
, next
);
623 /* open a file interface onto a data file */
624 if (object
->type
!= FSCACHE_COOKIE_TYPE_INDEX
) {
625 if (S_ISREG(object
->dentry
->d_inode
->i_mode
)) {
626 const struct address_space_operations
*aops
;
629 aops
= object
->dentry
->d_inode
->i_mapping
->a_ops
;
633 object
->backer
= object
->dentry
;
635 BUG(); // TODO: open file in data-class subdir
640 fscache_obtained_object(&object
->fscache
);
642 _leave(" = 0 [%lu]", object
->dentry
->d_inode
->i_ino
);
646 _debug("create error %d", ret
);
648 cachefiles_io_error(cache
, "Create/mkdir failed");
651 mark_active_timed_out
:
652 _debug("mark active timed out");
656 _debug("check error %d", ret
);
657 write_lock(&cache
->active_lock
);
658 rb_erase(&object
->active_node
, &cache
->active_nodes
);
659 clear_bit(CACHEFILES_OBJECT_ACTIVE
, &object
->flags
);
660 wake_up_bit(&object
->flags
, CACHEFILES_OBJECT_ACTIVE
);
661 write_unlock(&cache
->active_lock
);
663 dput(object
->dentry
);
664 object
->dentry
= NULL
;
668 _debug("delete error %d", ret
);
672 _debug("lookup error %ld", PTR_ERR(next
));
675 cachefiles_io_error(cache
, "Lookup failed");
678 mutex_unlock(&dir
->d_inode
->i_mutex
);
683 _leave(" = error %d", -ret
);
690 struct dentry
*cachefiles_get_directory(struct cachefiles_cache
*cache
,
694 struct dentry
*subdir
;
698 _enter(",,%s", dirname
);
700 /* search the current directory for the element name */
701 mutex_lock(&dir
->d_inode
->i_mutex
);
704 subdir
= lookup_one_len(dirname
, dir
, strlen(dirname
));
705 cachefiles_hist(cachefiles_lookup_histogram
, start
);
706 if (IS_ERR(subdir
)) {
707 if (PTR_ERR(subdir
) == -ENOMEM
)
712 _debug("subdir -> %p %s",
713 subdir
, subdir
->d_inode
? "positive" : "negative");
715 /* we need to create the subdir if it doesn't exist yet */
716 if (!subdir
->d_inode
) {
717 ret
= cachefiles_has_space(cache
, 1, 0);
721 _debug("attempt mkdir");
723 ret
= vfs_mkdir(dir
->d_inode
, subdir
, 0700);
727 ASSERT(subdir
->d_inode
);
729 _debug("mkdir -> %p{%p{ino=%lu}}",
732 subdir
->d_inode
->i_ino
);
735 mutex_unlock(&dir
->d_inode
->i_mutex
);
737 /* we need to make sure the subdir is a directory */
738 ASSERT(subdir
->d_inode
);
740 if (!S_ISDIR(subdir
->d_inode
->i_mode
)) {
741 kerror("%s is not a directory", dirname
);
747 if (!subdir
->d_inode
->i_op
||
748 !subdir
->d_inode
->i_op
->setxattr
||
749 !subdir
->d_inode
->i_op
->getxattr
||
750 !subdir
->d_inode
->i_op
->lookup
||
751 !subdir
->d_inode
->i_op
->mkdir
||
752 !subdir
->d_inode
->i_op
->create
||
753 !subdir
->d_inode
->i_op
->rename
||
754 !subdir
->d_inode
->i_op
->rmdir
||
755 !subdir
->d_inode
->i_op
->unlink
)
758 _leave(" = [%lu]", subdir
->d_inode
->i_ino
);
763 _leave(" = %d [check]", ret
);
767 mutex_unlock(&dir
->d_inode
->i_mutex
);
769 kerror("mkdir %s failed with error %d", dirname
, ret
);
773 mutex_unlock(&dir
->d_inode
->i_mutex
);
774 ret
= PTR_ERR(subdir
);
775 kerror("Lookup %s failed with error %d", dirname
, ret
);
779 mutex_unlock(&dir
->d_inode
->i_mutex
);
780 _leave(" = -ENOMEM");
781 return ERR_PTR(-ENOMEM
);
785 * find out if an object is in use or not
786 * - if finds object and it's not in use:
787 * - returns a pointer to the object and a reference on it
788 * - returns with the directory locked
790 static struct dentry
*cachefiles_check_active(struct cachefiles_cache
*cache
,
794 struct cachefiles_object
*object
;
796 struct dentry
*victim
;
800 //_enter(",%*.*s/,%s",
801 // dir->d_name.len, dir->d_name.len, dir->d_name.name, filename);
803 /* look up the victim */
804 mutex_lock_nested(&dir
->d_inode
->i_mutex
, 1);
807 victim
= lookup_one_len(filename
, dir
, strlen(filename
));
808 cachefiles_hist(cachefiles_lookup_histogram
, start
);
812 //_debug("victim -> %p %s",
813 // victim, victim->d_inode ? "positive" : "negative");
815 /* if the object is no longer there then we probably retired the object
816 * at the netfs's request whilst the cull was in progress
818 if (!victim
->d_inode
) {
819 mutex_unlock(&dir
->d_inode
->i_mutex
);
821 _leave(" = -ENOENT [absent]");
822 return ERR_PTR(-ENOENT
);
825 /* check to see if we're using this object */
826 read_lock(&cache
->active_lock
);
828 _n
= cache
->active_nodes
.rb_node
;
831 object
= rb_entry(_n
, struct cachefiles_object
, active_node
);
833 if (object
->dentry
> victim
)
835 else if (object
->dentry
< victim
)
841 read_unlock(&cache
->active_lock
);
843 //_leave(" = %p", victim);
847 read_unlock(&cache
->active_lock
);
848 mutex_unlock(&dir
->d_inode
->i_mutex
);
850 //_leave(" = -EBUSY [in use]");
851 return ERR_PTR(-EBUSY
);
854 mutex_unlock(&dir
->d_inode
->i_mutex
);
855 ret
= PTR_ERR(victim
);
856 if (ret
== -ENOENT
) {
857 /* file or dir now absent - probably retired by netfs */
858 _leave(" = -ESTALE [absent]");
859 return ERR_PTR(-ESTALE
);
863 cachefiles_io_error(cache
, "Lookup failed");
864 } else if (ret
!= -ENOMEM
) {
865 kerror("Internal error: %d", ret
);
869 _leave(" = %d", ret
);
874 * cull an object if it's not in use
875 * - called only by cache manager daemon
877 int cachefiles_cull(struct cachefiles_cache
*cache
, struct dentry
*dir
,
880 struct dentry
*victim
;
884 dir
->d_name
.len
, dir
->d_name
.len
, dir
->d_name
.name
, filename
);
886 victim
= cachefiles_check_active(cache
, dir
, filename
);
888 return PTR_ERR(victim
);
890 _debug("victim -> %p %s",
891 victim
, victim
->d_inode
? "positive" : "negative");
893 /* okay... the victim is not being used so we can cull it
894 * - start by marking it as stale
896 _debug("victim is cullable");
898 ret
= cachefiles_remove_object_xattr(cache
, victim
);
902 /* actually remove the victim (drops the dir mutex) */
905 ret
= cachefiles_bury_object(cache
, dir
, victim
, false);
914 mutex_unlock(&dir
->d_inode
->i_mutex
);
917 if (ret
== -ENOENT
) {
918 /* file or dir now absent - probably retired by netfs */
919 _leave(" = -ESTALE [absent]");
923 if (ret
!= -ENOMEM
) {
924 kerror("Internal error: %d", ret
);
928 _leave(" = %d", ret
);
933 * find out if an object is in use or not
934 * - called only by cache manager daemon
935 * - returns -EBUSY or 0 to indicate whether an object is in use or not
937 int cachefiles_check_in_use(struct cachefiles_cache
*cache
, struct dentry
*dir
,
940 struct dentry
*victim
;
942 //_enter(",%*.*s/,%s",
943 // dir->d_name.len, dir->d_name.len, dir->d_name.name, filename);
945 victim
= cachefiles_check_active(cache
, dir
, filename
);
947 return PTR_ERR(victim
);
949 mutex_unlock(&dir
->d_inode
->i_mutex
);