-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: libcrmcommon: handle schema versions properly #1308
Conversation
As a byproduct, this eliminates a dependency on the math library.
lib/common/schemas.c
Outdated
{ | ||
int rc = sscanf(filename, "pacemaker-%d.%d.rng", &version[0], &version[1]); | ||
|
||
return (rc == 2)? TRUE : FALSE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (rc == 2)
suffices
lib/common/schemas.c
Outdated
@@ -134,19 +130,27 @@ get_schema_path(const char *name, const char *file) | |||
return crm_strdup_printf("%s/%s.rng", base, name); | |||
} | |||
|
|||
static inline bool | |||
version_from_filename(const char *filename, int version[2]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated use of int[2]
might perhaps justify a typedef'd type.
(put on the line where it became obvious to me)
lib/common/schemas.c
Outdated
} | ||
|
||
static void | ||
__xml_schema_add(int type, float version, const char *name, | ||
__xml_schema_add(int type, int version[2], const char *name, | ||
const char *location, const char *transform, | ||
int after_transform) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const int version[2]
?
Do we need to reserve negative values for anything? Otherwise I'd be in favor of |
lib/common/schemas.c
Outdated
@@ -246,34 +255,35 @@ crm_schema_init(void) | |||
int lpc, max; | |||
const char *base = get_schema_root(); | |||
struct dirent **namelist = NULL; | |||
int zero[2] = {0, 0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be const
then...
Note that ceiling of 256 could also be good incentive not to bump the |
lib/common/schemas.c
Outdated
known_schemas[last].version = version; | ||
sscanf(name, "%*[^-]-%d.%d", | ||
&known_schemas[last].version[0], | ||
&known_schemas[last].version[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also nice cleanup :) (not that I am fluent with sscanf
, looked that up).
lib/common/schemas.c
Outdated
struct stat s; | ||
char *xslt = NULL; | ||
|
||
transform = crm_strdup_printf("upgrade-%.1f.xsl", version); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently upgrading from 2.10
was unexpected in the old world order.
On the more general note, following downside for this approach to
which used to be noticable simplification especially in XSLT handling Looking at some other possibly affected software pieces:
TL;DR: Not the end of the world :) |
for readability
Added commits for review items and a little more cleanup |
Originally, pacemaker was treating versions of its CIB schema files as floats, simplifying comparisons in a simplistic single-digit minor version realms. As the necessity to roll out a new schema version catering the new needs is around the corner, it was decided[1] that pacemaker will not bump the major part abrubtly (against the rules[2]), but rather the overflow to a new higher digit will occur. That breaks the assumption of easy comparisons in two previously common angles: - string (e.g. when looking at /cib@validate-with XPath within CIB or at the available, respectively named schema files) - mentioned float (when parsing the numerical part out of the string): 2.11 < 2.2, .... Here, just the former is relevant; XML.etree_rng_validator_proper_specs was supposed to return ordered sequence of embedded/available schemas, which is used, for instance, to grab the lowest possible for the purpose of upgrading the schema for particular CIB document internally. Formerly, the sorting was based on lexicographical comparison, now, thanks to `namever_partition` (added with the previous commit) wired into the process, it performs combined lexicographical+version comparison so everything should keep working as expected even when 2.10+ versions of CIB schemas are common. [1] ClusterLabs/pacemaker#1308 [2] https://github.com/ClusterLabs/pacemaker/blob/master/xml/Readme.md Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Originally, pacemaker was treating versions of its CIB schemas (respectively named files) as floats, simplifying comparisons in a simplistic single-digit minor version realms. As the necessity to roll out a new schema version catering the new needs is around the corner, it was decided[1] that pacemaker will not bump the major part abrubtly (against the rules[2]), but rather the overflow to a new higher digit in the minor part will occur. That breaks assumption of easy comparisons in two previously common angles: - string (e.g. when looking at /cib@validate-with XPath within CIB or at the available, respectively named schema files); example: pacemaker-2.10 < pacemaker-2.2 - mentioned float (when parsing the numerical part out of the string): example: 2.11 < 2.2 Here, just the former is relevant; XML.etree_rng_validator_proper_specs was supposed to return ordered sequence of embedded/available schemas, which is used, for instance, to grab the lowest possible for the purpose of upgrading the schema for particular CIB document internally. Formerly, the sorting was based on lexicographical comparison, now, thanks to `namever_partition` (added with the previous commit) wired into the process, it performs combined lexicographical+version comparison so everything should keep working as expected even when 2.10+ versions of CIB schemas are common. [1] ClusterLabs/pacemaker#1308 [2] https://github.com/ClusterLabs/pacemaker/blob/master/xml/Readme.md Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Originally, pacemaker was treating versions of its CIB schemas (respectively named files) as floats, simplifying comparisons in a simplistic single-digit minor version realms. As the necessity to roll out a new schema version catering the new needs is around the corner, it was decided[1] that pacemaker will not bump the major part abrubtly (against the rules[2]), but rather the overflow to a new higher digit in the minor part will occur. That breaks assumption of easy comparisons in two previously common angles: - string (e.g. when looking at /cib@validate-with XPath within CIB or at the available, respectively named schema files); example: pacemaker-2.10 < pacemaker-2.2 - mentioned float (when parsing the numerical part out of the string): example: 2.11 < 2.2 Here, just the former is relevant; XML.etree_rng_validator_proper_specs was supposed to return ordered sequence of embedded/available schemas, which is used, for instance, to grab the lowest possible for the purpose of upgrading the schema for particular CIB document internally. Formerly, the sorting was based on lexicographical comparison, now, thanks to `namever_partition` (added with the previous commit) wired into the process, it performs combined lexicographical+version comparison so everything should keep working as expected even when 2.10+ versions of CIB schemas are common. Note: misc/pacemaker-borrow-schemas with it's "sort -V" should be covered, but the eye should be kept on that when pacemaker-2.10.rng actually arrives. [1] ClusterLabs/pacemaker#1308 [2] https://github.com/ClusterLabs/pacemaker/blob/master/xml/Readme.md Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Originally, pacemaker was treating versions of its CIB schemas (respectively named files) as floats, simplifying comparisons in a simplistic single-digit minor version realms. As the necessity to roll out a new schema version catering the new needs is around the corner, it was decided[1] that pacemaker will not bump the major part abrubtly (against the rules[2]), but rather the overflow to a new higher digit in the minor part will occur. That breaks assumption of easy comparisons in two previously common angles: - string (e.g. when looking at /cib@validate-with XPath within CIB or at the available, respectively named schema files); example: pacemaker-2.10 < pacemaker-2.2 - mentioned float (when parsing the numerical part out of the string): example: 2.11 < 2.2 Here, just the former is relevant; XML.etree_rng_validator_proper_specs was supposed to return ordered sequence of embedded/available schemas, which is used, for instance, to grab the lowest possible for the purpose of upgrading the schema for particular CIB document internally. Formerly, the sorting was based on lexicographical comparison, now, thanks to `namever_partition` (added with the previous commit) wired into the process, it performs combined lexicographical+version comparison so everything should keep working as expected even when 2.10+ versions of CIB schemas are common. Note: misc/pacemaker-borrow-schemas with it's "sort -V" should be covered, but the eye should be kept on that when pacemaker-2.10.rng actually arrives. [1] ClusterLabs/pacemaker#1308 [2] https://github.com/ClusterLabs/pacemaker/blob/master/xml/Readme.md Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
As a byproduct, this eliminates a dependency on the math library.