Blame source/uds/indexLayout.h

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/uds-releases/jasper/src/uds/indexLayout.h#13 $
Packit Service 310c69
 */
Packit Service 310c69
Packit Service 310c69
#ifndef INDEX_LAYOUT_H
Packit Service 310c69
#define INDEX_LAYOUT_H
Packit Service 310c69
Packit Service 310c69
#include "buffer.h"
Packit Service 310c69
#include "indexState.h"
Packit Service 310c69
#include "indexVersion.h"
Packit Service 310c69
#include "ioFactory.h"
Packit Service 310c69
#include "uds.h"
Packit Service 310c69
Packit Service 310c69
typedef struct indexLayout IndexLayout;
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Construct an index layout.  This is a platform specific function that uses
Packit Service 310c69
 * the name string, a flag that indicates old vs. new indices, and a
Packit Service 310c69
 * UDSConfiguration (for new indices) to make an IOFactory and invoke
Packit Service 310c69
 * makeIndexLayoutFromFactory.
Packit Service 310c69
 *
Packit Service 310c69
 * @param name       String naming the index.  Each platform will use its own
Packit Service 310c69
 *                   conventions to interpret the string, but in general it is
Packit Service 310c69
 *                   a space-separated sequence of param=value settings.  For
Packit Service 310c69
 *                   backward compatibility a string without an equals is
Packit Service 310c69
 *                   treated as a platform-specific default parameter value.
Packit Service 310c69
 * @param newLayout  Whether this is a new layout.
Packit Service 310c69
 * @param config     The UdsConfiguration required for a new layout.
Packit Service 310c69
 * @param layoutPtr  Where to store the new index layout
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code.
Packit Service 310c69
 **/
Packit Service 310c69
int makeIndexLayout(const char              *name,
Packit Service 310c69
                    bool                     newLayout,
Packit Service 310c69
                    const UdsConfiguration   config,
Packit Service 310c69
                    IndexLayout            **layoutPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Construct an index layout using an IOFactory.  This method is common to all
Packit Service 310c69
 * platforms.
Packit Service 310c69
 *
Packit Service 310c69
 * @param factory    The IOFactory for the block storage containing the index.
Packit Service 310c69
 * @param offset     The offset of the start of the index within the block
Packit Service 310c69
 *                   storage address space.
Packit Service 310c69
 * @param namedSize  The size in bytes of the space within the block storage
Packit Service 310c69
 *                   address space, as specified in the name string.
Packit Service 310c69
 * @param newLayout  Whether this is a new layout.
Packit Service 310c69
 * @param config     The UdsConfiguration required for a new layout.
Packit Service 310c69
 * @param layoutPtr  Where to store the new index layout
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code.
Packit Service 310c69
 **/
Packit Service 310c69
int makeIndexLayoutFromFactory(IOFactory               *factory,
Packit Service 310c69
                               off_t                    offset,
Packit Service 310c69
                               uint64_t                 namedSize,
Packit Service 310c69
                               bool                     newLayout,
Packit Service 310c69
                               const UdsConfiguration   config,
Packit Service 310c69
                               IndexLayout            **layoutPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Decrement the use count of an index layout.  If the count goes to zero, free
Packit Service 310c69
 * the index layout.
Packit Service 310c69
 *
Packit Service 310c69
 * @param layoutPtr  Where the layout is being stored.  Always reset to NULL.
Packit Service 310c69
 **/
Packit Service 310c69
void putIndexLayout(IndexLayout **layoutPtr);
Packit Service 310c69
Packit Service 310c69
/*****************************************************************************/
Packit Service 310c69
int cancelIndexSave(IndexLayout *layout, unsigned int saveSlot)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/*****************************************************************************/
Packit Service 310c69
int commitIndexSave(IndexLayout *layout, unsigned int saveSlot)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/*****************************************************************************/
Packit Service 310c69
int discardIndexSaves(IndexLayout *layout, bool all)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Find the latest index save slot.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  layout          The single file layout.
Packit Service 310c69
 * @param [out] numZonesPtr     Where to store the actual number of zones
Packit Service 310c69
 *                                that were saved.
Packit Service 310c69
 * @param [out] slotPtr         Where to store the slot number we found.
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code.
Packit Service 310c69
 **/
Packit Service 310c69
int findLatestIndexSaveSlot(IndexLayout  *layout,
Packit Service 310c69
                            unsigned int *numZonesPtr,
Packit Service 310c69
                            unsigned int *slotPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get another reference to an index layout, incrementing it's use count.
Packit Service 310c69
 *
Packit Service 310c69
 * @param layout     The index layout.
Packit Service 310c69
 * @param layoutPtr  Where the new layout pointer is being stored.
Packit Service 310c69
 **/
Packit Service 310c69
void getIndexLayout(IndexLayout *layout, IndexLayout **layoutPtr);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Open a BufferedReader for a specified state, kind, and zone.
Packit Service 310c69
 *
Packit Service 310c69
 * @param layout     The index layout
Packit Service 310c69
 * @param slot       The save slot
Packit Service 310c69
 * @param kind       The kind if index save region to open.
Packit Service 310c69
 * @param zone       The zone number for the region.
Packit Service 310c69
 * @param readerPtr  Where to store the BufferedReader.
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code.
Packit Service 310c69
 **/
Packit Service 310c69
int openIndexBufferedReader(IndexLayout     *layout,
Packit Service 310c69
                            unsigned int     slot,
Packit Service 310c69
                            RegionKind       kind,
Packit Service 310c69
                            unsigned int     zone,
Packit Service 310c69
                            BufferedReader **readerPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Open a BufferedWriter for a specified state, kind, and zone.
Packit Service 310c69
 *
Packit Service 310c69
 * @param layout     The index layout
Packit Service 310c69
 * @param slot       The save slot
Packit Service 310c69
 * @param kind       The kind if index save region to open.
Packit Service 310c69
 * @param zone       The zone number for the region.
Packit Service 310c69
 * @param writerPtr  Where to store the BufferedWriter.
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code.
Packit Service 310c69
 **/
Packit Service 310c69
int openIndexBufferedWriter(IndexLayout     *layout,
Packit Service 310c69
                            unsigned int     slot,
Packit Service 310c69
                            RegionKind       kind,
Packit Service 310c69
                            unsigned int     zone,
Packit Service 310c69
                            BufferedWriter **writerPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Obtain the nonce to be used to store or validate the loading of volume index
Packit Service 310c69
 * pages.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  layout   The index layout.
Packit Service 310c69
 *
Packit Service 310c69
 * @return The nonce to use.
Packit Service 310c69
 **/
Packit Service 310c69
uint64_t getVolumeNonce(IndexLayout *layout)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
#ifdef __KERNEL__
Packit Service 310c69
/**
Packit Service 310c69
 * Obtain a dm_bufio_client for the specified index volume.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  layout           The index layout.
Packit Service 310c69
 * @param [in]  blockSize        The size of a volume page
Packit Service 310c69
 * @param [in]  reservedBuffers  The count of reserved buffers
Packit Service 310c69
 * @param [out] clientPtr        Where to put the new dm_bufio_client
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code.
Packit Service 310c69
 **/
Packit Service 310c69
int openVolumeBufio(IndexLayout             *layout,
Packit Service 310c69
                    size_t                   blockSize,
Packit Service 310c69
                    unsigned int             reservedBuffers,
Packit Service 310c69
                    struct dm_bufio_client **clientPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
#else
Packit Service 310c69
/**
Packit Service 310c69
 * Obtain an IORegion for the specified index volume.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  layout     The index layout.
Packit Service 310c69
 * @param [out] regionPtr  Where to put the new region.
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code.
Packit Service 310c69
 **/
Packit Service 310c69
int openVolumeRegion(IndexLayout *layout, struct ioRegion **regionPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
#endif
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Read the index configuration, and verify that it matches the given
Packit Service 310c69
 * configuration.
Packit Service 310c69
 *
Packit Service 310c69
 * @param layout  the generic index layout
Packit Service 310c69
 * @param config  the index configuration
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int verifyIndexConfig(IndexLayout *layout, UdsConfiguration config)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Determine which index save slot to use for a new index save.
Packit Service 310c69
 *
Packit Service 310c69
 * Also allocates the masterIndex regions and, if needed, the openChapter
Packit Service 310c69
 * region.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  layout          The index layout.
Packit Service 310c69
 * @param [in]  numZones        Actual number of zones currently in use.
Packit Service 310c69
 * @param [in]  saveType        The index save type.
Packit Service 310c69
 * @param [out] saveSlotPtr     Where to store the save slot number.
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int setupIndexSaveSlot(IndexLayout   *layout,
Packit Service 310c69
                       unsigned int   numZones,
Packit Service 310c69
                       IndexSaveType  saveType,
Packit Service 310c69
                       unsigned int  *saveSlotPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Write the index configuration.
Packit Service 310c69
 *
Packit Service 310c69
 * @param layout  the generic index layout
Packit Service 310c69
 * @param config  the index configuration to write
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int writeIndexConfig(IndexLayout *layout, UdsConfiguration config)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the index state buffer
Packit Service 310c69
 *
Packit Service 310c69
 * @param layout  the index layout
Packit Service 310c69
 * @param slot    the save slot
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
Buffer *getIndexStateBuffer(IndexLayout *layout, unsigned int slot)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the index version parameters.
Packit Service 310c69
 *
Packit Service 310c69
 * @param layout  the index layout
Packit Service 310c69
 *
Packit Service 310c69
 * @return the index version parameters.
Packit Service 310c69
 **/
Packit Service 310c69
const struct index_version *getIndexVersion(IndexLayout *layout)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
#endif // INDEX_LAYOUT_H