+/* Allocate thread local buffers if needed */
+static struct ost_thread_local_cache *ost_tls_get(struct ptlrpc_request *r)
+{
+ struct ost_thread_local_cache *tls =
+ (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
+
+ /* In normal mode of operation an I/O request is serviced only
+ * by ll_ost_io threads each of them has own tls buffers allocated by
+ * ost_thread_init().
+ * During recovery, an I/O request may be queued until any of the ost
+ * service threads process it. Not necessary it should be one of
+ * ll_ost_io threads. In that case we dynamically allocating tls
+ * buffers for the request service time. */
+ if (unlikely(tls == NULL)) {
+ LASSERT(r->rq_export->exp_in_recovery);
+ OBD_ALLOC_PTR(tls);
+ if (tls != NULL) {
+ tls->temporary = 1;
+ r->rq_svc_thread->t_data = tls;
+ }
+ }
+ return tls;
+}
+
+/* Free thread local buffers if they were allocated only for servicing
+ * this one request */
+static void ost_tls_put(struct ptlrpc_request *r)
+{
+ struct ost_thread_local_cache *tls =
+ (struct ost_thread_local_cache *)(r->rq_svc_thread->t_data);
+
+ if (unlikely(tls->temporary)) {
+ OBD_FREE_PTR(tls);
+ r->rq_svc_thread->t_data = NULL;
+ }
+}
+