From patchwork Tue Dec 4 02:34:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 1007414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4385Z13xHzz9s8J for ; Tue, 4 Dec 2018 13:35:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="ilC1sCKQ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="MElJoWTV"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4385Z06B9KzDqkK for ; Tue, 4 Dec 2018 13:35:20 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="ilC1sCKQ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="MElJoWTV"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mendozajonas.com (client-ip=64.147.123.25; helo=wout2-smtp.messagingengine.com; envelope-from=sam@mendozajonas.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="ilC1sCKQ"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="MElJoWTV"; dkim-atps=neutral Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4385Yq129GzDqSx for ; Tue, 4 Dec 2018 13:35:10 +1100 (AEDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 6A7DCFD6; Mon, 3 Dec 2018 21:35:08 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 03 Dec 2018 21:35:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= mendozajonas.com; h=from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=fm1; bh=yvDce1YCznk2q 6kE0Y1Ov9TZHLXBg1VC/6VoV6jaxuE=; b=ilC1sCKQTExdcbJCkzysxgEa3Ca+I UTTRGfm2unH+zekVnsnwFd3xBmnw9Fc3cM2TEYFK0e/yuRO+amJPh5kqlABGJLTn 1a9vObtSXnobmz4KRWzUpaeUzmr/pRDaRSig28TJqqQnJQOL+g6IwXZQR08qfcqD gelduliEvv16PMngmspCJOvbu5682Gd4UN4Oa6pW16XH8wkCaSembZsFjhuS2ani G7miFnSt5uG8joJodkrOYz8if3Xj9r4JHJYGGoShTJ6RL7ZnyK6KXoHYsK/Ek39j Na9BRjjGfT94WQt66EH4pT805HFtEcx55I4tjdyLW0XwBLRFSX2/KvX6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=yvDce1YCznk2q6kE0 Y1Ov9TZHLXBg1VC/6VoV6jaxuE=; b=MElJoWTVNAEJcfGyREuZit2lKItuklopK C91qKuQdidrEyLFXxZ1FTiCvZohdddihDMzY5o3cYvGzWgFESIRilhbyln5xv6rK gBeJD6Dun4XPX24ePPrZFB5G4vJLQLIP1zPKasrwSiL6F6CIMM7D+kFHuWRAfTN3 h6IQgAXvLIyXlbVDyr+KdphgIBIA2iHnQD6gWhLWxc1OrCOP7BkF5eVEyBcP4+FI rib1rUTGs5hfkvG9lUn1MUErVaUJwEfEhOAihwgHCOIchrQCwW0+icEMIkWIBoBi Q2UUF9SFg9+UkqM7lCJr7/eFPZ7vGUekfc05oD9RVNBowR0YBXARQ== X-ME-Sender: X-ME-Proxy: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id D018B102A0; Mon, 3 Dec 2018 21:35:05 -0500 (EST) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH] discover/devmapper: Retry dm-device remove if busy Date: Tue, 4 Dec 2018 13:34:50 +1100 Message-Id: <20181204023450.28142-1-sam@mendozajonas.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Buildroot's libdm is not built with --enable-udev_sync, so device-mapper actions are not able to sync or wait for udev events. (see 185676316, "discover/devmapper: Disable libdm udev sync support") This can cause an issue when tearing down a snapshot in devmapper_destroy_snapshot() which performs a DM_DEVICE_REMOVE task against the snapshot, origin, and base devices one after the other. In some cases if the interval between these actions is too short the action can fail as the preceding device hasn't disappeared yet and the device being removed is still busy. Since we don't yet have a way to tell exactly when the device is ready, pause for a short time and retry the action, letting devmapper_destroy_snapshot() continue and, for example, letting mount_device() fall back to the physical device. Signed-off-by: Samuel Mendoza-Jonas --- In the future we'll enable udev_sync in Buildroot but this should help us fallback properly on existing systems. Using usleep() isn't perfect, however it's similar to what existing lvm tools & libraries do in the same situation, and allows us to fall back to the physical device quickly. discover/devmapper.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/discover/devmapper.c b/discover/devmapper.c index f7407b77..0a4d320e 100644 --- a/discover/devmapper.c +++ b/discover/devmapper.c @@ -457,24 +457,32 @@ static int destroy_device(const char *dm_name) { struct dm_task *task; uint32_t cookie; - int rc = -1; + int rc, retries = 0; +retry: task = dm_task_create(DM_DEVICE_REMOVE); if (!task) { - pb_log_fn("could not create dm_task\n"); + pb_debug_fn("could not create dm_task\n"); return -1; } if (!dm_task_set_name(task, dm_name)) { - pb_log("No dm device named '%s'\n", dm_name); + rc = dm_task_get_errno(task); + pb_debug_fn("Couldn't set name for %s, %s (%d)\n", + dm_name, strerror(rc), rc); goto out; } - if (!set_cookie(task, &cookie)) + if (!set_cookie(task, &cookie)) { + rc = dm_task_get_errno(task); + pb_debug_fn("set_cookie failed, %s (%d)\n", strerror(rc), rc); goto out; + } if (!dm_task_run(task)) { - pb_log("Unable to remove device '%s'\n", dm_name); + rc = dm_task_get_errno(task); + pb_debug_fn("Unable to remove device '%s', %s (%d)\n", + dm_name, strerror(rc), rc); goto out; } @@ -485,6 +493,12 @@ static int destroy_device(const char *dm_name) out: dm_task_destroy(task); + if (rc == EBUSY && retries < 5) { + pb_log_fn("Device busy, retry %d..\n", retries); + usleep(100000); + retries++; + goto retry; + } return rc; }