From patchwork Fri Dec 2 15:08:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cedric Bosdonnat X-Patchwork-Id: 9458741 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 E6EDB60236 for ; Fri, 2 Dec 2016 15:11:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9126284E2 for ; Fri, 2 Dec 2016 15:11:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD0D028556; Fri, 2 Dec 2016 15:11:59 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1ED81284E2 for ; Fri, 2 Dec 2016 15:11:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCpSa-0002w9-Gt; Fri, 02 Dec 2016 15:09:12 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCpSY-0002ux-Cf for xen-devel@lists.xen.org; Fri, 02 Dec 2016 15:09:10 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id D0/E8-28843-69E81485; Fri, 02 Dec 2016 15:09:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42I53H6XVXdqn2O Ewc5WVYslHxezODB6HN39mymAMYo1My8pvyKBNePyuoesBT/DKzZtMmpgvG/fxcjFISSwhFFi 7amX7F2MnBxsAvYSXX+OMoHYIgLSEtc+X2YEsZkFSiSaznUyg9jCAh4SP76tBKthEVCVaH3zF KyXV8BC4uSn+WD1EgLyEgvPHwGr4RSwlHjQch0sLgRU03zjDgtEvaDEyZlPgGwOoPnqEuvnCU Gskpdo3jqbeQIj7ywkVbMQqmYhqVrAyLyKUaM4tagstUjX0FgvqSgzPaMkNzEzR9fQwEwvN7W 4ODE9NScxqVgvOT93EyMwoBiAYAfjl2UBhxglOZiURHlNcxwjhPiS8lMqMxKLM+KLSnNSiw8x ynBwKEnwNvcC5QSLUtNTK9Iyc4ChDZOW4OBREuFVBUnzFhck5hZnpkOkTjEqSonzOoMkBEASG aV5cG2weLrEKCslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYd59IFN4MvNK4Ka/AlrMBLS447o9yO KSRISUVAPjse+vL13bEfGyPfygmP/qsgOc8zh2f5mueMpA3Vk5aNdSg2gHpjTNzUkLXS2uZ38 VSvp/xELy+jGDeFOdkpX9+aXNSsYTPdasW/O1dm3hzr3rYm7/12KTvBl9Q3y6y/XiUzGLrj3y aDv3o/JnwFTjZWpbrt1ruvC65R83v5TBfhP+uUvNd93mUmIpzkg01GIuKk4EADE66s+iAgAA X-Env-Sender: cbosdonnat@suse.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1480691349!70773759!1 X-Originating-IP: [195.135.221.5] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33629 invoked from network); 2 Dec 2016 15:09:09 -0000 Received: from smtp.nue.novell.com (HELO smtp.nue.novell.com) (195.135.221.5) by server-7.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Dec 2016 15:09:09 -0000 Received: from laptop.vms (mhy71-2-88-167-63-197.fbx.proxad.net [88.167.63.197]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Fri, 02 Dec 2016 16:09:08 +0100 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= To: xen-devel@lists.xen.org Date: Fri, 2 Dec 2016 16:08:11 +0100 Message-Id: <20161202150841.31227-6-cbosdonnat@suse.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161202150841.31227-1-cbosdonnat@suse.com> References: <20161202150841.31227-1-cbosdonnat@suse.com> MIME-Version: 1.0 Cc: Ian Jackson , Wei Liu , Cedric Bosdonnat Subject: [Xen-devel] [PATCH v2 05/35] libxl/libxl_bootloader.c: used LOG*D functions X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Cedric Bosdonnat Use LOG*D functions to output the domain ID in logs as much as possible. This will help consumer code sorting the logs by domain. Signed-off-by: Cédric Bosdonnat Acked-by: Wei Liu --- tools/libxl/libxl_bootloader.c | 84 ++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c index 2cfc8cf..c7c2012 100644 --- a/tools/libxl/libxl_bootloader.c +++ b/tools/libxl/libxl_bootloader.c @@ -99,7 +99,7 @@ static int setup_xenconsoled_pty(libxl__egc *egc, libxl__bootloader_state *bl, r = ttyname_r(slave, slave_path, slave_path_len); if (r == -1) { - LOGE(ERROR,"ttyname_r failed"); + LOGED(ERROR, bl->domid, "ttyname_r failed"); rc = ERROR_FAIL; goto out; } @@ -125,7 +125,7 @@ static int setup_xenconsoled_pty(libxl__egc *egc, libxl__bootloader_state *bl, } static const char *bootloader_result_command(libxl__gc *gc, const char *buf, - const char *prefix, size_t prefixlen) { + const char *prefix, size_t prefixlen, uint32_t domid) { if (strncmp(buf, prefix, prefixlen)) return 0; @@ -136,7 +136,7 @@ static const char *bootloader_result_command(libxl__gc *gc, const char *buf, while (CTYPE(isspace,*rhs)) rhs++; - LOG(DEBUG,"bootloader output contained %s %s", prefix, rhs); + LOGD(DEBUG, domid, "bootloader output contained %s %s", prefix, rhs); return rhs; } @@ -151,7 +151,8 @@ static int parse_bootloader_result(libxl__egc *egc, f = fopen(bl->outputpath, "r"); if (!f) { - LOGE(ERROR,"open bootloader output file %s", bl->outputpath); + LOGED(ERROR, bl->domid, "open bootloader output file %s", + bl->outputpath); goto out; } @@ -166,21 +167,22 @@ static int parse_bootloader_result(libxl__egc *egc, } if (c == EOF) { if (ferror(f)) { - LOGE(ERROR,"read bootloader output file %s", bl->outputpath); + LOGED(ERROR, bl->domid, "read bootloader output file %s", + bl->outputpath); goto out; } if (!l) break; } if (l >= sizeof(buf)) { - LOG(WARN,"bootloader output contained" - " overly long item `%.150s...'", buf); + LOGD(WARN, bl->domid, "bootloader output contained" + " overly long item `%.150s...'", buf); continue; } buf[l] = 0; const char *rhs; -#define COMMAND(s) ((rhs = bootloader_result_command(gc, buf, s, sizeof(s)-1))) +#define COMMAND(s) ((rhs = bootloader_result_command(gc, buf, s, sizeof(s)-1, bl->domid))) if (COMMAND("kernel")) { bl->kernel->path = libxl__strdup(gc, rhs); @@ -193,7 +195,8 @@ static int parse_bootloader_result(libxl__egc *egc, } else if (COMMAND("args")) { bl->cmdline = libxl__strdup(gc, rhs); } else if (l) { - LOG(WARN, "unexpected output from bootloader: `%s'", buf); + LOGD(WARN, bl->domid, + "unexpected output from bootloader: `%s'", buf); } } rc = 0; @@ -276,7 +279,8 @@ static void bootloader_local_detached_cb(libxl__egc *egc, libxl__bootloader_state *bl = CONTAINER_OF(dls, *bl, dls); if (rc) { - LOG(ERROR, "unable to detach locally attached disk"); + LOGD(ERROR, bl->domid, + "unable to detach locally attached disk"); if (!bl->rc) bl->rc = rc; } @@ -295,8 +299,8 @@ static void bootloader_stop(libxl__egc *egc, libxl__datacopier_kill(&bl->display); if (libxl__ev_child_inuse(&bl->child)) { r = kill(bl->child.pid, SIGTERM); - if (r) LOGE(WARN, "%sfailed to kill bootloader [%lu]", - rc ? "after failure, " : "", (unsigned long)bl->child.pid); + if (r) LOGED(WARN, bl->domid, "%sfailed to kill bootloader [%lu]", + rc ? "after failure, " : "", (unsigned long)bl->child.pid); } if (!bl->rc) bl->rc = rc; @@ -321,13 +325,14 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl) libxl__bootloader_init(bl); if (info->type != LIBXL_DOMAIN_TYPE_PV) { - LOG(DEBUG, "not a PV domain, skipping bootloader"); + LOGD(DEBUG, domid, "not a PV domain, skipping bootloader"); rc = 0; goto out_ok; } if (!info->u.pv.bootloader) { - LOG(DEBUG, "no bootloader configured, using user supplied kernel"); + LOGD(DEBUG, domid, + "no bootloader configured, using user supplied kernel"); bl->kernel->path = bl->info->kernel; bl->ramdisk->path = bl->info->ramdisk; bl->cmdline = bl->info->cmdline; @@ -336,7 +341,7 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl) } if (!bl->disk) { - LOG(ERROR, "cannot run bootloader with no boot disk"); + LOGD(ERROR, domid, "cannot run bootloader with no boot disk"); rc = ERROR_FAIL; goto out; } @@ -354,7 +359,8 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl) bl->display.log = fopen(bl->logfile, "a"); if (!bl->display.log) { - LOGE(ERROR, "failed to create bootloader logfile %s", bl->logfile); + LOGED(ERROR, domid, + "failed to create bootloader logfile %s", bl->logfile); rc = ERROR_FAIL; goto out; } @@ -364,7 +370,8 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl) if (!r) break; if (errno == EINTR) continue; if (errno == EEXIST) break; - LOGE(ERROR, "failed to create bootloader dir %s", bl->outputdir); + LOGED(ERROR, domid, + "failed to create bootloader dir %s", bl->outputdir); rc = ERROR_FAIL; goto out; } @@ -373,7 +380,8 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl) r = open(bl->outputpath, O_WRONLY|O_CREAT|O_TRUNC, 0600); if (r>=0) { close(r); break; } if (errno == EINTR) continue; - LOGE(ERROR, "failed to precreate bootloader output %s", bl->outputpath); + LOGED(ERROR, domid, + "failed to precreate bootloader output %s", bl->outputpath); rc = ERROR_FAIL; goto out; } @@ -405,15 +413,18 @@ static void bootloader_disk_attached_cb(libxl__egc *egc, const char *bootloader; if (rc) { - LOG(ERROR, "failed to attach local disk for bootloader execution"); + LOGD(ERROR, bl->domid, + "failed to attach local disk for bootloader execution"); goto out; } - LOG(DEBUG, "Config bootloader value: %s", info->u.pv.bootloader); + LOGD(DEBUG, bl->domid, + "Config bootloader value: %s", info->u.pv.bootloader); if ( !strcmp(info->u.pv.bootloader, "/usr/bin/pygrub") ) - LOG(WARN, "bootloader='/usr/bin/pygrub' is deprecated; use " \ - "bootloader='pygrub' instead"); + LOGD(WARN, bl->domid, + "bootloader='/usr/bin/pygrub' is deprecated; use " \ + "bootloader='pygrub' instead"); bootloader = info->u.pv.bootloader; @@ -425,11 +436,13 @@ static void bootloader_disk_attached_cb(libxl__egc *egc, bltmp = libxl__abs_path(gc, bootloader, libxl__private_bindir_path()); /* Check to see if the file exists in this location; if not, * fall back to checking the path */ - LOG(DEBUG, "Checking for bootloader in libexec path: %s", bltmp); + LOGD(DEBUG, bl->domid, + "Checking for bootloader in libexec path: %s", bltmp); if ( lstat(bltmp, &st) ) - LOG(DEBUG, "%s doesn't exist, falling back to config path", - bltmp); + LOGD(DEBUG, bl->domid, + "%s doesn't exist, falling back to config path", + bltmp); else bootloader = bltmp; } @@ -488,7 +501,7 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) rc = libxl__xs_printf(gc, XBT_NULL, dom_console_xs_path, "%s", dom_console_slave_tty_path); if (rc) { - LOGE(ERROR,"xs write console path %s := %s failed", + LOGED(ERROR, bl->domid, "xs write console path %s := %s failed", dom_console_xs_path, dom_console_slave_tty_path); rc = ERROR_FAIL; goto out; @@ -537,11 +550,11 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) rc = libxl__datacopier_start(&bl->display); if (rc) goto out; - LOG(DEBUG, "executing bootloader: %s", bl->args[0]); + LOGD(DEBUG, bl->domid, "executing bootloader: %s", bl->args[0]); for (const char **blarg = bl->args; *blarg; blarg++) - LOG(DEBUG, " bootloader arg: %s", *blarg); + LOGD(DEBUG, bl->domid, " bootloader arg: %s", *blarg); struct termios termattr; @@ -554,7 +567,7 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) if (!pid) { /* child */ r = login_tty(libxl__carefd_fd(bl->ptys[0].slave)); - if (r) { LOGE(ERROR, "login_tty failed"); exit(-1); } + if (r) { LOGED(ERROR, bl->domid, "login_tty failed"); exit(-1); } libxl__exec(gc, -1, -1, -1, bl->args[0], (char **) bl->args, env); } @@ -589,10 +602,10 @@ static void bootloader_copyfail(libxl__egc *egc, const char *which, rc = 0; bl->got_pollhup = 1; } else { - LOG(ERROR, "unexpected POLLHUP on %s", which); + LOGD(ERROR, bl->domid, "unexpected POLLHUP on %s", which); } } else if (!rc) { - LOG(ERROR, "unexpected eof copying %s", which); + LOGD(ERROR, bl->domid, "unexpected eof copying %s", which); rc = ERROR_FAIL; } @@ -631,14 +644,15 @@ static void bootloader_finished(libxl__egc *egc, libxl__ev_child *child, if (status) { if (bl->got_pollhup && WIFSIGNALED(status) && WTERMSIG(status)==SIGTERM) - LOG(ERROR, "got POLLHUP, sent SIGTERM"); - LOG(ERROR, "bootloader failed - consult logfile %s", bl->logfile); + LOGD(ERROR, bl->domid, "got POLLHUP, sent SIGTERM"); + LOGD(ERROR, bl->domid, + "bootloader failed - consult logfile %s", bl->logfile); libxl_report_child_exitstatus(CTX, XTL_ERROR, "bootloader", pid, status); rc = ERROR_FAIL; goto out; } else { - LOG(DEBUG, "bootloader completed"); + LOGD(DEBUG, bl->domid, "bootloader completed"); } if (bl->rc) { @@ -651,7 +665,7 @@ static void bootloader_finished(libxl__egc *egc, libxl__ev_child *child, if (rc) goto out; rc = 0; - LOG(DEBUG, "bootloader execution successful"); + LOGD(DEBUG, bl->domid, "bootloader execution successful"); out: bootloader_callback(egc, bl, rc);