Commits
Kir Kolyshkin authored e644ed7baa9
Cookie-based ploop image registration Generally, we don't want to allow multiple mounts of the same image. Mounting the same image read/write is forbidden by the kernel, but mounting it read-only is fine from the kernel point of view. Still, We need to take care about it in userspace, because otherwise we'll have a conflict during unmount -- if an image is mounted two times and we ask to unmount it, it's not clear which device (and, optionally, mount point) to unmount it from. Initially, double mounting was prevented using hardlinks (function create_base_magic_delta(). Later, the new registration scheme with symlinks in /dev/ploop/ directory was introduced (commit c1a95cb), with an added parameter called component_name. If component is specified, we do allow multiple mounts for different components (and a pair of image and component_name clearly identifies what to unmount, so no problem here). Still, even this scheme was not working in a few corner cases, such as when image file is renamed. So, OpenVZ kernel 042stab61.1 introduced per ploop device in-kernel field called cookie, to be used for storing component_name. Here is the kernel patch description: > The patch adds 'cookie' field to ploop-device and makes it visible via: > > /sys/block/ploopN/pstate/cookie > > 'cookie' is an opaque string passed from user-space to kernel in ADD_DELTA > ioctl. Once set, it cannot be changed until uninitilizing ploop-device (e.g. by > CLEAR ioctl). > > The 'cookie' will be used to assign so-called component-name to given > ploop-device. Empty component-name will designate default use-case: > ploop-device instantiated for running CT. "backup" component-name will > designate ploop-device servicing backup process. Etc. > > Having component-name assigned, "ploop umount DiskDescriptor.xml" is able > to choose proper ploop-device among all devices referring to base-delta > defined in DiskDescriptor.xml". > > Previous approach based on keeping maps of <base_delta_name, component_name> > to <ploop_minor> in userspace turned out too fragile. E.g. any external > rename of ploop image led to unusable ploop-device becase maps became invalid. Now, this patch removes the symlink-based /dev/ploop/ registration mechanism, replacing it with cookie-based one, based on patches by Igor Sukhih <igor@openvz.org>. It's a bit complicated because we still want ploop to work on older kernels, but warn if component_name is used there, because we do not support such setup. So, we try to figure out if ploop cookie is supported by parsing kernel version from uname, and warn if cookie is set and kernel is old. While at it, untangle the mess and replace three functions: - ploop_find_dev - ploop_find_dev_locked - ploop_find_dev_by_delta with just one, ploop_find_dev(). References: ploop@793010, ploop@793813, ploop@795193 etc. Signed-off-by: Kir Kolyshkin <kir@openvz.org>