<commit_before>/* $Id$ */
/*
 * %PSC_START_COPYRIGHT%
 * -----------------------------------------------------------------------------
 * Copyright (c) 2006-2012, Pittsburgh Supercomputing Center (PSC).
 *
 * Permission to use, copy, and modify this software and its documentation
 * without fee for personal use or non-commercial use within your organization
 * is hereby granted, provided that the above copyright notice is preserved in
 * all copies and that the copyright and this permission notice appear in
 * supporting documentation.  Permission to redistribute this software to other
 * organizations or individuals is not permitted without the written permission
 * of the Pittsburgh Supercomputing Center.  PSC makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 * -----------------------------------------------------------------------------
 * %PSC_END_COPYRIGHT%
 */

/*
 * The bmap (block map) interface divides the space of a file in a SLASH
 * network into manageable units.  bmaps are ordered sequentially from
 * the beginning of the file space and are the fundamental elements of
 * I/O node file region ownership and in replication management.
 *
 * bmaps store information such as the state on each replicated instance
 * and are themselves subdivided into slivers which track cyclic redundancy
 * checksums for integrity and such.
 */

#ifndef _BMAP_H_
#define _BMAP_H_

#include <inttypes.h>
#include <time.h>

#include "psc_ds/tree.h"
#include "psc_ds/list.h"
#include "psc_util/atomic.h"
#include "psc_util/crc.h"
#include "psc_util/lock.h"

#include "cache_params.h"
#include "fid.h"
#include "slsubsys.h"
#include "sltypes.h"

struct fidc_membh;
struct srt_bmapdesc;

/**
 * bmap_core_state - Basic information needed by all nodes.
 * @bcs_crcstates: bits describing the state of each sliver.
 * @bcs_repls: bitmap used for tracking the replication status of this bmap.
 *
 * This structure must be 64-bit aligned and padded.
 */
struct bmap_core_state {
	uint8_t			bcs_crcstates[SLASH_CRCS_PER_BMAP];
	uint8_t			bcs_repls[SL_REPLICA_NBYTES];
};

/**
 * bmap_extra_state - Additional fields needed by MDS.
 * @bes_crcs: the CRC table, one 8-byte CRC per sliver.
 * @bes_gen: current generation number.
 * @bes_replpol: replication policy.
 *
 * This structure must be 64-bit aligned and padded.
 */
struct bmap_extra_state {
	uint64_t		bes_crcs[SLASH_CRCS_PER_BMAP];
	sl_bmapgen_t		bes_gen;
	uint32_t		bes_replpol;
};

/**
 * bmap_ondisk - Bmap over-wire/on-disk structure.  This structure maps
 *	the persistent state of the bmap within the inode's metafile.
 * @bod_bhcrc: on-disk checksum.
 */
struct bmap_ondisk {
	struct bmap_core_state	bod_corestate;
	struct bmap_extra_state	bod_extrastate;
#define bod_repls	bod_corestate.bcs_repls
#define bod_crcstates	bod_corestate.bcs_crcstates
#define bod_crcs	bod_extrastate.bes_crcs
#define bod_replpol	bod_extrastate.bes_replpol
};

/**
 * bmapc_memb - Central structure for block map caching used in all
 *	SLASH service contexts (mds, ios, client).  The pool for this
 *	structure and its private area for each service is initialized
 *	in bmap_cache_init().
 *
 * bmapc_memb sits in the middle of the GFC stratum.
 * XXX some of these elements may need to be moved into the bcm_info_pri
 *     area (as part of new structures?) so save space on the mds.
 */
struct bmapc_memb {
	sl_bmapno_t		 bcm_bmapno;	/* bmap index number */
	struct fidc_membh	*bcm_fcmh;	/* pointer to fid info */
	psc_atomic32_t		 bcm_opcnt;	/* pending opcnt */
	uint32_t		 bcm_flags;	/* see BMAP_* below */
	psc_spinlock_t		 bcm_lock;
	SPLAY_ENTRY(bmapc_memb)	 bcm_tentry;	/* bmap_cache splay tree entry */
	struct psc_listentry	 bcm_lentry;	/* free pool */

	/*
	 * This must start on a 64-bit boundary, and must lay at the end
	 * of this structure as the bmap_{mds,iod}_info begin with the
	 * next segment of the bmap_ondisk, which must lay contiguous in
	 * memory for I/O over the network and with ZFS.
	 */
	struct bmap_core_state	 bcm_corestate __attribute__ ((aligned (8)));

#define bcm_crcstates	bcm_corestate.bcs_crcstates
#define bcm_repls	bcm_corestate.bcs_repls
};

/* shared bmap_flags */
#define BMAP_RD			(1 << 0)	/* XXX use enum rw */
#define BMAP_WR			(1 << 1)	/* XXX use enum rw */
#define BMAP_INIT		(1 << 2)	/* initializing from disk/network */
#define BMAP_DIO		(1 << 3)	/* direct I/O, no client caching */
#define BMAP_DIORQ		(1 << 4)
#define BMAP_CLOSING		(1 << 5)	/* refcnt dropped to zero, removing */
#define BMAP_DIRTY		(1 << 6)
#define BMAP_MEMRLS		(1 << 7)
#define BMAP_DIRTY2LRU		(1 << 8)
#define BMAP_TIMEOQ		(1 << 9)	/* on timeout queue */
#define BMAP_IONASSIGN		(1 << 10)	/* has been assigned to an ION for writes */
#define BMAP_MDCHNG		(1 << 11)
#define BMAP_WAITERS		(1 << 12)	/* has bcm_fcmh waiters */
#define BMAP_ORPHAN		(1 << 13)	/* removed from fcmh_bmaptree */
#define BMAP_BUSY		(1 << 14)	/* temporary processing lock */
#define BMAP_NEW		(1 << 15)	/* just created */
#define BMAP_ARCHIVER		(1 << 16)	/* archiver */
#define _BMAP_FLSHFT		(1 << 17)

#define SL_MAX_IOSREASSIGN              	16
#define SL_MAX_BMAP_FLUSH_RETRIES             	128	

#define BMAP_LOCK_ENSURE(b)	LOCK_ENSURE(&(b)->bcm_lock)
#define BMAP_HASLOCK(b)		psc_spin_haslock(&(b)->bcm_lock)
#define BMAP_LOCK(b)		spinlock(&(b)->bcm_lock)
#define BMAP_ULOCK(b)		freelock(&(b)->bcm_lock)
#define BMAP_RLOCK(b)		reqlock(&(b)->bcm_lock)
#define BMAP_URLOCK(b, lk)	ureqlock(&(b)->bcm_lock, (lk))
#define BMAP_TRYLOCK(b)		trylock(&(b)->bcm_lock)

#define BMAP_SETATTR(b, fl)	SETATTR_LOCKED(&(b)->bcm_lock, &(b)->bcm_flags, (fl))
#define BMAP_CLEARATTR(b, fl)	CLEARATTR_LOCKED(&(b)->bcm_lock, &(b)->bcm_flags, (fl))

#define _DEBUG_BMAP_FMT		"bmap@%p bno:%u flg:%#x:"		\
				"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s "	\
				"fid:"SLPRI_FID" opcnt=%u "

#define _DEBUG_BMAP_FMTARGS(b)						\
	(b), (b)->bcm_bmapno, (b)->bcm_flags,				\
	(b)->bcm_flags & BMAP_RD	? "R" : "",			\
	(b)->bcm_flags & BMAP_WR	? "W" : "",			\
	(b)->bcm_flags & BMAP_INIT	? "I" : "",			\
	(b)->bcm_flags & BMAP_DIO	? "D" : "",			\
	(b)->bcm_flags & BMAP_DIORQ	? "Q" : "",			\
	(b)->bcm_flags & BMAP_CLOSING	? "C" : "",			\
	(b)->bcm_flags & BMAP_DIRTY	? "d" : "",			\<commit_msg>increase this value to overcome a bug in the flush retry logic<commit_after>/* $Id$ */
/*
 * %PSC_START_COPYRIGHT%
 * -----------------------------------------------------------------------------
 * Copyright (c) 2006-2012, Pittsburgh Supercomputing Center (PSC).
 *
 * Permission to use, copy, and modify this software and its documentation
 * without fee for personal use or non-commercial use within your organization
 * is hereby granted, provided that the above copyright notice is preserved in
 * all copies and that the copyright and this permission notice appear in
 * supporting documentation.  Permission to redistribute this software to other
 * organizations or individuals is not permitted without the written permission
 * of the Pittsburgh Supercomputing Center.  PSC makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 * -----------------------------------------------------------------------------
 * %PSC_END_COPYRIGHT%
 */

/*
 * The bmap (block map) interface divides the space of a file in a SLASH
 * network into manageable units.  bmaps are ordered sequentially from
 * the beginning of the file space and are the fundamental elements of
 * I/O node file region ownership and in replication management.
 *
 * bmaps store information such as the state on each replicated instance
 * and are themselves subdivided into slivers which track cyclic redundancy
 * checksums for integrity and such.
 */

#ifndef _BMAP_H_
#define _BMAP_H_

#include <inttypes.h>
#include <time.h>

#include "psc_ds/tree.h"
#include "psc_ds/list.h"
#include "psc_util/atomic.h"
#include "psc_util/crc.h"
#include "psc_util/lock.h"

#include "cache_params.h"
#include "fid.h"
#include "slsubsys.h"
#include "sltypes.h"

struct fidc_membh;
struct srt_bmapdesc;

/**
 * bmap_core_state - Basic information needed by all nodes.
 * @bcs_crcstates: bits describing the state of each sliver.
 * @bcs_repls: bitmap used for tracking the replication status of this bmap.
 *
 * This structure must be 64-bit aligned and padded.
 */
struct bmap_core_state {
	uint8_t			bcs_crcstates[SLASH_CRCS_PER_BMAP];
	uint8_t			bcs_repls[SL_REPLICA_NBYTES];
};

/**
 * bmap_extra_state - Additional fields needed by MDS.
 * @bes_crcs: the CRC table, one 8-byte CRC per sliver.
 * @bes_gen: current generation number.
 * @bes_replpol: replication policy.
 *
 * This structure must be 64-bit aligned and padded.
 */
struct bmap_extra_state {
	uint64_t		bes_crcs[SLASH_CRCS_PER_BMAP];
	sl_bmapgen_t		bes_gen;
	uint32_t		bes_replpol;
};

/**
 * bmap_ondisk - Bmap over-wire/on-disk structure.  This structure maps
 *	the persistent state of the bmap within the inode's metafile.
 * @bod_bhcrc: on-disk checksum.
 */
struct bmap_ondisk {
	struct bmap_core_state	bod_corestate;
	struct bmap_extra_state	bod_extrastate;
#define bod_repls	bod_corestate.bcs_repls
#define bod_crcstates	bod_corestate.bcs_crcstates
#define bod_crcs	bod_extrastate.bes_crcs
#define bod_replpol	bod_extrastate.bes_replpol
};

/**
 * bmapc_memb - Central structure for block map caching used in all
 *	SLASH service contexts (mds, ios, client).  The pool for this
 *	structure and its private area for each service is initialized
 *	in bmap_cache_init().
 *
 * bmapc_memb sits in the middle of the GFC stratum.
 * XXX some of these elements may need to be moved into the bcm_info_pri
 *     area (as part of new structures?) so save space on the mds.
 */
struct bmapc_memb {
	sl_bmapno_t		 bcm_bmapno;	/* bmap index number */
	struct fidc_membh	*bcm_fcmh;	/* pointer to fid info */
	psc_atomic32_t		 bcm_opcnt;	/* pending opcnt */
	uint32_t		 bcm_flags;	/* see BMAP_* below */
	psc_spinlock_t		 bcm_lock;
	SPLAY_ENTRY(bmapc_memb)	 bcm_tentry;	/* bmap_cache splay tree entry */
	struct psc_listentry	 bcm_lentry;	/* free pool */

	/*
	 * This must start on a 64-bit boundary, and must lay at the end
	 * of this structure as the bmap_{mds,iod}_info begin with the
	 * next segment of the bmap_ondisk, which must lay contiguous in
	 * memory for I/O over the network and with ZFS.
	 */
	struct bmap_core_state	 bcm_corestate __attribute__ ((aligned (8)));

#define bcm_crcstates	bcm_corestate.bcs_crcstates
#define bcm_repls	bcm_corestate.bcs_repls
};

/* shared bmap_flags */
#define BMAP_RD			(1 << 0)	/* XXX use enum rw */
#define BMAP_WR			(1 << 1)	/* XXX use enum rw */
#define BMAP_INIT		(1 << 2)	/* initializing from disk/network */
#define BMAP_DIO		(1 << 3)	/* direct I/O, no client caching */
#define BMAP_DIORQ		(1 << 4)
#define BMAP_CLOSING		(1 << 5)	/* refcnt dropped to zero, removing */
#define BMAP_DIRTY		(1 << 6)
#define BMAP_MEMRLS		(1 << 7)
#define BMAP_DIRTY2LRU		(1 << 8)
#define BMAP_TIMEOQ		(1 << 9)	/* on timeout queue */
#define BMAP_IONASSIGN		(1 << 10)	/* has been assigned to an ION for writes */
#define BMAP_MDCHNG		(1 << 11)
#define BMAP_WAITERS		(1 << 12)	/* has bcm_fcmh waiters */
#define BMAP_ORPHAN		(1 << 13)	/* removed from fcmh_bmaptree */
#define BMAP_BUSY		(1 << 14)	/* temporary processing lock */
#define BMAP_NEW		(1 << 15)	/* just created */
#define BMAP_ARCHIVER		(1 << 16)	/* archiver */
#define _BMAP_FLSHFT		(1 << 17)

#define SL_MAX_IOSREASSIGN              	16
#define SL_MAX_BMAP_FLUSH_RETRIES             	2048

#define BMAP_LOCK_ENSURE(b)	LOCK_ENSURE(&(b)->bcm_lock)
#define BMAP_HASLOCK(b)		psc_spin_haslock(&(b)->bcm_lock)
#define BMAP_LOCK(b)		spinlock(&(b)->bcm_lock)
#define BMAP_ULOCK(b)		freelock(&(b)->bcm_lock)
#define BMAP_RLOCK(b)		reqlock(&(b)->bcm_lock)
#define BMAP_URLOCK(b, lk)	ureqlock(&(b)->bcm_lock, (lk))
#define BMAP_TRYLOCK(b)		trylock(&(b)->bcm_lock)

#define BMAP_SETATTR(b, fl)	SETATTR_LOCKED(&(b)->bcm_lock, &(b)->bcm_flags, (fl))
#define BMAP_CLEARATTR(b, fl)	CLEARATTR_LOCKED(&(b)->bcm_lock, &(b)->bcm_flags, (fl))

#define _DEBUG_BMAP_FMT		"bmap@%p bno:%u flg:%#x:"		\
				"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s "	\
				"fid:"SLPRI_FID" opcnt=%u "

#define _DEBUG_BMAP_FMTARGS(b)						\
	(b), (b)->bcm_bmapno, (b)->bcm_flags,				\
	(b)->bcm_flags & BMAP_RD	? "R" : "",			\
	(b)->bcm_flags & BMAP_WR	? "W" : "",			\
	(b)->bcm_flags & BMAP_INIT	? "I" : "",			\
	(b)->bcm_flags & BMAP_DIO	? "D" : "",			\
	(b)->bcm_flags & BMAP_DIORQ	? "Q" : "",			\
	(b)->bcm_flags & BMAP_CLOSING	? "C" : "",			\
	(b)->bcm_flags & BMAP_DIRTY	? "d" : "",			\
{'fraction_non_alphanumeric': 0.1375226967711376, 'fraction_numerical': 0.012078629509749743, 'mean_word_length': 3.6250456370938298, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '601566', 'n_tokens_mistral': 4972, 'n_tokens_neox': 4757, 'n_words': 1351}