[CRIU] [PATCH 3/3] restore: Add support to flock&posix file locks' restore
Pavel Emelyanov
xemul at parallels.com
Thu Nov 8 12:51:37 EST 2012
> @@ -13,3 +16,77 @@ int dump_one_file_lock(FileLockEntry *fe, const struct cr_fdset *fdset)
> return pb_write_one(fdset_fd(fdset, CR_FD_FILE_LOCKS),
> fe, PB_FILE_LOCK);
> }
> +
> +static int restore_file_lock(FileLockEntry *fe)
> +{
> + int ret = -1;
> + unsigned int cmd;
> +
> + if (fe->flag & FL_FLOCK) {
> + if (fe->type & LOCK_MAND) {
> + cmd = fe->type;
> + } 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.
> + 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