Blame source/vdo/kernel/deadlockQueue.h

Packit Service d40955
/*
Packit Service d40955
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service d40955
 *
Packit Service d40955
 * This program is free software; you can redistribute it and/or
Packit Service d40955
 * modify it under the terms of the GNU General Public License
Packit Service d40955
 * as published by the Free Software Foundation; either version 2
Packit Service d40955
 * of the License, or (at your option) any later version.
Packit Service d40955
 * 
Packit Service d40955
 * This program is distributed in the hope that it will be useful,
Packit Service d40955
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service d40955
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service d40955
 * GNU General Public License for more details.
Packit Service d40955
 * 
Packit Service d40955
 * You should have received a copy of the GNU General Public License
Packit Service d40955
 * along with this program; if not, write to the Free Software
Packit Service d40955
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service d40955
 * 02110-1301, USA. 
Packit Service d40955
 *
Packit Service d40955
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/deadlockQueue.h#1 $
Packit Service d40955
 */
Packit Service d40955
Packit Service d40955
#ifndef DEADLOCK_QUEUE_H
Packit Service d40955
#define DEADLOCK_QUEUE_H
Packit Service d40955
Packit Service d40955
#include <linux/kernel.h>
Packit Service d40955
Packit Service d40955
#include "bio.h"
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * A holding space for incoming bios if we're not able to block until VIOs
Packit Service d40955
 * become available to process them.
Packit Service d40955
 **/
Packit Service d40955
typedef struct deadlockQueue {
Packit Service d40955
  /* Protection for the other fields. */
Packit Service d40955
  spinlock_t      lock;
Packit Service d40955
  /* List of bios we had to accept but don't have VIOs for. */
Packit Service d40955
  struct bio_list list;
Packit Service d40955
  /*
Packit Service d40955
   * Arrival time to use for statistics tracking for the above bios, since we
Packit Service d40955
   * haven't the space to store individual arrival times for each.
Packit Service d40955
   */
Packit Service d40955
  Jiffies         arrivalTime;
Packit Service d40955
} DeadlockQueue;
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Initialize the DeadlockQueue structure.
Packit Service d40955
 *
Packit Service d40955
 * @param queue  The structure to initialize
Packit Service d40955
 **/
Packit Service d40955
void initializeDeadlockQueue(DeadlockQueue *queue);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Add an incoming bio to the list of saved-up bios we're not ready to start
Packit Service d40955
 * processing yet.
Packit Service d40955
 *
Packit Service d40955
 * This excess buffering on top of what the caller implements is generally a
Packit Service d40955
 * bad idea, and should be used only when necessary, such as to avoid a
Packit Service d40955
 * possible deadlock situation.
Packit Service d40955
 *
Packit Service d40955
 * @param queue        The incoming-bio queue structure
Packit Service d40955
 * @param bio          The new incoming bio to save
Packit Service d40955
 * @param arrivalTime  The arrival time of this new bio
Packit Service d40955
 **/
Packit Service d40955
void addToDeadlockQueue(DeadlockQueue *queue, BIO *bio, Jiffies arrivalTime);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Pull an incoming bio off the queue.
Packit Service d40955
 *
Packit Service d40955
 * The arrival time returned may be incorrect if multiple bios were saved, as
Packit Service d40955
 * there is no per-bio storage used, only one saved arrival time for the whole
Packit Service d40955
 * queue.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  queue        The incoming-bio queue
Packit Service d40955
 * @param [out] arrivalTime  The arrival time to use for this bio
Packit Service d40955
 *
Packit Service d40955
 * @return  a BIO pointer, or NULL if none were queued
Packit Service d40955
 **/
Packit Service d40955
static inline BIO *pollDeadlockQueue(DeadlockQueue *queue,
Packit Service d40955
                                     Jiffies       *arrivalTime)
Packit Service d40955
{
Packit Service d40955
  spin_lock(&queue->lock);
Packit Service d40955
  BIO *bio = bio_list_pop(&queue->list);
Packit Service d40955
  if (unlikely(bio != NULL)) {
Packit Service d40955
    *arrivalTime = queue->arrivalTime;
Packit Service d40955
  }
Packit Service d40955
  spin_unlock(&queue->lock);
Packit Service d40955
  return bio;
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
#endif // DEADLOCK_QUEUE_H