overlay2: use index=off if possible
overlay2: use index=off if possible

As pointed out in https://github.com/moby/moby/issues/37970,
Docker overlay driver can't work with index=on feature of
the Linux kernel "overlay" filesystem. In case the global
default is set to "yes", Docker will fail with EBUSY when
trying to mount, like this:

> error creating overlay mount to ...../merged: device or resource busy

and the kernel log should contain something like:

> overlayfs: upperdir is in-use by another mount, mount with
> '-o index=off' to override exclusive upperdir protection.

A workaround is to set index=off in overlay kernel module
parameters, or even recompile the kernel with
CONFIG_OVERLAY_FS_INDEX=n in .config. Surely this is not
always practical or even possible.

The solution, as pointed out my Amir Goldstein (as well as
the above kernel message:) is to use 'index=off' option
when mounting.

NOTE since older (< 4.13rc1) kernels do not support "index="
overlayfs parameter, try to figure out whether the option
is supported. In case it's not possible to figure out,
assume it is not.

NOTE the default can be changed anytime (by writing to
/sys/module/overlay/parameters/index) so we need to always
use index=off.

[v2: move the detection code to Init()]
[v3: don't set index=off if stat() failed]

Signed-off-by: Kir Kolyshkin <3a017b8ddb3f9cf3e4a59978b004111bdeb97f08@gmail.com>

Ramzec/docker,jvanz/docker,gnailuy/docker,konstruktoid/docker-1,moby/moby,rancher/docker,ibuildthecloud/docker,laijs/docker,moby/moby,rancher/docker,thaJeztah/docker,thaJeztah/docker,laijs/moby,jimjag/docker,jimjag/docker,jlhawn/docker,trebonian/docker,flavio/docker,YuPengZTE/docker,ibuildthecloud/docker,cpuguy83/docker,scotttlin/docker,laijs/docker,estesp/docker,docker/docker,estesp/docker,pradipd/moby,thaJeztah/docker,kolyshkin/docker,kojiromike/docker,konstruktoid/docker-upstream,rremer/moby,YuPengZTE/docker,vdemeester/docker,djs55/docker,mikebrow/docker,laijs/docker,rremer/moby,dmcgowan/docker,mahak/docker,jthelin/docker,gnailuy/docker,jthelin/docker,maxamillion/docker,laijs/moby,KarthikNayak/docker,rremer/moby,jameszhan/docker,djs55/docker,AkihiroSuda/docker,x1022as/docker,moul/docker,jameszhan/docker,justincormack/docker,djs55/docker,jvanz/docker,cpuguy83/docker,konstruktoid/docker-upstream,SvenDowideit/docker,jwhonce/docker,kojiromike/docker,yosifkit/docker,yosifkit/docker,estesp/docker,Ramzec/docker,moby/moby,scotttlin/docker,justincormack/docker,jimjag/docker,yosifkit/docker,dmcgowan/docker,kolyshkin/moby,jwhonce/docker,unclejack/docker,vdemeester/docker,konstruktoid/docker-1,cpuguy83/docker,yongtang/docker,pradipd/moby,kolyshkin/moby,nalind/docker,Mokolea/docker,nawawi/docker,docker/docker,rancher/docker,cpuguy83/docker,nawawi/docker,dmcgowan/docker,maxamillion/docker,moby/moby,nawawi/docker,jvanz/docker,Mokolea/docker,kojiromike/docker,Mokolea/docker,pradipd/moby,dims/docker,SvenDowideit/docker,tmp6154/docker,dims/docker,jameszhan/docker,trebonian/docker,gnailuy/docker,gnailuy/docker,flavio/docker,Ramzec/docker,jlhawn/docker,paralin/docker,konstruktoid/docker-1,SvenDowideit/docker,crosbymichael/docker,mikebrow/docker,mikebrow/docker,AkihiroSuda/docker,ibuildthecloud/docker,dims/docker,moul/docker,crosbymichael/docker,unclejack/docker,KarthikNayak/docker,flavio/docker,YuPengZTE/docker,bearstech/moby,bearstech/moby,kolyshkin/moby,docker/docker,nalind/docker,mahak/docker,laijs/moby,paralin/docker,nawawi/docker,crosbymichael/docker,AkihiroSuda/docker,konstruktoid/docker-upstream,AkihiroSuda/docker,nalind/docker,trebonian/docker,vdemeester/docker,jimjag/docker,bearstech/moby,unclejack/docker,KarthikNayak/docker,yongtang/docker,konstruktoid/docker-upstream,bearstech/moby,scotttlin/docker,Mokolea/docker,moul/docker,ibuildthecloud/docker,yosifkit/docker,thaJeztah/docker,jwhonce/docker,mahak/docker,x1022as/docker,nalind/docker,maxamillion/docker,tmp6154/docker,yongtang/docker,Ramzec/docker,paralin/docker,kolyshkin/docker,trebonian/docker,jlhawn/docker,mahak/docker,ibuildthecloud/docker,paralin/docker,justincormack/docker,flavio/docker,tmp6154/docker,x1022as/docker,moul/docker