Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/include/daos_srv/rsvc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* (C) Copyright 2019-2024 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP
* (C) Copyright 2025-2026 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -53,6 +53,9 @@ struct ds_rsvc_class {
*/
void (*sc_free)(struct ds_rsvc *svc);

/** Prepare for being inserted into the hash table. */
int (*sc_insert)(struct ds_rsvc *svc);

/**
* Bootstrap (i.e., initialize) the DB with the argument passed to
* ds_rsvc_start. If supplied, this is called on a self-only service.
Expand Down
17 changes: 17 additions & 0 deletions src/pool/srv_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,20 @@ pool_svc_free_cb(struct ds_rsvc *rsvc)
D_FREE(svc);
}

static int
pool_svc_insert_cb(struct ds_rsvc *rsvc)
{
struct pool_svc *svc = pool_svc_obj(rsvc);

/*
* While we were starting svc, there might be a ds_pool_stop call who
* is waiting for us to put svc->ps_pool.
*/
if (svc->ps_pool->sp_stopping)
return -DER_CANCELED;
return 0;
}

/*
* Update svc->ps_pool with map_buf and map_version. This ensures that
* svc->ps_pool matches the latest pool map.
Expand Down Expand Up @@ -2727,16 +2741,19 @@ pool_svc_map_dist_cb(struct ds_rsvc *rsvc, uint32_t *version)
return rc;
}

/* clang-format off */
static struct ds_rsvc_class pool_svc_rsvc_class = {
.sc_name = pool_svc_name_cb,
.sc_locate = pool_svc_locate_cb,
.sc_alloc = pool_svc_alloc_cb,
.sc_free = pool_svc_free_cb,
.sc_insert = pool_svc_insert_cb,
.sc_step_up = pool_svc_step_up_cb,
.sc_step_down = pool_svc_step_down_cb,
.sc_drain = pool_svc_drain_cb,
.sc_map_dist = pool_svc_map_dist_cb
};
/* clang-format on */

void
ds_pool_rsvc_class_register(void)
Expand Down
11 changes: 10 additions & 1 deletion src/rsvc/srv.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* (C) Copyright 2019-2024 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP
* (C) Copyright 2025-2026 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -1042,10 +1042,19 @@ ds_rsvc_start(enum ds_rsvc_class_id class, d_iov_t *id, uuid_t db_uuid, uint64_t
if (rc != 0)
goto out;

if (rsvc_class(class)->sc_insert != NULL) {
rc = rsvc_class(class)->sc_insert(svc);
if (rc != 0) {
D_DEBUG(DB_MD, "%s: sc_insert: " DF_RC "\n", svc->s_name, DP_RC(rc));
goto err_svc_started;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unusual goto, though I see the reasoning (do not duplicate stop call line of code here, and do not generate inaccurate D_DEBUG log when it is sc_insert that failed rather than d_hash_rec_insert)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a bit unusual, though I occasionally use this method. If I revise this PR next time, I'll change this to just duplicate the stop call.

}
}

rc = d_hash_rec_insert(&rsvc_hash, svc->s_id.iov_buf, svc->s_id.iov_len,
&svc->s_entry, true /* exclusive */);
if (rc != 0) {
D_DEBUG(DB_MD, "%s: insert: "DF_RC"\n", svc->s_name, DP_RC(rc));
err_svc_started:
stop(svc, mode == DS_RSVC_CREATE /* destroy */);
goto out;
}
Expand Down
Loading