Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
d8bb582a
Unverified
Commit
d8bb582a
authored
Jul 25, 2017
by
Christian Brauner
Committed by
Stéphane Graber
Aug 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
btrfs: switch to new rsync helpers
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
a493a694
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
28 deletions
+33
-28
lxcbtrfs.c
src/lxc/bdev/lxcbtrfs.c
+33
-28
No files found.
src/lxc/bdev/lxcbtrfs.c
View file @
d8bb582a
...
@@ -242,8 +242,8 @@ static int btrfs_subvolume_create(const char *path)
...
@@ -242,8 +242,8 @@ static int btrfs_subvolume_create(const char *path)
*
p
=
'\0'
;
*
p
=
'\0'
;
fd
=
open
(
newfull
,
O_RDONLY
);
fd
=
open
(
newfull
,
O_RDONLY
);
free
(
newfull
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
free
(
newfull
);
return
-
errno
;
return
-
errno
;
}
}
...
@@ -255,6 +255,7 @@ static int btrfs_subvolume_create(const char *path)
...
@@ -255,6 +255,7 @@ static int btrfs_subvolume_create(const char *path)
saved_errno
=
errno
;
saved_errno
=
errno
;
close
(
fd
);
close
(
fd
);
free
(
newfull
);
errno
=
saved_errno
;
errno
=
saved_errno
;
return
ret
;
return
ret
;
}
}
...
@@ -416,8 +417,9 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -416,8 +417,9 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
bool
btrfs_create_clone
(
struct
lxc_conf
*
conf
,
struct
bdev
*
orig
,
bool
btrfs_create_clone
(
struct
lxc_conf
*
conf
,
struct
bdev
*
orig
,
struct
bdev
*
new
,
uint64_t
newsize
)
struct
bdev
*
new
,
uint64_t
newsize
)
{
{
int
pid
,
ret
;
int
ret
;
struct
rsync_data
data
;
struct
rsync_data
data
=
{
0
,
0
};
char
cmd_output
[
MAXPATHLEN
]
=
{
0
};
ret
=
rmdir
(
new
->
dest
);
ret
=
rmdir
(
new
->
dest
);
if
(
ret
<
0
&&
errno
!=
ENOENT
)
if
(
ret
<
0
&&
errno
!=
ENOENT
)
...
@@ -429,37 +431,29 @@ bool btrfs_create_clone(struct lxc_conf *conf, struct bdev *orig,
...
@@ -429,37 +431,29 @@ bool btrfs_create_clone(struct lxc_conf *conf, struct bdev *orig,
return
false
;
return
false
;
}
}
/* rsync contents */
/* rsync the contents from source to target */
pid
=
fork
();
data
.
orig
=
orig
;
if
(
pid
<
0
)
{
data
.
new
=
new
;
SYSERROR
(
"fork"
);
if
(
am_unpriv
())
{
return
false
;
ret
=
userns_exec_1
(
conf
,
lxc_rsync_exec_wrapper
,
&
data
,
}
"lxc_rsync_exec_wrapper"
);
if
(
pid
>
0
)
{
int
ret
=
wait_for_pid
(
pid
);
bdev_put
(
orig
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
bdev_put
(
new
);
ERROR
(
"Failed to rsync from
\"
%s
\"
into
\"
%s
\"
"
,
orig
->
dest
,
new
->
dest
);
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
data
.
orig
=
orig
;
ret
=
run_command
(
cmd_output
,
sizeof
(
cmd_output
),
data
.
new
=
new
;
lxc_rsync_exec_wrapper
,
(
void
*
)
&
data
);
if
(
am_unpriv
())
ret
=
userns_exec_1
(
conf
,
rsync_rootfs_wrapper
,
&
data
,
"rsync_rootfs_wrapper"
);
else
ret
=
rsync_rootfs
(
&
data
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to rsync"
);
ERROR
(
"Failed to rsync from
\"
%s
\"
into
\"
%s
\"
: %s"
,
orig
->
dest
,
new
->
dest
,
cmd_output
);
return
false
;
return
false
;
}
}
TRACE
(
"Created btrfs subvolume
\"
%s
\"
"
,
new
->
dest
);
return
true
;
return
true
;
}
}
...
@@ -845,16 +839,27 @@ int btrfs_create(struct bdev *bdev, const char *dest, const char *n,
...
@@ -845,16 +839,27 @@ int btrfs_create(struct bdev *bdev, const char *dest, const char *n,
/* strlen("btrfs:") */
/* strlen("btrfs:") */
len
+=
6
;
len
+=
6
;
bdev
->
src
=
malloc
(
len
);
bdev
->
src
=
malloc
(
len
);
if
(
!
bdev
->
src
)
if
(
!
bdev
->
src
)
{
ERROR
(
"Failed to allocate memory"
);
return
-
1
;
return
-
1
;
}
ret
=
snprintf
(
bdev
->
src
,
len
,
"btrfs:%s"
,
dest
);
ret
=
snprintf
(
bdev
->
src
,
len
,
"btrfs:%s"
,
dest
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
{
ERROR
(
"Failed to create string"
);
return
-
1
;
return
-
1
;
}
bdev
->
dest
=
strdup
(
dest
);
bdev
->
dest
=
strdup
(
dest
);
if
(
!
bdev
->
dest
)
if
(
!
bdev
->
dest
)
{
ERROR
(
"Failed to duplicate string
\"
%s
\"
"
,
dest
);
return
-
1
;
return
-
1
;
}
return
btrfs_subvolume_create
(
bdev
->
dest
);
ret
=
btrfs_subvolume_create
(
bdev
->
dest
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to create btrfs subvolume
\"
%s
\"
"
,
bdev
->
dest
);
}
return
ret
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment