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
75ffcb1b
Unverified
Commit
75ffcb1b
authored
Aug 15, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "btrfs: non-functional changes"
This reverts commit
fb49a3cb
. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
50da1a32
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
57 deletions
+38
-57
lxcbtrfs.c
src/lxc/bdev/lxcbtrfs.c
+38
-57
No files found.
src/lxc/bdev/lxcbtrfs.c
View file @
75ffcb1b
...
@@ -222,40 +222,38 @@ int btrfs_umount(struct bdev *bdev)
...
@@ -222,40 +222,38 @@ int btrfs_umount(struct bdev *bdev)
static
int
btrfs_subvolume_create
(
const
char
*
path
)
static
int
btrfs_subvolume_create
(
const
char
*
path
)
{
{
int
ret
,
saved_errno
;
int
ret
,
fd
=
-
1
;
struct
btrfs_ioctl_vol_args
args
;
struct
btrfs_ioctl_vol_args
args
;
char
*
p
,
*
newfull
;
char
*
p
,
*
newfull
=
strdup
(
path
);
int
fd
=
-
1
;
newfull
=
strdup
(
path
);
if
(
!
newfull
)
{
if
(
!
newfull
)
{
errno
=
ENOMEM
;
ERROR
(
"Error: out of memory"
)
;
return
-
ENOMEM
;
return
-
1
;
}
}
p
=
strrchr
(
newfull
,
'/'
);
p
=
strrchr
(
newfull
,
'/'
);
if
(
!
p
)
{
if
(
!
p
)
{
ERROR
(
"bad path: %s"
,
path
);
free
(
newfull
);
free
(
newfull
);
errno
=
EINVAL
;
return
-
1
;
return
-
EINVAL
;
}
}
*
p
=
'\0'
;
*
p
=
'\0'
;
fd
=
open
(
newfull
,
O_RDONLY
);
fd
=
open
(
newfull
,
O_RDONLY
);
free
(
newfull
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
return
-
errno
;
ERROR
(
"Error opening %s"
,
newfull
);
free
(
newfull
);
return
-
1
;
}
}
memset
(
&
args
,
0
,
sizeof
(
args
));
memset
(
&
args
,
0
,
sizeof
(
args
));
strncpy
(
args
.
name
,
p
+
1
,
BTRFS_SUBVOL_NAME_MAX
);
strncpy
(
args
.
name
,
p
+
1
,
BTRFS_SUBVOL_NAME_MAX
);
args
.
name
[
BTRFS_SUBVOL_NAME_MAX
-
1
]
=
0
;
args
.
name
[
BTRFS_SUBVOL_NAME_MAX
-
1
]
=
0
;
ret
=
ioctl
(
fd
,
BTRFS_IOC_SUBVOL_CREATE
,
&
args
);
ret
=
ioctl
(
fd
,
BTRFS_IOC_SUBVOL_CREATE
,
&
args
);
saved_errno
=
errno
;
INFO
(
"btrfs: snapshot create ioctl returned %d"
,
ret
)
;
free
(
newfull
);
close
(
fd
);
close
(
fd
);
errno
=
saved_errno
;
return
ret
;
return
ret
;
}
}
...
@@ -302,37 +300,39 @@ out:
...
@@ -302,37 +300,39 @@ out:
int
btrfs_snapshot
(
const
char
*
orig
,
const
char
*
new
)
int
btrfs_snapshot
(
const
char
*
orig
,
const
char
*
new
)
{
{
struct
btrfs_ioctl_vol_args_v2
args
;
char
*
newdir
,
*
newname
;
char
*
newfull
=
NULL
;
int
saved_errno
=
-
1
;
int
fd
=
-
1
,
fddst
=
-
1
,
ret
=
-
1
;
int
fd
=
-
1
,
fddst
=
-
1
,
ret
=
-
1
;
struct
btrfs_ioctl_vol_args_v2
args
;
char
*
newdir
,
*
newname
,
*
newfull
=
NULL
;
newfull
=
strdup
(
new
);
newfull
=
strdup
(
new
);
if
(
!
newfull
)
if
(
!
newfull
)
{
ERROR
(
"Error: out of memory"
);
goto
out
;
goto
out
;
}
ret
=
rmdir
(
newfull
);
// make sure the directory doesn't already exist
if
(
ret
<
0
&&
errno
!=
ENOENT
)
if
(
rmdir
(
newfull
)
<
0
&&
errno
!=
ENOENT
)
{
SYSERROR
(
"Error removing empty new rootfs"
);
goto
out
;
goto
out
;
}
newname
=
basename
(
newfull
);
newname
=
basename
(
newfull
);
newdir
=
dirname
(
newfull
);
fd
=
open
(
orig
,
O_RDONLY
);
fd
=
open
(
orig
,
O_RDONLY
);
if
(
fd
<
0
)
if
(
fd
<
0
)
{
SYSERROR
(
"Error opening original rootfs %s"
,
orig
);
goto
out
;
goto
out
;
}
newdir
=
dirname
(
newfull
);
fddst
=
open
(
newdir
,
O_RDONLY
);
fddst
=
open
(
newdir
,
O_RDONLY
);
if
(
fddst
<
0
)
if
(
fddst
<
0
)
{
SYSERROR
(
"Error opening new container dir %s"
,
newdir
);
goto
out
;
goto
out
;
}
memset
(
&
args
,
0
,
sizeof
(
args
));
memset
(
&
args
,
0
,
sizeof
(
args
));
args
.
fd
=
fd
;
args
.
fd
=
fd
;
strncpy
(
args
.
name
,
newname
,
BTRFS_SUBVOL_NAME_MAX
);
strncpy
(
args
.
name
,
newname
,
BTRFS_SUBVOL_NAME_MAX
);
args
.
name
[
BTRFS_SUBVOL_NAME_MAX
-
1
]
=
0
;
args
.
name
[
BTRFS_SUBVOL_NAME_MAX
-
1
]
=
0
;
ret
=
ioctl
(
fddst
,
BTRFS_IOC_SNAP_CREATE_V2
,
&
args
);
ret
=
ioctl
(
fddst
,
BTRFS_IOC_SNAP_CREATE_V2
,
&
args
);
saved_errno
=
errno
;
INFO
(
"btrfs: snapshot create ioctl returned %d"
,
ret
)
;
out:
out:
if
(
fddst
!=
-
1
)
if
(
fddst
!=
-
1
)
...
@@ -340,9 +340,6 @@ out:
...
@@ -340,9 +340,6 @@ out:
if
(
fd
!=
-
1
)
if
(
fd
!=
-
1
)
close
(
fd
);
close
(
fd
);
free
(
newfull
);
free
(
newfull
);
if
(
saved_errno
>=
0
)
errno
=
saved_errno
;
return
ret
;
return
ret
;
}
}
...
@@ -357,13 +354,13 @@ static int btrfs_snapshot_wrapper(void *data)
...
@@ -357,13 +354,13 @@ static int btrfs_snapshot_wrapper(void *data)
}
}
if
(
setgroups
(
0
,
NULL
)
<
0
)
if
(
setgroups
(
0
,
NULL
)
<
0
)
WARN
(
"Failed to clear groups"
);
WARN
(
"Failed to clear groups"
);
if
(
setuid
(
0
)
<
0
)
{
if
(
setuid
(
0
)
<
0
)
{
ERROR
(
"Failed to setuid to 0"
);
ERROR
(
"Failed to setuid to 0"
);
return
-
1
;
return
-
1
;
}
}
src
=
lxc_storage_get_path
(
arg
->
src
,
"btrfs"
);
src
=
lxc_storage_get_path
(
arg
->
src
,
"btrfs"
);
return
btrfs_snapshot
(
src
,
arg
->
dest
);
return
btrfs_snapshot
(
src
,
arg
->
dest
);
}
}
...
@@ -372,7 +369,6 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -372,7 +369,6 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
struct
lxc_conf
*
conf
)
{
{
int
ret
;
char
*
src
;
char
*
src
;
if
(
!
orig
->
dest
||
!
orig
->
src
)
if
(
!
orig
->
dest
||
!
orig
->
src
)
...
@@ -389,27 +385,16 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -389,27 +385,16 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
(
const
char
*
[]){
"btrfs:"
,
*
lxcpath
!=
'/'
?
lxcpath
:
++
lxcpath
,
(
const
char
*
[]){
"btrfs:"
,
*
lxcpath
!=
'/'
?
lxcpath
:
++
lxcpath
,
cname
,
"rootfs"
,
NULL
},
cname
,
"rootfs"
,
NULL
},
false
);
false
);
if
(
!
new
->
src
)
{
if
(
!
new
->
src
)
ERROR
(
"Failed to create new rootfs path"
);
return
-
1
;
return
-
1
;
}
TRACE
(
"Created new rootfs path
\"
%s
\"
"
,
new
->
src
);
src
=
lxc_storage_get_path
(
new
->
src
,
"btrfs"
);
src
=
lxc_storage_get_path
(
new
->
src
,
"btrfs"
);
new
->
dest
=
strdup
(
src
);
new
->
dest
=
strdup
(
src
);
if
(
!
new
->
dest
)
{
if
(
!
new
->
dest
)
ERROR
(
"Failed to duplicate string
\"
%s
\"
"
,
src
);
return
-
1
;
return
-
1
;
}
if
(
orig
->
mntopts
)
{
if
(
orig
->
mntopts
&&
(
new
->
mntopts
=
strdup
(
orig
->
mntopts
))
==
NULL
)
new
->
mntopts
=
strdup
(
orig
->
mntopts
);
if
(
!
new
->
mntopts
)
{
ERROR
(
"Failed to duplicate string
\"
%s
\"
"
,
orig
->
mntopts
);
return
-
1
;
return
-
1
;
}
}
if
(
snap
)
{
if
(
snap
)
{
struct
rsync_data_char
sdata
;
struct
rsync_data_char
sdata
;
...
@@ -421,16 +406,12 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -421,16 +406,12 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
"btrfs_snapshot_wrapper"
);
"btrfs_snapshot_wrapper"
);
}
}
ret
=
rmdir
(
new
->
dest
);
if
(
rmdir
(
new
->
dest
)
<
0
&&
errno
!=
ENOENT
)
{
if
(
ret
<
0
&&
errno
!=
ENOENT
)
{
SYSERROR
(
"removing %s"
,
new
->
dest
);
SYSERROR
(
"Failed to remove directory
\"
%s
\"
"
,
new
->
dest
);
return
-
1
;
return
-
1
;
}
}
ret
=
btrfs_subvolume_create
(
new
->
dest
);
return
btrfs_subvolume_create
(
new
->
dest
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to create btrfs subvolume
\"
%s
\"
"
,
new
->
dest
);
return
ret
;
}
}
static
int
btrfs_do_destroy_subvol
(
const
char
*
path
)
static
int
btrfs_do_destroy_subvol
(
const
char
*
path
)
...
...
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