-
Notifications
You must be signed in to change notification settings - Fork 61
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
Re-write zipl_helper in C #18
Conversation
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.
Please do not introduce a separate library for dasdview. We already have libdasd, which should be extended as needed (there are actually plans to unify dasd tool related code in the long run with libdasd).
In fact, dasdview_read_attribute() is only used to read the raw_track_access attribute and libdasd already provides a function for that: dasd_sys_raw_track_access().
Please use that function instead and avoid libdasdview.
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.
The new util_print_error() function is not required because we use the err()/warn() function family for s390-tools.
libutil/util_base.c
Outdated
va_end (args); | ||
|
||
fprintf(stderr, "Error: %s\n", error_str); | ||
} |
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.
We currently use the err()/warn() family for error printing in the newer s390-tools. See e.g. zconf/chp or zconf/qeth.
So I don't think we need a new libutil function for that.
I just submitted a new version according to the requested changes. |
I did a formal review of
Please review the following patch: In case you agree, update your code accordingly please. FYI: We just started with our coding style document. |
Please fix the following compiler warning (with gcc 4.8.5):
|
If I run the compile a 2nd time, I get the following error:
|
Great, thanks! |
@r4f4 : Thanks for updating your code |
@hoeppnerj / @stefan-haberland : Now it's time to do the functional review by our DASD and zipl experts. |
@r4f4 : You should add the zipl helper to the .gitignore file as follows:
|
@michael-holzheu you are right, I forgot about it. I'll submit a fixed version together with any fixes the DASD and zipl experts asked me to do, if you don't mind. |
@r4f4 I've had a closer look at the DASD changes, which seem to go beyond the scope of this pull request. From what I saw you only need a couple of information relevant to the zipl helper: geo information (sectors, heads, cylinders), type (FBA vs ECKD), format (CDL vs LDL), and blocksize. As we want to grow our libdasd I'd like to suggest to start a new file dasd_ioctl.c which accumulates all IOCTLs starting with the three mentioned ones. Possible function names could be: dasd_get_blocksize(), dasd_get_info(), dasd_get_geo(). To keep this small, it would be sufficient if you only make use of those new functions in the zipl helper for now and leave the DASD tools untouched. I'd prefer a 2nd pull-request for DASD tool related clean-ups then (You don't have to send one of course, we can and certainly will do it at one point anyway. I'm just trying to keep the scope of this particular pull-request at its minimum). |
@hoeppnerj What about I work on those DASD changes right now in a separate PR while I wait on Zipl guys to comment on my changes? |
@r4f4 Sure, feel free, any change is appreciated :-) I just didn't want to make a 2nd PR a prerequisite for the zipl helper. Only wanted to make sure that changes are within a certain scope. |
Hi, thank you very much for your effort. I have tested the helper program in a some setups and it works quite well. Very good. Unfortunately with SCSI devices and a multipath setup I get the following error: zipl_helper.device-mapper: ioctl error The following output is correct but the message itself could lead to some confusion. Another thing I have noticed is that with a multipath setup and the first path failing the message changed: original: new message: Again here. A change in the message that is afterwards visible in the zipl tool could lead to some confusion. Could you please have a look at these points? Thanks. Regards, |
@stefan-haberland Thank you very much for reviewing and trying this patch out. I must remind you that with #19, there will be some changes to this patch regarding the use of DASD ioctls. We can apply the changes in a second commit or wait for the libdasd changes to be merged, whatever you prefer.
This comes from using dasd_get_info. With the work to libdasd being done in #19, we'll be able to eliminate this warning message.
This is a result of using the warn/err family of functions. I guess I'll have to drop that and use my own macros to keep the warning messages intact. |
Changes from previous version:
|
Thanks again for the contribution. I did some quick tests and it works pretty good. |
Just a reminder for you guys not to forget this PR :) |
Not forgotten. Will have a deeper look. |
zipl/src/zipl_helper.device-mapper.c
Outdated
strcpy(name, "LDL"); | ||
break; | ||
default: | ||
WARN("Unrecognized dev type %d\n", type); |
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.
Set "name" to an empty string here to prevent the potential use of uninitialized strings in the calling function.
|
||
va_start(ap, fmt); | ||
util_vasprintf(&cmd, fmt, ap); | ||
va_end(ap); |
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.
Use util_asprintf to remove the need for va_start() and va_end().
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.
You mean I should util_asprintf the command before passing it to `exec_cmd_and_get_out_stream' function?
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.
I missed that this function itself is receiving varargs.. please ignore this comment.
zipl/src/zipl_helper.device-mapper.c
Outdated
util_list_remove(target->data, td); | ||
target_data_free(td); | ||
} | ||
util_list_free(target->data); |
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.
Call target_data_list_free(target->data) to reduce duplicate code.
zipl/src/zipl_helper.device-mapper.c
Outdated
|
||
static int get_dev_characteristics(struct device_characteristics *dc, dev_t dev) | ||
{ | ||
char devname[BDEVNAME_SIZE]; |
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.
devname must be PATH_MAX long or the call to create_temp_device_node could theoretically overrun it.
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.
Good catch.
zipl/src/zipl_helper.device-mapper.c
Outdated
if (res != 0) { | ||
ERR("Could not get block size for '%s'\n", devname); | ||
goto err; | ||
} |
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.
Since the call to dasd_get_blocksize() is done in both cases it can be moved outside of the if-clause. Also this can help getting rid of the "res" variable which is only used here.
zipl/src/zipl_helper.device-mapper.c
Outdated
if (strcmp(info.type, "FBA") == 0) { | ||
dc->type = DEV_TYPE_FBA; | ||
dc->bootsectors = dc->blocksize / SECTOR_SIZE; | ||
} else if (strcmp(info.type, "ECKD") == 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.
Access info.type either via memcmp or strncmp to prevent read access beyond end of type field.
zipl/src/zipl_helper.device-mapper.c
Outdated
struct target *target; | ||
|
||
table = get_table(dev); | ||
if (table == NULL || util_list_start(table) == NULL) { |
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.
Use util_list_is_empty() instead of util_list_start()==NULL to make the meaning clearer.
util_list_remove(table, target); | ||
table_free(table); | ||
|
||
target_list = util_list_new(struct target_entry, list); |
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.
The return value of util_list_new() must be checked for NULL.
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.
My bad. Not all places use util_malloc
.
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.
Yes, using util_malloc() in all library functions should be on our TODO list since its currently somewhat inconsistent (ping @michael-holzheu).
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.
Yes, using util_malloc() in all library functions should be on our TODO list since its currently somewhat inconsistent (ping @michael-holzheu).
Correct - I just submitted the following patch: 89ead06
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.
Ok, I'll remove the NULL checks from my patch.
zipl/src/zipl_helper.device-mapper.c
Outdated
int i; | ||
|
||
for (i = 1; i < argc; i++) | ||
cmdline = util_strcat_realloc(cmdline, argv[i]); |
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.
Why concatenate all of argv when the checked pattern "%u:%u" would be in argv[1] due to a lack of spaces?
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.
Because it might not. The original script handled cases like "maj:min", "maj :min", "maj : min". So to not break this behavior, I opted to concatenate the possible argvs into one single string and then sscanf that (which then ignores the spaces).
If I can assume the supplied string will always be "maj:min", I'd be happy to drop those lines from the patch.
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.
Actually sscanf() only implicitly ignores spaces in front of %-modifiers, so this would not match "maj :min". and "maj : min".
In any case, the format "major:minor" is documented in the initial source file comment and all s390-tools users (zipl, chreipl) use it in this form, so I would assume it is safe to only parse for that. @michael-holzheu - since you initially wrote that particular portion of the Perl-helper, do you see any reason to keep parsing for spaces around ":" in "major:minor"?
Thank you for the review, I'll re-submit the patch with fixes soon. |
bbe410d
to
8d50256
Compare
Code was updated to address @oberpar comments and @michael-holzheu change to util_list. |
Any updates on this? |
All my comments have been addressed. @michael-holzheu - how to proceed here? |
@r4f4 Could you please update the commit message somehow like the following:
@oberpar : Then IMHO we can apply the code. |
@michael-holzheu Done. The new message is much better, tks for the suggestion. |
There are 3 warnings regarding unused variables. Could you please have a look? zipl_helper.device-mapper.c: In function ‘target_free’: |
To remove the perl dependency from zipl rewrite the helper script in C. Signed-off-by: Rafael Fonseca <[email protected]>
@stefan-haberland unused variables were removed. |
thanks, I will integrate the code |
This is the first step in getting rid of Perl as per #5.