Skip to content
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

Some metadata improvements #476

Closed
wants to merge 5 commits into from

Conversation

mulkieran
Copy link
Member

@mulkieran mulkieran commented Jul 20, 2017

This PR does the following:

  • Adds some more tests.
  • Fixes a bug in MDARegions::initialize().
  • Improves StaticHeader implementation by abstracting some methods, simplifying some others, and refining sigblock_from_buf() so that it takes into account the possibility of a partial read.
  • Improves MDARegions::load() by having it return an error if there is truly an error in reading an MDA region.
  • Gets rid of one TODO.
  • Gets rid of two clippy errors.

@mulkieran mulkieran changed the title Master read exact When reading the StaticHeader distinguish a bit better between error and no header Jul 20, 2017
@mulkieran mulkieran force-pushed the master-read-exact branch 2 times, most recently from 2182cb3 to e685c70 Compare July 20, 2017 18:10
@mulkieran
Copy link
Member Author

rebased.

@mulkieran mulkieran requested a review from agrover July 20, 2017 20:31
@mulkieran mulkieran changed the title When reading the StaticHeader distinguish a bit better between error and no header Some metadata improvements Jul 20, 2017
@mulkieran
Copy link
Member Author

@agrover review?

@mulkieran
Copy link
Member Author

mulkieran commented Jul 20, 2017

It might actually be better to have an MDAHeader::initialize() function which initializes the MDAHeader with all 0s except for the correct crc. I think that would be slightly more correct. Easy to do by making a default MDAHeader object that is all 0s, and using to_buf() to get the correct data.

@mulkieran
Copy link
Member Author

Ok, I think this is ready to go now. @agrover review?

where F: Read + Seek
{
try!(f.seek(SeekFrom::Start(0)));
let mut buf = [0u8; _BDA_STATIC_HDR_SIZE];
try!(f.read(&mut buf));
Ok(buf)
let bytes = try!(f.read(&mut buf));
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what clippy suggested, so I tried it, then, when the existing tests failed I realized what was wrong. (I guess it is an archaism that the branch is called master-read-exact still).

What is wrong is that setup() is called in a context where it is not certain whether there is a static header or not. One perfectly good reason for there not being a static header is if we have some peculiar block device which we can't read a lot of data from and which does not belong to Stratis. The result of using read_exact() is to cause engine initialization to promptly fail, presumably in find_all when it tries to determine ownership on some slightly surprising device.

Copy link
Contributor

Choose a reason for hiding this comment

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

Match on read_into_buf returning Err in determine_ownership and return DevOwnership::Theirs instead?

If you do stick with this PR's current approach, it really is a change from "read all expected bytes into a buffer or fail" semantics to "read as much as I can and return that", yes? If so, it's likely that functions shouldn't be taking or returning fixed size arrays any longer, but Vecs and slices, which track their own length. Shouldn't need bytes, instead just call .len() on the vec or slice.

Copy link
Member Author

Choose a reason for hiding this comment

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

It never had that semantics in the first place. It read all the bytes it found, left the rest of the buffer filled in with zeros, and then fired away its various discovery mechanisms.

Copy link
Member Author

Choose a reason for hiding this comment

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

It could be changed to use Read's take() function which returns a Take adaptor which can then be manipulated, although the adaptor ultimately reads into a buffer. That would be a bit more rustic.

Or read_into_buf() could be changed so that it returned a vector which is the length of bytes read, as you suggest.

@mulkieran
Copy link
Member Author

I think that it is probably time to formalize the metadata reading behavior with a state machine, as the scenarios that are being considered are fairly sophisticated.

So, this depends on: stratis-storage/stratis-docs#44 and I'm moving it back to "in progress".

@agrover
Copy link
Contributor

agrover commented Aug 8, 2017

close this? obsoleted by #482?

@mulkieran
Copy link
Member Author

#482 was just the easy parts.

@mulkieran
Copy link
Member Author

rebased.

The current location is where the fix would have to happen.

Signed-off-by: mulhern <[email protected]>
It's an action that must be done twice, and there are a lot of decisions
involved, so make it a method.

Signed-off-by: mulhern <[email protected]>
It's a bit clearer and the plan is to use them a bit more.

Signed-off-by: mulhern <[email protected]>
When trying to read a StaticHeader it may be that the buffer doesn't
get filled with data from the file or device being read.

Signed-off-by: mulhern <[email protected]>
The last test indicates a desirable fix: if it is only possible to read
two sectors of the BDA, loading the BDA should return an error.

Signed-off-by: mulhern <[email protected]>
mulkieran added a commit to mulkieran/stratisd that referenced this pull request Sep 14, 2017
There is ongoing work, see:
stratis-storage#476, and the ultimate
plan is to come up w/ better formalization of how errors in reading
metadata are handled.

Signed-off-by: mulhern <[email protected]>
mulkieran added a commit to mulkieran/stratisd that referenced this pull request Sep 15, 2017
There is ongoing work, see:
stratis-storage#476, and the ultimate
plan is to come up w/ better formalization of how errors in reading
metadata are handled.

Signed-off-by: mulhern <[email protected]>
@agrover
Copy link
Contributor

agrover commented Feb 14, 2018

closing due to inactivity.

@agrover agrover closed this Feb 14, 2018
@mulkieran
Copy link
Member Author

mulkieran commented Feb 14, 2018

It is active again, but I don't seem to be able to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants