[PATCHv2,1/5] locks: Add c/r of non broken leases (kernel>=v4.1)

Submitted by Pavel Begunkov on Aug. 13, 2017, 11:49 p.m.

Details

Message ID 20170813234941.26329-1-asml.silence@gmail.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Pavel Begunkov Aug. 13, 2017, 11:49 p.m.
Leases in breaking state are not supported. In that case criu will
report an error during the dumping. Also lock info in
/proc/<pid>/fdinfo should be presented (since kernel 4.1).

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 criu/file-lock.c         | 9 +++++++++
 criu/include/file-lock.h | 1 +
 criu/proc_parse.c        | 5 +++++
 3 files changed, 15 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/file-lock.c b/criu/file-lock.c
index 2d4036c75..92d8bd394 100644
--- a/criu/file-lock.c
+++ b/criu/file-lock.c
@@ -292,6 +292,9 @@  int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p)
 			 */
 			if (fl->fl_owner != pid->real)
 				continue;
+		} else if (fl->fl_kind == FL_LEASE) {
+			pr_err("Leases are not supported for kernel <= v4.0");
+			return -1;
 		} else /* fl->fl_kind == FL_FLOCK || fl->fl_kind == FL_OFD */ {
 			int ret;
 
@@ -395,6 +398,12 @@  static int restore_file_lock(FileLockEntry *fle)
 			pr_err("Can not set ofd lock!\n");
 			goto err;
 		}
+	} else if (fle->flag & FL_LEASE) {
+		ret = fcntl(fle->fd, F_SETLEASE, fle->type);
+		if (ret < 0) {
+			pr_perror("Can't set lease!\n");
+			goto err;
+		}
 	} else {
 		pr_err("Unknown file lock style!\n");
 		goto err;
diff --git a/criu/include/file-lock.h b/criu/include/file-lock.h
index c3f2dabf7..f70739adb 100644
--- a/criu/include/file-lock.h
+++ b/criu/include/file-lock.h
@@ -10,6 +10,7 @@ 
 #define FL_POSIX	1
 #define FL_FLOCK	2
 #define FL_OFD		4
+#define FL_LEASE	8
 
 /* for posix fcntl() and lockf() */
 #ifndef F_RDLCK
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index e33da8d56..d3893272c 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1991,6 +1991,8 @@  static int parse_file_lock_buf(char *buf, struct file_lock *fl,
 		fl->fl_kind = FL_FLOCK;
 	else if (!strcmp(fl_flag, "OFDLCK"))
 		fl->fl_kind = FL_OFD;
+	else if (!strcmp(fl_flag, "LEASE"))
+		fl->fl_kind = FL_LEASE;
 	else
 		fl->fl_kind = FL_UNKNOWN;
 
@@ -2007,6 +2009,9 @@  static int parse_file_lock_buf(char *buf, struct file_lock *fl,
 			pr_err("Unknown lock option!\n");
 			return -1;
 		}
+	} else if (fl->fl_kind == FL_LEASE && !strcmp(fl_type, "BREAKING")) {
+		pr_err("Breaking leases are not supported (%d): %s\n",
+			num, buf);
 	} else {
 		if (!strcmp(fl_option, "UNLCK")) {
 			fl->fl_ltype |= F_UNLCK;

Comments

Andrei Vagin Aug. 29, 2017, 11:41 p.m.
Pls, don't ignore a cover letter

On Mon, Aug 14, 2017 at 02:49:37AM +0300, Pavel Begunkov wrote:
> Leases in breaking state are not supported. In that case criu will
> report an error during the dumping. Also lock info in
> /proc/<pid>/fdinfo should be presented (since kernel 4.1).
> 
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
>  criu/file-lock.c         | 9 +++++++++
>  criu/include/file-lock.h | 1 +
>  criu/proc_parse.c        | 5 +++++
>  3 files changed, 15 insertions(+)
> 
> diff --git a/criu/file-lock.c b/criu/file-lock.c
> index 2d4036c75..92d8bd394 100644
> --- a/criu/file-lock.c
> +++ b/criu/file-lock.c
> @@ -292,6 +292,9 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p)
>  			 */
>  			if (fl->fl_owner != pid->real)
>  				continue;
> +		} else if (fl->fl_kind == FL_LEASE) {
> +			pr_err("Leases are not supported for kernel <= v4.0");
> +			return -1;
>  		} else /* fl->fl_kind == FL_FLOCK || fl->fl_kind == FL_OFD */ {
>  			int ret;
>  
> @@ -395,6 +398,12 @@ static int restore_file_lock(FileLockEntry *fle)
>  			pr_err("Can not set ofd lock!\n");
>  			goto err;
>  		}
> +	} else if (fle->flag & FL_LEASE) {
> +		ret = fcntl(fle->fd, F_SETLEASE, fle->type);
> +		if (ret < 0) {
> +			pr_perror("Can't set lease!\n");
> +			goto err;
> +		}
>  	} else {
>  		pr_err("Unknown file lock style!\n");
>  		goto err;
> diff --git a/criu/include/file-lock.h b/criu/include/file-lock.h
> index c3f2dabf7..f70739adb 100644
> --- a/criu/include/file-lock.h
> +++ b/criu/include/file-lock.h
> @@ -10,6 +10,7 @@
>  #define FL_POSIX	1
>  #define FL_FLOCK	2
>  #define FL_OFD		4
> +#define FL_LEASE	8
>  
>  /* for posix fcntl() and lockf() */
>  #ifndef F_RDLCK
> diff --git a/criu/proc_parse.c b/criu/proc_parse.c
> index e33da8d56..d3893272c 100644
> --- a/criu/proc_parse.c
> +++ b/criu/proc_parse.c
> @@ -1991,6 +1991,8 @@ static int parse_file_lock_buf(char *buf, struct file_lock *fl,
>  		fl->fl_kind = FL_FLOCK;
>  	else if (!strcmp(fl_flag, "OFDLCK"))
>  		fl->fl_kind = FL_OFD;
> +	else if (!strcmp(fl_flag, "LEASE"))
> +		fl->fl_kind = FL_LEASE;
>  	else
>  		fl->fl_kind = FL_UNKNOWN;
>  
> @@ -2007,6 +2009,9 @@ static int parse_file_lock_buf(char *buf, struct file_lock *fl,
>  			pr_err("Unknown lock option!\n");
>  			return -1;
>  		}
> +	} else if (fl->fl_kind == FL_LEASE && !strcmp(fl_type, "BREAKING")) {
> +		pr_err("Breaking leases are not supported (%d): %s\n",
> +			num, buf);
>  	} else {
>  		if (!strcmp(fl_option, "UNLCK")) {
>  			fl->fl_ltype |= F_UNLCK;
> -- 
> 2.11.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
Pavel Begunkov Aug. 30, 2017, 1:04 a.m.
Yeah, thanks. Soon I'll make time to fix it along with one's noticed by
Pavel.

On 30/08/17 02:43, Andrei Vagin wrote:
> ===================== Run zdtm/static/file_lease01 in uns ======================
> Start test
> ./file_lease01 --pidfile=file_lease01.pid --outfile=file_lease01.out --filename=file_lease01.test
> Run criu dump
> Run criu restore
> =[log]=> dump/zdtm/static/file_lease01/124/1/restore.log
> ------------------------ grep Error ------------------------
> (00.308462)      4: 		Create fd for 3
> (00.308480)      4: 		Create fd for 4
> (00.308486)      4: 		Create fd for 5
> (00.308491)      4: 		Create fd for 6
> (00.308510)      4: Error (criu/file-lock.c:528): Can't restore non broken lease: Permission denied
> (00.310868)      1: Error (criu/cr-restore.c:1527): 4 exited, status=1
> (00.346609) uns: calling exit_usernsd (-1, 1)
> (00.346678) uns: daemon calls 0x4d3390 (146, -1, 1)
> (00.346690) uns: `- daemon exits w/ 0
> (00.349075) uns: daemon stopped
> (00.349092) Error (criu/cr-restore.c:2412): Restoring FAILED.
> ------------------------ ERROR OVER ------------------------
> ############## Test zdtm/static/file_lease01 FAIL at CRIU restore ##############
> 
> On Mon, Aug 14, 2017 at 01:12:36AM +0000, Patchwork wrote:
>> == Series Details ==
>>
>> Series: series starting with [PATCHv2,1/5] locks: Add c/r of non broken leases (kernel>=v4.1)
>> URL   : https://patchwork.criu.org/series/1885/
>> State : failure
>>
>> == Logs ==
>>
>> For more details see: https://travis-ci.org/criupatchwork/criu/builds/264198066?utm_source=github_status&utm_medium=notification
>> _______________________________________________
>> CRIU mailing list
>> CRIU@openvz.org
>> https://lists.openvz.org/mailman/listinfo/criu
Pavel Begunkov Sept. 3, 2017, 2:36 p.m.
Seems, CRIU can't set a lease on a file when user namespaces are used.
So, I found a notice from *fcntl* man:

"An unprivileged process may take out a lease only on a file whose UID
(owner) matches the filesystem UID of the process.  A process with the
CAP_LEASE capability may take out leases on arbitrary files."

I suppose, that restore stage is performed in user namespace and,
because of that, filesystem UID of new process differ from the original
one. Thus, it leads to violation of statements above.

Could somebody with a better understanding of namespaces in CRIU tell if
it sounds reasonable and guess what I can do about it, please?


On 30/08/17 04:04, Pavel Begunkov wrote:
> Yeah, thanks. Soon I'll make time to fix it along with one's noticed by
> Pavel.
> 
> On 30/08/17 02:43, Andrei Vagin wrote:
>> ===================== Run zdtm/static/file_lease01 in uns ======================
>> Start test
>> ./file_lease01 --pidfile=file_lease01.pid --outfile=file_lease01.out --filename=file_lease01.test
>> Run criu dump
>> Run criu restore
>> =[log]=> dump/zdtm/static/file_lease01/124/1/restore.log
>> ------------------------ grep Error ------------------------
>> (00.308462)      4: 		Create fd for 3
>> (00.308480)      4: 		Create fd for 4
>> (00.308486)      4: 		Create fd for 5
>> (00.308491)      4: 		Create fd for 6
>> (00.308510)      4: Error (criu/file-lock.c:528): Can't restore non broken lease: Permission denied
>> (00.310868)      1: Error (criu/cr-restore.c:1527): 4 exited, status=1
>> (00.346609) uns: calling exit_usernsd (-1, 1)
>> (00.346678) uns: daemon calls 0x4d3390 (146, -1, 1)
>> (00.346690) uns: `- daemon exits w/ 0
>> (00.349075) uns: daemon stopped
>> (00.349092) Error (criu/cr-restore.c:2412): Restoring FAILED.
>> ------------------------ ERROR OVER ------------------------
>> ############## Test zdtm/static/file_lease01 FAIL at CRIU restore ##############
>>
>> On Mon, Aug 14, 2017 at 01:12:36AM +0000, Patchwork wrote:
>>> == Series Details ==
>>>
>>> Series: series starting with [PATCHv2,1/5] locks: Add c/r of non broken leases (kernel>=v4.1)
>>> URL   : https://patchwork.criu.org/series/1885/
>>> State : failure
>>>
>>> == Logs ==
>>>
>>> For more details see: https://travis-ci.org/criupatchwork/criu/builds/264198066?utm_source=github_status&utm_medium=notification
>>> _______________________________________________
>>> CRIU mailing list
>>> CRIU@openvz.org
>>> https://lists.openvz.org/mailman/listinfo/criu
>