From patchwork Sun Oct 9 13:30:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugene Syromyatnikov X-Patchwork-Id: 9369123 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0EEEB60487 for ; Mon, 10 Oct 2016 08:33:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0164029325 for ; Mon, 10 Oct 2016 08:33:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA2FB2933B; Mon, 10 Oct 2016 08:33:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4A96B29325 for ; Mon, 10 Oct 2016 08:33:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9A8Umxn036869; Mon, 10 Oct 2016 04:30:48 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u99DUdDh016634 for ; Sun, 9 Oct 2016 09:30:39 -0400 Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u99DUdSP003595 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 9 Oct 2016 09:30:39 -0400 Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2258BC049D5B; Sun, 9 Oct 2016 13:30:38 +0000 (UTC) Received: by mail-lf0-f65.google.com with SMTP id p80so5474246lfp.1; Sun, 09 Oct 2016 06:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=QkPa7jXTh8vB5YqjL2VGqerlU80fhKXjszqML1OfCNo=; b=RQ63CPzW2MxgfP9JDg0NI8VPH+bnqri960YzYbJ/JvJccG4YW8V0QGitpODu20djyS EodYP2+Sd8uoZv7TWbKI+9n5tKY+P2HQtL+dW5kwAqa/4bdby4YN+PyF/yj9giusk90O ULukw6wwg01MLpkoFnOnPgSLykLWeBoGOB9W8+92ooB42L4FdiQ2j6nGt4tdMPTGaHgN DC5UuDbePCAdwxEZhZ1hW2aR7OyeiZLAfoL0yw0Ardwb73UJXlWz6kPBDyHSNmhudJvt U6x/R+lQW3QdxEfbq105PUAZ3VOwY7B+8bbLYzgU5VJP2A8+Xjnvwg4TSUvTas4Mo3Fg ExIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=QkPa7jXTh8vB5YqjL2VGqerlU80fhKXjszqML1OfCNo=; b=MWQmU2r67pMS95hszj0sU3smr7RszzLgLiPcP7rux4KxbCpLL9opXBE0mY/xGbmFfR FXWVywyDnELBmB3YCUio5SAzCMg2h7vmZJkSY5GCM523DsemqCiC0nF8iaz+9UFbx3DN EA5z5Im8uWGv1GfEWfFLTPMbPte7GvgmCCIr2DOfeHo5il5frXL8fzDQSu66cKjQXFQv DjcDuvJW6TK81K1/RbX9yS8Ho9t+R1Jr1OnhO/PsJ9vlqKZJcRAQ1lmrdMdn7I04TIBi Eunh4ndGBkz/VS5EkPTKVwD48HGCRPbirhYZfeHHld46e8VwFd8CLgRx4CN5mXVd0gtg cSWw== X-Gm-Message-State: AA6/9RnktVMsyrVxNdnlm5qkLQ38qEi6J2bDYpvZhzQT9PJikDoKFxX8iGuR6Ynk63u3lg== X-Received: by 10.25.34.11 with SMTP id i11mr11153953lfi.119.1476019836415; Sun, 09 Oct 2016 06:30:36 -0700 (PDT) Received: from obsidian (broadband-46-188-15-144.2com.net. [46.188.15.144]) by smtp.gmail.com with ESMTPSA id f35sm5154231lji.37.2016.10.09.06.30.35 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 09 Oct 2016 06:30:35 -0700 (PDT) Date: Sun, 9 Oct 2016 16:30:33 +0300 From: Eugene Syromyatnikov To: strace-devel@lists.sourceforge.net Message-ID: <20161009133033.GA3547@obsidian> References: <20161005.192828.566127461630656590.yamato@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161005.192828.566127461630656590.yamato@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 09 Oct 2016 13:30:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sun, 09 Oct 2016 13:30:38 +0000 (UTC) for IP:'209.85.215.65' DOMAIN:'mail-lf0-f65.google.com' HELO:'mail-lf0-f65.google.com' FROM:'evgsyr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.67 (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.65 mail-lf0-f65.google.com 209.85.215.65 mail-lf0-f65.google.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Mon, 10 Oct 2016 04:29:54 -0400 Cc: dm-devel@redhat.com, mpatocka@redhat.com, yamato@redhat.com Subject: [dm-devel] [PATCH 11/21] dm: Compare entering field values with exiting ones X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Virus-Scanned: ClamAV using ClamSMTP --- dm.c | 74 ++++++++++++++++++++++++++++++++++++++++-------------- tests/ioctl_dm.c | 26 +++++++------------ 2 files changed, 64 insertions(+), 36 deletions(-) diff --git a/dm.c b/dm.c index f23a65d..b6fb11d 100644 --- a/dm.c +++ b/dm.c @@ -282,28 +282,62 @@ dm_decode_string(const struct dm_ioctl *ioc, const char *extra, static int dm_known_ioctl(struct tcb *tcp, const unsigned int code, long arg) { - struct dm_ioctl ioc; + struct dm_ioctl *ioc; + struct dm_ioctl *entering_ioc = NULL; + bool ioc_changed = false; char *extra = NULL; uint32_t extra_size = 0; - if (umoven(tcp, arg, sizeof(ioc) - sizeof(ioc.data), &ioc) < 0) + ioc = malloc(sizeof(* ioc)); + if (!ioc) return 0; + + if (umoven(tcp, arg, sizeof(*ioc) - sizeof(ioc->data), ioc) < 0) { + free(ioc); + return 0; + } + if (entering(tcp)) + set_tcb_priv_data(tcp, ioc, free); + else { + entering_ioc = get_tcb_priv_data(tcp); + + /* + * retrieve_status, __dev_status called only in case of success, + * so it looks like there's no need to check open_count, + * event_nr, target_count, dev fields for change (they are + * printed only in case of absence of errors). + */ + if (!entering_ioc || + (ioc->version[0] != entering_ioc->version[0]) || + (ioc->version[1] != entering_ioc->version[1]) || + (ioc->version[2] != entering_ioc->version[2]) || + (ioc->data_size != entering_ioc->data_size) || + (ioc->data_start != entering_ioc->data_start) || + (ioc->flags != entering_ioc->flags)) + ioc_changed = true; + } + + if (exiting(tcp) && syserror(tcp) && !ioc_changed) { + free(ioc); + return 1; + } + tprintf("%s{version=%d.%d.%d", entering(tcp) ? ", " : " => ", - ioc.version[0], ioc.version[1], ioc.version[2]); + ioc->version[0], ioc->version[1], ioc->version[2]); /* * if we use a different version of ABI, do not attempt to decode * ioctl fields */ - if (ioc.version[0] != DM_VERSION_MAJOR) { + if (ioc->version[0] != DM_VERSION_MAJOR) { tprints(", /* Unsupported device mapper ABI version */ ..."); goto skip; } - if (ioc.data_size > sizeof(ioc)) { - extra = malloc(ioc.data_size); + if (ioc->data_size > sizeof(ioc)) { + extra = malloc(ioc->data_size); if (extra) { - extra_size = ioc.data_size; + extra_size = ioc->data_size; if (umoven(tcp, arg, extra_size, extra) < 0) { free(extra); extra = NULL; @@ -311,9 +345,9 @@ dm_known_ioctl(struct tcb *tcp, const unsigned int code, long arg) } } } - dm_decode_device(code, &ioc); - dm_decode_values(tcp, code, &ioc); - dm_decode_flags(&ioc); + dm_decode_device(code, ioc); + dm_decode_values(tcp, code, ioc); + dm_decode_flags(ioc); if (abbrev(tcp)) tprints(", ..."); else @@ -322,42 +356,42 @@ dm_known_ioctl(struct tcb *tcp, const unsigned int code, long arg) case DM_TABLE_STATUS: if (entering(tcp) || syserror(tcp)) break; - dm_decode_dm_target_spec(tcp, &ioc, extra, extra_size); + dm_decode_dm_target_spec(tcp, ioc, extra, extra_size); break; case DM_TABLE_LOAD: if (!entering(tcp)) break; - dm_decode_dm_target_spec(tcp, &ioc, extra, extra_size); + dm_decode_dm_target_spec(tcp, ioc, extra, extra_size); break; case DM_TABLE_DEPS: if (entering(tcp) || syserror(tcp)) break; - dm_decode_dm_target_deps(&ioc, extra, extra_size); + dm_decode_dm_target_deps(ioc, extra, extra_size); break; case DM_LIST_DEVICES: if (entering(tcp) || syserror(tcp)) break; - dm_decode_dm_name_list(&ioc, extra, extra_size); + dm_decode_dm_name_list(ioc, extra, extra_size); break; case DM_LIST_VERSIONS: if (entering(tcp) || syserror(tcp)) break; - dm_decode_dm_target_versions(&ioc, extra, extra_size); + dm_decode_dm_target_versions(ioc, extra, extra_size); break; case DM_TARGET_MSG: if (entering(tcp)) { - dm_decode_dm_target_msg(&ioc, extra, + dm_decode_dm_target_msg(ioc, extra, extra_size); } else if (!syserror(tcp) && - ioc.flags & DM_DATA_OUT_FLAG) { - dm_decode_string(&ioc, extra, extra_size); + ioc->flags & DM_DATA_OUT_FLAG) { + dm_decode_string(ioc, extra, extra_size); } break; case DM_DEV_RENAME: case DM_DEV_SET_GEOMETRY: if (!entering(tcp)) break; - dm_decode_string(&ioc, extra, extra_size); + dm_decode_string(ioc, extra, extra_size); break; } @@ -365,6 +399,8 @@ dm_known_ioctl(struct tcb *tcp, const unsigned int code, long arg) tprints("}"); if (extra) free(extra); + if (exiting(tcp)) + free(ioc); return 1; } diff --git a/tests/ioctl_dm.c b/tests/ioctl_dm.c index 3c43913..31f474c 100644 --- a/tests/ioctl_dm.c +++ b/tests/ioctl_dm.c @@ -42,8 +42,6 @@ main(void) ioctl(-1, DM_VERSION, &s); printf("ioctl(-1, DM_VERSION, " "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", flags=0} => " - "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " "uuid=\"uuu\", flags=0}) = -1 EBADF (%m)\n"); init_s(); @@ -58,9 +56,8 @@ main(void) printf("ioctl(-1, DM_TABLE_LOAD, " "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " "uuid=\"uuu\", target_count=1, flags=0, {sector_start=16, " - "length=32, target_type=\"tgt\", string=\"tparams\"}} => " - "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", flags=0}) = -1 EBADF (%m)\n"); + "length=32, target_type=\"tgt\", string=\"tparams\"}}) = " + "-1 EBADF (%m)\n"); init_s(); s.u.tm.target_msg.sector = 0x1234; @@ -69,27 +66,24 @@ main(void) ioctl(-1, DM_TARGET_MSG, &s); printf("ioctl(-1, DM_TARGET_MSG, " "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", flags=0, {sector=4660, message=\"tmsg\"}} => " - "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", flags=0}) = -1 EBADF (%m)\n"); + "uuid=\"uuu\", flags=0, {sector=4660, message=\"tmsg\"}}) = " + "-1 EBADF (%m)\n"); init_s(); strcpy(s.u.string, "10 20 30 40"); ioctl(-1, DM_DEV_SET_GEOMETRY, &s); printf("ioctl(-1, DM_DEV_SET_GEOMETRY, " "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", flags=0, string=\"10 20 30 40\"} => " - "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", flags=0}) = -1 EBADF (%m)\n"); + "uuid=\"uuu\", flags=0, string=\"10 20 30 40\"}) = " + "-1 EBADF (%m)\n"); init_s(); strcpy(s.u.string, "new-name"); ioctl(-1, DM_DEV_RENAME, &s); printf("ioctl(-1, DM_DEV_RENAME, " "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", event_nr=0, flags=0, string=\"new-name\"} => " - "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", flags=0}) = -1 EBADF (%m)\n"); + "uuid=\"uuu\", event_nr=0, flags=0, string=\"new-name\"}) = " + "-1 EBADF (%m)\n"); init_s(); s.ioc.target_count = -1U; @@ -98,9 +92,7 @@ main(void) "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " "uuid=\"uuu\", target_count=4294967295, flags=0, " "{sector_start=0, length=0, target_type=\"\", string=\"\"}, " - "/* misplaced struct dm_target_spec */ ...} => " - "{version=4.1.2, dev=makedev(18, 52), name=\"nnn\", " - "uuid=\"uuu\", flags=0}) = -1 EBADF (%m)\n"); + "/* misplaced struct dm_target_spec */ ...}) = -1 EBADF (%m)\n"); puts("+++ exited with 0 +++"); return 0;