Save restore device Id: issue #8978

Fixes #8978

During testing of docker with device mapper backend, I often noticed bunch of warnings on console and often thought that if something is wrong with my docker setup. It turned out that docker does not keep track of already used device ids.  This patch series should make docker little bit smarter about it.

More details are in issue and patches. Please review and pull.

Thanks
Vivek
On Tue, Nov 11, 2014 at 10:12:35AM -0800, Michael Crosby wrote:
> > @@ -535,6 +550,24 @@ func (devices *DeviceSet) ResizePool(size int64) error {
> >  	return nil
> >  }
> >  
> > +func (devices *DeviceSet) loadDeviceSetMetaData() error {
> > +	jsonData, err := ioutil.ReadFile(devices.deviceSetMetaFile())
> > +	if err != nil {
> > +		return nil
> > +	}
> > +
> > +	return json.Unmarshal(jsonData, devices)
> > +}
> > +
> > +func (devices *DeviceSet) saveDeviceSetMetaData() error {
> > +	jsonData, err := json.Marshal(devices)
> 
> Like my comment above I would use a json.Encoder so that we don't marshal into a in memory byte array before writing to disk. 

@crosbymichael

Thinking more about it. Right now to write to a meta file, we first write
contents to a temporary file and then rename that temp file to actual
file. I think this makes sure that in the event of crash, either we will
see the old file or new file but not a corrupted version.

I have a function writeMetaFile() which can do all this on a byte
array of json encoded data.

If we want to directly write to a file, that means I will have to write
this logic once for "DeviceSet struct" and once for "DevInfo struct".
By converting DeviceSet and Devinfo into a byte stream right now
can use a single function.

My be there are smart ways to program where I can use writeMetaFile()
both for "DeviceSet" and "DevInfo". Just that I don't know how to
do that.

So I will prefer to leave Marshal()/Unmarshal() interface in place as
files are really small and having another 64/128 bytes in memory really
might not be a big problem.

What do you think?


> 
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/docker/docker/pull/8982/files#r20168115