Blame source/vdo/kernel/deadlockQueue.h

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