@@ -19,6 +19,7 @@ static void fscache_cookie_lru_timed_out(struct timer_list *timer);
1919static void fscache_cookie_lru_worker (struct work_struct * work );
2020static void fscache_cookie_worker (struct work_struct * work );
2121static void fscache_unhash_cookie (struct fscache_cookie * cookie );
22+ static void fscache_perform_invalidation (struct fscache_cookie * cookie );
2223
2324#define fscache_cookie_hash_shift 15
2425static struct hlist_bl_head fscache_cookie_hash [1 << fscache_cookie_hash_shift ];
@@ -28,7 +29,7 @@ static LIST_HEAD(fscache_cookie_lru);
2829static DEFINE_SPINLOCK (fscache_cookie_lru_lock );
2930DEFINE_TIMER (fscache_cookie_lru_timer , fscache_cookie_lru_timed_out );
3031static DECLARE_WORK (fscache_cookie_lru_work , fscache_cookie_lru_worker ) ;
31- static const char fscache_cookie_states [FSCACHE_COOKIE_STATE__NR ] = "-LCAFUWRD " ;
32+ static const char fscache_cookie_states [FSCACHE_COOKIE_STATE__NR ] = "-LCAIFUWRD " ;
3233unsigned int fscache_lru_cookie_timeout = 10 * HZ ;
3334
3435void fscache_print_cookie (struct fscache_cookie * cookie , char prefix )
@@ -236,6 +237,19 @@ void fscache_cookie_lookup_negative(struct fscache_cookie *cookie)
236237}
237238EXPORT_SYMBOL (fscache_cookie_lookup_negative );
238239
240+ /**
241+ * fscache_resume_after_invalidation - Allow I/O to resume after invalidation
242+ * @cookie: The cookie that was invalidated
243+ *
244+ * Tell fscache that invalidation is sufficiently complete that I/O can be
245+ * allowed again.
246+ */
247+ void fscache_resume_after_invalidation (struct fscache_cookie * cookie )
248+ {
249+ fscache_set_cookie_state (cookie , FSCACHE_COOKIE_STATE_ACTIVE );
250+ }
251+ EXPORT_SYMBOL (fscache_resume_after_invalidation );
252+
239253/**
240254 * fscache_caching_failed - Report that a failure stopped caching on a cookie
241255 * @cookie: The cookie that was affected
@@ -566,6 +580,7 @@ void __fscache_use_cookie(struct fscache_cookie *cookie, bool will_modify)
566580 set_bit (FSCACHE_COOKIE_LOCAL_WRITE , & cookie -> flags );
567581 break ;
568582 case FSCACHE_COOKIE_STATE_ACTIVE :
583+ case FSCACHE_COOKIE_STATE_INVALIDATING :
569584 if (will_modify &&
570585 !test_and_set_bit (FSCACHE_COOKIE_LOCAL_WRITE , & cookie -> flags )) {
571586 set_bit (FSCACHE_COOKIE_DO_PREP_TO_WRITE , & cookie -> flags );
@@ -671,6 +686,11 @@ static void fscache_cookie_state_machine(struct fscache_cookie *cookie)
671686 fscache_perform_lookup (cookie );
672687 goto again ;
673688
689+ case FSCACHE_COOKIE_STATE_INVALIDATING :
690+ spin_unlock (& cookie -> lock );
691+ fscache_perform_invalidation (cookie );
692+ goto again ;
693+
674694 case FSCACHE_COOKIE_STATE_ACTIVE :
675695 if (test_and_clear_bit (FSCACHE_COOKIE_DO_PREP_TO_WRITE , & cookie -> flags )) {
676696 spin_unlock (& cookie -> lock );
@@ -962,6 +982,72 @@ struct fscache_cookie *fscache_get_cookie(struct fscache_cookie *cookie,
962982}
963983EXPORT_SYMBOL (fscache_get_cookie );
964984
985+ /*
986+ * Ask the cache to effect invalidation of a cookie.
987+ */
988+ static void fscache_perform_invalidation (struct fscache_cookie * cookie )
989+ {
990+ if (!cookie -> volume -> cache -> ops -> invalidate_cookie (cookie ))
991+ fscache_caching_failed (cookie );
992+ fscache_end_cookie_access (cookie , fscache_access_invalidate_cookie_end );
993+ }
994+
995+ /*
996+ * Invalidate an object.
997+ */
998+ void __fscache_invalidate (struct fscache_cookie * cookie ,
999+ const void * aux_data , loff_t new_size ,
1000+ unsigned int flags )
1001+ {
1002+ bool is_caching ;
1003+
1004+ _enter ("c=%x" , cookie -> debug_id );
1005+
1006+ fscache_stat (& fscache_n_invalidates );
1007+
1008+ if (WARN (test_bit (FSCACHE_COOKIE_RELINQUISHED , & cookie -> flags ),
1009+ "Trying to invalidate relinquished cookie\n" ))
1010+ return ;
1011+
1012+ if ((flags & FSCACHE_INVAL_DIO_WRITE ) &&
1013+ test_and_set_bit (FSCACHE_COOKIE_DISABLED , & cookie -> flags ))
1014+ return ;
1015+
1016+ spin_lock (& cookie -> lock );
1017+ set_bit (FSCACHE_COOKIE_NO_DATA_TO_READ , & cookie -> flags );
1018+ fscache_update_aux (cookie , aux_data , & new_size );
1019+ cookie -> inval_counter ++ ;
1020+ trace_fscache_invalidate (cookie , new_size );
1021+
1022+ switch (cookie -> state ) {
1023+ case FSCACHE_COOKIE_STATE_INVALIDATING : /* is_still_valid will catch it */
1024+ default :
1025+ spin_unlock (& cookie -> lock );
1026+ _leave (" [no %u]" , cookie -> state );
1027+ return ;
1028+
1029+ case FSCACHE_COOKIE_STATE_LOOKING_UP :
1030+ case FSCACHE_COOKIE_STATE_CREATING :
1031+ spin_unlock (& cookie -> lock );
1032+ _leave (" [look %x]" , cookie -> inval_counter );
1033+ return ;
1034+
1035+ case FSCACHE_COOKIE_STATE_ACTIVE :
1036+ is_caching = fscache_begin_cookie_access (
1037+ cookie , fscache_access_invalidate_cookie );
1038+ if (is_caching )
1039+ __fscache_set_cookie_state (cookie , FSCACHE_COOKIE_STATE_INVALIDATING );
1040+ spin_unlock (& cookie -> lock );
1041+ wake_up_cookie_state (cookie );
1042+
1043+ if (is_caching )
1044+ fscache_queue_cookie (cookie , fscache_cookie_get_inval_work );
1045+ _leave (" [inv]" );
1046+ return ;
1047+ }
1048+ }
1049+ EXPORT_SYMBOL (__fscache_invalidate );
1050+
9651051/*
9661052 * Generate a list of extant cookies in /proc/fs/fscache/cookies
9671053 */
0 commit comments