[Devel,criu,3/3] mount: don't create a temporary directory if /tmp exists

Submitted by Andrei Vagin on Nov. 22, 2016, 1:07 a.m.

Details

Message ID 1479776840-23544-3-git-send-email-avagin@openvz.org
State New
Series "Series without cover letter"
Headers show

Commit Message

Andrei Vagin Nov. 22, 2016, 1:07 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

pivot_root requires a place where to move an old root. Currently
a temporary directory is created for that, but it doesn't
work if the / directory is read-only.

Actually we can use any existing directory. In this patch,
criu tries to use /tmp and only if it doesn't exist,
criu creates a temporary directory.

https://bugs.openvz.org/browse/OVZ-6778

v2: don't give a constant string to mkdtemp
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/mount.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index 3a98e63..c76542b 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -3019,8 +3019,11 @@  static int do_umount_one(struct mount_info *mi)
 
 static int cr_pivot_root(char *root)
 {
-	char put_root[] = "crtools-put-root.XXXXXX";
+	char tmp_dir_tmpl[] = "crtools-put-root.XXXXXX";
+	bool tmp_dir = false;
+	char *put_root = "tmp";
 	int exit_code = -1;
+	struct stat st;
 
 	pr_info("Move the root to %s\n", root ? : ".");
 
@@ -3031,9 +3034,13 @@  static int cr_pivot_root(char *root)
 		}
 	}
 
-	if (mkdtemp(put_root) == NULL) {
-		pr_perror("Can't create a temporary directory");
-		return -1;
+	if (stat(put_root, &st) || !S_ISDIR(st.st_mode)) {
+		put_root = mkdtemp(tmp_dir_tmpl);
+		if (put_root == NULL) {
+			pr_perror("Can't create a temporary directory");
+			return -1;
+		}
+		tmp_dir = true;
 	}
 
 	if (mount(put_root, put_root, NULL, MS_BIND, NULL)) {
@@ -3070,7 +3077,7 @@  err_tmpfs:
 	}
 
 err_root:
-	if (rmdir(put_root)) {
+	if (tmp_dir && rmdir(put_root)) {
 		pr_perror("Can't remove the directory %s", put_root);
 		return -1;
 	}

Comments

Pavel Emelianov Nov. 22, 2016, 11:45 a.m.
I've somehow lost 1/3 and 2/3 :( What are the subjects?
Kirill Gorkunov Nov. 22, 2016, 12:01 p.m.
On Tue, Nov 22, 2016 at 02:45:46PM +0300, Pavel Emelyanov wrote:
> I've somehow lost 1/3 and 2/3 :( What are the subjects?

1063   C Nov 21 Andrey Vagin         [PATCH criu 1/3] mount: handle error from restore_shared_options()
1064   C Nov 21 Andrey Vagin         ├─>[PATCH criu 2/3] mount: fix mounting non-root shared mounts
1065   C Nov 21 Andrey Vagin         └─>[PATCH criu 3/3] mount: don't create a temporary directory if /tmp exists

	Cyrill
Kirill Gorkunov Nov. 22, 2016, 12:43 p.m.
On Tue, Nov 22, 2016 at 03:44:35PM +0300, Pavel Emelyanov wrote:
> On 11/22/2016 03:01 PM, Cyrill Gorcunov wrote:
> > On Tue, Nov 22, 2016 at 02:45:46PM +0300, Pavel Emelyanov wrote:
> >> I've somehow lost 1/3 and 2/3 :( What are the subjects?
> > 
> > 1063   C Nov 21 Andrey Vagin         [PATCH criu 1/3] mount: handle error from restore_shared_options()
> 
> Cannot find one nor in my mailbox, nor on the ML archives :(
> 
> > 1064   C Nov 21 Andrey Vagin         ├─>[PATCH criu 2/3] mount: fix mounting non-root shared mounts
> 
> This one sits in my mailbox as "[PATCH 2/2] mount: fix mounting non-root shared mounts". Is it the same?

Hmm. Not sure :/ Mind simply grab them from criu-stable?

https://src.openvz.org/projects/OVZ/repos/criu/commits?until=refs%2Fheads%2Fvz7-u3
Pavel Emelianov Nov. 22, 2016, 12:44 p.m.
On 11/22/2016 03:01 PM, Cyrill Gorcunov wrote:
> On Tue, Nov 22, 2016 at 02:45:46PM +0300, Pavel Emelyanov wrote:
>> I've somehow lost 1/3 and 2/3 :( What are the subjects?
> 
> 1063   C Nov 21 Andrey Vagin         [PATCH criu 1/3] mount: handle error from restore_shared_options()

Cannot find one nor in my mailbox, nor on the ML archives :(

> 1064   C Nov 21 Andrey Vagin         ├─>[PATCH criu 2/3] mount: fix mounting non-root shared mounts

This one sits in my mailbox as "[PATCH 2/2] mount: fix mounting non-root shared mounts". Is it the same?

> 1065   C Nov 21 Andrey Vagin         └─>[PATCH criu 3/3] mount: don't create a temporary directory if /tmp exists
> 
> 	Cyrill
> .
>
Pavel Emelianov Nov. 22, 2016, 12:51 p.m.
On 11/22/2016 03:43 PM, Cyrill Gorcunov wrote:
> On Tue, Nov 22, 2016 at 03:44:35PM +0300, Pavel Emelyanov wrote:
>> On 11/22/2016 03:01 PM, Cyrill Gorcunov wrote:
>>> On Tue, Nov 22, 2016 at 02:45:46PM +0300, Pavel Emelyanov wrote:
>>>> I've somehow lost 1/3 and 2/3 :( What are the subjects?
>>>
>>> 1063   C Nov 21 Andrey Vagin         [PATCH criu 1/3] mount: handle error from restore_shared_options()
>>
>> Cannot find one nor in my mailbox, nor on the ML archives :(
>>
>>> 1064   C Nov 21 Andrey Vagin         ├─>[PATCH criu 2/3] mount: fix mounting non-root shared mounts
>>
>> This one sits in my mailbox as "[PATCH 2/2] mount: fix mounting non-root shared mounts". Is it the same?
> 
> Hmm. Not sure :/ Mind simply grab them from criu-stable?
> 
> https://src.openvz.org/projects/OVZ/repos/criu/commits?until=refs%2Fheads%2Fvz7-u3
> .
> 

BTW, why isn't criu@openvz.org in Cc for this particular patch? %)

-- Pavel
Dmitry Safonov Nov. 22, 2016, 12:51 p.m.
On 11/22/2016 03:44 PM, Pavel Emelyanov wrote:
> On 11/22/2016 03:01 PM, Cyrill Gorcunov wrote:
>> On Tue, Nov 22, 2016 at 02:45:46PM +0300, Pavel Emelyanov wrote:
>>> I've somehow lost 1/3 and 2/3 :( What are the subjects?
>>
>> 1063   C Nov 21 Andrey Vagin         [PATCH criu 1/3] mount: handle error from restore_shared_options()
>
> Cannot find one nor in my mailbox, nor on the ML archives :(

Here they are:
https://lists.openvz.org/pipermail/devel/2016-November/069621.html
https://lists.openvz.org/pipermail/devel/2016-November/069623.html
https://lists.openvz.org/pipermail/devel/2016-November/069622.html

Not sure, why it's on @devel list..

>
>> 1064   C Nov 21 Andrey Vagin         ├─>[PATCH criu 2/3] mount: fix mounting non-root shared mounts
>
> This one sits in my mailbox as "[PATCH 2/2] mount: fix mounting non-root shared mounts". Is it the same?
>
>> 1065   C Nov 21 Andrey Vagin         └─>[PATCH criu 3/3] mount: don't create a temporary directory if /tmp exists
>>
>> 	Cyrill
>> .
>>
>
> _______________________________________________
> Devel mailing list
> Devel@openvz.org
> https://lists.openvz.org/mailman/listinfo/devel
>