[CRIU] [PATCH v6 4/7] mount: Create binfmt_misc image w/o device suffix

Kirill Tkhai ktkhai at virtuozzo.com
Mon Aug 29 10:04:36 PDT 2016



On 29.08.2016 17:20, Pavel Emelyanov wrote:
> On 08/23/2016 07:16 PM, Kirill Tkhai wrote:
>> Use name binfmt_misc.img for any mounted binfmt_misc.
>> Note, that newly created binfmt_misc images won't restore
>> on old criu.
>>
>> Iterate over binfmt_misc_list if it's not empty on restore.
>>
>> Also, because of above, let's change a behaviour of dump and now
>> we do not create binfmt_misc images if there is no registered
>> binfmt_misc entries.
>>
>> v5: New
>> v6: Use {open,close}_image sequence to determ if image exists
>>     Iterate over binfmt_misc_list
>>
>> Suggested-by: Pavel Emelyanov <xemul at virtuozzo.com>
>> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
>> ---
>>  criu/mount.c |   29 ++++++++++++++++++++++++-----
>>  1 file changed, 24 insertions(+), 5 deletions(-)
>>
>> diff --git a/criu/mount.c b/criu/mount.c
>> index 768e739..9b22eeb 100644
>> --- a/criu/mount.c
>> +++ b/criu/mount.c
>> @@ -1369,7 +1369,7 @@ static int dump_binfmt_misc_entry(int dfd, char *name, struct cr_img *img)
>>  
>>  static int binfmt_misc_dump(struct mount_info *pm)
>>  {
>> -	struct cr_img *img;
>> +	struct cr_img *img = NULL;
>>  	struct dirent *de;
>>  	DIR *fdir = NULL;
>>  	int fd, ret;
>> @@ -1389,10 +1389,6 @@ static int binfmt_misc_dump(struct mount_info *pm)
>>  	}
>>  
>>  	ret = -1;
>> -	img = open_image(CR_FD_BINFMT_MISC_OLD, O_DUMP, pm->s_dev);
>> -	if (!img)
>> -		goto out;
>> -
>>  	while ((de = readdir(fdir))) {
>>  		if (dir_dots(de))
>>  			continue;
>> @@ -1401,6 +1397,13 @@ static int binfmt_misc_dump(struct mount_info *pm)
>>  		if (!strcmp(de->d_name, "status"))
>>  			continue;
>>  
>> +		if (!img) {
>> +			/* Create image only if an extry exists, i.e. here */
>> +			img = open_image(CR_FD_BINFMT_MISC, O_DUMP);
>> +			if (!img)
>> +				goto out;
>> +		}
>> +
>>  		if (dump_binfmt_misc_entry(fd, de->d_name, img))
>>  			goto out;
>>  	}
>> @@ -1528,8 +1531,24 @@ static int binfmt_misc_restore(struct mount_info *mi)
>>  	if (!buf)
>>  		return -1;
>>  
>> +	if (!list_empty(&binfmt_misc_list)) {
>> +		struct binfmt_misc_info *bmi;
>> +
>> +		list_for_each_entry(bmi, &binfmt_misc_list, list) {
> 
> Old code restored a single bmi object for the given mi. And thus was prepared to
> have multiple _different_ binfmt-misc super blocks. New code takes _all_ the bmi-s
> found in the images and restored them all into _every_ new binfmt-misc mount point.
> 
> This is odd. Either we should add some ID into the new image file, or explicitly
> ban more than one entry in it.

mount: Prohibit second binfmt_misc superblock
    
This is need to catch the moment when binfmt_misc in mainline kernel is virtualized
    
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>

diff --git a/criu/mount.c b/criu/mount.c
index 7fd9b0a..adc9a85 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -1461,6 +1461,7 @@ static int dump_binfmt_misc_entry(int dfd, char *name, struct cr_img *img)
 
 static int binfmt_misc_dump(struct mount_info *pm)
 {
+	static bool dumped = false;
 	struct cr_img *img = NULL;
 	struct dirent *de;
 	DIR *fdir = NULL;
@@ -1470,6 +1471,12 @@ static int binfmt_misc_dump(struct mount_info *pm)
 	if (ret <= 0)
 		return ret;
 
+	if (dumped) {
+		pr_err("Second binfmt_misc superblock\n");
+		return -1;
+	}
+	dumped = true;
+
 	fd = open_mountpoint(pm);
 	if (fd < 0)
 		return fd;



More information about the CRIU mailing list