From patchwork Wed Oct 30 23:36:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11220465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1551114DB for ; Wed, 30 Oct 2019 23:34:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6F442087F for ; Wed, 30 Oct 2019 23:34:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="geiDVIWD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727837AbfJ3Xet (ORCPT ); Wed, 30 Oct 2019 19:34:49 -0400 Received: from mail-qk1-f175.google.com ([209.85.222.175]:44248 "EHLO mail-qk1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725963AbfJ3Xes (ORCPT ); Wed, 30 Oct 2019 19:34:48 -0400 Received: by mail-qk1-f175.google.com with SMTP id m16so4490323qki.11 for ; Wed, 30 Oct 2019 16:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/N9E7ULsRydeKAv0sRp5OU/NL2F6LtxCx93MmNsRpmo=; b=geiDVIWDTVNu6Bs+CgOYPL/ZiD5hGOSqiiDcTmp5l3yDbUPF7rCiTwB1U4VpvMdg71 RBTainSfbBICTo2PuYrJi1xTKKErLRymxDeW9s2fo77eIVhQdfdeUmjW8Vz9jj86y8I4 97wD+eQXBV6S/m5886MdpxFoi/8vVWvbLhOBiMqT68mFI+JKZC3po0/PeiEjkigWyfWi FUcWmoKYGHUvjQj8lPt7I+VGE99cCvOxhWw9Y5mBPWbaB3cTKZEV6va9Ma39plL/v5yX 55sedGewwcYcR2U+F9TgQ6Hmnzts6f0GgKD5mxeVNPUZIjUNjKqEZHfDyi1GeN6/bV3+ dpAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/N9E7ULsRydeKAv0sRp5OU/NL2F6LtxCx93MmNsRpmo=; b=tqtRzAWnfA4qsnw9rl6CXneSSwjCB+fMGawWHXIVRCjyznKV4j2V+zLAL494aIBOJS SkBgGJkIOuFP+dGU98tCcHTWChZbvisgKhC70+496mxc6cxe80bdAbMG7f2R3KgJUGxh 0mVOLmVvoFlBjGgACUGvafqF87M5l4W2cWw7zqPZOJhb0E93sw7DT7sgZPWefRhn1q7F K2W+vRHqJyb2EwlkJHXJwbMyEfVEWl0HD/Pp/XJZV7Bk0jrVDJ3la/wJHwMpCXPpElhN +ITw2uXAtdmR0M8LBxRZ2f905U1v1l2pev5x1M+k2jUF6T34HJ5CC99U8MOaNHXIwNOu f4tg== X-Gm-Message-State: APjAAAUAgSFvgkgyxgNC+TgxtHDrAI69KaBVYxMa1tmFVAXaTlT7ZLKM LdnQPwK5Sca4J3frbkl4Jm4= X-Google-Smtp-Source: APXvYqzsos5Nk0i5V8LIU8UJflysq5XvDXPcWDCxfuiuy4V64+VMqmPSNPt75zQ456/ss6ou4bDyQQ== X-Received: by 2002:ae9:f204:: with SMTP id m4mr2530943qkg.300.1572478486198; Wed, 30 Oct 2019 16:34:46 -0700 (PDT) Received: from localhost.localdomain (179.187.204.103.dynamic.adsl.gvt.net.br. [179.187.204.103]) by smtp.gmail.com with ESMTPSA id c185sm820317qkf.122.2019.10.30.16.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2019 16:34:45 -0700 (PDT) From: Marcos Paulo de Souza Cc: dsterba@suse.com, linux-btrfs@vger.kernel.org, mpdesouza@suse.com, anand.jain@oracle.com Subject: [PATCH btrfs-progs 1/2] btrfs-progs: balance: Don't set stderr to /dev/null on balance_start Date: Wed, 30 Oct 2019 20:36:40 -0300 Message-Id: <20191030233641.30123-2-marcos.souza.org@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191030233641.30123-1-marcos.souza.org@gmail.com> References: <20191030233641.30123-1-marcos.souza.org@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza Remove the close/open calls in order to receive the error messages when starting balance in the background. Signed-off-by: Marcos Paulo de Souza --- cmds/balance.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmds/balance.c b/cmds/balance.c index 32830002..f0394a2e 100644 --- a/cmds/balance.c +++ b/cmds/balance.c @@ -659,10 +659,8 @@ static int cmd_balance_start(const struct cmd_struct *cmd, i = chdir("/"); close(0); close(1); - close(2); open("/dev/null", O_RDONLY); open("/dev/null", O_WRONLY); - open("/dev/null", O_WRONLY); break; default: exit(0); From patchwork Wed Oct 30 23:36:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11220467 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B016139A for ; Wed, 30 Oct 2019 23:34:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 491BF2087F for ; Wed, 30 Oct 2019 23:34:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="itd8Ng3E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727846AbfJ3Xeu (ORCPT ); Wed, 30 Oct 2019 19:34:50 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:42348 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725963AbfJ3Xet (ORCPT ); Wed, 30 Oct 2019 19:34:49 -0400 Received: by mail-qk1-f194.google.com with SMTP id m4so4839205qke.9 for ; Wed, 30 Oct 2019 16:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fnvQKr00lcp7W3rou9u91KKXF7CowzuhIEK3agkqeyw=; b=itd8Ng3Eo1LrOA7ymTai8lBdKDCRqaOSB+2P0KLpZX61R4BnoBGOlEZdjrrJS++8d/ l96rsBxo3Ek7Vg3laoAM5vYtbIb7p2GUWWWfABSsurmOD662t/m2qcv+SAktALUAUpiI Z5EDHUsgOf4E99QKw/K/vO7FR3F8ul4q+FluEhud66yrjAetu6w16LYXADIu6tjpJzNH z21upoevVLToZ+mcW7YJr3vKS8DUt6qUtAwFPoqoa0yUNhdK0ZVOI1y+lCfMrcLr2Cti xHy8r8+qhoMKOcFCAMT0yE/+RbXs4p/HDmZfU/RQuJlSgj5nc3GW00VjjWpmfIESpoys 3ctQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fnvQKr00lcp7W3rou9u91KKXF7CowzuhIEK3agkqeyw=; b=ZHQzPgcmteL31KFc76INmYsM1xIdOoC3NpT6hhLDDDO3d4daRHTJjN/dq8yP/jDMoA HEFvxko6iRyVjoFvNLgX55AH1UxWUh8/vmErZxgBVYt6SJflSajA4cHboOu7qBqro5ah GUC0VrDV4YEA05xw85Q0tndrLncqcqa2jPQ7dCq4oRT43W6fXVSywVvYyB6Mx2PvD165 eOshE/sL3OhFFCHJURf9p9lMWX7PXo6FJ8ZAw/0KCeUO4setqRqURZA0Awfuc7qXLSNr CnBQks6lCDS7UyJgYnodWFBYo/UND69qTmGXSz29QhgJSDadfD46cO7wN0nPU6gWnuAJ 5FUg== X-Gm-Message-State: APjAAAUfaTdEqtca0AiyZpNbnjpbaeD6YQerl0SVA5DwnyPX0aRErXGI lQqxucEaJyjPUdvwqAIZzxg= X-Google-Smtp-Source: APXvYqyc436/DO/LbnehqZ0ba2XbbAOMNTZLO0ZpKB/zJ5MYZQrey//hKiIaUzKlxAwM/HG/empf9Q== X-Received: by 2002:a37:9d96:: with SMTP id g144mr2602578qke.93.1572478488685; Wed, 30 Oct 2019 16:34:48 -0700 (PDT) Received: from localhost.localdomain (179.187.204.103.dynamic.adsl.gvt.net.br. [179.187.204.103]) by smtp.gmail.com with ESMTPSA id c185sm820317qkf.122.2019.10.30.16.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2019 16:34:48 -0700 (PDT) From: Marcos Paulo de Souza Cc: dsterba@suse.com, linux-btrfs@vger.kernel.org, mpdesouza@suse.com, anand.jain@oracle.com Subject: [PATCH btrfs-progs 2/2] btrfs-progs: balance: Verify EINPROGRESS on background balance Date: Wed, 30 Oct 2019 20:36:41 -0300 Message-Id: <20191030233641.30123-3-marcos.souza.org@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191030233641.30123-1-marcos.souza.org@gmail.com> References: <20191030233641.30123-1-marcos.souza.org@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza Introduce a sleep of 3 seconds after triggering balance to check if isn't there another balance already being executed. Fix: #167 Signed-off-by: Marcos Paulo de Souza --- cmds/balance.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmds/balance.c b/cmds/balance.c index f0394a2e..2accc102 100644 --- a/cmds/balance.c +++ b/cmds/balance.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -507,6 +508,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd, int force = 0; int verbose = 0; int background = 0; + pid_t child; unsigned start_flags = 0; int i; @@ -639,13 +641,13 @@ static int cmd_balance_start(const struct cmd_struct *cmd, if (verbose) dump_ioctl_balance_args(&args); if (background) { - switch (fork()) { + switch (child = fork()) { case (-1): error("unable to fork to run balance in background"); return 1; case (0): setsid(); - switch(fork()) { + switch(child = fork()) { case (-1): error( "unable to fork to run balance in background"); @@ -663,10 +665,21 @@ static int cmd_balance_start(const struct cmd_struct *cmd, open("/dev/null", O_WRONLY); break; default: + /* wait up to three seconds to check if balance + * isn't already running */ + i = 0; + while (waitpid(child, NULL, WNOHANG) == 0 && i++ < 3) + sleep(1); + + /* ensure that any error message from + * do_balance is flushed */ + fflush(stderr); exit(0); } break; default: + /* Wait for the first child to return */ + waitpid(child, NULL, 0); exit(0); } }