[CRIU] [PATCH 3/3] restore: Add support to flock&posix file locks' restore

Gu Zheng cengku.gu at huawei.com
Mon Nov 12 22:27:50 EST 2012


On 2012/11/9 1:51, Pavel Emelyanov wrote:
>> @@ -13,3 +16,77 @@ int dump_one_file_lock(FileLockEntry *fe, const struct cr_fdset *fdset)
......
>> +		} else if (fe->type & F_RDLCK) {
>> +			cmd |= LOCK_SH;
>> +		} else if (fe->type & F_WRLCK) {
>> +			cmd |= LOCK_EX;
>> +		} else if (fe->type & F_UNLCK) {
>> +			cmd |= LOCK_UN;
>> +		} else {
>> +			pr_err("Unknow flock type!\n");
>> +			goto err;
>> +		}
>> +
>> +		ret = flock(fe->fd, cmd);
> 
> I believe it's not that simple. What if your app tried to lock a file and
> hung on it since some other one was holding it. On restore time you will
> either dead-lock here, since the lock would be busy by another restored
> task or you will screw the locking up by locking the lock with wrong task.

Yes, the real situation is complex as you said, this one only can handle the simplest situation. 
I'll send a full-scale one later, thanks! 

> 
>> +		if (ret < 0) {
>> +			pr_err("Can not set flock!\n");
>> +			goto err;
>> +		}
>> +	} else if (fe->flag & FL_POSIX) {
>> +		struct flock flk;
>> +		memset(&flk, 0, sizeof(flk));
>> +
>> +		flk.l_whence = SEEK_SET;
>> +		flk.l_start = fe->start;
>> +		flk.l_len = fe->len;
>> +		flk.l_pid = fe->pid;
>> +		flk.l_type = fe->type;
>> +
>> +		ret = fcntl(fe->fd, F_SETLKW, &flk);
>> +		if (ret < 0) {
>> +			pr_err("Can not set posix lock!\n");
>> +			goto err;
>> +		}
>> +	} else {
>> +		pr_err("Unknow file lock style!\n");
>> +	}
>> +err:
>> +	return ret;
>> +}
> 
> 




More information about the CRIU mailing list