pdr: Add pldm_pdr_delete_by_record_handle() API
Adds a new libpldm API to delete the PDR record from the PDR repo
based on the record handle of the PDR record.
Change-Id: I44f5568aa024660f7d370d9a2c6b3f9286d96ed8
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/src/dsp/pdr.c b/src/dsp/pdr.c
index 95526ff..efc94d2 100644
--- a/src/dsp/pdr.c
+++ b/src/dsp/pdr.c
@@ -456,6 +456,46 @@
return -ENOENT;
}
+LIBPLDM_ABI_TESTING
+int pldm_pdr_delete_by_record_handle(pldm_pdr *repo, uint32_t record_handle,
+ bool is_remote)
+{
+ pldm_pdr_record *record;
+ pldm_pdr_record *prev = NULL;
+ int rc = 0;
+ uint16_t rec_handle = 0;
+
+ if (!repo) {
+ return -EINVAL;
+ }
+ record = repo->first;
+
+ while (record != NULL) {
+ struct pldm_msgbuf _buf;
+ struct pldm_msgbuf *buf = &_buf;
+ rc = pldm_msgbuf_init_errno(buf, sizeof(struct pldm_pdr_hdr),
+ record->data, record->size);
+
+ if (rc) {
+ return rc;
+ }
+ if ((rc = pldm_msgbuf_extract(buf, rec_handle))) {
+ return rc;
+ }
+ if (record->is_remote == is_remote &&
+ rec_handle == record_handle) {
+ prev = pldm_pdr_get_prev_record(repo, record);
+ return pldm_pdr_remove_record(repo, record, prev);
+ }
+ rc = pldm_msgbuf_destroy(buf);
+ if (rc) {
+ return rc;
+ }
+ record = record->next;
+ }
+ return -ENOENT;
+}
+
typedef struct pldm_entity_association_tree {
pldm_entity_node *root;
uint16_t last_used_container_id;