Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'fscache-fixes' into for-next

Al Viro 8ea3a7c0 a6de82ca

+397 -203
+23
Documentation/filesystems/caching/backend-api.txt
··· 676 676 as possible. 677 677 678 678 679 + (*) Indicate that a stale object was found and discarded: 680 + 681 + void fscache_object_retrying_stale(struct fscache_object *object); 682 + 683 + This is called to indicate that the lookup procedure found an object in 684 + the cache that the netfs decided was stale. The object has been 685 + discarded from the cache and the lookup will be performed again. 686 + 687 + 688 + (*) Indicate that the caching backend killed an object: 689 + 690 + void fscache_object_mark_killed(struct fscache_object *object, 691 + enum fscache_why_object_killed why); 692 + 693 + This is called to indicate that the cache backend preemptively killed an 694 + object. The why parameter should be set to indicate the reason: 695 + 696 + FSCACHE_OBJECT_IS_STALE - the object was stale and needs discarding. 697 + FSCACHE_OBJECT_NO_SPACE - there was insufficient cache space 698 + FSCACHE_OBJECT_WAS_RETIRED - the object was retired when relinquished. 699 + FSCACHE_OBJECT_WAS_CULLED - the object was culled to make space. 700 + 701 + 679 702 (*) Get and release references on a retrieval record: 680 703 681 704 void fscache_get_retrieval(struct fscache_retrieval *op);
+6 -1
Documentation/filesystems/caching/fscache.txt
··· 284 284 enq=N Number of times async ops queued for processing 285 285 can=N Number of async ops cancelled 286 286 rej=N Number of async ops rejected due to object lookup/create failure 287 + ini=N Number of async ops initialised 287 288 dfr=N Number of async ops queued for deferred release 288 - rel=N Number of async ops released 289 + rel=N Number of async ops released (should equal ini=N when idle) 289 290 gc=N Number of deferred-release async ops garbage collected 290 291 CacheOp alo=N Number of in-progress alloc_object() cache ops 291 292 luo=N Number of in-progress lookup_object() cache ops ··· 304 303 wrp=N Number of in-progress write_page() cache ops 305 304 ucp=N Number of in-progress uncache_page() cache ops 306 305 dsp=N Number of in-progress dissociate_pages() cache ops 306 + CacheEv nsp=N Number of object lookups/creations rejected due to lack of space 307 + stl=N Number of stale objects deleted 308 + rtr=N Number of objects retired when relinquished 309 + cul=N Number of objects culled 307 310 308 311 309 312 (*) /proc/fs/fscache/histogram
-1
fs/cachefiles/internal.h
··· 43 43 loff_t i_size; /* object size */ 44 44 unsigned long flags; 45 45 #define CACHEFILES_OBJECT_ACTIVE 0 /* T if marked active */ 46 - #define CACHEFILES_OBJECT_BURIED 1 /* T if preemptively buried */ 47 46 atomic_t usage; /* object usage count */ 48 47 uint8_t type; /* object type */ 49 48 uint8_t new; /* T if object new */
+21 -12
fs/cachefiles/namei.c
··· 97 97 * call vfs_unlink(), vfs_rmdir() or vfs_rename() 98 98 */ 99 99 static void cachefiles_mark_object_buried(struct cachefiles_cache *cache, 100 - struct dentry *dentry) 100 + struct dentry *dentry, 101 + enum fscache_why_object_killed why) 101 102 { 102 103 struct cachefiles_object *object; 103 104 struct rb_node *p; ··· 133 132 pr_err("\n"); 134 133 pr_err("Error: Can't preemptively bury live object\n"); 135 134 cachefiles_printk_object(object, NULL); 136 - } else if (test_and_set_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) { 137 - pr_err("Error: Object already preemptively buried\n"); 135 + } else { 136 + if (why != FSCACHE_OBJECT_IS_STALE) 137 + fscache_object_mark_killed(&object->fscache, why); 138 138 } 139 139 140 140 write_unlock(&cache->active_lock); ··· 267 265 static int cachefiles_bury_object(struct cachefiles_cache *cache, 268 266 struct dentry *dir, 269 267 struct dentry *rep, 270 - bool preemptive) 268 + bool preemptive, 269 + enum fscache_why_object_killed why) 271 270 { 272 271 struct dentry *grave, *trap; 273 272 struct path path, path_to_graveyard; ··· 292 289 ret = vfs_unlink(d_inode(dir), rep, NULL); 293 290 294 291 if (preemptive) 295 - cachefiles_mark_object_buried(cache, rep); 292 + cachefiles_mark_object_buried(cache, rep, why); 296 293 } 297 294 298 295 mutex_unlock(&d_inode(dir)->i_mutex); ··· 397 394 "Rename failed with error %d", ret); 398 395 399 396 if (preemptive) 400 - cachefiles_mark_object_buried(cache, rep); 397 + cachefiles_mark_object_buried(cache, rep, why); 401 398 } 402 399 403 400 unlock_rename(cache->graveyard, dir); ··· 425 422 426 423 mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT); 427 424 428 - if (test_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) { 425 + if (test_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->fscache.flags)) { 429 426 /* object allocation for the same key preemptively deleted this 430 427 * object's file so that it could create its own file */ 431 428 _debug("object preemptively buried"); ··· 436 433 * may have been renamed */ 437 434 if (dir == object->dentry->d_parent) { 438 435 ret = cachefiles_bury_object(cache, dir, 439 - object->dentry, false); 436 + object->dentry, false, 437 + FSCACHE_OBJECT_WAS_RETIRED); 440 438 } else { 441 439 /* it got moved, presumably by cachefilesd culling it, 442 440 * so it's no longer in the key path and we can ignore ··· 526 522 if (d_is_negative(next)) { 527 523 ret = cachefiles_has_space(cache, 1, 0); 528 524 if (ret < 0) 529 - goto create_error; 525 + goto no_space_error; 530 526 531 527 path.dentry = dir; 532 528 ret = security_path_mkdir(&path, next, 0); ··· 555 551 if (d_is_negative(next)) { 556 552 ret = cachefiles_has_space(cache, 1, 0); 557 553 if (ret < 0) 558 - goto create_error; 554 + goto no_space_error; 559 555 560 556 path.dentry = dir; 561 557 ret = security_path_mknod(&path, next, S_IFREG, 0); ··· 606 602 * mutex) */ 607 603 object->dentry = NULL; 608 604 609 - ret = cachefiles_bury_object(cache, dir, next, true); 605 + ret = cachefiles_bury_object(cache, dir, next, true, 606 + FSCACHE_OBJECT_IS_STALE); 610 607 dput(next); 611 608 next = NULL; 612 609 ··· 615 610 goto delete_error; 616 611 617 612 _debug("redo lookup"); 613 + fscache_object_retrying_stale(&object->fscache); 618 614 goto lookup_again; 619 615 } 620 616 } ··· 668 662 _leave(" = 0 [%lu]", d_backing_inode(object->dentry)->i_ino); 669 663 return 0; 670 664 665 + no_space_error: 666 + fscache_object_mark_killed(&object->fscache, FSCACHE_OBJECT_NO_SPACE); 671 667 create_error: 672 668 _debug("create error %d", ret); 673 669 if (ret == -EIO) ··· 935 927 /* actually remove the victim (drops the dir mutex) */ 936 928 _debug("bury"); 937 929 938 - ret = cachefiles_bury_object(cache, dir, victim, false); 930 + ret = cachefiles_bury_object(cache, dir, victim, false, 931 + FSCACHE_OBJECT_WAS_CULLED); 939 932 if (ret < 0) 940 933 goto error; 941 934
+4 -4
fs/fscache/cookie.c
··· 327 327 328 328 object_already_extant: 329 329 ret = -ENOBUFS; 330 - if (fscache_object_is_dead(object)) { 330 + if (fscache_object_is_dying(object) || 331 + fscache_cache_is_broken(object)) { 331 332 spin_unlock(&cookie->lock); 332 333 goto error; 333 334 } ··· 672 671 if (!op) 673 672 return -ENOMEM; 674 673 675 - fscache_operation_init(op, NULL, NULL); 674 + fscache_operation_init(op, NULL, NULL, NULL); 676 675 op->flags = FSCACHE_OP_MYTHREAD | 677 676 (1 << FSCACHE_OP_WAITING) | 678 677 (1 << FSCACHE_OP_UNUSE_COOKIE); ··· 696 695 /* the work queue now carries its own ref on the object */ 697 696 spin_unlock(&cookie->lock); 698 697 699 - ret = fscache_wait_for_operation_activation(object, op, 700 - NULL, NULL, NULL); 698 + ret = fscache_wait_for_operation_activation(object, op, NULL, NULL); 701 699 if (ret == 0) { 702 700 /* ask the cache to honour the operation */ 703 701 ret = object->cache->ops->check_consistency(op);
+8 -4
fs/fscache/internal.h
··· 124 124 struct fscache_operation *); 125 125 extern int fscache_submit_op(struct fscache_object *, 126 126 struct fscache_operation *); 127 - extern int fscache_cancel_op(struct fscache_operation *, 128 - void (*)(struct fscache_operation *)); 127 + extern int fscache_cancel_op(struct fscache_operation *, bool); 129 128 extern void fscache_cancel_all_ops(struct fscache_object *); 130 129 extern void fscache_abort_object(struct fscache_object *); 131 130 extern void fscache_start_operations(struct fscache_object *); ··· 137 138 extern int fscache_wait_for_operation_activation(struct fscache_object *, 138 139 struct fscache_operation *, 139 140 atomic_t *, 140 - atomic_t *, 141 - void (*)(struct fscache_operation *)); 141 + atomic_t *); 142 142 extern void fscache_invalidate_writes(struct fscache_cookie *); 143 143 144 144 /* ··· 162 164 extern atomic_t fscache_n_op_run; 163 165 extern atomic_t fscache_n_op_enqueue; 164 166 extern atomic_t fscache_n_op_deferred_release; 167 + extern atomic_t fscache_n_op_initialised; 165 168 extern atomic_t fscache_n_op_release; 166 169 extern atomic_t fscache_n_op_gc; 167 170 extern atomic_t fscache_n_op_cancelled; ··· 269 270 extern atomic_t fscache_n_cop_write_page; 270 271 extern atomic_t fscache_n_cop_uncache_page; 271 272 extern atomic_t fscache_n_cop_dissociate_pages; 273 + 274 + extern atomic_t fscache_n_cache_no_space_reject; 275 + extern atomic_t fscache_n_cache_stale_objects; 276 + extern atomic_t fscache_n_cache_retired_objects; 277 + extern atomic_t fscache_n_cache_culled_objects; 272 278 273 279 static inline void fscache_stat(atomic_t *stat) 274 280 {
+65 -4
fs/fscache/object.c
··· 328 328 EXPORT_SYMBOL(fscache_object_init); 329 329 330 330 /* 331 + * Mark the object as no longer being live, making sure that we synchronise 332 + * against op submission. 333 + */ 334 + static inline void fscache_mark_object_dead(struct fscache_object *object) 335 + { 336 + spin_lock(&object->lock); 337 + clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); 338 + spin_unlock(&object->lock); 339 + } 340 + 341 + /* 331 342 * Abort object initialisation before we start it. 332 343 */ 333 344 static const struct fscache_state *fscache_abort_initialisation(struct fscache_object *object, ··· 621 610 object->cache->ops->lookup_complete(object); 622 611 fscache_stat_d(&fscache_n_cop_lookup_complete); 623 612 613 + set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags); 614 + 624 615 cookie = object->cookie; 625 616 set_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags); 626 617 if (test_and_clear_bit(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags)) ··· 642 629 _enter("{OBJ%x,%d,%d},%d", 643 630 object->debug_id, object->n_ops, object->n_children, event); 644 631 645 - clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); 632 + fscache_mark_object_dead(object); 646 633 object->oob_event_mask = 0; 647 634 648 635 if (list_empty(&object->dependents) && ··· 961 948 if (!op) 962 949 goto nomem; 963 950 964 - fscache_operation_init(op, object->cache->ops->invalidate_object, NULL); 951 + fscache_operation_init(op, object->cache->ops->invalidate_object, 952 + NULL, NULL); 965 953 op->flags = FSCACHE_OP_ASYNC | 966 954 (1 << FSCACHE_OP_EXCLUSIVE) | 967 955 (1 << FSCACHE_OP_UNUSE_COOKIE); ··· 988 974 return transit_to(UPDATE_OBJECT); 989 975 990 976 nomem: 991 - clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); 977 + fscache_mark_object_dead(object); 992 978 fscache_unuse_cookie(object); 993 979 _leave(" [ENOMEM]"); 994 980 return transit_to(KILL_OBJECT); 995 981 996 982 submit_op_failed: 997 - clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); 983 + fscache_mark_object_dead(object); 998 984 spin_unlock(&cookie->lock); 999 985 fscache_unuse_cookie(object); 1000 986 kfree(op); ··· 1030 1016 _leave(""); 1031 1017 return transit_to(WAIT_FOR_CMD); 1032 1018 } 1019 + 1020 + /** 1021 + * fscache_object_retrying_stale - Note retrying stale object 1022 + * @object: The object that will be retried 1023 + * 1024 + * Note that an object lookup found an on-disk object that was adjudged to be 1025 + * stale and has been deleted. The lookup will be retried. 1026 + */ 1027 + void fscache_object_retrying_stale(struct fscache_object *object) 1028 + { 1029 + fscache_stat(&fscache_n_cache_no_space_reject); 1030 + } 1031 + EXPORT_SYMBOL(fscache_object_retrying_stale); 1032 + 1033 + /** 1034 + * fscache_object_mark_killed - Note that an object was killed 1035 + * @object: The object that was culled 1036 + * @why: The reason the object was killed. 1037 + * 1038 + * Note that an object was killed. Returns true if the object was 1039 + * already marked killed, false if it wasn't. 1040 + */ 1041 + void fscache_object_mark_killed(struct fscache_object *object, 1042 + enum fscache_why_object_killed why) 1043 + { 1044 + if (test_and_set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags)) { 1045 + pr_err("Error: Object already killed by cache [%s]\n", 1046 + object->cache->identifier); 1047 + return; 1048 + } 1049 + 1050 + switch (why) { 1051 + case FSCACHE_OBJECT_NO_SPACE: 1052 + fscache_stat(&fscache_n_cache_no_space_reject); 1053 + break; 1054 + case FSCACHE_OBJECT_IS_STALE: 1055 + fscache_stat(&fscache_n_cache_stale_objects); 1056 + break; 1057 + case FSCACHE_OBJECT_WAS_RETIRED: 1058 + fscache_stat(&fscache_n_cache_retired_objects); 1059 + break; 1060 + case FSCACHE_OBJECT_WAS_CULLED: 1061 + fscache_stat(&fscache_n_cache_culled_objects); 1062 + break; 1063 + } 1064 + } 1065 + EXPORT_SYMBOL(fscache_object_mark_killed);
+187 -105
fs/fscache/operation.c
··· 20 20 atomic_t fscache_op_debug_id; 21 21 EXPORT_SYMBOL(fscache_op_debug_id); 22 22 23 + static void fscache_operation_dummy_cancel(struct fscache_operation *op) 24 + { 25 + } 26 + 27 + /** 28 + * fscache_operation_init - Do basic initialisation of an operation 29 + * @op: The operation to initialise 30 + * @release: The release function to assign 31 + * 32 + * Do basic initialisation of an operation. The caller must still set flags, 33 + * object and processor if needed. 34 + */ 35 + void fscache_operation_init(struct fscache_operation *op, 36 + fscache_operation_processor_t processor, 37 + fscache_operation_cancel_t cancel, 38 + fscache_operation_release_t release) 39 + { 40 + INIT_WORK(&op->work, fscache_op_work_func); 41 + atomic_set(&op->usage, 1); 42 + op->state = FSCACHE_OP_ST_INITIALISED; 43 + op->debug_id = atomic_inc_return(&fscache_op_debug_id); 44 + op->processor = processor; 45 + op->cancel = cancel ?: fscache_operation_dummy_cancel; 46 + op->release = release; 47 + INIT_LIST_HEAD(&op->pend_link); 48 + fscache_stat(&fscache_n_op_initialised); 49 + } 50 + EXPORT_SYMBOL(fscache_operation_init); 51 + 23 52 /** 24 53 * fscache_enqueue_operation - Enqueue an operation for processing 25 54 * @op: The operation to enqueue ··· 105 76 } 106 77 107 78 /* 108 - * submit an exclusive operation for an object 109 - * - other ops are excluded from running simultaneously with this one 110 - * - this gets any extra refs it needs on an op 111 - */ 112 - int fscache_submit_exclusive_op(struct fscache_object *object, 113 - struct fscache_operation *op) 114 - { 115 - int ret; 116 - 117 - _enter("{OBJ%x OP%x},", object->debug_id, op->debug_id); 118 - 119 - ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED); 120 - ASSERTCMP(atomic_read(&op->usage), >, 0); 121 - 122 - spin_lock(&object->lock); 123 - ASSERTCMP(object->n_ops, >=, object->n_in_progress); 124 - ASSERTCMP(object->n_ops, >=, object->n_exclusive); 125 - ASSERT(list_empty(&op->pend_link)); 126 - 127 - op->state = FSCACHE_OP_ST_PENDING; 128 - if (fscache_object_is_active(object)) { 129 - op->object = object; 130 - object->n_ops++; 131 - object->n_exclusive++; /* reads and writes must wait */ 132 - 133 - if (object->n_in_progress > 0) { 134 - atomic_inc(&op->usage); 135 - list_add_tail(&op->pend_link, &object->pending_ops); 136 - fscache_stat(&fscache_n_op_pend); 137 - } else if (!list_empty(&object->pending_ops)) { 138 - atomic_inc(&op->usage); 139 - list_add_tail(&op->pend_link, &object->pending_ops); 140 - fscache_stat(&fscache_n_op_pend); 141 - fscache_start_operations(object); 142 - } else { 143 - ASSERTCMP(object->n_in_progress, ==, 0); 144 - fscache_run_op(object, op); 145 - } 146 - 147 - /* need to issue a new write op after this */ 148 - clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); 149 - ret = 0; 150 - } else if (test_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) { 151 - op->object = object; 152 - object->n_ops++; 153 - object->n_exclusive++; /* reads and writes must wait */ 154 - atomic_inc(&op->usage); 155 - list_add_tail(&op->pend_link, &object->pending_ops); 156 - fscache_stat(&fscache_n_op_pend); 157 - ret = 0; 158 - } else { 159 - /* If we're in any other state, there must have been an I/O 160 - * error of some nature. 161 - */ 162 - ASSERT(test_bit(FSCACHE_IOERROR, &object->cache->flags)); 163 - ret = -EIO; 164 - } 165 - 166 - spin_unlock(&object->lock); 167 - return ret; 168 - } 169 - 170 - /* 171 79 * report an unexpected submission 172 80 */ 173 81 static void fscache_report_unexpected_submission(struct fscache_object *object, ··· 142 176 } 143 177 144 178 /* 179 + * submit an exclusive operation for an object 180 + * - other ops are excluded from running simultaneously with this one 181 + * - this gets any extra refs it needs on an op 182 + */ 183 + int fscache_submit_exclusive_op(struct fscache_object *object, 184 + struct fscache_operation *op) 185 + { 186 + const struct fscache_state *ostate; 187 + unsigned long flags; 188 + int ret; 189 + 190 + _enter("{OBJ%x OP%x},", object->debug_id, op->debug_id); 191 + 192 + ASSERTCMP(op->state, ==, FSCACHE_OP_ST_INITIALISED); 193 + ASSERTCMP(atomic_read(&op->usage), >, 0); 194 + 195 + spin_lock(&object->lock); 196 + ASSERTCMP(object->n_ops, >=, object->n_in_progress); 197 + ASSERTCMP(object->n_ops, >=, object->n_exclusive); 198 + ASSERT(list_empty(&op->pend_link)); 199 + 200 + ostate = object->state; 201 + smp_rmb(); 202 + 203 + op->state = FSCACHE_OP_ST_PENDING; 204 + flags = READ_ONCE(object->flags); 205 + if (unlikely(!(flags & BIT(FSCACHE_OBJECT_IS_LIVE)))) { 206 + fscache_stat(&fscache_n_op_rejected); 207 + op->cancel(op); 208 + op->state = FSCACHE_OP_ST_CANCELLED; 209 + ret = -ENOBUFS; 210 + } else if (unlikely(fscache_cache_is_broken(object))) { 211 + op->cancel(op); 212 + op->state = FSCACHE_OP_ST_CANCELLED; 213 + ret = -EIO; 214 + } else if (flags & BIT(FSCACHE_OBJECT_IS_AVAILABLE)) { 215 + op->object = object; 216 + object->n_ops++; 217 + object->n_exclusive++; /* reads and writes must wait */ 218 + 219 + if (object->n_in_progress > 0) { 220 + atomic_inc(&op->usage); 221 + list_add_tail(&op->pend_link, &object->pending_ops); 222 + fscache_stat(&fscache_n_op_pend); 223 + } else if (!list_empty(&object->pending_ops)) { 224 + atomic_inc(&op->usage); 225 + list_add_tail(&op->pend_link, &object->pending_ops); 226 + fscache_stat(&fscache_n_op_pend); 227 + fscache_start_operations(object); 228 + } else { 229 + ASSERTCMP(object->n_in_progress, ==, 0); 230 + fscache_run_op(object, op); 231 + } 232 + 233 + /* need to issue a new write op after this */ 234 + clear_bit(FSCACHE_OBJECT_PENDING_WRITE, &object->flags); 235 + ret = 0; 236 + } else if (flags & BIT(FSCACHE_OBJECT_IS_LOOKED_UP)) { 237 + op->object = object; 238 + object->n_ops++; 239 + object->n_exclusive++; /* reads and writes must wait */ 240 + atomic_inc(&op->usage); 241 + list_add_tail(&op->pend_link, &object->pending_ops); 242 + fscache_stat(&fscache_n_op_pend); 243 + ret = 0; 244 + } else if (flags & BIT(FSCACHE_OBJECT_KILLED_BY_CACHE)) { 245 + op->cancel(op); 246 + op->state = FSCACHE_OP_ST_CANCELLED; 247 + ret = -ENOBUFS; 248 + } else { 249 + fscache_report_unexpected_submission(object, op, ostate); 250 + op->cancel(op); 251 + op->state = FSCACHE_OP_ST_CANCELLED; 252 + ret = -ENOBUFS; 253 + } 254 + 255 + spin_unlock(&object->lock); 256 + return ret; 257 + } 258 + 259 + /* 145 260 * submit an operation for an object 146 261 * - objects may be submitted only in the following states: 147 262 * - during object creation (write ops may be submitted) ··· 234 187 struct fscache_operation *op) 235 188 { 236 189 const struct fscache_state *ostate; 190 + unsigned long flags; 237 191 int ret; 238 192 239 193 _enter("{OBJ%x OP%x},{%u}", ··· 252 204 smp_rmb(); 253 205 254 206 op->state = FSCACHE_OP_ST_PENDING; 255 - if (fscache_object_is_active(object)) { 207 + flags = READ_ONCE(object->flags); 208 + if (unlikely(!(flags & BIT(FSCACHE_OBJECT_IS_LIVE)))) { 209 + fscache_stat(&fscache_n_op_rejected); 210 + op->cancel(op); 211 + op->state = FSCACHE_OP_ST_CANCELLED; 212 + ret = -ENOBUFS; 213 + } else if (unlikely(fscache_cache_is_broken(object))) { 214 + op->cancel(op); 215 + op->state = FSCACHE_OP_ST_CANCELLED; 216 + ret = -EIO; 217 + } else if (flags & BIT(FSCACHE_OBJECT_IS_AVAILABLE)) { 256 218 op->object = object; 257 219 object->n_ops++; 258 220 ··· 280 222 fscache_run_op(object, op); 281 223 } 282 224 ret = 0; 283 - } else if (test_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) { 225 + } else if (flags & BIT(FSCACHE_OBJECT_IS_LOOKED_UP)) { 284 226 op->object = object; 285 227 object->n_ops++; 286 228 atomic_inc(&op->usage); 287 229 list_add_tail(&op->pend_link, &object->pending_ops); 288 230 fscache_stat(&fscache_n_op_pend); 289 231 ret = 0; 290 - } else if (fscache_object_is_dying(object)) { 291 - fscache_stat(&fscache_n_op_rejected); 292 - op->state = FSCACHE_OP_ST_CANCELLED; 293 - ret = -ENOBUFS; 294 - } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) { 295 - fscache_report_unexpected_submission(object, op, ostate); 296 - ASSERT(!fscache_object_is_active(object)); 232 + } else if (flags & BIT(FSCACHE_OBJECT_KILLED_BY_CACHE)) { 233 + op->cancel(op); 297 234 op->state = FSCACHE_OP_ST_CANCELLED; 298 235 ret = -ENOBUFS; 299 236 } else { 237 + fscache_report_unexpected_submission(object, op, ostate); 238 + ASSERT(!fscache_object_is_active(object)); 239 + op->cancel(op); 300 240 op->state = FSCACHE_OP_ST_CANCELLED; 301 241 ret = -ENOBUFS; 302 242 } ··· 349 293 * cancel an operation that's pending on an object 350 294 */ 351 295 int fscache_cancel_op(struct fscache_operation *op, 352 - void (*do_cancel)(struct fscache_operation *)) 296 + bool cancel_in_progress_op) 353 297 { 354 298 struct fscache_object *object = op->object; 299 + bool put = false; 355 300 int ret; 356 301 357 302 _enter("OBJ%x OP%x}", op->object->debug_id, op->debug_id); ··· 366 309 ret = -EBUSY; 367 310 if (op->state == FSCACHE_OP_ST_PENDING) { 368 311 ASSERT(!list_empty(&op->pend_link)); 369 - fscache_stat(&fscache_n_op_cancelled); 370 312 list_del_init(&op->pend_link); 371 - if (do_cancel) 372 - do_cancel(op); 313 + put = true; 314 + 315 + fscache_stat(&fscache_n_op_cancelled); 316 + op->cancel(op); 373 317 op->state = FSCACHE_OP_ST_CANCELLED; 374 318 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags)) 375 319 object->n_exclusive--; 376 320 if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags)) 377 321 wake_up_bit(&op->flags, FSCACHE_OP_WAITING); 378 - fscache_put_operation(op); 322 + ret = 0; 323 + } else if (op->state == FSCACHE_OP_ST_IN_PROGRESS && cancel_in_progress_op) { 324 + ASSERTCMP(object->n_in_progress, >, 0); 325 + if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags)) 326 + object->n_exclusive--; 327 + object->n_in_progress--; 328 + if (object->n_in_progress == 0) 329 + fscache_start_operations(object); 330 + 331 + fscache_stat(&fscache_n_op_cancelled); 332 + op->cancel(op); 333 + op->state = FSCACHE_OP_ST_CANCELLED; 334 + if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags)) 335 + object->n_exclusive--; 336 + if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags)) 337 + wake_up_bit(&op->flags, FSCACHE_OP_WAITING); 379 338 ret = 0; 380 339 } 381 340 341 + if (put) 342 + fscache_put_operation(op); 382 343 spin_unlock(&object->lock); 383 344 _leave(" = %d", ret); 384 345 return ret; ··· 420 345 list_del_init(&op->pend_link); 421 346 422 347 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING); 348 + op->cancel(op); 423 349 op->state = FSCACHE_OP_ST_CANCELLED; 424 350 425 351 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags)) ··· 453 377 454 378 spin_lock(&object->lock); 455 379 456 - op->state = cancelled ? 457 - FSCACHE_OP_ST_CANCELLED : FSCACHE_OP_ST_COMPLETE; 380 + if (!cancelled) { 381 + op->state = FSCACHE_OP_ST_COMPLETE; 382 + } else { 383 + op->cancel(op); 384 + op->state = FSCACHE_OP_ST_CANCELLED; 385 + } 458 386 459 387 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags)) 460 388 object->n_exclusive--; ··· 489 409 return; 490 410 491 411 _debug("PUT OP"); 492 - ASSERTIFCMP(op->state != FSCACHE_OP_ST_COMPLETE, 412 + ASSERTIFCMP(op->state != FSCACHE_OP_ST_INITIALISED && 413 + op->state != FSCACHE_OP_ST_COMPLETE, 493 414 op->state, ==, FSCACHE_OP_ST_CANCELLED); 494 - op->state = FSCACHE_OP_ST_DEAD; 495 415 496 416 fscache_stat(&fscache_n_op_release); 497 417 ··· 499 419 op->release(op); 500 420 op->release = NULL; 501 421 } 422 + op->state = FSCACHE_OP_ST_DEAD; 502 423 503 424 object = op->object; 425 + if (likely(object)) { 426 + if (test_bit(FSCACHE_OP_DEC_READ_CNT, &op->flags)) 427 + atomic_dec(&object->n_reads); 428 + if (test_bit(FSCACHE_OP_UNUSE_COOKIE, &op->flags)) 429 + fscache_unuse_cookie(object); 504 430 505 - if (test_bit(FSCACHE_OP_DEC_READ_CNT, &op->flags)) 506 - atomic_dec(&object->n_reads); 507 - if (test_bit(FSCACHE_OP_UNUSE_COOKIE, &op->flags)) 508 - fscache_unuse_cookie(object); 431 + /* now... we may get called with the object spinlock held, so we 432 + * complete the cleanup here only if we can immediately acquire the 433 + * lock, and defer it otherwise */ 434 + if (!spin_trylock(&object->lock)) { 435 + _debug("defer put"); 436 + fscache_stat(&fscache_n_op_deferred_release); 509 437 510 - /* now... we may get called with the object spinlock held, so we 511 - * complete the cleanup here only if we can immediately acquire the 512 - * lock, and defer it otherwise */ 513 - if (!spin_trylock(&object->lock)) { 514 - _debug("defer put"); 515 - fscache_stat(&fscache_n_op_deferred_release); 438 + cache = object->cache; 439 + spin_lock(&cache->op_gc_list_lock); 440 + list_add_tail(&op->pend_link, &cache->op_gc_list); 441 + spin_unlock(&cache->op_gc_list_lock); 442 + schedule_work(&cache->op_gc); 443 + _leave(" [defer]"); 444 + return; 445 + } 516 446 517 - cache = object->cache; 518 - spin_lock(&cache->op_gc_list_lock); 519 - list_add_tail(&op->pend_link, &cache->op_gc_list); 520 - spin_unlock(&cache->op_gc_list_lock); 521 - schedule_work(&cache->op_gc); 522 - _leave(" [defer]"); 523 - return; 447 + ASSERTCMP(object->n_ops, >, 0); 448 + object->n_ops--; 449 + if (object->n_ops == 0) 450 + fscache_raise_event(object, FSCACHE_OBJECT_EV_CLEARED); 451 + 452 + spin_unlock(&object->lock); 524 453 } 525 - 526 - ASSERTCMP(object->n_ops, >, 0); 527 - object->n_ops--; 528 - if (object->n_ops == 0) 529 - fscache_raise_event(object, FSCACHE_OBJECT_EV_CLEARED); 530 - 531 - spin_unlock(&object->lock); 532 454 533 455 kfree(op); 534 456 _leave(" [done]");
+43 -43
fs/fscache/page.c
··· 213 213 return -ENOMEM; 214 214 } 215 215 216 - fscache_operation_init(op, fscache_attr_changed_op, NULL); 216 + fscache_operation_init(op, fscache_attr_changed_op, NULL, NULL); 217 217 op->flags = FSCACHE_OP_ASYNC | 218 218 (1 << FSCACHE_OP_EXCLUSIVE) | 219 219 (1 << FSCACHE_OP_UNUSE_COOKIE); ··· 239 239 wake_cookie = __fscache_unuse_cookie(cookie); 240 240 nobufs: 241 241 spin_unlock(&cookie->lock); 242 - kfree(op); 242 + fscache_put_operation(op); 243 243 if (wake_cookie) 244 244 __fscache_wake_unused_cookie(cookie); 245 245 fscache_stat(&fscache_n_attr_changed_nobufs); ··· 247 247 return -ENOBUFS; 248 248 } 249 249 EXPORT_SYMBOL(__fscache_attr_changed); 250 + 251 + /* 252 + * Handle cancellation of a pending retrieval op 253 + */ 254 + static void fscache_do_cancel_retrieval(struct fscache_operation *_op) 255 + { 256 + struct fscache_retrieval *op = 257 + container_of(_op, struct fscache_retrieval, op); 258 + 259 + atomic_set(&op->n_pages, 0); 260 + } 250 261 251 262 /* 252 263 * release a retrieval op reference ··· 269 258 270 259 _enter("{OP%x}", op->op.debug_id); 271 260 272 - ASSERTCMP(atomic_read(&op->n_pages), ==, 0); 261 + ASSERTIFCMP(op->op.state != FSCACHE_OP_ST_INITIALISED, 262 + atomic_read(&op->n_pages), ==, 0); 273 263 274 264 fscache_hist(fscache_retrieval_histogram, op->start_time); 275 265 if (op->context) 276 - fscache_put_context(op->op.object->cookie, op->context); 266 + fscache_put_context(op->cookie, op->context); 277 267 278 268 _leave(""); 279 269 } ··· 297 285 return NULL; 298 286 } 299 287 300 - fscache_operation_init(&op->op, NULL, fscache_release_retrieval_op); 288 + fscache_operation_init(&op->op, NULL, 289 + fscache_do_cancel_retrieval, 290 + fscache_release_retrieval_op); 301 291 op->op.flags = FSCACHE_OP_MYTHREAD | 302 292 (1UL << FSCACHE_OP_WAITING) | 303 293 (1UL << FSCACHE_OP_UNUSE_COOKIE); 294 + op->cookie = cookie; 304 295 op->mapping = mapping; 305 296 op->end_io_func = end_io_func; 306 297 op->context = context; 307 298 op->start_time = jiffies; 308 299 INIT_LIST_HEAD(&op->to_do); 300 + 301 + /* Pin the netfs read context in case we need to do the actual netfs 302 + * read because we've encountered a cache read failure. 303 + */ 304 + if (context) 305 + fscache_get_context(op->cookie, context); 309 306 return op; 310 307 } 311 308 ··· 351 330 } 352 331 353 332 /* 354 - * Handle cancellation of a pending retrieval op 355 - */ 356 - static void fscache_do_cancel_retrieval(struct fscache_operation *_op) 357 - { 358 - struct fscache_retrieval *op = 359 - container_of(_op, struct fscache_retrieval, op); 360 - 361 - atomic_set(&op->n_pages, 0); 362 - } 363 - 364 - /* 365 333 * wait for an object to become active (or dead) 366 334 */ 367 335 int fscache_wait_for_operation_activation(struct fscache_object *object, 368 336 struct fscache_operation *op, 369 337 atomic_t *stat_op_waits, 370 - atomic_t *stat_object_dead, 371 - void (*do_cancel)(struct fscache_operation *)) 338 + atomic_t *stat_object_dead) 372 339 { 373 340 int ret; 374 341 ··· 368 359 fscache_stat(stat_op_waits); 369 360 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING, 370 361 TASK_INTERRUPTIBLE) != 0) { 371 - ret = fscache_cancel_op(op, do_cancel); 362 + ret = fscache_cancel_op(op, false); 372 363 if (ret == 0) 373 364 return -ERESTARTSYS; 374 365 ··· 386 377 _leave(" = -ENOBUFS [cancelled]"); 387 378 return -ENOBUFS; 388 379 } 389 - if (unlikely(fscache_object_is_dead(object))) { 390 - pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state); 391 - fscache_cancel_op(op, do_cancel); 380 + if (unlikely(fscache_object_is_dying(object) || 381 + fscache_cache_is_broken(object))) { 382 + enum fscache_operation_state state = op->state; 383 + fscache_cancel_op(op, true); 392 384 if (stat_object_dead) 393 385 fscache_stat(stat_object_dead); 386 + _leave(" = -ENOBUFS [obj dead %d]", state); 394 387 return -ENOBUFS; 395 388 } 396 389 return 0; ··· 464 453 465 454 fscache_stat(&fscache_n_retrieval_ops); 466 455 467 - /* pin the netfs read context in case we need to do the actual netfs 468 - * read because we've encountered a cache read failure */ 469 - fscache_get_context(object->cookie, op->context); 470 - 471 456 /* we wait for the operation to become active, and then process it 472 457 * *here*, in this thread, and not in the thread pool */ 473 458 ret = fscache_wait_for_operation_activation( 474 459 object, &op->op, 475 460 __fscache_stat(&fscache_n_retrieval_op_waits), 476 - __fscache_stat(&fscache_n_retrievals_object_dead), 477 - fscache_do_cancel_retrieval); 461 + __fscache_stat(&fscache_n_retrievals_object_dead)); 478 462 if (ret < 0) 479 463 goto error; 480 464 ··· 509 503 spin_unlock(&cookie->lock); 510 504 if (wake_cookie) 511 505 __fscache_wake_unused_cookie(cookie); 512 - kfree(op); 506 + fscache_put_retrieval(op); 513 507 nobufs: 514 508 fscache_stat(&fscache_n_retrievals_nobufs); 515 509 _leave(" = -ENOBUFS"); ··· 590 584 591 585 fscache_stat(&fscache_n_retrieval_ops); 592 586 593 - /* pin the netfs read context in case we need to do the actual netfs 594 - * read because we've encountered a cache read failure */ 595 - fscache_get_context(object->cookie, op->context); 596 - 597 587 /* we wait for the operation to become active, and then process it 598 588 * *here*, in this thread, and not in the thread pool */ 599 589 ret = fscache_wait_for_operation_activation( 600 590 object, &op->op, 601 591 __fscache_stat(&fscache_n_retrieval_op_waits), 602 - __fscache_stat(&fscache_n_retrievals_object_dead), 603 - fscache_do_cancel_retrieval); 592 + __fscache_stat(&fscache_n_retrievals_object_dead)); 604 593 if (ret < 0) 605 594 goto error; 606 595 ··· 633 632 wake_cookie = __fscache_unuse_cookie(cookie); 634 633 nobufs_unlock: 635 634 spin_unlock(&cookie->lock); 636 - kfree(op); 635 + fscache_put_retrieval(op); 637 636 if (wake_cookie) 638 637 __fscache_wake_unused_cookie(cookie); 639 638 nobufs: ··· 701 700 ret = fscache_wait_for_operation_activation( 702 701 object, &op->op, 703 702 __fscache_stat(&fscache_n_alloc_op_waits), 704 - __fscache_stat(&fscache_n_allocs_object_dead), 705 - fscache_do_cancel_retrieval); 703 + __fscache_stat(&fscache_n_allocs_object_dead)); 706 704 if (ret < 0) 707 705 goto error; 708 706 ··· 726 726 wake_cookie = __fscache_unuse_cookie(cookie); 727 727 nobufs_unlock: 728 728 spin_unlock(&cookie->lock); 729 - kfree(op); 729 + fscache_put_retrieval(op); 730 730 if (wake_cookie) 731 731 __fscache_wake_unused_cookie(cookie); 732 732 nobufs: ··· 944 944 if (!op) 945 945 goto nomem; 946 946 947 - fscache_operation_init(&op->op, fscache_write_op, 947 + fscache_operation_init(&op->op, fscache_write_op, NULL, 948 948 fscache_release_write_op); 949 949 op->op.flags = FSCACHE_OP_ASYNC | 950 950 (1 << FSCACHE_OP_WAITING) | ··· 1016 1016 spin_unlock(&object->lock); 1017 1017 spin_unlock(&cookie->lock); 1018 1018 radix_tree_preload_end(); 1019 - kfree(op); 1019 + fscache_put_operation(&op->op); 1020 1020 fscache_stat(&fscache_n_stores_ok); 1021 1021 _leave(" = 0"); 1022 1022 return 0; ··· 1036 1036 nobufs: 1037 1037 spin_unlock(&cookie->lock); 1038 1038 radix_tree_preload_end(); 1039 - kfree(op); 1039 + fscache_put_operation(&op->op); 1040 1040 if (wake_cookie) 1041 1041 __fscache_wake_unused_cookie(cookie); 1042 1042 fscache_stat(&fscache_n_stores_nobufs); ··· 1044 1044 return -ENOBUFS; 1045 1045 1046 1046 nomem_free: 1047 - kfree(op); 1047 + fscache_put_operation(&op->op); 1048 1048 nomem: 1049 1049 fscache_stat(&fscache_n_stores_oom); 1050 1050 _leave(" = -ENOMEM");
+13 -1
fs/fscache/stats.c
··· 23 23 atomic_t fscache_n_op_enqueue; 24 24 atomic_t fscache_n_op_requeue; 25 25 atomic_t fscache_n_op_deferred_release; 26 + atomic_t fscache_n_op_initialised; 26 27 atomic_t fscache_n_op_release; 27 28 atomic_t fscache_n_op_gc; 28 29 atomic_t fscache_n_op_cancelled; ··· 130 129 atomic_t fscache_n_cop_write_page; 131 130 atomic_t fscache_n_cop_uncache_page; 132 131 atomic_t fscache_n_cop_dissociate_pages; 132 + 133 + atomic_t fscache_n_cache_no_space_reject; 134 + atomic_t fscache_n_cache_stale_objects; 135 + atomic_t fscache_n_cache_retired_objects; 136 + atomic_t fscache_n_cache_culled_objects; 133 137 134 138 /* 135 139 * display the general statistics ··· 252 246 atomic_read(&fscache_n_op_enqueue), 253 247 atomic_read(&fscache_n_op_cancelled), 254 248 atomic_read(&fscache_n_op_rejected)); 255 - seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n", 249 + seq_printf(m, "Ops : ini=%u dfr=%u rel=%u gc=%u\n", 250 + atomic_read(&fscache_n_op_initialised), 256 251 atomic_read(&fscache_n_op_deferred_release), 257 252 atomic_read(&fscache_n_op_release), 258 253 atomic_read(&fscache_n_op_gc)); ··· 278 271 atomic_read(&fscache_n_cop_write_page), 279 272 atomic_read(&fscache_n_cop_uncache_page), 280 273 atomic_read(&fscache_n_cop_dissociate_pages)); 274 + seq_printf(m, "CacheEv: nsp=%d stl=%d rtr=%d cul=%d\n", 275 + atomic_read(&fscache_n_cache_no_space_reject), 276 + atomic_read(&fscache_n_cache_stale_objects), 277 + atomic_read(&fscache_n_cache_retired_objects), 278 + atomic_read(&fscache_n_cache_culled_objects)); 281 279 return 0; 282 280 } 283 281
+27 -28
include/linux/fscache-cache.h
··· 74 74 */ 75 75 typedef void (*fscache_operation_release_t)(struct fscache_operation *op); 76 76 typedef void (*fscache_operation_processor_t)(struct fscache_operation *op); 77 + typedef void (*fscache_operation_cancel_t)(struct fscache_operation *op); 77 78 78 79 enum fscache_operation_state { 79 80 FSCACHE_OP_ST_BLANK, /* Op is not yet submitted */ ··· 110 109 * the op in a non-pool thread */ 111 110 fscache_operation_processor_t processor; 112 111 112 + /* Operation cancellation cleanup (optional) */ 113 + fscache_operation_cancel_t cancel; 114 + 113 115 /* operation releaser */ 114 116 fscache_operation_release_t release; 115 117 }; ··· 123 119 extern void fscache_enqueue_operation(struct fscache_operation *); 124 120 extern void fscache_op_complete(struct fscache_operation *, bool); 125 121 extern void fscache_put_operation(struct fscache_operation *); 126 - 127 - /** 128 - * fscache_operation_init - Do basic initialisation of an operation 129 - * @op: The operation to initialise 130 - * @release: The release function to assign 131 - * 132 - * Do basic initialisation of an operation. The caller must still set flags, 133 - * object and processor if needed. 134 - */ 135 - static inline void fscache_operation_init(struct fscache_operation *op, 136 - fscache_operation_processor_t processor, 137 - fscache_operation_release_t release) 138 - { 139 - INIT_WORK(&op->work, fscache_op_work_func); 140 - atomic_set(&op->usage, 1); 141 - op->state = FSCACHE_OP_ST_INITIALISED; 142 - op->debug_id = atomic_inc_return(&fscache_op_debug_id); 143 - op->processor = processor; 144 - op->release = release; 145 - INIT_LIST_HEAD(&op->pend_link); 146 - } 122 + extern void fscache_operation_init(struct fscache_operation *, 123 + fscache_operation_processor_t, 124 + fscache_operation_cancel_t, 125 + fscache_operation_release_t); 147 126 148 127 /* 149 128 * data read operation 150 129 */ 151 130 struct fscache_retrieval { 152 131 struct fscache_operation op; 132 + struct fscache_cookie *cookie; /* The netfs cookie */ 153 133 struct address_space *mapping; /* netfs pages */ 154 134 fscache_rw_complete_t end_io_func; /* function to call on I/O completion */ 155 135 void *context; /* netfs read context (pinned) */ ··· 359 371 #define FSCACHE_OBJECT_IS_LOOKED_UP 4 /* T if object has been looked up */ 360 372 #define FSCACHE_OBJECT_IS_AVAILABLE 5 /* T if object has become active */ 361 373 #define FSCACHE_OBJECT_RETIRED 6 /* T if object was retired on relinquishment */ 374 + #define FSCACHE_OBJECT_KILLED_BY_CACHE 7 /* T if object was killed by the cache */ 362 375 363 376 struct list_head cache_link; /* link in cache->object_list */ 364 377 struct hlist_node cookie_link; /* link in cookie->backing_objects */ ··· 399 410 return test_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags); 400 411 } 401 412 413 + static inline bool fscache_cache_is_broken(struct fscache_object *object) 414 + { 415 + return test_bit(FSCACHE_IOERROR, &object->cache->flags); 416 + } 417 + 402 418 static inline bool fscache_object_is_active(struct fscache_object *object) 403 419 { 404 420 return fscache_object_is_available(object) && 405 421 fscache_object_is_live(object) && 406 - !test_bit(FSCACHE_IOERROR, &object->cache->flags); 407 - } 408 - 409 - static inline bool fscache_object_is_dead(struct fscache_object *object) 410 - { 411 - return fscache_object_is_dying(object) && 412 - test_bit(FSCACHE_IOERROR, &object->cache->flags); 422 + !fscache_cache_is_broken(object); 413 423 } 414 424 415 425 /** ··· 538 550 extern enum fscache_checkaux fscache_check_aux(struct fscache_object *object, 539 551 const void *data, 540 552 uint16_t datalen); 553 + 554 + extern void fscache_object_retrying_stale(struct fscache_object *object); 555 + 556 + enum fscache_why_object_killed { 557 + FSCACHE_OBJECT_IS_STALE, 558 + FSCACHE_OBJECT_NO_SPACE, 559 + FSCACHE_OBJECT_WAS_RETIRED, 560 + FSCACHE_OBJECT_WAS_CULLED, 561 + }; 562 + extern void fscache_object_mark_killed(struct fscache_object *object, 563 + enum fscache_why_object_killed why); 541 564 542 565 #endif /* _LINUX_FSCACHE_CACHE_H */