Blame vdo/kernel/dedupeIndex.c

Packit Service b3514a
/*
Packit Service b3514a
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service b3514a
 *
Packit Service b3514a
 * This program is free software; you can redistribute it and/or
Packit Service b3514a
 * modify it under the terms of the GNU General Public License
Packit Service b3514a
 * as published by the Free Software Foundation; either version 2
Packit Service b3514a
 * of the License, or (at your option) any later version.
Packit Service b3514a
 * 
Packit Service b3514a
 * This program is distributed in the hope that it will be useful,
Packit Service b3514a
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service b3514a
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service b3514a
 * GNU General Public License for more details.
Packit Service b3514a
 * 
Packit Service b3514a
 * You should have received a copy of the GNU General Public License
Packit Service b3514a
 * along with this program; if not, write to the Free Software
Packit Service b3514a
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service b3514a
 * 02110-1301, USA. 
Packit Service b3514a
 *
Packit Service b3514a
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/dedupeIndex.c#1 $
Packit Service b3514a
 */
Packit Service b3514a
Packit Service b3514a
#include "dedupeIndex.h"
Packit Service b3514a
Packit Service b3514a
#include "numeric.h"
Packit Service b3514a
Packit Service b3514a
#include "udsIndex.h"
Packit Service b3514a
Packit Service b3514a
// These times are in milliseconds
Packit Service b3514a
unsigned int albireoTimeoutInterval  = 5000;
Packit Service b3514a
unsigned int minAlbireoTimerInterval = 100;
Packit Service b3514a
Packit Service b3514a
// These times are in jiffies
Packit Service b3514a
Jiffies albireoTimeoutJiffies = 0;
Packit Service b3514a
static Jiffies minAlbireoTimerJiffies = 0;
Packit Service b3514a
Packit Service b3514a
/**********************************************************************/
Packit Service b3514a
Jiffies getAlbireoTimeout(Jiffies startJiffies)
Packit Service b3514a
{
Packit Service b3514a
  return maxULong(startJiffies + albireoTimeoutJiffies,
Packit Service b3514a
                  jiffies + minAlbireoTimerJiffies);
Packit Service b3514a
}
Packit Service b3514a
Packit Service b3514a
/**********************************************************************/
Packit Service b3514a
void setAlbireoTimeoutInterval(unsigned int value)
Packit Service b3514a
{
Packit Service b3514a
  // Arbitrary maximum value is two minutes
Packit Service b3514a
  if (value > 120000) {
Packit Service b3514a
    value = 120000;
Packit Service b3514a
  }
Packit Service b3514a
  // Arbitrary minimum value is 2 jiffies
Packit Service b3514a
  Jiffies albJiffies = msecs_to_jiffies(value);
Packit Service b3514a
  if (albJiffies < 2) {
Packit Service b3514a
    albJiffies = 2;
Packit Service b3514a
    value      = jiffies_to_msecs(albJiffies);
Packit Service b3514a
  }
Packit Service b3514a
  albireoTimeoutInterval = value;
Packit Service b3514a
  albireoTimeoutJiffies  = albJiffies;
Packit Service b3514a
}
Packit Service b3514a
Packit Service b3514a
/**********************************************************************/
Packit Service b3514a
void setMinAlbireoTimerInterval(unsigned int value)
Packit Service b3514a
{
Packit Service b3514a
  // Arbitrary maximum value is one second
Packit Service b3514a
  if (value > 1000) {
Packit Service b3514a
    value = 1000;
Packit Service b3514a
  }
Packit Service b3514a
Packit Service b3514a
  // Arbitrary minimum value is 2 jiffies
Packit Service b3514a
  Jiffies minJiffies = msecs_to_jiffies(value);
Packit Service b3514a
  if (minJiffies < 2) {
Packit Service b3514a
    minJiffies = 2;
Packit Service b3514a
    value = jiffies_to_msecs(minJiffies);
Packit Service b3514a
  }
Packit Service b3514a
Packit Service b3514a
  minAlbireoTimerInterval = value;
Packit Service b3514a
  minAlbireoTimerJiffies  = minJiffies;
Packit Service b3514a
}
Packit Service b3514a
Packit Service b3514a
/**********************************************************************/
Packit Service b3514a
int makeDedupeIndex(DedupeIndex **indexPtr, KernelLayer *layer)
Packit Service b3514a
{
Packit Service b3514a
  if (albireoTimeoutJiffies == 0) {
Packit Service b3514a
    setAlbireoTimeoutInterval(albireoTimeoutInterval);
Packit Service b3514a
  }
Packit Service b3514a
Packit Service b3514a
  if (minAlbireoTimerJiffies == 0) {
Packit Service b3514a
    setMinAlbireoTimerInterval(minAlbireoTimerInterval);
Packit Service b3514a
  }
Packit Service b3514a
Packit Service b3514a
  return makeUDSIndex(layer, indexPtr);
Packit Service b3514a
}