Skip to content

devicemapper: Compare uuid of base device on startup - #13896

Merged
calavera merged 1 commit into
moby:masterfrom
rhvgoyal:verify-base-uuid
Jun 17, 2015
Merged

calavera merged 1 commit into
moby:masterfrom
rhvgoyal:verify-base-uuid

Conversation

@rhvgoyal

Copy link
Copy Markdown
Contributor

Fixes issue #13894

It is easy for one to use docker for a while, shut it down and restart
docker with different set of storage options for device mapper driver
which will effectively change the thin pool. That means any of the
metadata stored in /var/lib/docker/devicemapper/metadata/ is not valid
for the new pool and user will run into various kind of issues like
container not found in the pool etc.

Users think that their images or containers are lost but it might just
be the case of configuration issue. People might use wrong metadata
with wrong pool.

To detect such situations, save UUID of base image and once docker
starts later, query and compare the UUID of base image with the
stored one. If they don't match, fail the initialization with the
error that UUID failed to match.

That way user will be forced to cleanup /var/lib/docker/ directory
and start docker again.

Signed-off-by: Vivek Goyal [email protected]

@rhvgoyal

Copy link
Copy Markdown
Contributor Author

@vbatts What do you think about this one. I think with this we should be able to catch lot of errors early and tell users that there was most likely a configuration issue.

@rhvgoyal
rhvgoyal force-pushed the verify-base-uuid branch 2 times, most recently from 6c071df to 6e82131 Compare June 12, 2015 13:18
@unclejack

Copy link
Copy Markdown
Contributor

I haven't reviewed the actual code, but it sounds like the right thing to do.

@vbatts

vbatts commented Jun 16, 2015

Copy link
Copy Markdown
Contributor

so, this is one check. I don't think this will go the full way for a configuration/state comparison.

This kind of check may be nicer to make a part of a generic call around Init(). Like LoadConfig(homePath string, configOpts map[string]string) or similar. And have a pre-defined error in the graphdriver package like ErrConfigChanged or ErrDeviceChanged, which should expect to run a Validate(path, opts) on the setup, before continuing.

It seems like a generic case like this, for all drivers, could allow for catching odd changes with config, or switched pool devices or similar.

Thoughts?

Otherwise, this PR is simple and overall LGTM. I'll walk through the code more in a minute.

@rhvgoyal

Copy link
Copy Markdown
Contributor Author

Right now validation is practically in Init(). Just 2 levels down. And Init() is right place to do such kind of checks for every graph driver.

What other cases of error do you want to detect/cover? For devicemapper, I think it should cover
vast majority of issues. If there are more, we can add more checks down the line.

@vbatts

vbatts commented Jun 16, 2015

Copy link
Copy Markdown
Contributor

agreed Init() is a right place for it. Besides the thin pool being different, I could imaging block size changes or similar needing to bail. Or on btrfs, if the the device is changed, a Check or Validate would include asserting images/container subvolumes are present.

@vbatts

vbatts commented Jun 16, 2015

Copy link
Copy Markdown
Contributor

This can all stay in Init(), it seems like the pattern for "what is involved in Init of a storage driver?" is what i'm looking at.

@rhvgoyal

Copy link
Copy Markdown
Contributor Author

@vbatts

I suspect that block size will be stored in pool metadata and if you try to create same pool with different block size this time, pool creation should fail. Otherwise all the metadata thin pool has already created will not work.

I think every target will have separate sanity checks based on kind of tunables they offer and they all need to come up with their own checks to make sure they have right configuration. But I am open to any suggestions to improve it.

@vbatts

vbatts commented Jun 16, 2015

Copy link
Copy Markdown
Contributor

right on. For now we'll review this PR as is, and let the rest evolve.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there simple way to do this without shelling out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not aware of any other easy way to do it. blkid comes from util-linux package and mkfs comes from util-linux too. As we are already using mkfs, I think it is safe to assume that blkid is available too on machines running docker.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there is a header and way to link to libbklid, but that seems too much. Please would require additional build time packages, where blkid is provided by util-linux which is on every major distro (even debian minbase).

@vbatts

vbatts commented Jun 16, 2015

Copy link
Copy Markdown
Contributor

LGTM

@vbatts

vbatts commented Jun 16, 2015

Copy link
Copy Markdown
Contributor

@tiborvass care to review?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the error returned by saveBaseDeviceUUID ignored here on purpose? should we return it? or log like we do in line 728?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not critical, but wouldn't hurt
On Jun 16, 2015 17:40, "David Calavera" [email protected] wrote:

In daemon/graphdriver/devmapper/deviceset.go
#13896 (comment):

@@ -721,6 +783,7 @@ func (devices *DeviceSet) setupBaseImage() error {
return err
}

  • devices.saveBaseDeviceUUID(info)

is the error returned by saveBaseDeviceUUID ignored here on purpose?
should we return it?

—
Reply to this email directly or view it on GitHub
https://github.com/docker/docker/pull/13896/files#r32574282.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok I added the error check and pushed the patch again. PTAL.

It is easy for one to use docker for a while, shut it down and restart
docker with different set of storage options for device mapper driver
which will effectively change the thin pool. That means any of the
metadata stored in /var/lib/docker/devicemapper/metadata/ is not valid
for the new pool and user will run into various kind of issues like
container not found in the pool etc.

Users think that their images or containers are lost but it might just
be the case of configuration issue. People might use wrong metadata
with wrong pool.

To detect such situations, save UUID of base image and once docker
starts later, query and compare the UUID of base image with the
stored one. If they don't match, fail the initialization with the
error that UUID failed to match.

That way user will be forced to cleanup /var/lib/docker/ directory
and start docker again.

Signed-off-by: Vivek Goyal <[email protected]>
@calavera

Copy link
Copy Markdown
Contributor

LGTM. Merging 🎊

calavera added a commit that referenced this pull request Jun 17, 2015
devicemapper: Compare uuid of base device on startup
@calavera
calavera merged commit 85d3b75 into moby:master Jun 17, 2015
icecrime pushed a commit to icecrime/docker that referenced this pull request Jul 8, 2015
The ability to save and verify base device UUID (moby#13896) introduced a
situation where the initialization would panic when removing the device
returns EBUSY.

Functions `verifyBaseDeviceUUID` and `saveBaseDeviceUUID` now take the
lock on the `DeviceSet`, which solves the problem as `removeDevice`
assumes it owns the lock.

Signed-off-by: Arnaud Porterie <[email protected]>
calavera pushed a commit to calavera/docker that referenced this pull request Jul 25, 2015
The ability to save and verify base device UUID (moby#13896) introduced a
situation where the initialization would panic when removing the device
returns EBUSY.

Functions `verifyBaseDeviceUUID` and `saveBaseDeviceUUID` now take the
lock on the `DeviceSet`, which solves the problem as `removeDevice`
assumes it owns the lock.

Signed-off-by: Arnaud Porterie <[email protected]>
tiborvass pushed a commit to tiborvass/docker that referenced this pull request Jul 27, 2015
The ability to save and verify base device UUID (moby#13896) introduced a
situation where the initialization would panic when removing the device
returns EBUSY.

Functions `verifyBaseDeviceUUID` and `saveBaseDeviceUUID` now take the
lock on the `DeviceSet`, which solves the problem as `removeDevice`
assumes it owns the lock.

Signed-off-by: Arnaud Porterie <[email protected]>
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.

6 participants