[CRIU] [PATCH 2/6] locks: Parse lock kind earlier
Pavel Emelyanov
xemul at parallels.com
Tue Aug 26 10:30:15 PDT 2014
Currently we keep the lock type (posix/flock) till the
time we dump it, then "decode" it into binary value.
I will need the easy-to-check one early, so parse the
kind in proc_parse.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
file-lock.c | 17 +++++------------
include/file-lock.h | 3 ++-
proc_parse.c | 23 +++++++++++++++++++----
3 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/file-lock.c b/file-lock.c
index b90c774..665600b 100644
--- a/file-lock.c
+++ b/file-lock.c
@@ -72,17 +72,10 @@ static int dump_one_file_lock(FileLockEntry *fle)
fle, PB_FILE_LOCK);
}
-static int fill_flock_entry(FileLockEntry *fle, const char *fl_flag,
+static int fill_flock_entry(FileLockEntry *fle, int fl_kind,
const char *fl_type, const char *fl_option)
{
- if (!strcmp(fl_flag, "POSIX")) {
- fle->flag |= FL_POSIX;
- } else if (!strcmp(fl_flag, "FLOCK")) {
- fle->flag |= FL_FLOCK;
- } else {
- pr_err("Unknown file lock!\n");
- goto err;
- }
+ fle->flag |= fl_kind;
if (!strcmp(fl_type, "MSNFS")) {
fle->type |= LOCK_MAND;
@@ -150,15 +143,15 @@ int dump_task_file_locks(struct parasite_ctl *ctl,
list_for_each_entry(fl, &file_lock_list, list) {
if (fl->fl_owner != pid)
continue;
- pr_info("lockinfo: %lld:%s %s %s %d %02x:%02x:%ld %lld %s\n",
- fl->fl_id, fl->fl_flag, fl->fl_type, fl->fl_option,
+ pr_info("lockinfo: %lld:%d %s %s %d %02x:%02x:%ld %lld %s\n",
+ fl->fl_id, fl->fl_kind, fl->fl_type, fl->fl_option,
fl->fl_owner, fl->maj, fl->min, fl->i_no,
fl->start, fl->end);
file_lock_entry__init(&fle);
fle.pid = ctl->pid.virt;
- ret = fill_flock_entry(&fle, fl->fl_flag, fl->fl_type,
+ ret = fill_flock_entry(&fle, fl->fl_kind, fl->fl_type,
fl->fl_option);
if (ret)
goto err;
diff --git a/include/file-lock.h b/include/file-lock.h
index 536ce94..b64720f 100644
--- a/include/file-lock.h
+++ b/include/file-lock.h
@@ -6,6 +6,7 @@
#include "protobuf.h"
#include "protobuf/file-lock.pb-c.h"
+#define FL_UNKNOWN -1
#define FL_POSIX 1
#define FL_FLOCK 2
@@ -30,7 +31,7 @@
struct file_lock {
long long fl_id;
- char fl_flag[10];
+ int fl_kind;
char fl_type[15];
char fl_option[10];
diff --git a/proc_parse.c b/proc_parse.c
index 768d4f5..8e2011e 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -1367,15 +1367,16 @@ static int parse_file_lock_buf(char *buf, struct file_lock *fl,
bool is_blocked)
{
int num;
+ char fl_flag[10];
if (is_blocked) {
num = sscanf(buf, "%lld: -> %s %s %s %d %x:%x:%ld %lld %s",
- &fl->fl_id, fl->fl_flag, fl->fl_type, fl->fl_option,
+ &fl->fl_id, fl_flag, fl->fl_type, fl->fl_option,
&fl->fl_owner, &fl->maj, &fl->min, &fl->i_no,
&fl->start, fl->end);
} else {
num = sscanf(buf, "%lld:%s %s %s %d %x:%x:%ld %lld %s",
- &fl->fl_id, fl->fl_flag, fl->fl_type, fl->fl_option,
+ &fl->fl_id, fl_flag, fl->fl_type, fl->fl_option,
&fl->fl_owner, &fl->maj, &fl->min, &fl->i_no,
&fl->start, fl->end);
}
@@ -1385,6 +1386,13 @@ static int parse_file_lock_buf(char *buf, struct file_lock *fl,
return -1;
}
+ if (!strcmp(fl_flag, "POSIX"))
+ fl->fl_kind = FL_POSIX;
+ else if (!strcmp(fl_flag, "FLOCK"))
+ fl->fl_kind = FL_FLOCK;
+ else
+ fl->fl_kind = FL_UNKNOWN;
+
return 0;
}
@@ -1428,6 +1436,13 @@ int parse_file_locks(void)
continue;
}
+ if (fl->fl_kind == FL_UNKNOWN) {
+ pr_err("Unknown file lock!\n");
+ ret = -1;
+ xfree(fl);
+ goto err;
+ }
+
if (is_blocked) {
/*
* Here the task is in the pstree.
@@ -1443,8 +1458,8 @@ int parse_file_locks(void)
goto err;
}
- pr_info("lockinfo: %lld:%s %s %s %d %02x:%02x:%ld %lld %s\n",
- fl->fl_id, fl->fl_flag, fl->fl_type, fl->fl_option,
+ pr_info("lockinfo: %lld:%d %s %s %d %02x:%02x:%ld %lld %s\n",
+ fl->fl_id, fl->fl_kind, fl->fl_type, fl->fl_option,
fl->fl_owner, fl->maj, fl->min, fl->i_no,
fl->start, fl->end);
--
1.8.4.2
More information about the CRIU
mailing list