Blame vdo/kernel/workQueueHandle.h

Packit Service 693862
/*
Packit Service 693862
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service 693862
 *
Packit Service 693862
 * This program is free software; you can redistribute it and/or
Packit Service 693862
 * modify it under the terms of the GNU General Public License
Packit Service 693862
 * as published by the Free Software Foundation; either version 2
Packit Service 693862
 * of the License, or (at your option) any later version.
Packit Service 693862
 * 
Packit Service 693862
 * This program is distributed in the hope that it will be useful,
Packit Service 693862
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 693862
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 693862
 * GNU General Public License for more details.
Packit Service 693862
 * 
Packit Service 693862
 * You should have received a copy of the GNU General Public License
Packit Service 693862
 * along with this program; if not, write to the Free Software
Packit Service 693862
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 693862
 * 02110-1301, USA. 
Packit Service 693862
 *
Packit Service 693862
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/workQueueHandle.h#1 $
Packit Service 693862
 */
Packit Service 693862
Packit Service 693862
#ifndef WORK_QUEUE_HANDLE_H
Packit Service 693862
#define WORK_QUEUE_HANDLE_H
Packit Service 693862
Packit Service 693862
#include <linux/version.h>
Packit Service 693862
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
Packit Service 693862
#include <linux/sched/task_stack.h>
Packit Service 693862
#else
Packit Service 693862
#include <linux/sched.h>
Packit Service 693862
#endif
Packit Service 693862
Packit Service 693862
#include "workQueueInternals.h"
Packit Service 693862
Packit Service 693862
/*
Packit Service 693862
 * Layout of a special structure stored at a consistent place on the
Packit Service 693862
 * stack in work queue threads.
Packit Service 693862
 */
Packit Service 693862
typedef struct workQueueStackHandle {
Packit Service 693862
  unsigned long    nonce;
Packit Service 693862
  SimpleWorkQueue *queue;
Packit Service 693862
} WorkQueueStackHandle;
Packit Service 693862
Packit Service 693862
typedef struct workQueueStackHandleGlobals {
Packit Service 693862
  /*
Packit Service 693862
   * Location in the stack, relative to the task structure which is
Packit Service 693862
   * contained in the same memory allocation.
Packit Service 693862
   */
Packit Service 693862
  long          offset;
Packit Service 693862
  /*
Packit Service 693862
   * A lock is used to guard against multiple updaters, but once an
Packit Service 693862
   * update is done, the offset variable will be read-only.
Packit Service 693862
   */
Packit Service 693862
  spinlock_t    offsetLock;
Packit Service 693862
  /*
Packit Service 693862
   * A nonce chosen differently each time the module is loaded, used
Packit Service 693862
   * as a marker so we can check that the current thread really is a
Packit Service 693862
   * work queue thread. Set at module initialization time, before any
Packit Service 693862
   * work queues are created.
Packit Service 693862
   */
Packit Service 693862
  unsigned long nonce;
Packit Service 693862
} WorkQueueStackHandleGlobals;
Packit Service 693862
Packit Service 693862
extern WorkQueueStackHandleGlobals workQueueStackHandleGlobals;
Packit Service 693862
Packit Service 693862
/**
Packit Service 693862
 * Initialize a stack handle associated with a work queue.
Packit Service 693862
 *
Packit Service 693862
 * @param [out] handle  The handle to be initialized
Packit Service 693862
 * @param [in]  queue   The work queue pointer
Packit Service 693862
 **/
Packit Service 693862
void initializeWorkQueueStackHandle(WorkQueueStackHandle *handle,
Packit Service 693862
                                    SimpleWorkQueue      *queue);
Packit Service 693862
Packit Service 693862
/**
Packit Service 693862
 * Return the work queue pointer recorded at initialization time in
Packit Service 693862
 * the work-queue stack handle initialized on the stack of the current
Packit Service 693862
 * thread, if any.
Packit Service 693862
 *
Packit Service 693862
 * @return   the work queue pointer, or NULL
Packit Service 693862
 **/
Packit Service 693862
static inline SimpleWorkQueue *getCurrentThreadWorkQueue(void)
Packit Service 693862
{
Packit Service 693862
  WorkQueueStackHandle *handle
Packit Service 693862
    = (WorkQueueStackHandle *)(task_stack_page(current)
Packit Service 693862
                               + workQueueStackHandleGlobals.offset);
Packit Service 693862
  if (likely(handle->nonce == workQueueStackHandleGlobals.nonce)) {
Packit Service 693862
    return handle->queue;
Packit Service 693862
  } else {
Packit Service 693862
    return NULL;
Packit Service 693862
  }
Packit Service 693862
}
Packit Service 693862
Packit Service 693862
/**
Packit Service 693862
 * Initialize the global state used by the work-queue stack-handle
Packit Service 693862
 * code.
Packit Service 693862
 **/
Packit Service 693862
void initWorkQueueStackHandleOnce(void);
Packit Service 693862
Packit Service 693862
#endif // WORK_QUEUE_HANDLE_H