Skip to content

Commit

Permalink
Add a function users can use to cycle oids
Browse files Browse the repository at this point in the history
Required-githooks: true

Signed-off-by: Jeff Olivier <jeffolivier@google.com>
  • Loading branch information
jolivier23 committed Aug 29, 2024
1 parent 79e8165 commit 1b5a38c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
19 changes: 3 additions & 16 deletions src/client/dfs/dfs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,6 @@
/** Max recursion depth for symlinks */
#define DFS_MAX_RECURSION 40

/** MAX value for the HI OID */
#define MAX_OID_HI ((1UL << 32) - 1)

/** Use a large prime for cycling through all oids */
#define OID_INC (999999937)

static inline void
oid_inc(daos_obj_id_t *oid)
{
oid->hi = (oid->hi + OID_INC) & MAX_OID_HI;
/** Skip reserved entries */
if (oid->lo == RESERVED_LO && oid->hi <= 1)
oid->hi += OID_INC;
}

typedef uint64_t dfs_magic_t;
typedef uint16_t dfs_sb_ver_t;
typedef uint16_t dfs_layout_ver_t;
Expand Down Expand Up @@ -371,7 +356,9 @@ oid_gen(dfs_t *dfs, daos_oclass_id_t oclass, bool file, daos_obj_id_t *oid)

/** set oid and lo, bump the current hi value */
oid->lo = dfs->oid.lo;
oid_inc(&dfs->oid);
daos_obj_oid_cycle(&dfs->oid);
if (unlikely(dfs->oid.lo == RESERVED_LO && dfs->oid.hi <= 1))
daos_obj_oid_cycle(&dfs->oid); /* Avoid reserved oids */
oid->hi = dfs->oid.hi;
D_MUTEX_UNLOCK(&dfs->lock);

Expand Down
8 changes: 2 additions & 6 deletions src/client/dfs/mnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,17 @@ dfs_mount(daos_handle_t poh, daos_handle_t coh, int flags, dfs_t **_dfs)
dfs->last_hi = (unsigned int)d_rand();
/** Avoid potential conflict with SB or ROOT */
if (dfs->last_hi <= 1)
dfs->last_hi += OID_INC;
dfs->last_hi = 2;

rc = daos_cont_alloc_oids(coh, 1, &dfs->oid.lo, NULL);
if (rc) {
D_ERROR("daos_cont_alloc_oids() Failed, " DF_RC "\n", DP_RC(rc));
D_GOTO(err_root, rc = daos_der2errno(rc));
}

/*
* if this is the first time we allocate on this container,
* account 0 for SB, 1 for root obj.
*/
dfs->oid.hi = dfs->last_hi;
/** Increment so that dfs->last_hi is the last value */
oid_inc(&dfs->oid);
daos_obj_oid_cycle(&dfs->oid);
}

dfs->mounted = DFS_MOUNT;
Expand Down
17 changes: 16 additions & 1 deletion src/include/daos_obj.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright 2015-2023 Intel Corporation.
* (C) Copyright 2015-2024 Intel Corporation.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -564,6 +564,21 @@ daos_obj_generate_oid(daos_handle_t coh, daos_obj_id_t *oid,
enum daos_otype_t type, daos_oclass_id_t cid,
daos_oclass_hints_t hints, uint32_t args);


/**
* This function, if called 2^32 times will set oid->hi to every unique 32-bit
* value. The caller is responsible for setting the initial value, tracking the
* final value, and avoiding any values that are otherwise reserved.
*
* \param[in, out] oid oid to cycle
*/
static inline void
daos_obj_oid_cycle(daos_obj_id_t *oid)
{
/** Uses a large prime number to guarantee hitting every unique value */
oid->hi = (oid->hi + 999999937) & UINT_MAX;
}

/**
* Open an DAOS object.
*
Expand Down

0 comments on commit 1b5a38c

Please sign in to comment.