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
cf5a3f44
Commit
cf5a3f44
authored
Aug 12, 2016
by
Serge Hallyn
Committed by
GitHub
Aug 12, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1125 from brauner/2016-08-12/smarter_btrfs_subvol_detection
bdev: be smarter about btrfs subvolume detection
parents
121e90aa
6e0fa6a0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
lxcbtrfs.c
src/lxc/bdev/lxcbtrfs.c
+27
-0
lxcbtrfs.h
src/lxc/bdev/lxcbtrfs.h
+5
-0
lxccontainer.c
src/lxc/lxccontainer.c
+4
-0
No files found.
src/lxc/bdev/lxcbtrfs.c
View file @
cf5a3f44
...
...
@@ -33,6 +33,7 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include "bdev.h"
#include "log.h"
...
...
@@ -142,6 +143,32 @@ bool is_btrfs_fs(const char *path)
return
true
;
}
/*
* Taken from btrfs toolsuite. Test if path is a subvolume.
* return 0; path exists but it is not a subvolume
* return 1; path exists and it is a subvolume
* return < 0; error
*/
int
is_btrfs_subvol
(
const
char
*
path
)
{
struct
stat
st
;
struct
statfs
stfs
;
int
ret
;
ret
=
stat
(
path
,
&
st
);
if
(
ret
<
0
)
return
-
errno
;
if
(
st
.
st_ino
!=
BTRFS_FIRST_FREE_OBJECTID
||
!
S_ISDIR
(
st
.
st_mode
))
return
0
;
ret
=
statfs
(
path
,
&
stfs
);
if
(
ret
<
0
)
return
-
errno
;
return
stfs
.
f_type
==
BTRFS_SUPER_MAGIC
;
}
int
btrfs_detect
(
const
char
*
path
)
{
struct
stat
st
;
...
...
src/lxc/bdev/lxcbtrfs.h
View file @
cf5a3f44
...
...
@@ -30,6 +30,10 @@
#include <stdint.h>
#include <byteswap.h>
#ifndef BTRFS_SUPER_MAGIC
# define BTRFS_SUPER_MAGIC 0x9123683E
#endif
typedef
uint8_t
u8
;
typedef
uint16_t
u16
;
typedef
uint32_t
u32
;
...
...
@@ -404,6 +408,7 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
int
name_len
);
int
btrfs_list_get_path_rootid
(
int
fd
,
u64
*
treeid
);
bool
is_btrfs_fs
(
const
char
*
path
);
int
is_btrfs_subvol
(
const
char
*
path
);
bool
btrfs_try_remove_subvol
(
const
char
*
path
);
int
btrfs_same_fs
(
const
char
*
orig
,
const
char
*
new
);
int
btrfs_snapshot
(
const
char
*
orig
,
const
char
*
new
);
...
...
src/lxc/lxccontainer.c
View file @
cf5a3f44
...
...
@@ -2826,6 +2826,7 @@ bool should_default_to_snapshot(struct lxc_container *c0,
size_t
l1
=
strlen
(
c1
->
config_path
)
+
strlen
(
c1
->
name
)
+
2
;
char
*
p0
=
alloca
(
l0
+
1
);
char
*
p1
=
alloca
(
l1
+
1
);
char
*
rootfs
=
c0
->
lxc_conf
->
rootfs
.
path
;
snprintf
(
p0
,
l0
,
"%s/%s"
,
c0
->
config_path
,
c0
->
name
);
snprintf
(
p1
,
l1
,
"%s/%s"
,
c1
->
config_path
,
c1
->
name
);
...
...
@@ -2833,6 +2834,9 @@ bool should_default_to_snapshot(struct lxc_container *c0,
if
(
!
is_btrfs_fs
(
p0
)
||
!
is_btrfs_fs
(
p1
))
return
false
;
if
(
is_btrfs_subvol
(
rootfs
)
<=
0
)
return
false
;
return
btrfs_same_fs
(
p0
,
p1
)
==
0
;
}
...
...
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