[CRIU] [PATCH 2/3] dump: Add support to flock&posix file locks' dump
Pavel Emelyanov
xemul at parallels.com
Thu Nov 8 12:56:36 EST 2012
> +static int dump_task_file_locks(struct parasite_ctl *ctl,
> + struct cr_fdset *fdset, struct parasite_drain_fd *dfds)
> +{
> + pid_t pid = ctl->pid;
> + FileLockEntry fe;
> + FILE *fp_locks = NULL;
> + char buf[100];
> +
> + long long fl_id = 0;
> + char fl_flag[10], fl_type[15], fl_option[10];
> + pid_t fl_own;
> + int maj, min;
> + unsigned long i_no;
> + long long start;
> + char end[32];
> +
> + int num = 0, ret = 0;
> + bool is_block;
> +
> + fp_locks = fopen("/proc/locks", "r");
> + if (fp_locks == NULL)
> + return -1;
> +
> + while (fgets(buf, sizeof(buf), fp_locks)) {
The proc parsing stuff should be in proc_parse.c file.
> + file_lock_entry__init(&fe);
> + is_block = false;
> +
> + if (strstr(buf, "->")) {
> + is_block = true;
> + pr_info("There is a blocked lock!\n");
> +
> + num = sscanf(buf,
> + "%lld: -> %s %s %s %d %02x:%02x:%ld %lld %s",
> + &fl_id, fl_flag, fl_type, fl_option,
> + &fl_own, &maj, &min, &i_no, &start, end);
> + } else {
> + num = sscanf(buf,
> + "%lld:%s %s %s %d %02x:%02x:%ld %lld %s",
> + &fl_id, fl_flag, fl_type, fl_option,
> + &fl_own, &maj, &min, &i_no, &start, end);
> + }
> +
<snip>
> @@ -1564,6 +1731,15 @@ static int dump_one_task(struct pstree_item *item)
> goto err_cure;
> }
>
> + if (opts.handle_file_locks) {
> + ret = dump_task_file_locks(parasite_ctl, cr_fdset, dfds);
> + if (ret) {
> + pr_err("Dump file locks (pid: %d) failed with %d\n",
> + pid, ret);
> + goto err_cure;
> + }
You parse the full /proc/locks file for every task. This is not optimal, please,
collect locks from proc after all tasks are frozen and then get data from that
image.
Besides, in the "else" branch you should check that task is holding a lock and
abort dumping in that case.
> + }
> +
> ret = parasite_dump_pages_seized(parasite_ctl, &vma_area_list, cr_fdset);
> if (ret) {
> pr_err("Can't dump pages (pid: %d) with parasite\n", pid);
> @@ -61,6 +61,7 @@
> #define NETDEV_MAGIC 0x57373951 /* Yaroslavl */
> #define TTY_MAGIC 0x59433025 /* Pushkin */
> #define TTY_INFO_MAGIC 0x59453036 /* Kolpino */
> +#define FILE_LOCKS_MAGIC 0x87654321 /* Town on the Mars */
Please, follow the rules of images' magic generation.
> #define IFADDR_MAGIC RAW_IMAGE_MAGIC
> #define ROUTE_MAGIC RAW_IMAGE_MAGIC
More information about the CRIU
mailing list