Skip to content

[meta] Add check for struct/union binary backward compatibility#1795

Merged
kcudnik merged 7 commits intoopencomputeproject:masterfrom
kcudnik:structbc
Jun 29, 2023
Merged

[meta] Add check for struct/union binary backward compatibility#1795
kcudnik merged 7 commits intoopencomputeproject:masterfrom
kcudnik:structbc

Conversation

@kcudnik
Copy link
Collaborator

@kcudnik kcudnik commented May 13, 2023

This change will force future PRs to be binary backward compatible with structs and unions. This was added to keep all code binary backward compatible if for example, existing code will be using struct array for some sai type, and then only binary sai library will be updated. This change will make sure that no binary break will be possible.

Added restrictions:

  • type of each field and name in union and struct is checked on each index and must match
  • new members can be added only at the end of union (size of union must stay fixed)
  • no existing members can be removed from structs or unions
  • new members can be added at the end of any _api_t struct
  • non _api_t struct cannot be modified
  • alignment of the existing non _api_t structures and union is validated
  • api pattern in api struct must follow rules: create/remove/set/get

Extension headers are ignored in this check.

There maybe some exceptions added in the future for some non essential structures, which would break backward compatibility.

kcudnik added a commit to kcudnik/sonic-sairedis that referenced this pull request May 19, 2023
since commit 8e1fb37 (v1.8.0) there is check enum binary backward
compatibility so we are relaxing this check below, versions do not have
to be equal but both need to be at least 2ebde24 (v1.9.0), this will
make sure that enums are always ok, but since that commit some data
structures changed and are not binary backwad compatible like next hop
group api, acl_capability, structs are backward binary compatible from
commit aed34c8, which closest tag version for it is commit 3ff228a
(v1.12.0), so min version check should be set to (v1.12.0), but some
production branches do not use that high SAI version yet, some use even
version v1.7.0 which then it is impossible to provide even enum backward
compatibility, check those links:
opencomputeproject/SAI#1297 (enums)
opencomputeproject/SAI#1795 (structs)
StormLiangMS pushed a commit to sonic-net/sonic-sairedis that referenced this pull request May 20, 2023
* [configure] Check for minimal SAI version

since commit 8e1fb37 (v1.8.0) there is check enum binary backward
compatibility so we are relaxing this check below, versions do not have
to be equal but both need to be at least 2ebde24 (v1.9.0), this will
make sure that enums are always ok, but since that commit some data
structures changed and are not binary backwad compatible like next hop
group api, acl_capability, structs are backward binary compatible from
commit aed34c8, which closest tag version for it is commit 3ff228a
(v1.12.0), so min version check should be set to (v1.12.0), but some
production branches do not use that high SAI version yet, some use even
version v1.7.0 which then it is impossible to provide even enum backward
compatibility, check those links:
opencomputeproject/SAI#1297 (enums)
opencomputeproject/SAI#1795 (structs)

* Fix condition
@kcudnik
Copy link
Collaborator Author

kcudnik commented May 25, 2023

TODO mark BEGIN_COMMIT=aed34c8 as v1.12.0, and add README.me with explanation and examples

CHECK_STRUCT_SIZE(sai_u32_list_t, 16);
CHECK_STRUCT_SIZE(sai_u32_range_t, 8);
CHECK_STRUCT_SIZE(sai_u8_list_t, 16);
CHECK_STRUCT_SIZE(sai_vlan_list_t, 16);
Copy link
Contributor

Choose a reason for hiding this comment

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

All these structs are part of
https://github.com/opencomputeproject/SAI/blob/6f9d06e9d046c701b273574bcc42e6bc34ed6eba/meta/saimetadatatypes.h#L478C3-L478C24

Imposing this check will not let us define a new structure without impacting the size of sai_attr_value_type_t.

We need to overcome this else we will NEVER be able to add new structures.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thats the point to make it const and be backward compatible

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you can still add new structures, but less in size of current value size

@JaiOCP
Copy link
Contributor

JaiOCP commented Jun 23, 2023 via email

@kcudnik kcudnik merged commit ba8ccba into opencomputeproject:master Jun 29, 2023
@kcudnik kcudnik deleted the structbc branch June 29, 2023 14:52
@rck-innovium
Copy link
Contributor

TODO mark BEGIN_COMMIT=aed34c8 as v1.12.0, and add README.me with explanation and examples

@kcudnik

Can you please point to the readme with explanation and examples.

During the community review, Rita suggested to create a document with examples as to how to handle the case where we need to change the size of an existing struct (for example, when we need add a new field in a key like sai_fdb_entry_t).
You were suggesting an approach of creating a new version like sai_fdb_entry_v2_t etc. It would be helpful if you can add those examples.

@kcudnik
Copy link
Collaborator Author

kcudnik commented Jul 12, 2023

the whole point its you CAN'T change the structures, from that commit, size of structures, members sizes and types and order are constant. Please refer to description of this PR, if something is unclear, i will explain.

I think if you want to create new entry members, just copy one of existing one, add what you need, add specific objects, etc, bring up PR, and we will be discussing your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants