]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/storage/rsync.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <sys/mount.h>
34 #include <sys/types.h>
41 #include "syscall_wrappers.h"
44 lxc_log_define(rsync
, lxc
);
46 int lxc_storage_rsync_exec_wrapper(void *data
)
48 struct rsync_data
*arg
= data
;
49 return lxc_rsync(arg
);
52 int lxc_rsync_exec_wrapper(void *data
)
54 struct rsync_data_char
*args
= data
;
56 if (!lxc_switch_uid_gid(0, 0))
59 if (!lxc_setgroups(0, NULL
))
62 return lxc_rsync_exec(args
->src
, args
->dest
);
65 int lxc_rsync_exec(const char *src
, const char *dest
)
76 ret
= snprintf(s
, l
, "%s", src
);
77 if (ret
< 0 || (size_t)ret
>= l
) {
85 execlp("rsync", "rsync", "-aHXS", "--delete", s
, dest
, (char *)NULL
);
90 int lxc_rsync(struct rsync_data
*data
)
93 const char *dest
, *src
;
94 struct lxc_storage
*orig
= data
->orig
, *new = data
->new;
96 ret
= unshare(CLONE_NEWNS
);
98 SYSERROR("Failed to unshare CLONE_NEWNS");
102 ret
= detect_shared_rootfs();
104 ret
= mount(NULL
, "/", NULL
, MS_SLAVE
|MS_REC
, NULL
);
106 SYSERROR("Failed to make \"/\" a slave mount");
109 ret
= orig
->ops
->mount(orig
);
111 ERROR("Failed mounting \"%s\" on \"%s\"", orig
->src
, orig
->dest
);
115 ret
= new->ops
->mount(new);
117 ERROR("Failed mounting \"%s\" onto \"%s\"", new->src
, new->dest
);
121 if (!lxc_switch_uid_gid(0, 0))
124 if (!lxc_setgroups(0, NULL
))
127 src
= lxc_storage_get_path(orig
->dest
, orig
->type
);
128 dest
= lxc_storage_get_path(new->dest
, new->type
);
130 ret
= lxc_rsync_exec(src
, dest
);
132 ERROR("Failed to rsync from \"%s\" into \"%s\"", src
, dest
);