|
@@ -1,113 +0,0 @@
|
1
|
|
-One of the 'features' of overlayfs is that depending on whether a file
|
2
|
|
-is on the upper or lower dir you get back a different device from stat.
|
3
|
|
-That breaks our lxc_rmdir_onedev.
|
4
|
|
-
|
5
|
|
-So at lxc_rmdir_ondev check the device of the directory being deleted.
|
6
|
|
-If it is overlayfs, then skip the device check.
|
7
|
|
-
|
8
|
|
-Note this is unrelated to overlayfs snapshots - in those cases when you
|
9
|
|
-delete a container, /var/lib/lxc/$container/ does not actually have an
|
10
|
|
-overlayfs under it. Rather, to reproduce this you would
|
11
|
|
-
|
12
|
|
-sudo mkdir /opt/{lower,upper,workdir}
|
13
|
|
-sudo mount -t overlayfs -o lower=/opt/lower,upper=/opt/upper,workdir=/opt/workdir \
|
14
|
|
- lxc /var/lib/lxc
|
15
|
|
-sudo lxc-create -t download -n c1 -- -d ubuntu -r trusty -a amd64
|
16
|
|
-sudo lxc-destroy -n c1
|
17
|
|
-
|
18
|
|
-Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
|
19
|
|
----
|
20
|
|
- src/lxc/utils.c | 39 ++++++++++++++++++++++++++++++++-------
|
21
|
|
- 1 file changed, 32 insertions(+), 7 deletions(-)
|
22
|
|
-
|
23
|
|
---- a/src/lxc/utils.c
|
24
|
|
-+++ b/src/lxc/utils.c
|
25
|
|
-@@ -29,6 +29,7 @@
|
26
|
|
- #include <stddef.h>
|
27
|
|
- #include <string.h>
|
28
|
|
- #include <sys/types.h>
|
29
|
|
-+#include <sys/vfs.h>
|
30
|
|
- #include <sys/stat.h>
|
31
|
|
- #include <sys/mman.h>
|
32
|
|
- #include <sys/param.h>
|
33
|
|
-@@ -68,8 +69,8 @@
|
34
|
|
-
|
35
|
|
- lxc_log_define(lxc_utils, lxc);
|
36
|
|
-
|
37
|
|
--static int _recursive_rmdir_onedev(char *dirname, dev_t pdev,
|
38
|
|
-- const char *exclude, int level)
|
39
|
|
-+static int _recursive_rmdir(char *dirname, dev_t pdev,
|
40
|
|
-+ const char *exclude, int level, bool onedev)
|
41
|
|
- {
|
42
|
|
- struct dirent dirent, *direntp;
|
43
|
|
- DIR *dir;
|
44
|
|
-@@ -106,7 +107,7 @@ static int _recursive_rmdir_onedev(char
|
45
|
|
- if (ret < 0) {
|
46
|
|
- switch(errno) {
|
47
|
|
- case ENOTEMPTY:
|
48
|
|
-- INFO("Not deleting snapshots");
|
49
|
|
-+ INFO("Not deleting snapshot %s", pathname);
|
50
|
|
- hadexclude = true;
|
51
|
|
- break;
|
52
|
|
- case ENOTDIR:
|
53
|
|
-@@ -129,14 +130,14 @@ static int _recursive_rmdir_onedev(char
|
54
|
|
- failed=1;
|
55
|
|
- continue;
|
56
|
|
- }
|
57
|
|
-- if (mystat.st_dev != pdev)
|
58
|
|
-+ if (onedev && mystat.st_dev != pdev)
|
59
|
|
- continue;
|
60
|
|
- if (S_ISDIR(mystat.st_mode)) {
|
61
|
|
-- if (_recursive_rmdir_onedev(pathname, pdev, exclude, level+1) < 0)
|
62
|
|
-+ if (_recursive_rmdir(pathname, pdev, exclude, level+1, onedev) < 0)
|
63
|
|
- failed=1;
|
64
|
|
- } else {
|
65
|
|
- if (unlink(pathname) < 0) {
|
66
|
|
-- ERROR("%s: failed to delete %s", __func__, pathname);
|
67
|
|
-+ SYSERROR("%s: failed to delete %s", __func__, pathname);
|
68
|
|
- failed=1;
|
69
|
|
- }
|
70
|
|
- }
|
71
|
|
-@@ -158,17 +159,41 @@ static int _recursive_rmdir_onedev(char
|
72
|
|
- return failed ? -1 : 0;
|
73
|
|
- }
|
74
|
|
-
|
75
|
|
-+/* we have two different magic values for overlayfs, yay */
|
76
|
|
-+#define OVERLAYFS_SUPER_MAGIC 0x794c764f
|
77
|
|
-+#define OVERLAY_SUPER_MAGIC 0x794c7630
|
78
|
|
-+/*
|
79
|
|
-+ * In overlayfs, st_dev is unreliable. so on overlayfs we don't do
|
80
|
|
-+ * the lxc_rmdir_onedev()
|
81
|
|
-+ */
|
82
|
|
-+static bool is_native_overlayfs(const char *path)
|
83
|
|
-+{
|
84
|
|
-+ struct statfs sb;
|
85
|
|
-+
|
86
|
|
-+ if (statfs(path, &sb) < 0)
|
87
|
|
-+ return false;
|
88
|
|
-+ if (sb.f_type == OVERLAYFS_SUPER_MAGIC ||
|
89
|
|
-+ sb.f_type == OVERLAY_SUPER_MAGIC)
|
90
|
|
-+ return true;
|
91
|
|
-+ return false;
|
92
|
|
-+}
|
93
|
|
-+
|
94
|
|
- /* returns 0 on success, -1 if there were any failures */
|
95
|
|
- extern int lxc_rmdir_onedev(char *path, const char *exclude)
|
96
|
|
- {
|
97
|
|
- struct stat mystat;
|
98
|
|
-+ bool onedev = true;
|
99
|
|
-+
|
100
|
|
-+ if (is_native_overlayfs(path)) {
|
101
|
|
-+ onedev = false;
|
102
|
|
-+ }
|
103
|
|
-
|
104
|
|
- if (lstat(path, &mystat) < 0) {
|
105
|
|
- ERROR("%s: failed to stat %s", __func__, path);
|
106
|
|
- return -1;
|
107
|
|
- }
|
108
|
|
-
|
109
|
|
-- return _recursive_rmdir_onedev(path, mystat.st_dev, exclude, 0);
|
110
|
|
-+ return _recursive_rmdir(path, mystat.st_dev, exclude, 0, onedev);
|
111
|
|
- }
|
112
|
|
-
|
113
|
|
- static int mount_fs(const char *source, const char *target, const char *type)
|