From patchwork Fri Sep 30 04:06:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9357621 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 DACBE600C8 for ; Fri, 30 Sep 2016 04:07:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D871529D9D for ; Fri, 30 Sep 2016 04:07:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD11329DB8; Fri, 30 Sep 2016 04:07:09 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AD0A29D9D for ; Fri, 30 Sep 2016 04:07:08 +0000 (UTC) Received: from localhost ([::1]:41678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpp6J-0006oF-BN for patchwork-qemu-devel@patchwork.kernel.org; Fri, 30 Sep 2016 00:07:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpp63-0006ks-CK for qemu-devel@nongnu.org; Fri, 30 Sep 2016 00:06:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpp5z-0003Cr-4J for qemu-devel@nongnu.org; Fri, 30 Sep 2016 00:06:50 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:40398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpp5w-0003BZ-Ur for qemu-devel@nongnu.org; Fri, 30 Sep 2016 00:06:47 -0400 Received: from 172.24.1.47 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DNX99844; Fri, 30 Sep 2016 12:06:34 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Fri, 30 Sep 2016 12:06:27 +0800 From: zhanghailiang To: , , Date: Fri, 30 Sep 2016 12:06:09 +0800 Message-ID: <1475208369-13756-1-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Subject: [Qemu-devel] [PATCH] colo-compare: fix find_and_check_chardev() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, zhanghailiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP find_and_check_chardev() uses 'opts' member of CharDriverState to check if the chardev is 'socket' chardev or not, which the opts will be NULL if We add the chardev by qmp 'chardev-add' command. All the related info can be found in 'filename' member of CharDriverState, For tcp socket device, it will be like 'disconnected:tcp:9.61.1.8:9004,server' or 'tcp:9.61.1.8:9001,server <-> 9.61.1.8:50256', we can simply check it to identify if it is a tcp socket char device. Besides, fix this helper function to return -1 while some errors happen. Signed-off-by: zhanghailiang Reviewed-by: Zhang Chen --- net/colo-compare.c | 54 ++++++++---------------------------------------------- 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 22b1da1..6693258 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -92,10 +92,6 @@ typedef struct CompareClass { ObjectClass parent_class; } CompareClass; -typedef struct CompareChardevProps { - bool is_socket; -} CompareChardevProps; - enum { PRIMARY_IN = 0, SECONDARY_IN, @@ -564,56 +560,22 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs) } } -static int compare_chardev_opts(void *opaque, - const char *name, const char *value, - Error **errp) -{ - CompareChardevProps *props = opaque; - - if (strcmp(name, "backend") == 0 && - strcmp(value, "socket") == 0) { - props->is_socket = true; - return 0; - } else if (strcmp(name, "host") == 0 || - (strcmp(name, "port") == 0) || - (strcmp(name, "server") == 0) || - (strcmp(name, "wait") == 0) || - (strcmp(name, "path") == 0)) { - return 0; - } else { - error_setg(errp, - "COLO-compare does not support a chardev with option %s=%s", - name, value); - return -1; - } -} - -/* - * Return 0 is success. - * Return 1 is failed. - */ static int find_and_check_chardev(CharDriverState **chr, char *chr_name, Error **errp) { - CompareChardevProps props; - *chr = qemu_chr_find(chr_name); if (*chr == NULL) { error_setg(errp, "Device '%s' not found", chr_name); - return 1; + return -1; } - memset(&props, 0, sizeof(props)); - if (qemu_opt_foreach((*chr)->opts, compare_chardev_opts, &props, errp)) { - return 1; - } + if (!strstr((*chr)->filename, "tcp")) { + error_setg(errp, "chardev \"%s\" is not a tcp socket, filename '%s'", + chr_name, (*chr)->filename); + return -1; - if (!props.is_socket) { - error_setg(errp, "chardev \"%s\" is not a tcp socket", - chr_name); - return 1; } return 0; } @@ -660,15 +622,15 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) return; } - if (find_and_check_chardev(&s->chr_pri_in, s->pri_indev, errp)) { + if (find_and_check_chardev(&s->chr_pri_in, s->pri_indev, errp) < 0) { return; } - if (find_and_check_chardev(&s->chr_sec_in, s->sec_indev, errp)) { + if (find_and_check_chardev(&s->chr_sec_in, s->sec_indev, errp) < 0) { return; } - if (find_and_check_chardev(&s->chr_out, s->outdev, errp)) { + if (find_and_check_chardev(&s->chr_out, s->outdev, errp) < 0) { return; }