Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp388031imm; Sat, 8 Sep 2018 00:38:37 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZmy2qFH8qUEZn0tfhpavXEm+8pnDE+T2mdhcfB4iVO3waNIjXYkTWKoODnd+RecjeaAE+R X-Received: by 2002:a65:52cc:: with SMTP id z12-v6mr12063809pgp.69.1536392317632; Sat, 08 Sep 2018 00:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536392317; cv=none; d=google.com; s=arc-20160816; b=ai8ZdiK8vCiSUOIDZnaetF13fKCIVZkjZBX+nlxBSg+kbdnjTmvI+7MyVohWc1dQaQ BVuiYtZBMDPN3FWgG+RbIVURQJhFoLobniN+v7w+2KzQ2VW57KNgI3/clzLDVlauG8/j BvxDx91viBCfLYAO37m0aQuqZD3AptzhVx4QLhN2BRK0QOsk5NNk6eupmCsV+cyST2L2 HS3aXMhlgzO35C8jH0VJ6ABIa3coiHvWFO4Z137lpIxk6djXogeeKBLTTt///ihYsEZP D84bRC59z/xhNAmRdOToTY6WHfhPyqUioaMmMeIlJ6cnF5wvi0bjNZlv3gd2NCNUB7Oc fDOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:cc:to:from :date; bh=q2u1jmupUMzOx+JXwLkfLADcAIw3ivp45aA8GttP1EM=; b=FqaCFt84zhM1tFvSwriB7egUyb47ir1pG8iwgpUsyeX2wjryErWWrfEFj3V7Rk0cgJ TpDCB+ujqmBoiFIryxQeAwHIKoPAFUWNyljJf64MzuBnFgwThkDJVu3YFKd5q80QTR3L w8FviGFe2/0VahxC4Tst/rEsdYwMZJXI0VBdMnto43fATvbpOUxjdImJJup15g44oKNu s57giJ5effNOBTr9sa/a1/+ezJpBI3BCvQgpypCx6rCRoN4DcVMLmvV1+Zo2PpxqwrYt ydyj4qDEcpkGXbkCIBWWydW1rVagAHMVHdyPIZhwW4OmYFmBAmB8lE2e7jhirY2n8z+L T7XQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si10083738plt.325.2018.09.08.00.37.49; Sat, 08 Sep 2018 00:38:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726434AbeIHMT3 (ORCPT + 99 others); Sat, 8 Sep 2018 08:19:29 -0400 Received: from mail.CARNet.hr ([161.53.123.6]:60269 "EHLO mail.carnet.hr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726346AbeIHMT3 (ORCPT ); Sat, 8 Sep 2018 08:19:29 -0400 Received: from [2001:b68:ff:12::131] (port=51580 helo=gavran.carpriv.carnet.hr) by mail.carnet.hr with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fyXlK-0002Pl-HB; Sat, 08 Sep 2018 09:34:35 +0200 Received: by gavran.carpriv.carnet.hr (Postfix, from userid 1000) id 1B930202EF; Sat, 8 Sep 2018 09:34:32 +0200 (CEST) Date: Sat, 8 Sep 2018 09:34:32 +0200 From: Valentin Vidic To: drbd-user@lists.linbit.com Cc: Jens Axboe , Konrad Rzeszutek Wilk , linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-block@vger.kernel.org, xen-devel@lists.xenproject.org, Roger Pau =?iso-8859-1?Q?Monn=E9?= Message-ID: <20180908073432.GP26705@gavran.carpriv.carnet.hr> References: <20180829065214.23546-1-Valentin.Vidic@CARNet.hr> <20180905103649.edugijsjx4v2fbxd@mac.bytemobile.com> <20180905162756.GA26705@gavran.carpriv.carnet.hr> <20180907120337.GB11834@soda.linbit> <20180907121348.GM26705@gavran.carpriv.carnet.hr> <20180907132828.GC11834@soda.linbit> <20180907164500.GN26705@gavran.carpriv.carnet.hr> <20180907171459.GO26705@gavran.carpriv.carnet.hr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180907171459.GO26705@gavran.carpriv.carnet.hr> User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:b68:ff:12::131 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on rigel.CARNet.hr X-Spam-Level: X-Spam-Status: No, score=-2.9 required=10.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.2 Subject: Re: [DRBD-user] [PATCH] xen-blkback: Switch to closed state after releasing the backing device X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 07, 2018 at 07:14:59PM +0200, Valentin Vidic wrote: > In fact the first one is the original code path before I modified > blkback. The problem is it gets executed async from workqueue so > it might not always run before the call to drbdadm secondary. As the DRBD device gets released only when the last IO request has finished, I found a way to check and wait for this in the block-drbd script: --- block-drbd.orig 2018-09-08 09:07:23.499648515 +0200 +++ block-drbd 2018-09-08 09:28:12.892193649 +0200 @@ -230,6 +230,24 @@ and so cannot be mounted ${m2}${when}." } +wait_for_inflight() +{ + local dev="$1" + local inflight="/sys/block/${dev#/dev/}/inflight" + local rd wr + + if ! [ -f "$inflight" ]; then + return + fi + + while true; do + read rd wr < $inflight + if [ "$rd" = "0" -a "$wr" = "0" ]; then + return + fi + sleep 1 + done +} t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING') @@ -285,6 +303,8 @@ drbd_lrole="${drbd_role%%/*}" drbd_dev="$(drbdadm sh-dev $drbd_resource)" + wait_for_inflight $drbd_dev + if [ "$drbd_lrole" != 'Secondary' ]; then drbdadm secondary $drbd_resource fi -- Valentin