Advertisement
ffilz

Untitled

Apr 17th, 2020
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. /*
  2.  * To use the export_admin_counter, a process that might get bad results due
  3.  * to an in progress export update should save the export_admin_counter as
  4.  * start_export_admin_counter before executing the code that could be confused.
  5.  * The after the code is complete, the code can call
  6.  * is_export_admin_counter_valid(start_export_admin_counter) to determine if
  7.  * and export update might have upended things.
  8.  *
  9.  * Depending on how the code functions, it may only need to perform this check
  10.  * if an unexpected result occurred. On the other hand the check is cheap, while
  11.  * a false negative is possible, that still requires the code have been
  12.  * executing parallel with an export update which are expected to be extremely
  13.  * rare so even if the code catches a half-updated counter (due to NOT using
  14.  * atomics) it just results in a false negative.
  15.  */
  16. static inline
  17. bool is_export_admin_counter_valid(uint64_t start_export_admin_counter)
  18. {
  19.         return (start_export_admin_counter % 2) == 0 &&
  20.                 start_export_admin_counter == export_admin_counter;
  21. }
  22.  
  23. /**
  24.  * @brief Simple check if an export update is in progress
  25.  *
  26.  * If code uses locks in a way that guarantee that an export update can not
  27.  * upset their world while the code is executing then a simple check after
  28.  * failure that an update is in progress (seqlock value is odd) is sufficient.
  29.  * For example, code implementing a lookup in a pseudo fs where lookup holds a
  30.  * lock that prevents the update from changing the pseudo fs while the lookup
  31.  * in in progress means that any update that will upset this lookups apple cart
  32.  * can not start AND end while the lookup is in progress.
  33.  */
  34. static inline bool is_export_update_in_progress(void)
  35. {
  36.         return (export_admin_counter % 2) != 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement