+int ofd_dlm_init(void)
+{
+ ldlm_glimpse_work_kmem = kmem_cache_create("ldlm_glimpse_work_kmem",
+ sizeof(struct ldlm_glimpse_work),
+ 0, 0, NULL);
+ if (ldlm_glimpse_work_kmem == NULL)
+ return -ENOMEM;
+ else
+ return 0;
+}
+
+void ofd_dlm_exit(void)
+{
+ if (ldlm_glimpse_work_kmem) {
+ kmem_cache_destroy(ldlm_glimpse_work_kmem);
+ ldlm_glimpse_work_kmem = NULL;
+ }
+}
+
+/**
+ * OFD interval callback.
+ *
+ * The interval_callback_t is part of interval_iterate_reverse() and is called
+ * for each interval in tree. The OFD interval callback searches for locks
+ * covering extents beyond the given args->size. This is used to decide if the
+ * size is too small and needs to be updated. Note that we are only interested
+ * in growing the size, as truncate is the only operation which can shrink it,
+ * and it is handled differently. This is why we only look at locks beyond the
+ * current size.
+ *
+ * It finds the highest lock (by starting point) in this interval, and adds it
+ * to the list of locks to glimpse. We must glimpse a list of locks - rather
+ * than only the highest lock on the file - because lockahead creates extent
+ * locks in advance of IO, and so breaks the assumption that the holder of the
+ * highest lock knows the current file size.
+ *
+ * This assumption is normally true because locks which are created as part of
+ * IO - rather than in advance of it - are guaranteed to be 'active', i.e.,
+ * involved in IO, and the holder of the highest 'active' lock always knows the
+ * current file size, because the size is either not changing or the holder of
+ * that lock is responsible for updating it.
+ *
+ * So we need only glimpse until we find the first client with an 'active'
+ * lock.
+ *
+ * Unfortunately, there is no way to know if a manually requested/speculative
+ * lock is 'active' from the server side. So when we see a potentially
+ * speculative lock, we must send a glimpse for that lock unless we have
+ * already sent a glimpse to the holder of that lock.
+ *
+ * However, *all* non-speculative locks are active. So we can stop glimpsing
+ * as soon as we find a non-speculative lock. Currently, all speculative PW
+ * locks have LDLM_FL_NO_EXPANSION set, and we use this to identify them. This
+ * is enforced by an assertion in osc_lock_init, which references this comment.
+ *
+ * If that ever changes, we will either need to find a new way to identify
+ * active locks or we will need to consider all PW locks (we will still only
+ * glimpse one per client).
+ *
+ * Note that it is safe to glimpse only the 'top' lock from each interval
+ * because ofd_intent_cb is only called for PW extent locks, and for PW locks,
+ * there is only one lock per interval.
+ *
+ * \param[in] n interval node
+ * \param[in,out] args intent arguments, gl work list for identified locks
+ *
+ * \retval INTERVAL_ITER_STOP if the interval is lower than
+ * file size, caller stops execution
+ * \retval INTERVAL_ITER_CONT if callback finished successfully
+ * and caller may continue execution
+ */