Skip to content

Commit

Permalink
mount: Handle deleted bindmounts
Browse files Browse the repository at this point in the history
To handle deleted bindmounts we simply create
the former directory bindmount lived at, mount
the target and remove the directory back.

For this sake we add @deleted entry into the image.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
Cyrill Gorcunov authored and xemul committed Aug 21, 2015
1 parent 60f6ec7 commit 80ef8fd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct mount_info {
};
bool need_plugin;
bool is_ns_root;
bool deleted;
struct mount_info *next;
struct ns_id *nsid;

Expand Down
23 changes: 21 additions & 2 deletions mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,10 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img)
me.has_with_plugin = true;
me.with_plugin = true;
}
if (pm->deleted) {
me.has_deleted = true;
me.deleted = true;
}

if (pm->internal_sharing) {
me.has_internal_sharing = true;
Expand Down Expand Up @@ -1990,11 +1994,25 @@ static int do_bind_mount(struct mount_info *mi)
root = rpath;
do_bind:
pr_info("\tBind %s to %s\n", root, mi->mountpoint);
if (mount(root, mi->mountpoint, NULL,
MS_BIND, NULL) < 0) {

if (unlikely(mi->deleted)) {
if (mkdir(root, 0700)) {
pr_perror("Can't re-create deleted %s\n", root);
return -1;
}
}

if (mount(root, mi->mountpoint, NULL, MS_BIND, NULL) < 0) {
pr_perror("Can't mount at %s", mi->mountpoint);
return -1;
}

if (unlikely(mi->deleted)) {
if (rmdir(root)) {
pr_perror("Can't remove deleted %s\n", root);
return -1;
}
}
} else {
if (restore_ext_mount(mi))
return -1;
Expand Down Expand Up @@ -2308,6 +2326,7 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
pm->shared_id = me->shared_id;
pm->master_id = me->master_id;
pm->need_plugin = me->with_plugin;
pm->deleted = me->deleted;
pm->is_ns_root = is_root(me->mountpoint);

pr_debug("\t\tGetting source for %d\n", pm->mnt_id);
Expand Down
9 changes: 9 additions & 0 deletions proc_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "sysfs_parse.h"
#include "seccomp.h"
#include "namespaces.h"
#include "files-reg.h"

#include "protobuf.h"
#include "protobuf/fdinfo.pb-c.h"
Expand Down Expand Up @@ -1008,6 +1009,7 @@ static void cure_path(char *path)

static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
{
struct fd_link root_link;
unsigned int kmaj, kmin;
int ret, n;
char *sub, *opt = NULL;
Expand All @@ -1027,6 +1029,13 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
cure_path(new->mountpoint);
cure_path(new->root);

root_link.len = strlen(new->root);
strcpy(root_link.name, new->root);
if (strip_deleted(&root_link)) {
strcpy(new->root, root_link.name);
new->deleted = true;
}

new->mountpoint = xrealloc(new->mountpoint, strlen(new->mountpoint) + 1);
if (!new->mountpoint)
goto err;
Expand Down
2 changes: 2 additions & 0 deletions protobuf/mnt.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ message mnt_entry {

optional string fsname = 14;
optional bool internal_sharing = 15;

optional bool deleted = 16;
}

0 comments on commit 80ef8fd

Please sign in to comment.