|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/hashLock.h#3 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef HASH_LOCK_H
|
|
Packit Service |
310c69 |
#define HASH_LOCK_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "types.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the PBN lock on the duplicate data location for a DataVIO from the
|
|
Packit Service |
310c69 |
* HashLock the DataVIO holds (if there is one).
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO to query
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The PBN lock on the DataVIO's duplicate location
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
PBNLock *getDuplicateLock(DataVIO *dataVIO)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Acquire or share a lock on the hash (chunk name) of the data in a DataVIO,
|
|
Packit Service |
310c69 |
* updating the DataVIO to reference the lock. This must only be called in the
|
|
Packit Service |
310c69 |
* correct thread for the zone. In the unlikely case of a hash collision, this
|
|
Packit Service |
310c69 |
* function will succeed, but the DataVIO will not get a lock reference.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO acquiring a lock on its chunk name
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int acquireHashLock(DataVIO *dataVIO)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Asynchronously process a DataVIO that has just acquired its reference to a
|
|
Packit Service |
310c69 |
* hash lock. This may place the DataVIO on a wait queue, or it may use the
|
|
Packit Service |
310c69 |
* DataVIO to perform operations on the lock's behalf.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO that has just acquired a lock on its chunk name
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void enterHashLock(DataVIO *dataVIO);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Asynchronously continue processing a DataVIO in its hash lock after it has
|
|
Packit Service |
310c69 |
* finished writing, compressing, or deduplicating, so it can share the result
|
|
Packit Service |
310c69 |
* with any DataVIOs waiting in the hash lock, or update Albireo, or simply
|
|
Packit Service |
310c69 |
* release its share of the lock. This must only be called in the correct
|
|
Packit Service |
310c69 |
* thread for the hash zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO to continue processing in its hash lock
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void continueHashLock(DataVIO *dataVIO);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Re-enter the hash lock after encountering an error, to clean up the hash
|
|
Packit Service |
310c69 |
* lock.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO with an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void continueHashLockOnError(DataVIO *dataVIO);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Release a DataVIO's share of a hash lock, if held, and null out the
|
|
Packit Service |
310c69 |
* DataVIO's reference to it. This must only be called in the correct thread
|
|
Packit Service |
310c69 |
* for the hash zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* If the DataVIO is the only one holding the lock, this also releases any
|
|
Packit Service |
310c69 |
* resources or locks used by the hash lock (such as a PBN read lock on a
|
|
Packit Service |
310c69 |
* block containing data with the same hash) and returns the lock to the hash
|
|
Packit Service |
310c69 |
* zone's lock pool.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO releasing its hash lock
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void releaseHashLock(DataVIO *dataVIO);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Make a DataVIO's hash lock a shared holder of the PBN lock on the
|
|
Packit Service |
310c69 |
* compressed block to which its data was just written. If the lock is still a
|
|
Packit Service |
310c69 |
* write lock (as it will be for the first share), it will be converted to a
|
|
Packit Service |
310c69 |
* read lock. This also reserves a reference count increment for the DataVIO.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO which was just compressed
|
|
Packit Service |
310c69 |
* @param pbnLock The PBN lock on the compressed block
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void shareCompressedWriteLock(DataVIO *dataVIO, PBNLock *pbnLock);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif // HASH_LOCK_H
|