[LU-7557] Add fid_to_string and string_to_fid functions Created: 15/Dec/15 Updated: 03/Feb/16 |
|
| Status: | Open |
| Project: | Lustre |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor |
| Reporter: | Ben Evans (Inactive) | Assignee: | Ben Evans (Inactive) |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Rank (Obsolete): | 9223372036854775807 |
| Description |
|
Add fid_to_string and string_to_fid functions for more readable print/scan statements. Allow for error checking, defaults, etc. Example print statement: Original: C_DEBUG(D_PAGE, "%lu@"DFID" %p %lx %d\n", New: C_DEBUG(D_PAGE, "%lu@%s %p %lx %d\n", Example scan: Original: if (sscanf(opt.o_src, SFID, RFID(&old_fid)) != 3 || ... New: |
| Comments |
| Comment by Ben Evans (Inactive) [ 15/Dec/15 ] |
|
Offshoot from discussion of |
| Comment by James A Simmons [ 15/Dec/15 ] |
|
Yes please do this. The upstream reviewers hate macros so replacing this with inline functions would be the way to go. |
| Comment by Robert Read (Inactive) [ 15/Dec/15 ] |
|
The caller should be managing memory for fid_to_string, and you''ll need handle bad strings in string_to_fid, so how about these prototypes: int fid_to_string(const struct lu_fid *fid, char * str, size_t length); To keep things simple I suggest that fid_to_string should not include the braces, and let applications add the braces where needed. |
| Comment by Ben Evans (Inactive) [ 15/Dec/15 ] |
|
I was thinking: const str* fid_to_string(const struct lu_fid fid, str string, int sz); struct lu_fid string_to_fid(char* fidstr); I'm fine with the nobraces version. 99% of all the uses of this are going to be for printk statements, and all but one place where fids are read in. |
| Comment by Robert Read (Inactive) [ 15/Dec/15 ] |
|
If these are going to be library functions then there will be more uses than just what you can find in the Lustre tree. We need to be able to handle whatever is thrown at us from external applications. Returning a pointer to the passed in buffer is reasonable for fid_to_string, just make sure to handle case when the buffer is too small in a sane way. I would prefer an actual return code from string_to_fid so applications using this can deal with garbage as early as possible. |
| Comment by Ben Evans (Inactive) [ 16/Dec/15 ] |
|
I was thinking it should look like atoi and itoa |
| Comment by Robert Read (Inactive) [ 16/Dec/15 ] |
|
Well, atoi does no error checking and is essentially the poster child for what not to do. There is strtol which does check errors, but with an overly complex interface for our needs. Instead of returning the error code (which seems the most conventional to me), another option is to pass &error to the string_to_fid(). |
| Comment by James A Simmons [ 16/Dec/15 ] |
|
Just as a note I had discussion with Greg about the policy of UAPI type headers. What I was told was UAPI headers, ones shared between kernel and user space, should only contain data structure or simple defines. No functions should be used in UAPI headers. |
| Comment by Ben Evans (Inactive) [ 16/Dec/15 ] |
|
I think we've got more flexability with str_to_fid in terms of return and fields than fid_to_str. But yes, error checking is a good thing here. |
| Comment by Robert Read (Inactive) [ 17/Dec/15 ] |
|
James, that's right and also there shouldn't be any inline functions in GPL headers intended to be used by non-GPL code. |
| Comment by Andreas Dilger [ 24/Dec/15 ] |
|
I agree with Robert here. Having an explicit error returned from string_to_fid() is needed to make the error handling reasonable. It might make sense to have a separate fid_to_string_br() or something that prints the standard square brackets around the FID, or it will make for a lot of "[%s]" in the code, and easy to miss those and have inconsistent output. |
| Comment by Gerrit Updater [ 11/Jan/16 ] |
|
Ben Evans (bevans@cray.com) uploaded a new patch: http://review.whamcloud.com/17933 |
| Comment by Ben Evans (Inactive) [ 03/Feb/16 ] |
|
Started based on comments in: https://jira.hpdd.intel.com/browse/LU-5011 |