From 5ffad3ec21332a7cd8b967231b84d5eecee5be92 Mon Sep 17 00:00:00 2001 From: James Davidson Date: Fri, 19 Oct 2012 12:11:03 -0700 Subject: Add support for overlayfs and start using it --- src/common/unionfs.c | 15 +++++++++++++-- src/cstore/unionfs/cstore-unionfs.cpp | 20 ++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/common/unionfs.c b/src/common/unionfs.c index d8b7626..c1752ac 100644 --- a/src/common/unionfs.c +++ b/src/common/unionfs.c @@ -71,9 +71,20 @@ static inline void sys_mount_session(void) { char mopts[MAX_LENGTH_DIR_PATH * 2]; - snprintf(mopts, MAX_LENGTH_DIR_PATH * 2, "dirs=%s=rw:%s=ro", + const char *fstype; + const char *moptfmt; + int local_errno; + +#ifdef USE_OVERLAYFS + fstype = "overlayfs"; + moptfmt = "upperdir=%s,lowerdir=%s"; +#else + fstype = "unionfs"; + moptfmt = "dirs=%s=rw:%s=ro"; +#endif + snprintf(mopts, MAX_LENGTH_DIR_PATH * 2, moptfmt, get_cdirp(), get_adirp()); - if (mount("unionfs", get_mdirp(), "unionfs", 0, mopts) != 0) { + if (mount(fstype, get_mdirp(), fstype, 0, mopts) != 0) { perror("mount"); } } diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp index e21e660..c53e443 100644 --- a/src/cstore/unionfs/cstore-unionfs.cpp +++ b/src/cstore/unionfs/cstore-unionfs.cpp @@ -1477,14 +1477,26 @@ bool UnionfsCstore::do_mount(const FsPath& rwdir, const FsPath& rdir, const FsPath& mdir) { - string mopts = "dirs="; + const char *fstype; + string mopts; + +#ifdef USE_OVERLAYFS + fstype = "overlayfs"; + mopts = "upperdir="; + mopts += rwdir.path_cstr(); + mopts += ",lowerdir="; + mopts += rdir.path_cstr(); +#else + fstype = "unionfs"; + mopts = "dirs="; mopts += rwdir.path_cstr(); mopts += "=rw:"; mopts += rdir.path_cstr(); mopts += "=ro"; - if (mount("unionfs", mdir.path_cstr(), "unionfs", 0, mopts.c_str()) != 0) { - output_internal("union mount failed [%s][%s]\n", - strerror(errno), mdir.path_cstr()); +#endif + if (mount(fstype, mdir.path_cstr(), fstype, 0, mopts.c_str()) != 0) { + output_internal("union mount failed [%s][%s][%s]\n", + strerror(errno), mdir.path_cstr(), mopts.c_str()); return false; } return true; -- cgit v1.2.3