Commit 38683db4 by Christian Brauner

Split bdev into modules: overlay

With this commit we start to split bdev.{c,h} into modules located in the subfolder bdev. We start by creating a module for overlay: overlay.{c,h}. - The functions: - overlayfs_detect() - overlayfs_mount() - overlayfs_umount() - overlayfs_clonepaths() - overlayfs_destroy() - overlayfs_create() move from bdev.{c,h} to overlay.{c,h}. The only thing that remains in bdev.c is the static definition of - static const struct bdev_ops overlayfs_ops - The functions: - update_ovl_paths() - overlay_getlower() move from lxccontainer.c to overlay.{c,h}. update_ovl_paths() is used to update absolute paths for overlay lxc.mount.entry entries but it seems to fit more here than into lxccontainer.c. The Function overlay_getlower() is used to extract the lower directory for overlay (and aufs) rootfs. It should at some point become a common helper. - The functions: - do_rsync() - dir_new_path() remain in bdev.c for now but become extern. We declare them extern in overlay.c to be able to call them. As the comment to them correctly notices, they should at some point become common helpers and probably move to utils.{c,h} or some other more appropriate place. - The structs: - struct bdev; /* defined in bdev.h */ - struct bdev_specs; /* defined in lxccontainer.h */ - struct lxc_conf; /* defined conf.h */ are forward declared/put as incomplete types in overlay.h so that the functions have access to it. - The header overlay.h is *not* included in bdev.h but only in bdev.c so that when bdev.h is included the public functions in overlay.h cannot be accessed, i.e. if an implementation wants to call functions from overlay.h they need to explicitly include it. (As is e.g. done in the case of lxccontainer.c.) - The header - lxc-btrfs.h also moves to the bdev subfolder. - Adapt Makefile.am to the new bdev layout. Signed-off-by: 's avatarChristian Brauner <christian.brauner@mailbox.org>
parent fbc617e8
......@@ -6,7 +6,9 @@ pkginclude_HEADERS = \
noinst_HEADERS = \
arguments.h \
attach.h \
bdev.h \
bdev/bdev.h \
bdev/lxc-btrfs.h \
bdev/overlay.h \
caps.h \
cgroup.h \
conf.h \
......@@ -16,7 +18,6 @@ noinst_HEADERS = \
list.h \
log.h \
lxc.h \
lxc-btrfs.h \
lxclock.h \
monitor.h \
namespace.h \
......@@ -60,7 +61,7 @@ endif
liblxc_so_SOURCES = \
arguments.c arguments.h \
bdev.c bdev.h lxc-btrfs.h \
bdev/bdev.c bdev/bdev.h bdev/overlay.c bdev/overlay.h bdev/lxc-btrfs.h \
commands.c commands.h \
start.c start.h \
execute.c \
......
......@@ -27,11 +27,11 @@
* aufs, dir, raw, btrfs, overlayfs, aufs, lvm, loop, zfs, nbd (qcow2, raw, vdi, qed)
*/
#include "config.h"
#include <stdint.h>
#include <lxc/lxccontainer.h>
#include <sys/mount.h>
#include "config.h"
/* define constants if the kernel/glibc headers don't define them */
#ifndef MS_DIRSYNC
......@@ -97,8 +97,6 @@ struct bdev {
int nbd_idx;
};
char *overlay_getlower(char *p);
bool bdev_is_dir(struct lxc_conf *conf, const char *path);
bool bdev_can_backup(struct lxc_conf *conf);
......
/*
* lxc: linux Container library
*
* (C) Copyright IBM Corp. 2007, 2008
*
* Authors:
* Daniel Lezcano <daniel.lezcano at free.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __LXC_OVERLAY_H
#define __LXC_OVERLAY_H
#include <grp.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
/* defined in bdev.h */
struct bdev;
/* defined in lxccontainer.h */
struct bdev_specs;
/* defined conf.h */
struct lxc_conf;
int overlayfs_detect(const char *path);
int overlayfs_mount(struct bdev *bdev);
int overlayfs_umount(struct bdev *bdev);
int overlayfs_clonepaths(struct bdev *orig, struct bdev *new,
const char *oldname, const char *cname,
const char *oldpath, const char *lxcpath, int snap,
uint64_t newsize, struct lxc_conf *conf);
int overlayfs_destroy(struct bdev *orig);
int overlayfs_create(struct bdev *bdev, const char *dest, const char *n,
struct bdev_specs *specs);
/*
* To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
* with overlay lxc.mount.entry entries we need to update absolute paths for
* upper- and workdir. This update is done in two locations:
* lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates are done
* independent of each other since lxc_conf->mountlist may container more mount
* entries (e.g. from other included files) than lxc_conf->unexpanded_config .
*/
int update_ovl_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
const char *lxc_name, const char *newpath,
const char *newname);
/*
* To be called from functions in lxccontainer.c: Get lower directory for
* overlay rootfs.
*/
char *overlay_getlower(char *p);
#endif /* __LXC_OVERLAY_H */
......@@ -19,48 +19,46 @@
*/
#define _GNU_SOURCE
#include <sys/mman.h>
#include <assert.h>
#include <stdarg.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <dirent.h>
#include <sched.h>
#include <arpa/inet.h>
#include <grp.h>
#include <libgen.h>
#include <pthread.h>
#include <sched.h>
#include <stdarg.h>
#include <stdint.h>
#include <grp.h>
#include <stdio.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <lxc/lxccontainer.h>
#include <lxc/version.h>
#include <lxc/network.h>
#include "config.h"
#include "lxc.h"
#include "state.h"
#include "attach.h"
#include "bdev/bdev.h"
#include "bdev/overlay.h"
#include "cgroup.h"
#include "conf.h"
#include "config.h"
#include "commands.h"
#include "confile.h"
#include "console.h"
#include "cgroup.h"
#include "commands.h"
#include "criu.h"
#include "log.h"
#include "bdev.h"
#include "utils.h"
#include "attach.h"
#include "lxc.h"
#include "lxccontainer.h"
#include "lxclock.h"
#include "monitor.h"
#include "namespace.h"
#include "network.h"
#include "lxclock.h"
#include "sync.h"
#include "state.h"
#include "utils.h"
#include "version.h"
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
......@@ -2997,102 +2995,6 @@ static int create_file_dirname(char *path, struct lxc_conf *conf)
return ret;
}
/* When we clone a container with overlay lxc.mount.entry entries we need to
* update absolute paths for upper- and workdir. This update is done in two
* locations: lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates
* are done independent of each other since lxc_conf->mountlist may container
* more mount entries (e.g. from other included files) than
* lxc_conf->unexpanded_config . */
static int update_ovl_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
const char *lxc_name, const char *newpath,
const char *newname)
{
char new_upper[MAXPATHLEN];
char new_work[MAXPATHLEN];
char old_upper[MAXPATHLEN];
char old_work[MAXPATHLEN];
char *cleanpath = NULL;
int i;
int fret = -1;
int ret = 0;
struct lxc_list *iterator;
const char *ovl_dirs[] = {"br", "upperdir", "workdir"};
cleanpath = strdup(newpath);
if (!cleanpath)
goto err;
remove_trailing_slashes(cleanpath);
/* We have to update lxc_conf->unexpanded_config separately from
* lxc_conf->mount_list. */
for (i = 0; i < sizeof(ovl_dirs) / sizeof(ovl_dirs[0]); i++) {
if (!clone_update_unexp_ovl_paths(lxc_conf, lxc_path, newpath,
lxc_name, newname,
ovl_dirs[i]))
goto err;
}
ret = snprintf(old_work, MAXPATHLEN, "workdir=%s/%s", lxc_path, lxc_name);
if (ret < 0 || ret >= MAXPATHLEN)
goto err;
ret = snprintf(new_work, MAXPATHLEN, "workdir=%s/%s", cleanpath, newname);
if (ret < 0 || ret >= MAXPATHLEN)
goto err;
lxc_list_for_each(iterator, &lxc_conf->mount_list) {
char *mnt_entry = NULL;
char *new_mnt_entry = NULL;
char *tmp = NULL;
char *tmp_mnt_entry = NULL;
mnt_entry = iterator->elem;
if (strstr(mnt_entry, "overlay"))
tmp = "upperdir";
else if (strstr(mnt_entry, "aufs"))
tmp = "br";
if (!tmp)
continue;
ret = snprintf(old_upper, MAXPATHLEN, "%s=%s/%s", tmp, lxc_path, lxc_name);
if (ret < 0 || ret >= MAXPATHLEN)
goto err;
ret = snprintf(new_upper, MAXPATHLEN, "%s=%s/%s", tmp, cleanpath, newname);
if (ret < 0 || ret >= MAXPATHLEN)
goto err;
if (strstr(mnt_entry, old_upper)) {
tmp_mnt_entry = lxc_string_replace(old_upper, new_upper, mnt_entry);
}
if (strstr(mnt_entry, old_work)) {
if (tmp_mnt_entry)
new_mnt_entry = lxc_string_replace(old_work, new_work, tmp_mnt_entry);
else
new_mnt_entry = lxc_string_replace(old_work, new_work, mnt_entry);
}
if (new_mnt_entry) {
free(iterator->elem);
iterator->elem = strdup(new_mnt_entry);
} else if (tmp_mnt_entry) {
free(iterator->elem);
iterator->elem = strdup(tmp_mnt_entry);
}
free(new_mnt_entry);
free(tmp_mnt_entry);
}
fret = 0;
err:
free(cleanpath);
return fret;
}
static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char *newname,
const char *lxcpath, int flags,
const char *bdevtype, const char *bdevdata, uint64_t newsize,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment