ploop_open_dd: fixed memleak on error path

Reference: ploop@971198
ploop_lock_dd(): improve "is opened" check

Either di or di->runtime could be NULL, so it wouldn't hurt
to check.

Reference: ploop@973777
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_read_diskdescriptor(): add di->runtime check

Just to be on the safe side.

Reference: ploop@973778
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Remove unused ploop_read_dd() function

This was mistakenly added by me (not Igor) in commit 0f71d9d.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_read_diskdescriptor(): fix get_basedir() len argument

The third argument of get_basedir() should be the size of the second
argument, not the first one. Since they are of the same size this
is harmless, but still worth fixing.

Reference: ploop@972047
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Introduce ploop_read_dd()

A new API (ploop_open_dd()/ploop_close_dd()) was introduced recently.
A side effect is DiskDescriptor.xml file name is now saved in
di->runtime->xml_fname by ploop_open_dd(). Nevertheless,
ploop_read_diskdescriptor(), which is used both internally and
externally, saves the DiskDescriptor.xml file name one more time.
It is no longer necessary when ploop_read_diskdescriptor() is used
internally.

To fix, rename read_diskdescriptor() to ploop_read_dd() and factor
out xml_fname manipulation.

NB: currently not all functions are converted to use the new API
(i.e. use ploop_lock_dd() to read dd.xml). Once this conversion
is done, we can remove reading of dd.xml out of
ploop_read_diskdescriptor() and ploop_read_disk_descr().

Reference: ploop@973779
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_read_disk_descr(): switch to new API

Make ploop_read_disk_descr() a wrapper for ploop_open_dd()
and ploop_read_dd().

NB: currently not all functions are converted to use the new API
(i.e. use ploop_lock_dd() to read dd.xml). Once this conversion
is done, we can remove reading of dd.xml out of ploop_read_disk_descr(),
making it an alias for ploop_open_dd().

References: ploop@973780, ploop@973813
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
libploop.h: obsolete all *_diskdescriptor() calls

The following functions are to be removed from external API:
* ploop_store_diskdescriptor()	-> why is it in external API?
* ploop_free_diskdescriptor()	-> use ploop_close_dd() instead
* ploop_read_disk_descr()	-> use ploop_open_dd() instead

The following functions were already removed from external API
earlier (commit 57feac7, Sat Sep 8 03:01:34 2012):
* ploop_alloc_diskdescriptor()
* ploop_read_diskdescriptor()

@noreview
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_read_dd(): print error

As per Igor's suggestion, in case any of the required di field
is NULL, print an appropriate error.

Note that ploop_read_dd() is an internal function, and currently
everyone calling it makes sure all these fields are set, so this
check is always false, and the error message added by this patch
is never going to be printed. So this is more like an assert.

Reference: ploop@973782
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_get_info_by_descr(): use new dd API

Use ploop_open_dd()/ploop_close_dd(). Reading is now done
inside ploop_lock_dd() which is called by ploop_get_info().

This eliminates double reading/parsing of DiskDescriptor.xml,
which happens when we use old and new API together
(first ploop_{alloc,read}_diskdescriptor and then ploop_lock_dd()).

Reference: ploop@973853
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
tools/*: use new dd API

This is another addition to commit 0f71d9d/ploop@964778.

Note this is still incomplete, as there are cases that require reading
of DiskDescriptor.xml (that should probably moved from tools to the
library).

Reference: ploop@973854
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_read_dd(): call ploop_clear_dd()

As pointed out by Igor, it makes sense to move ploop_clear_dd()
call from ploop_lock_dd() to ploop_read_dd().

Signed-off-by: Kir Kolyshkin <kir@openvz.org>