Handle hardlink directory during chkpnt/restore

The OpenVZ kernel (since 028stab065) has a feature to support
creating hardlink files during chkpnt. This is needed to prevent
a live migration fail when CT is over NFS and there is a deleted but
opened file in container being migrated. The error you get from
the kernel in this case is the following:

 # vzctl suspend 100
 Setup checkpoint ...
 Can not dump Container: Device or resource busy
 Error: deleted reference to existing inode, checkpointing is impossible: -2
 Checkpointing of Container failed

The test case is:
 Open r/w and unlink file, and fork before migration
 Check that the child can write to it and the parent
 Check that file can be read from it after migration

Now with this support in the kernel vzctl needs to do some trickery.
In particular, it should (a) tell the kernel where to store such
hardlinked files (during chkpnt) and (b) during restore, enable these
files.

vzctl now does:
a) On chkpnt: call ioctl CPT_LINKDIR_ADD to tell directory for
   storing hardlinked files.
b) On restore: call CPT_HARDLNK_ON ioctl to enable open hardlinked
   files.
c) Clean hardlinked directory (delete hardlinks) in the following cases:
  1. Before 'chkpnt --dump' (Filesystem must be clean before doing dump)
  2. Before 'chkpnt --resume'
  3. Before 'start' (To prevent: vzctl dump; vzctl start)
  4. After successfull 'restore --undump' (or in other words,
     before 'restore --resume')
  5. After failed 'chkpnt --dump'

Note, that vzctl doesn't clean hardlink directory after stopping CT.

Patch is based on code from Igor Sukhih <igor@openvz.org>

[kir@openvz.org: expanded the description, trim down to 80 column width,
 fixed an error message, moved _GNU_SOURCE declaration to the .c file]
4 files changed