]>
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
32 #include <sys/types.h>
33 #include <sys/mount.h>
40 lxc_log_define(rsync
, lxc
);
42 int lxc_storage_rsync_exec_wrapper(void *data
)
44 struct rsync_data
*arg
= data
;
45 return lxc_rsync(arg
);
48 int lxc_rsync_exec_wrapper(void *data
)
51 struct rsync_data_char
*args
= data
;
53 ret
= lxc_switch_uid_gid(0, 0);
57 ret
= lxc_setgroups(0, NULL
);
61 return lxc_rsync_exec(args
->src
, args
->dest
);
64 int lxc_rsync_exec(const char *src
, const char *dest
)
75 ret
= snprintf(s
, l
, "%s", src
);
76 if (ret
< 0 || (size_t)ret
>= l
)
82 execlp("rsync", "rsync", "-aHXS", "--delete", s
, dest
, (char *)NULL
);
86 int lxc_rsync(struct rsync_data
*data
)
89 const char *dest
, *src
;
90 struct lxc_storage
*orig
= data
->orig
, *new = data
->new;
92 ret
= unshare(CLONE_NEWNS
);
94 SYSERROR("Failed to unshare CLONE_NEWNS");
98 ret
= detect_shared_rootfs();
100 ret
= mount(NULL
, "/", NULL
, MS_SLAVE
|MS_REC
, NULL
);
102 SYSERROR("Failed to make \"/\" a slave mount");
105 ret
= orig
->ops
->mount(orig
);
107 ERROR("Failed mounting \"%s\" on \"%s\"", orig
->src
, orig
->dest
);
111 ret
= new->ops
->mount(new);
113 ERROR("Failed mounting \"%s\" onto \"%s\"", new->src
, new->dest
);
117 ret
= lxc_switch_uid_gid(0, 0);
121 ret
= lxc_setgroups(0, NULL
);
125 src
= lxc_storage_get_path(orig
->dest
, orig
->type
);
126 dest
= lxc_storage_get_path(new->dest
, new->type
);
128 ret
= lxc_rsync_exec(src
, dest
);
130 ERROR("Failed to rsync from \"%s\" into \"%s\"", src
, dest
);