]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/storage/rsync.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
12 #include <sys/mount.h>
13 #include <sys/types.h>
20 #include "syscall_wrappers.h"
23 lxc_log_define(rsync
, lxc
);
25 int lxc_storage_rsync_exec_wrapper(void *data
)
27 struct rsync_data
*arg
= data
;
28 return lxc_rsync(arg
);
31 int lxc_rsync_exec_wrapper(void *data
)
33 struct rsync_data_char
*args
= data
;
35 if (!lxc_switch_uid_gid(0, 0))
38 if (!lxc_setgroups(0, NULL
))
41 return lxc_rsync_exec(args
->src
, args
->dest
);
44 int lxc_rsync_exec(const char *src
, const char *dest
)
55 ret
= snprintf(s
, l
, "%s", src
);
56 if (ret
< 0 || (size_t)ret
>= l
) {
64 execlp("rsync", "rsync", "-aHXS", "--delete", s
, dest
, (char *)NULL
);
69 int lxc_rsync(struct rsync_data
*data
)
72 const char *dest
, *src
;
73 struct lxc_storage
*orig
= data
->orig
, *new = data
->new;
75 ret
= unshare(CLONE_NEWNS
);
77 SYSERROR("Failed to unshare CLONE_NEWNS");
81 ret
= detect_shared_rootfs();
83 ret
= mount(NULL
, "/", NULL
, MS_SLAVE
|MS_REC
, NULL
);
85 SYSERROR("Failed to make \"/\" a slave mount");
88 ret
= orig
->ops
->mount(orig
);
90 ERROR("Failed mounting \"%s\" on \"%s\"", orig
->src
, orig
->dest
);
94 ret
= new->ops
->mount(new);
96 ERROR("Failed mounting \"%s\" onto \"%s\"", new->src
, new->dest
);
100 if (!lxc_switch_uid_gid(0, 0))
103 if (!lxc_setgroups(0, NULL
))
106 src
= lxc_storage_get_path(orig
->dest
, orig
->type
);
107 dest
= lxc_storage_get_path(new->dest
, new->type
);
109 ret
= lxc_rsync_exec(src
, dest
);
111 ERROR("Failed to rsync from \"%s\" into \"%s\"", src
, dest
);